Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions cuda_pathfinder/cuda/pathfinder/_headers/find_nvidia_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ class HeaderDescriptorSpec:
system_install_dirs_windows: tuple[str, ...] = ()
# Whether to search /usr/include/<sysconfig MULTIARCH> before system_install_dirs.
use_linux_multiarch_include_dir: bool = False
# Whether to use targets/<arch>/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/<arch>/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, ...] = (
Expand Down Expand Up @@ -170,102 +176,78 @@ 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",
packaged_with="other",
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",
packaged_with="other",
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",
packaged_with="other",
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",
packaged_with="other",
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",
packaged_with="other",
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",
packaged_with="other",
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",
Expand All @@ -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",
Expand All @@ -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,
),
)
7 changes: 4 additions & 3 deletions cuda_pathfinder/tests/test_driver_lib_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand All @@ -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")

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.

Expand Down
Loading