|
11 | 11 | _FindNvidiaDynamicLib, |
12 | 12 | derive_ctk_root, |
13 | 13 | ) |
14 | | -from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError, LoadedDL, load_dependencies |
| 14 | +from cuda.pathfinder._dynamic_libs.load_dl_common import ( |
| 15 | + DynamicLibNotAvailableError, |
| 16 | + DynamicLibNotFoundError, |
| 17 | + DynamicLibUnknownError, |
| 18 | + LoadedDL, |
| 19 | + load_dependencies, |
| 20 | +) |
15 | 21 | from cuda.pathfinder._dynamic_libs.supported_nvidia_libs import ( |
16 | 22 | _CTK_ROOT_CANARY_ANCHOR_LIBNAMES, |
17 | 23 | _CTK_ROOT_CANARY_DISCOVERABLE_LIBNAMES, |
|
41 | 47 | _ALL_SUPPORTED_LIBNAMES: frozenset[str] = frozenset( |
42 | 48 | (SUPPORTED_WINDOWS_DLLS if IS_WINDOWS else SUPPORTED_LINUX_SONAMES).keys() |
43 | 49 | ) |
| 50 | +_ALL_KNOWN_LIBNAMES: frozenset[str] = frozenset(SUPPORTED_LINUX_SONAMES) | frozenset(SUPPORTED_WINDOWS_DLLS) |
| 51 | +_PLATFORM_NAME = "Windows" if IS_WINDOWS else "Linux" |
44 | 52 |
|
45 | 53 | # Driver libraries: shipped with the NVIDIA display driver, always on the |
46 | 54 | # system linker path. These skip all CTK search steps (site-packages, |
@@ -205,7 +213,9 @@ def load_nvidia_dynamic_lib(libname: str) -> LoadedDL: |
205 | 213 | https://github.com/NVIDIA/cuda-python/issues/1011 |
206 | 214 |
|
207 | 215 | Raises: |
208 | | - ValueError: If ``libname`` is not a recognized library name. |
| 216 | + DynamicLibUnknownError: If ``libname`` is not a recognized library name. |
| 217 | + DynamicLibNotAvailableError: If ``libname`` is recognized but not |
| 218 | + supported on this platform. |
209 | 219 | DynamicLibNotFoundError: If the library cannot be found or loaded. |
210 | 220 | RuntimeError: If Python is not 64-bit. |
211 | 221 |
|
@@ -278,6 +288,11 @@ def load_nvidia_dynamic_lib(libname: str) -> LoadedDL: |
278 | 288 | f" Currently running: {pointer_size_bits}-bit Python" |
279 | 289 | f" {sys.version_info.major}.{sys.version_info.minor}" |
280 | 290 | ) |
| 291 | + if libname not in _ALL_KNOWN_LIBNAMES: |
| 292 | + raise DynamicLibUnknownError(f"Unknown library name: {libname!r}. Known names: {sorted(_ALL_KNOWN_LIBNAMES)}") |
281 | 293 | if libname not in _ALL_SUPPORTED_LIBNAMES: |
282 | | - raise ValueError(f"Unsupported library name: {libname!r}. Supported names: {sorted(_ALL_SUPPORTED_LIBNAMES)}") |
| 294 | + raise DynamicLibNotAvailableError( |
| 295 | + f"Library name {libname!r} is known but not available on {_PLATFORM_NAME}. " |
| 296 | + f"Supported names on {_PLATFORM_NAME}: {sorted(_ALL_SUPPORTED_LIBNAMES)}" |
| 297 | + ) |
283 | 298 | return _load_lib_no_cache(libname) |
0 commit comments