@@ -53,16 +53,50 @@ def _load_lib_no_cache(libname: str) -> LoadedDL:
5353
5454@functools .cache
5555def load_nvidia_dynamic_lib (libname : str ) -> LoadedDL :
56- """Load a NVIDIA dynamic library by name.
56+ """Load an NVIDIA dynamic library by name.
5757
5858 Args:
59- libname: The name of the library to load (e.g. "cudart", "nvvm", etc.)
59+ libname (str): The short name of the library to load (e.g., ``"cudart"``,
60+ ``"nvvm"``, etc.).
6061
6162 Returns:
62- A LoadedDL object containing the library handle and path
63+ LoadedDL: Object containing the OS library handle and absolute path.
6364
6465 Raises:
65- RuntimeError: If the library cannot be found or loaded
66+ DynamicLibNotFoundError: If the library cannot be found or loaded.
67+ RuntimeError: If Python is not 64-bit.
68+
69+ Search order:
70+ 0. **Already loaded in the current process**
71+ - If a matching library is already loaded by some other component,
72+ return its absolute path and handle and skip the rest of the search.
73+
74+ 1. **NVIDIA Python wheels**
75+ - Scan installed distributions (``site-packages``) to find libraries
76+ shipped in NVIDIA wheels.
77+
78+ 2. **OS default mechanisms / Conda environments**
79+ - Fall back to the native loader:
80+ - Linux: ``dlopen()``
81+ - Windows: ``LoadLibraryW()``
82+ - Conda installations are commonly discovered via:
83+ - **Linux**: ``$ORIGIN/../lib`` in the ``RPATH`` of the ``python`` binary
84+ (note: this can take precedence over ``LD_LIBRARY_PATH`` and
85+ ``/etc/ld.so.conf.d/``).
86+ - **Windows**: ``%CONDA_PREFIX%\\ Library\\ bin`` on the system ``PATH``.
87+ - CUDA Toolkit (CTK) system installs with system config updates are often
88+ discovered via:
89+ - **Linux**: ``/etc/ld.so.conf.d/*cuda*.conf``
90+ - **Windows**: ``C:\\ Program Files\\ NVIDIA GPU Computing Toolkit\\ CUDA\\ vX.Y\\ bin``
91+ on the system ``PATH``.
92+
93+ 3. **Environment variables**
94+ - If set, use ``CUDA_HOME`` or ``CUDA_PATH`` (in that order).
95+
96+ Notes:
97+ The search is performed **per library**. There is currently no mechanism to
98+ guarantee that multiple libraries are all resolved from the same location.
99+
66100 """
67101 pointer_size_bits = struct .calcsize ("P" ) * 8
68102 if pointer_size_bits != 64 :
0 commit comments