Skip to content

Commit 147b242

Browse files
authored
First version of cuda.bindings.path_finder (#447)
* Unmodified copies of: * https://github.com/NVIDIA/numba-cuda/blob/bf487d78a40eea87f009d636882a5000a7524c95/numba_cuda/numba/cuda/cuda_paths.py * https://github.com/numba/numba/blob/f0d24824fcd6a454827e3c108882395d00befc04/numba/misc/findlib.py * Add Forked from URLs. * Strip down cuda_paths.py to minimum required for `_get_nvvm_path()` Tested interactively with: ``` import cuda_paths nvvm_path = cuda_paths._get_nvvm_path() print(f"{nvvm_path=}") ``` * ruff auto-fixes (NO manual changes) * Make `get_nvvm_path()` a pubic API (i.e. remove leading underscore). * Fetch numba-cuda/numba_cuda/numba/cuda/cuda_paths.py from NVIDIA/numba-cuda#155 AS-IS * ruff format NO MANUAL CHANGES * Minimal changes to adapt numba-cuda/numba_cuda/numba/cuda/cuda_paths.py from NVIDIA/numba-cuda#155 * Rename ecosystem/cuda_paths.py -> path_finder.py * Plug cuda.bindings.path_finder into cuda/bindings/_internal/nvvm_linux.pyx * Plug cuda.bindings.path_finder into cuda/bindings/_internal/nvjitlink_linux.pyx * Fix `os.path.exists(None)` issue: ``` ______________________ ERROR collecting test_nvjitlink.py ______________________ tests/test_nvjitlink.py:62: in <module> not check_nvjitlink_usable(), reason="nvJitLink not usable, maybe not installed or too old (<12.3)" tests/test_nvjitlink.py:58: in check_nvjitlink_usable return inner_nvjitlink._inspect_function_pointer("__nvJitLinkVersion") != 0 cuda/bindings/_internal/nvjitlink.pyx:257: in cuda.bindings._internal.nvjitlink._inspect_function_pointer ??? cuda/bindings/_internal/nvjitlink.pyx:260: in cuda.bindings._internal.nvjitlink._inspect_function_pointer ??? cuda/bindings/_internal/nvjitlink.pyx:208: in cuda.bindings._internal.nvjitlink._inspect_function_pointers ??? cuda/bindings/_internal/nvjitlink.pyx:102: in cuda.bindings._internal.nvjitlink._check_or_init_nvjitlink ??? cuda/bindings/_internal/nvjitlink.pyx:59: in cuda.bindings._internal.nvjitlink.load_library ??? /opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/cuda/bindings/path_finder.py:312: in get_cuda_paths "nvvm": _get_nvvm_path(), /opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/cuda/bindings/path_finder.py:285: in _get_nvvm_path by, path = _get_nvvm_path_decision() /opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/cuda/bindings/path_finder.py:96: in _get_nvvm_path_decision if os.path.exists(nvvm_ctk_dir): <frozen genericpath>:19: in exists ??? E TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType ``` * Fix another `os.path.exists(None)` issue: ``` ______________________ ERROR collecting test_nvjitlink.py ______________________ tests/test_nvjitlink.py:62: in <module> not check_nvjitlink_usable(), reason="nvJitLink not usable, maybe not installed or too old (<12.3)" tests/test_nvjitlink.py:58: in check_nvjitlink_usable return inner_nvjitlink._inspect_function_pointer("__nvJitLinkVersion") != 0 cuda/bindings/_internal/nvjitlink.pyx:257: in cuda.bindings._internal.nvjitlink._inspect_function_pointer ??? cuda/bindings/_internal/nvjitlink.pyx:260: in cuda.bindings._internal.nvjitlink._inspect_function_pointer ??? cuda/bindings/_internal/nvjitlink.pyx:208: in cuda.bindings._internal.nvjitlink._inspect_function_pointers ??? cuda/bindings/_internal/nvjitlink.pyx:102: in cuda.bindings._internal.nvjitlink._check_or_init_nvjitlink ??? cuda/bindings/_internal/nvjitlink.pyx:59: in cuda.bindings._internal.nvjitlink.load_library ??? /opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/cuda/bindings/path_finder.py:313: in get_cuda_paths "libdevice": _get_libdevice_paths(), /opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/cuda/bindings/path_finder.py:126: in _get_libdevice_paths by, libdir = _get_libdevice_path_decision() /opt/hostedtoolcache/Python/3.13.2/x64/lib/python3.13/site-packages/cuda/bindings/path_finder.py:73: in _get_libdevice_path_decision if os.path.exists(libdevice_ctk_dir): <frozen genericpath>:19: in exists ??? E TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType ``` * Change "/lib64/" → "/lib/" in nvjitlink_linux.pyx * nvjitlink_linux.pyx load_library() enhancements, mainly to avoid os.path.join(None, "libnvJitLink.so") * Add missing f-string f * Add back get_nvjitlink_dso_version_suffix() call. * pytest -ra -s -v * Rewrite nvjitlink_linux.pyx load_library() to produce detailed error messages. * Attach listdir output to "Unable to load" exception message. * Guard os.listdir() call with os.path.isdir() * Fix logic error in nvjitlink_linux.pyx load_library() * Move path_finder.py to _path_finder_utils/cuda_paths.py, import only public functions from new path_finder.py * Add find_nvidia_dynamic_library() and use from nvjitlink_linux.pyx, nvvm_linux.pyx * Fix oversight in _find_using_lib_dir() * Also look for versioned library in _find_using_nvidia_lib_dirs() * glob.glob() Python 3.9 compatibility * Reduce build-and-test.yml to Windows-only, Python 3.12 only. * Comment out `if: ${{ github.repository_owner == nvidia }}` * Revert "Comment out `if: ${{ github.repository_owner == nvidia }}`" This reverts commit b0db24f. * Add back `linux-64` `host-platform` * Rewrite load_library() in nvjitlink_windows.pyx to use path_finder.find_nvidia_dynamic_library() * Revert "Rewrite load_library() in nvjitlink_windows.pyx to use path_finder.find_nvidia_dynamic_library()" This reverts commit 1bb7151. * Add _inspect_environment() in find_nvidia_dynamic_library.py, call from nvjitlink_windows.pyx, nvvm_windows.pyx * Add & use _find_dll_using_nvidia_bin_dirs(), _find_dll_using_cudalib_dir() * Fix silly oversight: forgot to undo experimental change. * Also reduce test test-linux matrix. * Reimplement load_library() functions in nvjitlink_windows.pyx, nvvm_windows.pyx to actively use path_finder.find_nvidia_dynamic_library() * Factor out load_nvidia_dynamic_library() from _internal/nvjitlink_linux.pyx, nvvm_linux.pyx * Generalize load_nvidia_dynamic_library.py to also work under Windows. * Add `void*` return type to load_library() implementations in _internal/nvjitlink_windows.pyx, nvvm_windows.pyx * Resolve cython error: object handle vs `void*` handle ``` Error compiling Cython file: ------------------------------------------------------------ ... err = (<int (*)(int*) nogil>__cuDriverGetVersion)(&driver_ver) if err != 0: raise RuntimeError('something went wrong') # Load library handle = load_library(driver_ver) ^ ------------------------------------------------------------ cuda\bindings\_internal\nvjitlink.pyx:72:29: Cannot convert 'void *' to Python object ``` * Resolve another cython error: `void*` handle vs `intptr_t` handle ``` Error compiling Cython file: ------------------------------------------------------------ ... handle = load_library(driver_ver) # Load function global __nvJitLinkCreate try: __nvJitLinkCreate = <void*><intptr_t>win32api.GetProcAddress(handle, 'nvJitLinkCreate') ^ ------------------------------------------------------------ cuda\bindings\_internal\nvjitlink.pyx:78:73: Cannot convert 'void *' to Python object ``` * Resolve signed/unsigned runtime error. Use uintptr_t consistently. https://github.com/NVIDIA/cuda-python/actions/runs/14224673173/job/39861750852?pr=447#logs ``` =================================== ERRORS ==================================== _____________________ ERROR collecting test_nvjitlink.py ______________________ tests\test_nvjitlink.py:62: in <module> not check_nvjitlink_usable(), reason="nvJitLink not usable, maybe not installed or too old (<12.3)" tests\test_nvjitlink.py:58: in check_nvjitlink_usable return inner_nvjitlink._inspect_function_pointer("__nvJitLinkVersion") != 0 cuda\\bindings\\_internal\\nvjitlink.pyx:221: in cuda.bindings._internal.nvjitlink._inspect_function_pointer ??? cuda\\bindings\\_internal\\nvjitlink.pyx:224: in cuda.bindings._internal.nvjitlink._inspect_function_pointer ??? cuda\\bindings\\_internal\\nvjitlink.pyx:172: in cuda.bindings._internal.nvjitlink._inspect_function_pointers ??? cuda\\bindings\\_internal\\nvjitlink.pyx:73: in cuda.bindings._internal.nvjitlink._check_or_init_nvjitlink ??? cuda\\bindings\\_internal\\nvjitlink.pyx:46: in cuda.bindings._internal.nvjitlink.load_library ??? E OverflowError: can't convert negative value to size_t ``` * Change <void*><uintptr_t>win32api.GetProcAddress` back to `intptr_t`. Changing load_nvidia_dynamic_library() to also use to-`intptr_t` conversion, for compatibility with win32api.GetProcAddress. Document that CDLL behaves differently (it uses to-`uintptr_t`). * Use win32api.LoadLibrary() instead of ctypes.windll.kernel32.LoadLibraryW(), to be more similar to original (and working) cython code. Hoping to resolve this kind of error: ``` _ ERROR at setup of test_c_or_v_program_fail_bad_option[txt-compile_program] __ request = <SubRequest 'minimal_nvvmir' for <Function test_c_or_v_program_fail_bad_option[txt-compile_program]>> @pytest.fixture(params=MINIMAL_NVVMIR_FIXTURE_PARAMS) def minimal_nvvmir(request): for pass_counter in range(2): nvvmir = MINIMAL_NVVMIR_CACHE.get(request.param, -1) if nvvmir != -1: if nvvmir is None: pytest.skip(f"UNAVAILABLE: {request.param}") return nvvmir if pass_counter: raise AssertionError("This code path is meant to be unreachable.") # Build cache entries, then try again (above). > major, minor, debug_major, debug_minor = nvvm.ir_version() tests\test_nvvm.py:148: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ cuda\bindings\nvvm.pyx:95: in cuda.bindings.nvvm.ir_version cpdef tuple ir_version(): cuda\bindings\nvvm.pyx:113: in cuda.bindings.nvvm.ir_version status = nvvmIRVersion(&major_ir, &minor_ir, &major_dbg, &minor_dbg) cuda\bindings\cynvvm.pyx:19: in cuda.bindings.cynvvm.nvvmIRVersion return _nvvm._nvvmIRVersion(majorIR, minorIR, majorDbg, minorDbg) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ > ??? E cuda.bindings._internal.utils.FunctionNotFoundError: function nvvmIRVersion is not found ``` * Remove debug print statements. * Remove some cruft. * Trivial renaming of variables. No functional changes. * Revert debug changes under .github/workflows * Rename _path_finder_utils → _path_finder * Remove LD_LIBRARY_PATH in fetch_ctk/action.yml * Linux: First try using the platform-specific dynamic loader search mechanisms * Add _windows_load_with_dll_basename() * Revert "Revert debug changes under .github/workflows" This reverts commit cc6113c. * Add debug prints in load_nvidia_dynamic_library() * Report dlopen error for libnvrtc.so.12 * print("\nLOOOK dlfcn.dlopen('libnvrtc.so.12', dlfcn.RTLD_NOW)", flush=True) * Revert "Remove LD_LIBRARY_PATH in fetch_ctk/action.yml" This reverts commit 1b1139c. * Only remove ${CUDA_PATH}/nvvm/lib64 from LD_LIBRARY_PATH * Use path_finder.load_nvidia_dynamic_library("nvrtc") from cuda/bindings/_bindings/cynvrtc.pyx.in * Somewhat ad hoc heuristics for nvidia_cuda_nvrtc wheels. * Remove LD_LIBRARY_PATH entirely from .github/actions/fetch_ctk/action.yml * Remove CUDA_PATH\nvvm\bin in .github/workflows/test-wheel-windows.yml * Revert "Remove LD_LIBRARY_PATH entirely from .github/actions/fetch_ctk/action.yml" This reverts commit bff8cf0. * Revert "Somewhat ad hoc heuristics for nvidia_cuda_nvrtc wheels." This reverts commit 43abec8. * Restore cuda/bindings/_bindings/cynvrtc.pyx.in as-is on main * Remove debug print from load_nvidia_dynamic_library.py * Reapply "Revert debug changes under .github/workflows" This reverts commit aaa6aff.
1 parent 37b401a commit 147b242

16 files changed

+889
-162
lines changed

.github/actions/fetch_ctk/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,4 @@ runs:
123123
echo "CUDA_PATH=${CUDA_PATH}" >> $GITHUB_ENV
124124
echo "CUDA_HOME=${CUDA_PATH}" >> $GITHUB_ENV
125125
echo "${CUDA_PATH}/bin" >> $GITHUB_PATH
126-
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:${CUDA_PATH}/lib:${CUDA_PATH}/nvvm/lib64" >> $GITHUB_ENV
126+
echo "LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:${CUDA_PATH}/lib" >> $GITHUB_ENV

.github/workflows/test-wheel-windows.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,13 +164,6 @@ jobs:
164164
method: 'network'
165165
sub-packages: ${{ env.MINI_CTK_DEPS }}
166166

167-
- name: Update PATH
168-
if: ${{ inputs.local-ctk == '1' }}
169-
run: |
170-
# mimics actual CTK installation
171-
echo $PATH
172-
echo "$env:CUDA_PATH\nvvm\bin" >> $env:GITHUB_PATH
173-
174167
- name: Run cuda.bindings tests
175168
if: ${{ env.SKIP_CUDA_BINDINGS_TEST == '0' }}
176169
run: |

cuda_bindings/cuda/bindings/_internal/nvjitlink_linux.pyx

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
#
55
# This code was automatically generated across versions from 12.0.1 to 12.8.0. Do not modify it directly.
66

7-
from libc.stdint cimport intptr_t
8-
9-
from .utils cimport get_nvjitlink_dso_version_suffix
7+
from libc.stdint cimport intptr_t, uintptr_t
108

119
from .utils import FunctionNotFoundError, NotSupportedError
1210

11+
from cuda.bindings import path_finder
12+
1313
###############################################################################
1414
# Extern
1515
###############################################################################
@@ -52,17 +52,9 @@ cdef void* __nvJitLinkGetInfoLog = NULL
5252
cdef void* __nvJitLinkVersion = NULL
5353

5454

55-
cdef void* load_library(const int driver_ver) except* with gil:
56-
cdef void* handle
57-
for suffix in get_nvjitlink_dso_version_suffix(driver_ver):
58-
so_name = "libnvJitLink.so" + (f".{suffix}" if suffix else suffix)
59-
handle = dlopen(so_name.encode(), RTLD_NOW | RTLD_GLOBAL)
60-
if handle != NULL:
61-
break
62-
else:
63-
err_msg = dlerror()
64-
raise RuntimeError(f'Failed to dlopen libnvJitLink ({err_msg.decode()})')
65-
return handle
55+
cdef void* load_library(int driver_ver) except* with gil:
56+
cdef uintptr_t handle = path_finder.load_nvidia_dynamic_library("nvJitLink")
57+
return <void*>handle
6658

6759

6860
cdef int _check_or_init_nvjitlink() except -1 nogil:

cuda_bindings/cuda/bindings/_internal/nvjitlink_windows.pyx

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
from libc.stdint cimport intptr_t
88

9-
from .utils cimport get_nvjitlink_dso_version_suffix
10-
119
from .utils import FunctionNotFoundError, NotSupportedError
1210

13-
import os
14-
import site
11+
from cuda.bindings import path_finder
1512

1613
import win32api
1714

@@ -42,54 +39,9 @@ cdef void* __nvJitLinkGetInfoLog = NULL
4239
cdef void* __nvJitLinkVersion = NULL
4340

4441

45-
cdef inline list get_site_packages():
46-
return [site.getusersitepackages()] + site.getsitepackages()
47-
48-
49-
cdef load_library(const int driver_ver):
50-
handle = 0
51-
52-
for suffix in get_nvjitlink_dso_version_suffix(driver_ver):
53-
if len(suffix) == 0:
54-
continue
55-
dll_name = f"nvJitLink_{suffix}0_0.dll"
56-
57-
# First check if the DLL has been loaded by 3rd parties
58-
try:
59-
handle = win32api.GetModuleHandle(dll_name)
60-
except:
61-
pass
62-
else:
63-
break
64-
65-
# Next, check if DLLs are installed via pip
66-
for sp in get_site_packages():
67-
mod_path = os.path.join(sp, "nvidia", "nvJitLink", "bin")
68-
if not os.path.isdir(mod_path):
69-
continue
70-
os.add_dll_directory(mod_path)
71-
try:
72-
handle = win32api.LoadLibraryEx(
73-
# Note: LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR needs an abs path...
74-
os.path.join(mod_path, dll_name),
75-
0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR)
76-
except:
77-
pass
78-
else:
79-
break
80-
81-
# Finally, try default search
82-
try:
83-
handle = win32api.LoadLibrary(dll_name)
84-
except:
85-
pass
86-
else:
87-
break
88-
else:
89-
raise RuntimeError('Failed to load nvJitLink')
90-
91-
assert handle != 0
92-
return handle
42+
cdef void* load_library(int driver_ver) except* with gil:
43+
cdef intptr_t handle = path_finder.load_nvidia_dynamic_library("nvJitLink")
44+
return <void*>handle
9345

9446

9547
cdef int _check_or_init_nvjitlink() except -1 nogil:
@@ -98,23 +50,24 @@ cdef int _check_or_init_nvjitlink() except -1 nogil:
9850
return 0
9951

10052
cdef int err, driver_ver
53+
cdef intptr_t handle
10154
with gil:
10255
# Load driver to check version
10356
try:
104-
handle = win32api.LoadLibraryEx("nvcuda.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32)
57+
nvcuda_handle = win32api.LoadLibraryEx("nvcuda.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32)
10558
except Exception as e:
10659
raise NotSupportedError(f'CUDA driver is not found ({e})')
10760
global __cuDriverGetVersion
10861
if __cuDriverGetVersion == NULL:
109-
__cuDriverGetVersion = <void*><intptr_t>win32api.GetProcAddress(handle, 'cuDriverGetVersion')
62+
__cuDriverGetVersion = <void*><intptr_t>win32api.GetProcAddress(nvcuda_handle, 'cuDriverGetVersion')
11063
if __cuDriverGetVersion == NULL:
11164
raise RuntimeError('something went wrong')
11265
err = (<int (*)(int*) noexcept nogil>__cuDriverGetVersion)(&driver_ver)
11366
if err != 0:
11467
raise RuntimeError('something went wrong')
11568

11669
# Load library
117-
handle = load_library(driver_ver)
70+
handle = <intptr_t>load_library(driver_ver)
11871

11972
# Load function
12073
global __nvJitLinkCreate

cuda_bindings/cuda/bindings/_internal/nvvm_linux.pyx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
#
55
# This code was automatically generated across versions from 11.0.3 to 12.8.0. Do not modify it directly.
66

7-
from libc.stdint cimport intptr_t
8-
9-
from .utils cimport get_nvvm_dso_version_suffix
7+
from libc.stdint cimport intptr_t, uintptr_t
108

119
from .utils import FunctionNotFoundError, NotSupportedError
1210

11+
from cuda.bindings import path_finder
12+
1313
###############################################################################
1414
# Extern
1515
###############################################################################
@@ -51,16 +51,8 @@ cdef void* __nvvmGetProgramLog = NULL
5151

5252

5353
cdef void* load_library(const int driver_ver) except* with gil:
54-
cdef void* handle
55-
for suffix in get_nvvm_dso_version_suffix(driver_ver):
56-
so_name = "libnvvm.so" + (f".{suffix}" if suffix else suffix)
57-
handle = dlopen(so_name.encode(), RTLD_NOW | RTLD_GLOBAL)
58-
if handle != NULL:
59-
break
60-
else:
61-
err_msg = dlerror()
62-
raise RuntimeError(f'Failed to dlopen libnvvm ({err_msg.decode()})')
63-
return handle
54+
cdef uintptr_t handle = path_finder.load_nvidia_dynamic_library("nvvm")
55+
return <void*>handle
6456

6557

6658
cdef int _check_or_init_nvvm() except -1 nogil:

cuda_bindings/cuda/bindings/_internal/nvvm_windows.pyx

Lines changed: 8 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,9 @@
66

77
from libc.stdint cimport intptr_t
88

9-
from .utils cimport get_nvvm_dso_version_suffix
10-
119
from .utils import FunctionNotFoundError, NotSupportedError
1210

13-
import os
14-
import site
11+
from cuda.bindings import path_finder
1512

1613
import win32api
1714

@@ -40,54 +37,9 @@ cdef void* __nvvmGetProgramLogSize = NULL
4037
cdef void* __nvvmGetProgramLog = NULL
4138

4239

43-
cdef inline list get_site_packages():
44-
return [site.getusersitepackages()] + site.getsitepackages()
45-
46-
47-
cdef load_library(const int driver_ver):
48-
handle = 0
49-
50-
for suffix in get_nvvm_dso_version_suffix(driver_ver):
51-
if len(suffix) == 0:
52-
continue
53-
dll_name = "nvvm64_40_0"
54-
55-
# First check if the DLL has been loaded by 3rd parties
56-
try:
57-
handle = win32api.GetModuleHandle(dll_name)
58-
except:
59-
pass
60-
else:
61-
break
62-
63-
# Next, check if DLLs are installed via pip
64-
for sp in get_site_packages():
65-
mod_path = os.path.join(sp, "nvidia", "cuda_nvcc", "nvvm", "bin")
66-
if not os.path.isdir(mod_path):
67-
continue
68-
os.add_dll_directory(mod_path)
69-
try:
70-
handle = win32api.LoadLibraryEx(
71-
# Note: LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR needs an abs path...
72-
os.path.join(mod_path, dll_name),
73-
0, LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR)
74-
except:
75-
pass
76-
else:
77-
break
78-
79-
# Finally, try default search
80-
try:
81-
handle = win32api.LoadLibrary(dll_name)
82-
except:
83-
pass
84-
else:
85-
break
86-
else:
87-
raise RuntimeError('Failed to load nvvm')
88-
89-
assert handle != 0
90-
return handle
40+
cdef void* load_library(int driver_ver) except* with gil:
41+
cdef intptr_t handle = path_finder.load_nvidia_dynamic_library("nvvm")
42+
return <void*>handle
9143

9244

9345
cdef int _check_or_init_nvvm() except -1 nogil:
@@ -96,23 +48,24 @@ cdef int _check_or_init_nvvm() except -1 nogil:
9648
return 0
9749

9850
cdef int err, driver_ver
51+
cdef intptr_t handle
9952
with gil:
10053
# Load driver to check version
10154
try:
102-
handle = win32api.LoadLibraryEx("nvcuda.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32)
55+
nvcuda_handle = win32api.LoadLibraryEx("nvcuda.dll", 0, LOAD_LIBRARY_SEARCH_SYSTEM32)
10356
except Exception as e:
10457
raise NotSupportedError(f'CUDA driver is not found ({e})')
10558
global __cuDriverGetVersion
10659
if __cuDriverGetVersion == NULL:
107-
__cuDriverGetVersion = <void*><intptr_t>win32api.GetProcAddress(handle, 'cuDriverGetVersion')
60+
__cuDriverGetVersion = <void*><intptr_t>win32api.GetProcAddress(nvcuda_handle, 'cuDriverGetVersion')
10861
if __cuDriverGetVersion == NULL:
10962
raise RuntimeError('something went wrong')
11063
err = (<int (*)(int*) noexcept nogil>__cuDriverGetVersion)(&driver_ver)
11164
if err != 0:
11265
raise RuntimeError('something went wrong')
11366

11467
# Load library
115-
handle = load_library(driver_ver)
68+
handle = <intptr_t>load_library(driver_ver)
11669

11770
# Load function
11871
global __nvvmVersion

cuda_bindings/cuda/bindings/_internal/utils.pxd

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,3 @@ cdef int get_nested_resource_ptr(nested_resource[ResT] &in_out_ptr, object obj,
165165

166166
cdef bint is_nested_sequence(data)
167167
cdef void* get_buffer_pointer(buf, Py_ssize_t size, readonly=*) except*
168-
169-
cdef tuple get_nvjitlink_dso_version_suffix(int driver_ver)
170-
cdef tuple get_nvvm_dso_version_suffix(int driver_ver)

cuda_bindings/cuda/bindings/_internal/utils.pyx

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,17 +127,3 @@ cdef int get_nested_resource_ptr(nested_resource[ResT] &in_out_ptr, object obj,
127127
class FunctionNotFoundError(RuntimeError): pass
128128

129129
class NotSupportedError(RuntimeError): pass
130-
131-
132-
cdef tuple get_nvjitlink_dso_version_suffix(int driver_ver):
133-
if 12000 <= driver_ver < 13000:
134-
return ('12', '')
135-
raise NotSupportedError(f'CUDA driver version {driver_ver} is not supported')
136-
137-
138-
cdef tuple get_nvvm_dso_version_suffix(int driver_ver):
139-
if 11000 <= driver_ver < 11020:
140-
return ('3', '')
141-
if 11020 <= driver_ver < 13000:
142-
return ('4', '')
143-
raise NotSupportedError(f'CUDA driver version {driver_ver} is not supported')

0 commit comments

Comments
 (0)