Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
bc169d9
Revert "Reapply "Revert debug changes under .github/workflows""
rwgk Apr 10, 2025
7be2b78
Add names of all CTK 12.8.1 x86_64-linux libraries (.so) as `path_fin…
rwgk Apr 11, 2025
808074d
Add `SUPPORTED_WINDOWS_DLLS`
rwgk Apr 14, 2025
832fcc6
Add copyright notice
rwgk Apr 15, 2025
3c0a84d
Move SUPPORTED_LIBNAMES, SUPPORTED_WINDOWS_DLLS to _path_finder/suppo…
rwgk Apr 15, 2025
31fe756
Use SUPPORTED_WINDOWS_DLLS in _windows_load_with_dll_basename()
rwgk Apr 15, 2025
f002d9a
Change "Set up mini CTK" to use `method: local`, remove `sub-packages…
rwgk Apr 15, 2025
d499806
Use Jimver/cuda-toolkit@v0.2.21 also under Linux, `method: local`, no…
rwgk Apr 15, 2025
741bd8d
Add more `nvidia-*-cu12` wheels to get as many of the supported share…
rwgk Apr 15, 2025
3acc5b7
Revert "Use Jimver/cuda-toolkit@v0.2.21 also under Linux, `method: lo…
rwgk Apr 16, 2025
cdf8f93
Change test_path_finder::test_find_and_load() to skip cufile on Windo…
rwgk Apr 16, 2025
ae2fa44
Add nvidia-cuda-runtime-cu12 to pyproject.toml (for libname cudart)
rwgk Apr 16, 2025
e7e12c1
test_path_finder.py: before loading cusolver, load nvJitLink, cuspars…
rwgk Apr 17, 2025
e47652d
test_path_finder.py: load *only* nvJitLink before loading cusolver
rwgk Apr 17, 2025
556a2b4
Run each test_find_or_load_nvidia_dynamic_library() subtest in a subp…
rwgk Apr 17, 2025
ffc33a7
Add cublasLt to supported_libs.py and load deps for cusolver, cusolve…
rwgk Apr 18, 2025
5c54cbe
Add supported_libs.DIRECT_DEPENDENCIES
rwgk Apr 19, 2025
9e8ee07
Remove cufile_rdma from supported libs (comment out).
rwgk Apr 19, 2025
09e955a
Split out `PARTIALLY_SUPPORTED_LIBNAMES`. Fix up test code.
rwgk Apr 19, 2025
a6b178a
Reduce public API to only load_nvidia_dynamic_library, SUPPORTED_LIBN…
rwgk Apr 19, 2025
5535f4e
Set CUDA_BINDINGS_PATH_FINDER_TEST_ALL_LIBNAMES=1 to match expected a…
rwgk Apr 19, 2025
97a95c4
Refactor as `class _find_nvidia_dynamic_library`
rwgk Apr 21, 2025
b9f66be
Strict wheel, conda, system rule: try using the platform-specific dyn…
rwgk Apr 21, 2025
efa983c
Merge branch 'main' into path_finder_cont
rwgk Apr 21, 2025
016a103
Introduce _load_and_report_path_linux(), add supported_libs.EXPECTED_…
rwgk Apr 21, 2025
c813450
Plug in ctypes.windll.kernel32.GetModuleFileNameW()
rwgk Apr 21, 2025
1344621
Keep track of nvrtc-related GitHub comment
rwgk Apr 22, 2025
a3ae3a3
Factor out `_find_dll_under_dir(dirpath, file_wild)` and reuse from `…
rwgk Apr 22, 2025
d58535d
Minimal "is already loaded" code.
rwgk Apr 23, 2025
b98e1fa
Add THIS FILE NEEDS TO BE REVIEWED/UPDATED FOR EACH CTK RELEASE comme…
rwgk Apr 23, 2025
ec89acc
Add SUPPORTED_LINUX_SONAMES in _path_finder/supported_libs.py
rwgk Apr 23, 2025
38a1d6c
Update SUPPORTED_WINDOWS_DLLS in _path_finder/supported_libs.py based…
rwgk Apr 24, 2025
74d7230
Remove `os.add_dll_directory()` and `os.environ["PATH"]` manipulation…
rwgk Apr 24, 2025
c1a4983
Move nvrtc-specific code from find_nvidia_dynamic_library.py to `supp…
rwgk Apr 24, 2025
9ff46d8
Introduce dataclass LoadedDL as return type for load_nvidia_dynamic_l…
rwgk Apr 24, 2025
fb0a430
Factor out _abs_path_for_dynamic_library_* and use on handle obtained…
rwgk Apr 25, 2025
cb3ca5a
Factor out _load_nvidia_dynamic_library_no_cache() and use for exerci…
rwgk Apr 25, 2025
93db730
_check_nvjitlink_usable() in test_path_finder.py
rwgk Apr 25, 2025
37ac259
Undo changes in .github/workflows/ and cuda_bindings/pyproject.toml
rwgk Apr 25, 2025
5769b72
Move cuda_bindings/tests/path_finder.py -> toolshed/run_cuda_bindings…
rwgk Apr 25, 2025
09fbbe2
Merge branch 'path_finder_dev' into path_finder_cont
rwgk Apr 25, 2025
b3cd45b
Add bandit suppressions in test_path_finder.py
rwgk Apr 25, 2025
bcac5cd
Add pytest info_summary_append fixture and use from test_path_finder.…
rwgk Apr 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cuda_bindings/cuda/bindings/_bindings/cynvrtc.pyx.in
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ cdef int cuPythonInit() except -1 nogil:

