|
13 | 13 | ) |
14 | 14 | from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError, LoadedDL, load_dependencies |
15 | 15 | from cuda.pathfinder._dynamic_libs.supported_nvidia_libs import ( |
| 16 | + _CTK_ROOT_CANARY_ANCHOR_LIBNAMES, |
| 17 | + _CTK_ROOT_CANARY_DISCOVERABLE_LIBNAMES, |
16 | 18 | SUPPORTED_LINUX_SONAMES, |
17 | 19 | SUPPORTED_WINDOWS_DLLS, |
18 | 20 | ) |
@@ -66,12 +68,6 @@ def _load_driver_lib_no_cache(libname: str) -> LoadedDL: |
66 | 68 | ) |
67 | 69 |
|
68 | 70 |
|
69 | | -# Libs that reside on the standard linker path in system CTK installs. |
70 | | -# Used to discover the CTK root when a lib with a non-standard path |
71 | | -# (e.g. nvvm under $CTK_ROOT/nvvm/lib64) can't be found directly. |
72 | | -_CTK_ROOT_CANARY_LIBNAMES = ("cudart",) |
73 | | - |
74 | | - |
75 | 71 | def _resolve_system_loaded_abs_path_in_subprocess(libname: str) -> str | None: |
76 | 72 | """Resolve a library's system-search absolute path in a child process. |
77 | 73 |
|
@@ -111,15 +107,15 @@ def _resolve_system_loaded_abs_path_in_subprocess(libname: str) -> str | None: |
111 | 107 | def _try_ctk_root_canary(finder: _FindNvidiaDynamicLib) -> str | None: |
112 | 108 | """Derive the CTK root from a system-installed canary lib. |
113 | 109 |
|
114 | | - For libs like nvvm whose shared object doesn't reside on the standard |
115 | | - linker path, we locate a well-known CTK lib that IS on the linker path |
116 | | - via system search, derive the CTK installation root from its resolved |
117 | | - path, and then look for the target lib relative to that root. |
| 110 | + For discoverable libs (currently nvvm) whose shared object doesn't reside |
| 111 | + on the standard linker path, we locate a well-known CTK lib that IS on |
| 112 | + the linker path via system search, derive the CTK installation root from |
| 113 | + its resolved path, and then look for the target lib relative to that root. |
118 | 114 |
|
119 | 115 | The canary load is performed in a subprocess to avoid introducing loader |
120 | 116 | state into the current process. |
121 | 117 | """ |
122 | | - for canary_libname in _CTK_ROOT_CANARY_LIBNAMES: |
| 118 | + for canary_libname in _CTK_ROOT_CANARY_ANCHOR_LIBNAMES: |
123 | 119 | canary_abs_path = _resolve_system_loaded_abs_path_in_subprocess(canary_libname) |
124 | 120 | if canary_abs_path is None: |
125 | 121 | continue |
@@ -167,11 +163,14 @@ def _load_lib_no_cache(libname: str) -> LoadedDL: |
167 | 163 | if abs_path is not None: |
168 | 164 | found_via = "CUDA_HOME" |
169 | 165 | else: |
170 | | - # Canary probe: if the direct system search and CUDA_HOME both |
171 | | - # failed (e.g. nvvm isn't on the linker path and CUDA_HOME is |
172 | | - # unset), try to discover the CTK root by loading a well-known CTK |
173 | | - # lib in a subprocess, then look for the target lib relative to |
174 | | - # that root. |
| 166 | + if libname not in _CTK_ROOT_CANARY_DISCOVERABLE_LIBNAMES: |
| 167 | + finder.raise_not_found_error() |
| 168 | + |
| 169 | + # Canary probe (discoverable libs only): if the direct system |
| 170 | + # search and CUDA_HOME both failed (e.g. nvvm isn't on the linker |
| 171 | + # path and CUDA_HOME is unset), try to discover the CTK root by |
| 172 | + # loading a well-known CTK lib in a subprocess, then look for the |
| 173 | + # target lib relative to that root. |
175 | 174 | abs_path = _try_ctk_root_canary(finder) |
176 | 175 | if abs_path is not None: |
177 | 176 | found_via = "system-ctk-root" |
@@ -246,10 +245,10 @@ def load_nvidia_dynamic_lib(libname: str) -> LoadedDL: |
246 | 245 |
|
247 | 246 | - If set, use ``CUDA_HOME`` or ``CUDA_PATH`` (in that order). |
248 | 247 |
|
249 | | - 5. **CTK root canary probe** |
| 248 | + 5. **CTK root canary probe (discoverable libs only)** |
250 | 249 |
|
251 | | - - For libraries whose shared object doesn't reside on the standard |
252 | | - linker path (e.g. ``libnvvm.so`` lives under ``$CTK_ROOT/nvvm/lib64``), |
| 250 | + - For selected libraries whose shared object doesn't reside on the |
| 251 | + standard linker path (currently ``nvvm``), |
253 | 252 | attempt to discover the CTK installation root by system-loading a |
254 | 253 | well-known CTK library (``cudart``) in a subprocess, then derive |
255 | 254 | the root from its resolved absolute path. |
|
0 commit comments