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 @@ -129,11 +129,6 @@ def _resolve_system_loaded_abs_path_in_subprocess(
return None


def _loadable_via_canary_subprocess(libname: str, *, timeout: float = _CANARY_PROBE_TIMEOUT_SECONDS) -> bool:
"""Return True if the canary subprocess can resolve ``libname`` via system search."""
return _resolve_system_loaded_abs_path_in_subprocess(libname, timeout=timeout) is not None


def resolve_ctk_root_via_canary(canary_libname: str) -> str | None:
"""Resolve the CUDA Toolkit root from a system-loadable canary library.

Expand Down
12 changes: 0 additions & 12 deletions cuda_pathfinder/cuda/pathfinder/_utils/platform_aware.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,3 @@
# These describe the Python process ABI, not the Windows host architecture.
IS_WINDOWS_X64 = _WINDOWS_PYTHON_ARCH == "x64"
IS_WINDOWS_ARM64 = _WINDOWS_PYTHON_ARCH == "arm64"


def quote_for_shell(s: str) -> str:
if IS_WINDOWS:
# This is a relatively heavy import; keep pathfinder lean if possible.
from subprocess import list2cmdline

return list2cmdline([s])
else:
import shlex

return shlex.quote(s)
5 changes: 4 additions & 1 deletion cuda_pathfinder/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ def skip_if_missing_libnvcudla_so(libname: str, *, timeout: float) -> None:
# pytest collection for the whole test suite.
from cuda.pathfinder._dynamic_libs import load_nvidia_dynamic_lib as load_nvidia_dynamic_lib_module

if load_nvidia_dynamic_lib_module._loadable_via_canary_subprocess("nvcudla", timeout=timeout):
canary_abs_path = load_nvidia_dynamic_lib_module._resolve_system_loaded_abs_path_in_subprocess(
"nvcudla", timeout=timeout
)
if canary_abs_path is not None:
return
pytest.skip("libnvcudla.so is not loadable via canary subprocess on this host.")
13 changes: 13 additions & 0 deletions cuda_pathfinder/tests/local_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

from packaging.version import Version

from cuda.pathfinder._utils.platform_aware import IS_WINDOWS


@functools.cache
def have_distribution(name_pattern: str, *, minimum_version: str | None = None) -> bool:
Expand All @@ -18,3 +20,14 @@ def have_distribution(name_pattern: str, *, minimum_version: str | None = None)
for dist in importlib.metadata.distributions()
if "Name" in dist.metadata
)


def quote_for_shell(s: str) -> str:
if IS_WINDOWS:
from subprocess import list2cmdline

return list2cmdline([s])
else:
import shlex

return shlex.quote(s)
3 changes: 2 additions & 1 deletion cuda_pathfinder/tests/test_driver_lib_loading.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
run_load_nvidia_dynamic_lib_in_subprocess,
)
from conftest import skip_if_missing_libnvcudla_so
from local_helpers import quote_for_shell

from cuda.pathfinder._dynamic_libs.lib_descriptor import LIB_DESCRIPTORS
from cuda.pathfinder._dynamic_libs.load_dl_common import DynamicLibNotFoundError, LoadedDL
Expand All @@ -27,7 +28,7 @@
)
from cuda.pathfinder._dynamic_libs.subprocess_protocol import STATUS_NOT_FOUND, parse_dynamic_lib_subprocess_payload
from cuda.pathfinder._utils import driver_info
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS, quote_for_shell
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS

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
2 changes: 1 addition & 1 deletion cuda_pathfinder/tests/test_find_static_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from pathlib import Path

import pytest
from local_helpers import quote_for_shell

import cuda.pathfinder._static_libs.find_static_lib as find_static_lib_module
from cuda.pathfinder._static_libs.find_static_lib import (
Expand All @@ -14,7 +15,6 @@
locate_static_lib,
)
from cuda.pathfinder._utils.env_vars import get_cuda_path_or_home
from cuda.pathfinder._utils.platform_aware import quote_for_shell

STRICTNESS = os.environ.get("CUDA_PATHFINDER_TEST_FIND_NVIDIA_STATIC_LIB_STRICTNESS", "see_what_works")
assert STRICTNESS in ("see_what_works", "all_must_work")
Expand Down
4 changes: 2 additions & 2 deletions cuda_pathfinder/tests/test_load_nvidia_dynamic_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
run_load_nvidia_dynamic_lib_in_subprocess,
)
from conftest import skip_if_missing_libnvcudla_so
from local_helpers import have_distribution
from local_helpers import have_distribution, quote_for_shell

from cuda.pathfinder import DynamicLibNotAvailableError, DynamicLibUnknownError, load_nvidia_dynamic_lib
from cuda.pathfinder._dynamic_libs import load_nvidia_dynamic_lib as load_nvidia_dynamic_lib_module
Expand All @@ -21,7 +21,7 @@
STATUS_NOT_FOUND,
parse_dynamic_lib_subprocess_payload,
)
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS, quote_for_shell
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS

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
Loading