{{if 'Windows' == platform.system()}}
with gil:
handle = path_finder.load_nvidia_dynamic_library("nvrtc")
handle = path_finder.load_nvidia_dynamic_library("nvrtc").handle
{{if 'nvrtcGetErrorString' in found_functions}}
try:
global __nvrtcGetErrorString
Expand Down Expand Up @@ -242,7 +242,7 @@ cdef int cuPythonInit() except -1 nogil:

{{else}}
with gil:
handle = <void*><uintptr_t>path_finder.load_nvidia_dynamic_library("nvrtc")
handle = <void*><uintptr_t>path_finder.load_nvidia_dynamic_library("nvrtc").handle
{{if 'nvrtcGetErrorString' in found_functions}}
global __nvrtcGetErrorString
__nvrtcGetErrorString = dlfcn.dlsym(handle, 'nvrtcGetErrorString')
Expand Down
2 changes: 1 addition & 1 deletion cuda_bindings/cuda/bindings/_internal/nvjitlink_linux.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ cdef void* __nvJitLinkVersion = NULL


cdef void* load_library(int driver_ver) except* with gil:
cdef uintptr_t handle = path_finder.load_nvidia_dynamic_library("nvJitLink")
cdef uintptr_t handle = path_finder.load_nvidia_dynamic_library("nvJitLink").handle
return <void*>handle


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ cdef void* __nvJitLinkVersion = NULL


cdef void* load_library(int driver_ver) except* with gil:
cdef intptr_t handle = path_finder.load_nvidia_dynamic_library("nvJitLink")
cdef intptr_t handle = path_finder.load_nvidia_dynamic_library("nvJitLink").handle
return <void*>handle


Expand Down
2 changes: 1 addition & 1 deletion cuda_bindings/cuda/bindings/_internal/nvvm_linux.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ cdef void* __nvvmGetProgramLog = NULL


cdef void* load_library(const int driver_ver) except* with gil:
cdef uintptr_t handle = path_finder.load_nvidia_dynamic_library("nvvm")
cdef uintptr_t handle = path_finder.load_nvidia_dynamic_library("nvvm").handle
return <void*>handle


Expand Down
2 changes: 1 addition & 1 deletion cuda_bindings/cuda/bindings/_internal/nvvm_windows.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ cdef void* __nvvmGetProgramLog = NULL


cdef void* load_library(int driver_ver) except* with gil:
cdef intptr_t handle = path_finder.load_nvidia_dynamic_library("nvvm")
cdef intptr_t handle = path_finder.load_nvidia_dynamic_library("nvvm").handle
return <void*>handle


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os

from .cuda_paths import IS_WIN32, get_cuda_paths
from .supported_libs import is_suppressed_dll_file
from .sys_path_find_sub_dirs import sys_path_find_sub_dirs


