From e6711dd09f6aa308f20ef76ac7635c2c02eb611b Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Wed, 25 Nov 2026 16:14:55 -0700 Subject: [PATCH 1/3] refactor(pathfinder): derive two header flags and the driver check from packaged_with Both restated what `packaged_with` already says. - Header catalog: every CTK entry had `conda_targets_layout` and `use_ctk_root_canary` set to `True`, and every other entry set both to `False`, in all nine versions of the file since it was added. They are now read-only properties derived from `packaged_with`, and the 14 non-CTK entries no longer repeat them. Readers of the two names are unchanged. - Loader: `_DRIVER_ONLY_LIBNAMES` was a second copy of `desc.packaged_with == "driver"`. The loader asks the descriptor. Two tests used the set as test data; they build it from the catalog. No behavior change. The flag values are identical for all 31 header entries. 1293 passed, 6 skipped. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Rob Parolin --- .../_dynamic_libs/load_nvidia_dynamic_lib.py | 9 ++-- .../_headers/header_descriptor_catalog.py | 42 +++++-------------- .../tests/test_driver_lib_loading.py | 7 ++-- 3 files changed, 17 insertions(+), 41 deletions(-) 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 a542a37aa140..05804a5d1f85 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/header_descriptor_catalog.py b/cuda_pathfinder/cuda/pathfinder/_headers/header_descriptor_catalog.py index 66570bd264d0..f9c97e1853d2 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 c3ecb569e4c6..19008bb97800 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. From 7c0a3a4000dd7c58f6d873e286fde9d369a18619 Mon Sep 17 00:00:00 2001 From: Rob Parolin Date: Thu, 26 Nov 2026 10:32:56 -0700 Subject: [PATCH 2/3] docs(pathfinder): stop calling the header canary step an opt-in flag This change made `use_ctk_root_canary` a property derived from `packaged_with == "ctk"`. Three docstrings in `find_nvidia_headers.py` still described it as a flag a descriptor sets (`use_ctk_root_canary=True`, "does not opt in"). They now say what decides it: the canary step runs for CUDA Toolkit headers only. Docstrings only. No code changes. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Rob Parolin --- .../cuda/pathfinder/_headers/find_nvidia_headers.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cuda_pathfinder/cuda/pathfinder/_headers/find_nvidia_headers.py b/cuda_pathfinder/cuda/pathfinder/_headers/find_nvidia_headers.py index 5ed4043ba35f..e3d4ee99d8e6 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) From 7e2dd0be0715e9055f4213d8fc2fe6e4f33cd150 Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Thu, 26 Nov 2026 11:17:27 -0800 Subject: [PATCH 3/3] ci: require manual copy-pr-bot approval Signed-off-by: Ralf W. Grosse-Kunstleve