diff --git a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py index a542a37aa14..05804a5d1f8 100644 --- a/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py +++ b/cuda_pathfinder/cuda/pathfinder/_dynamic_libs/load_nvidia_dynamic_lib.py @@ -49,11 +49,6 @@ _PLATFORM_NAME = "Windows" if IS_WINDOWS else "Linux" _CANARY_PROBE_TIMEOUT_SECONDS = 10.0 -# Driver libraries: shipped with the NVIDIA display driver, always on the -# system linker path. These skip all CTK search steps (site-packages, -# conda, CUDA_PATH, canary) and go straight to system search. -_DRIVER_ONLY_LIBNAMES = frozenset(name for name, desc in LIB_DESCRIPTORS.items() if desc.packaged_with == "driver") - def _load_driver_lib_no_cache(desc: LibDescriptor) -> LoadedDL: """Load an NVIDIA driver library (system-search only). @@ -165,7 +160,9 @@ def _try_ctk_root_canary(ctx: SearchContext) -> FindResult | NotFound: def _load_lib_no_cache(libname: str) -> LoadedDL: desc = LIB_DESCRIPTORS[libname] - if libname in _DRIVER_ONLY_LIBNAMES: + # Driver libraries ship with the NVIDIA display driver and are always on the + # system linker path, so they skip every CTK search step. + if desc.packaged_with == "driver": return _load_driver_lib_no_cache(desc) ctx = search_context(desc) diff --git a/cuda_pathfinder/cuda/pathfinder/_headers/find_nvidia_headers.py b/cuda_pathfinder/cuda/pathfinder/_headers/find_nvidia_headers.py index 5ed4043ba35..e3d4ee99d8e 100644 --- a/cuda_pathfinder/cuda/pathfinder/_headers/find_nvidia_headers.py +++ b/cuda_pathfinder/cuda/pathfinder/_headers/find_nvidia_headers.py @@ -138,7 +138,7 @@ def find_in_cuda_path(desc: HeaderDescriptor) -> LocatedHeaderDir | None: def find_via_ctk_root_canary(desc: HeaderDescriptor) -> LocatedHeaderDir | None: """Try CTK header lookup via CTK-root canary probing. - Skips immediately if the descriptor does not opt in (``use_ctk_root_canary``). + Skips immediately unless the header ships with the CUDA Toolkit (``use_ctk_root_canary``). Otherwise, system-loads ``cudart`` in a fully isolated Python subprocess, derives CTK root from the resolved library path, and searches the expected include layout under that root. @@ -216,8 +216,8 @@ def locate_nvidia_header_directory(libname: str) -> LocatedHeaderDir | None: 2. **Conda environments** — platform-specific conda include layouts. 3. **Product environment variables** — for example, ``CUDNN_PATH``. 4. **CUDA Toolkit environment variables** — ``CUDA_PATH`` / ``CUDA_HOME``. - 5. **CTK root canary probe** — subprocess canary (descriptors with - ``use_ctk_root_canary=True`` only). + 5. **CTK root canary probe** — subprocess canary (CUDA Toolkit + headers only). 6. **System install directories** — glob patterns from the descriptor. """ desc = HEADER_DESCRIPTORS.get(libname) @@ -245,8 +245,8 @@ def find_nvidia_header_directory(libname: str) -> str | None: 2. **Conda environments** — platform-specific conda include layouts. 3. **Product environment variables** — for example, ``CUDNN_PATH``. 4. **CUDA Toolkit environment variables** — ``CUDA_PATH`` / ``CUDA_HOME``. - 5. **CTK root canary probe** — subprocess canary (descriptors with - ``use_ctk_root_canary=True`` only). + 5. **CTK root canary probe** — subprocess canary (CUDA Toolkit + headers only). 6. **System install directories** — glob patterns from the descriptor. """ found = locate_nvidia_header_directory(libname) diff --git a/cuda_pathfinder/cuda/pathfinder/_headers/header_descriptor_catalog.py b/cuda_pathfinder/cuda/pathfinder/_headers/header_descriptor_catalog.py index 66570bd264d..f9c97e1853d 100644 --- a/cuda_pathfinder/cuda/pathfinder/_headers/header_descriptor_catalog.py +++ b/cuda_pathfinder/cuda/pathfinder/_headers/header_descriptor_catalog.py @@ -35,10 +35,16 @@ class HeaderDescriptorSpec: system_install_dirs_windows: tuple[str, ...] = () # Whether to search /usr/include/ before system_install_dirs. use_linux_multiarch_include_dir: bool = False - # Whether to use targets//include layout for conda on Linux. - conda_targets_layout: bool = True - # Whether to attempt CTK-root canary probing (spawns a subprocess). - use_ctk_root_canary: bool = True + + @property + def conda_targets_layout(self) -> bool: + """Whether to use targets//include layout for conda on Linux: CTK headers only.""" + return self.packaged_with == "ctk" + + @property + def use_ctk_root_canary(self) -> bool: + """Whether to attempt CTK-root canary probing (spawns a subprocess): CTK headers only.""" + return self.packaged_with == "ctk" HEADER_DESCRIPTOR_CATALOG: tuple[HeaderDescriptorSpec, ...] = ( @@ -170,8 +176,6 @@ class HeaderDescriptorSpec: ), system_install_dirs_windows=("${ProgramFiles}/NVIDIA/CUDNN/v9.*/include",), use_linux_multiarch_include_dir=True, - conda_targets_layout=False, - use_ctk_root_canary=False, ), HeaderDescriptorSpec( name="cusolverMp", @@ -179,32 +183,24 @@ class HeaderDescriptorSpec: header_basename="cusolverMp.h", site_packages_dirs=("nvidia/cu13/include", "nvidia/cu12/include"), available_on_windows=False, - conda_targets_layout=False, - use_ctk_root_canary=False, ), HeaderDescriptorSpec( name="cusparseLt", packaged_with="other", header_basename="cusparseLt.h", site_packages_dirs=("nvidia/cu13/include", "nvidia/cusparselt/include"), - conda_targets_layout=False, - use_ctk_root_canary=False, ), HeaderDescriptorSpec( name="cute", packaged_with="other", header_basename="cute/tensor.hpp", site_packages_dirs=("cutlass_library/source/include",), - conda_targets_layout=False, - use_ctk_root_canary=False, ), HeaderDescriptorSpec( name="cutensor", packaged_with="other", header_basename="cutensor.h", site_packages_dirs=("cutensor/include",), - conda_targets_layout=False, - use_ctk_root_canary=False, ), HeaderDescriptorSpec( name="cudensitymat", @@ -212,8 +208,6 @@ class HeaderDescriptorSpec: header_basename="cudensitymat.h", site_packages_dirs=("cuquantum/include",), available_on_windows=False, - conda_targets_layout=False, - use_ctk_root_canary=False, ), HeaderDescriptorSpec( name="cupauliprop", @@ -221,8 +215,6 @@ class HeaderDescriptorSpec: header_basename="cupauliprop.h", site_packages_dirs=("cuquantum/include",), available_on_windows=False, - conda_targets_layout=False, - use_ctk_root_canary=False, ), HeaderDescriptorSpec( name="cutensornet", @@ -230,8 +222,6 @@ class HeaderDescriptorSpec: header_basename="cutensornet.h", site_packages_dirs=("cuquantum/include",), available_on_windows=False, - conda_targets_layout=False, - use_ctk_root_canary=False, ), HeaderDescriptorSpec( name="custabilizer", @@ -239,8 +229,6 @@ class HeaderDescriptorSpec: header_basename="custabilizer.h", site_packages_dirs=("cuquantum/include",), available_on_windows=False, - conda_targets_layout=False, - use_ctk_root_canary=False, ), HeaderDescriptorSpec( name="custatevec", @@ -248,24 +236,18 @@ class HeaderDescriptorSpec: header_basename="custatevec.h", site_packages_dirs=("cuquantum/include",), available_on_windows=False, - conda_targets_layout=False, - use_ctk_root_canary=False, ), HeaderDescriptorSpec( name="cutlass", packaged_with="other", header_basename="cutlass/cutlass.h", site_packages_dirs=("cutlass_library/source/include",), - conda_targets_layout=False, - use_ctk_root_canary=False, ), HeaderDescriptorSpec( name="mathdx", packaged_with="other", header_basename="libmathdx.h", site_packages_dirs=("nvidia/cu13/include", "nvidia/cu12/include"), - conda_targets_layout=False, - use_ctk_root_canary=False, ), HeaderDescriptorSpec( name="nccl", @@ -276,8 +258,6 @@ class HeaderDescriptorSpec: anchor_include_rel_dirs=("include", "build/include"), product_root_env_vars=("NCCL_HOME",), system_install_dirs=("/usr/include", "/usr/local/include"), - conda_targets_layout=False, - use_ctk_root_canary=False, ), HeaderDescriptorSpec( name="nvshmem", @@ -286,7 +266,5 @@ class HeaderDescriptorSpec: site_packages_dirs=("nvidia/nvshmem/include",), available_on_windows=False, system_install_dirs=("/usr/include/nvshmem_*",), - conda_targets_layout=False, - use_ctk_root_canary=False, ), ) diff --git a/cuda_pathfinder/tests/test_driver_lib_loading.py b/cuda_pathfinder/tests/test_driver_lib_loading.py index c3ecb569e4c..19008bb9780 100644 --- a/cuda_pathfinder/tests/test_driver_lib_loading.py +++ b/cuda_pathfinder/tests/test_driver_lib_loading.py @@ -22,7 +22,6 @@ from cuda.pathfinder._dynamic_libs.lib_descriptor import LIB_DESCRIPTORS from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError, LoadedDL from cuda.pathfinder._dynamic_libs.load_nvidia_dynamic_lib import ( - _DRIVER_ONLY_LIBNAMES, _load_driver_lib_no_cache, _load_lib_no_cache, ) @@ -31,6 +30,8 @@ from cuda.pathfinder._utils import driver_info from cuda.pathfinder._utils.platform_aware import IS_WINDOWS +_DRIVER_LIBNAMES = sorted(name for name, desc in LIB_DESCRIPTORS.items() if desc.packaged_with == "driver") + STRICTNESS = os.environ.get("CUDA_PATHFINDER_TEST_LOAD_NVIDIA_DYNAMIC_LIB_STRICTNESS", "see_what_works") assert STRICTNESS in ("see_what_works", "all_must_work") @@ -98,7 +99,7 @@ def test_driver_lib_does_not_search_site_packages(mocker): # --------------------------------------------------------------------------- -@pytest.mark.parametrize("libname", sorted(_DRIVER_ONLY_LIBNAMES)) +@pytest.mark.parametrize("libname", _DRIVER_LIBNAMES) def test_load_lib_no_cache_dispatches_to_driver_path(libname, mocker): loaded = _make_loaded_dl(f"/usr/lib/fake_{libname}.so", "system-search") mock_driver = mocker.patch(f"{_MODULE}._load_driver_lib_no_cache", return_value=loaded) @@ -132,7 +133,7 @@ def test_load_lib_no_cache_does_not_dispatch_ctk_lib_to_driver_path(mocker): # For libname=nvcudla: # This test is not currently run in any CI job -@pytest.mark.parametrize("libname", sorted(_DRIVER_ONLY_LIBNAMES)) +@pytest.mark.parametrize("libname", _DRIVER_LIBNAMES) def test_real_load_driver_lib(info_summary_append, libname): """Load a real driver library in a dedicated subprocess.