Expand Down Expand Up @@ -38,9 +39,13 @@ def _find_so_using_nvidia_lib_dirs(libname, so_basename, error_messages, attachm
return None


def _append_to_os_environ_path(dirpath):
curr_path = os.environ.get("PATH")
os.environ["PATH"] = dirpath if curr_path is None else os.pathsep.join((curr_path, dirpath))
def _find_dll_under_dir(dirpath, file_wild):
for path in sorted(glob.glob(os.path.join(dirpath, file_wild))):
if not os.path.isfile(path):
continue
if not is_suppressed_dll_file(os.path.basename(path)):
return path
return None


def _find_dll_using_nvidia_bin_dirs(libname, error_messages, attachments):
Expand All @@ -50,30 +55,8 @@ def _find_dll_using_nvidia_bin_dirs(libname, error_messages, attachments):
nvidia_sub_dirs = ("nvidia", "*", "bin")
file_wild = libname + "*.dll"
for bin_dir in sys_path_find_sub_dirs(nvidia_sub_dirs):
dll_name = None
have_builtins = False
for path in sorted(glob.glob(os.path.join(bin_dir, file_wild))):
# nvidia_cuda_nvrtc_cu12-12.8.93-py3-none-win_amd64.whl:
# nvidia\cuda_nvrtc\bin\
# nvrtc-builtins64_128.dll
# nvrtc64_120_0.alt.dll
# nvrtc64_120_0.dll
node = os.path.basename(path)
if node.endswith(".alt.dll"):
continue
if "-builtins" in node:
have_builtins = True
continue
if dll_name is not None:
continue
if os.path.isfile(path):
dll_name = path
dll_name = _find_dll_under_dir(bin_dir, file_wild)
if dll_name is not None:
if have_builtins:
# Add the DLL directory to the search path
os.add_dll_directory(bin_dir)
# Update PATH as a fallback for dependent DLL resolution
_append_to_os_environ_path(bin_dir)
return dll_name
_no_such_file_in_sub_dirs(nvidia_sub_dirs, file_wild, error_messages, attachments)
return None
Expand Down Expand Up @@ -122,41 +105,52 @@ def _find_dll_using_cudalib_dir(libname, error_messages, attachments):
if cudalib_dir is None:
return None
file_wild = libname + "*.dll"
for dll_name in sorted(glob.glob(os.path.join(cudalib_dir, file_wild))):
if os.path.isfile(dll_name):
return dll_name
dll_name = _find_dll_under_dir(cudalib_dir, file_wild)
if dll_name is not None:
return dll_name
error_messages.append(f"No such file: {file_wild}")
attachments.append(f' listdir("{cudalib_dir}"):')
for node in sorted(os.listdir(cudalib_dir)):
attachments.append(f" {node}")
return None


@functools.cache
def find_nvidia_dynamic_library(name: str) -> str:
error_messages = []
attachments = []

if IS_WIN32:
dll_name = _find_dll_using_nvidia_bin_dirs(name, error_messages, attachments)
if dll_name is None:
if name == "nvvm":
dll_name = _get_cuda_paths_info("nvvm", error_messages)
else:
dll_name = _find_dll_using_cudalib_dir(name, error_messages, attachments)
if dll_name is None:
attachments = "\n".join(attachments)
raise RuntimeError(f'Failure finding "{name}*.dll": {", ".join(error_messages)}\n{attachments}')
return dll_name

so_basename = f"lib{name}.so"
so_name = _find_so_using_nvidia_lib_dirs(name, so_basename, error_messages, attachments)
if so_name is None:
if name == "nvvm":
so_name = _get_cuda_paths_info("nvvm", error_messages)
class _find_nvidia_dynamic_library:
def __init__(self, libname: str):
self.libname = libname
self.error_messages = []
self.attachments = []
self.abs_path = None

if IS_WIN32:
self.abs_path = _find_dll_using_nvidia_bin_dirs(libname, self.error_messages, self.attachments)
if self.abs_path is None:
if libname == "nvvm":
self.abs_path = _get_cuda_paths_info("nvvm", self.error_messages)
else:
self.abs_path = _find_dll_using_cudalib_dir(libname, self.error_messages, self.attachments)
self.lib_searched_for = f"{libname}*.dll"
else:
so_name = _find_so_using_cudalib_dir(so_basename, error_messages, attachments)
if so_name is None:
attachments = "\n".join(attachments)
raise RuntimeError(f'Failure finding "{so_basename}": {", ".join(error_messages)}\n{attachments}')
return so_name
self.lib_searched_for = f"lib{libname}.so"
self.abs_path = _find_so_using_nvidia_lib_dirs(
libname, self.lib_searched_for, self.error_messages, self.attachments
)
if self.abs_path is None:
if libname == "nvvm":
self.abs_path = _get_cuda_paths_info("nvvm", self.error_messages)
else:
self.abs_path = _find_so_using_cudalib_dir(
self.lib_searched_for, self.error_messages, self.attachments
)

def raise_if_abs_path_is_None(self):
if self.abs_path:
return self.abs_path
err = ", ".join(self.error_messages)
att = "\n".join(self.attachments)
raise RuntimeError(f'Failure finding "{self.lib_searched_for}": {err}\n{att}')


@functools.cache
def find_nvidia_dynamic_library(libname: str) -> str:
return _find_nvidia_dynamic_library(libname).raise_if_abs_path_is_None()
Loading
Loading