|
21 | 21 |
|
22 | 22 | _LINUX_CDLL_MODE = os.RTLD_NOW | os.RTLD_GLOBAL
|
23 | 23 |
|
24 |
| -from .find_nvidia_dynamic_library import find_nvidia_dynamic_library |
| 24 | +from .find_nvidia_dynamic_library import _find_nvidia_dynamic_library |
25 | 25 | from .supported_libs import DIRECT_DEPENDENCIES, SUPPORTED_WINDOWS_DLLS
|
26 | 26 |
|
27 | 27 |
|
@@ -63,38 +63,39 @@ def _windows_load_with_dll_basename(name: str) -> int:
|
63 | 63 |
|
64 | 64 |
|
65 | 65 | @functools.cache
|
66 |
| -def load_nvidia_dynamic_library(name: str) -> int: |
67 |
| - for dep in DIRECT_DEPENDENCIES.get(name, ()): |
| 66 | +def load_nvidia_dynamic_library(libname: str) -> int: |
| 67 | + for dep in DIRECT_DEPENDENCIES.get(libname, ()): |
68 | 68 | load_nvidia_dynamic_library(dep)
|
69 | 69 |
|
70 |
| - # First try using the platform-specific dynamic loader search mechanisms |
71 |
| - if sys.platform == "win32": |
72 |
| - handle = _windows_load_with_dll_basename(name) |
73 |
| - if handle: |
74 |
| - return handle |
75 |
| - else: |
76 |
| - dl_path = f"lib{name}.so" # Version intentionally no specified. |
77 |
| - try: |
78 |
| - handle = ctypes.CDLL(dl_path, _LINUX_CDLL_MODE) |
79 |
| - except OSError: |
80 |
| - pass |
| 70 | + found = _find_nvidia_dynamic_library(libname) |
| 71 | + if found.abs_path is None: |
| 72 | + if sys.platform == "win32": |
| 73 | + handle = _windows_load_with_dll_basename(libname) |
| 74 | + if handle: |
| 75 | + # Use `cdef void* ptr = <void*><intptr_t>` in cython to convert back to void* |
| 76 | + return handle |
81 | 77 | else:
|
82 |
| - # Use `cdef void* ptr = <void*><uintptr_t>` in cython to convert back to void* |
83 |
| - return handle._handle # C unsigned int |
| 78 | + try: |
| 79 | + handle = ctypes.CDLL(found.lib_searched_for, _LINUX_CDLL_MODE) |
| 80 | + except OSError: |
| 81 | + pass |
| 82 | + else: |
| 83 | + # Use `cdef void* ptr = <void*><uintptr_t>` in cython to convert back to void* |
| 84 | + return handle._handle # C unsigned int |
| 85 | + found.raise_if_abs_path_is_None() |
84 | 86 |
|
85 |
| - dl_path = find_nvidia_dynamic_library(name) |
86 | 87 | if sys.platform == "win32":
|
87 | 88 | flags = _WINBASE_LOAD_LIBRARY_SEARCH_DEFAULT_DIRS | _WINBASE_LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR
|
88 | 89 | try:
|
89 |
| - handle = win32api.LoadLibraryEx(dl_path, 0, flags) |
| 90 | + handle = win32api.LoadLibraryEx(found.abs_path, 0, flags) |
90 | 91 | except pywintypes.error as e:
|
91 |
| - raise RuntimeError(f"Failed to load DLL at {dl_path}: {e}") from e |
| 92 | + raise RuntimeError(f"Failed to load DLL at {found.abs_path}: {e}") from e |
92 | 93 | # Use `cdef void* ptr = <void*><intptr_t>` in cython to convert back to void*
|
93 | 94 | return handle # C signed int, matches win32api.GetProcAddress
|
94 | 95 | else:
|
95 | 96 | try:
|
96 |
| - handle = ctypes.CDLL(dl_path, _LINUX_CDLL_MODE) |
| 97 | + handle = ctypes.CDLL(found.abs_path, _LINUX_CDLL_MODE) |
97 | 98 | except OSError as e:
|
98 |
| - raise RuntimeError(f"Failed to dlopen {dl_path}: {e}") from e |
| 99 | + raise RuntimeError(f"Failed to dlopen {found.abs_path}: {e}") from e |
99 | 100 | # Use `cdef void* ptr = <void*><uintptr_t>` in cython to convert back to void*
|
100 | 101 | return handle._handle # C unsigned int
|
0 commit comments