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
32 changes: 22 additions & 10 deletions cuda_pathfinder/cuda/pathfinder/_static_libs/find_static_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from cuda.pathfinder._utils.env_vars import get_cuda_path_or_home
from cuda.pathfinder._utils.find_sub_dirs import find_sub_dirs_all_sitepackages
from cuda.pathfinder._utils.platform_aware import IS_WINDOWS
from cuda.pathfinder._utils.windows_arch import windows_python_arch


class StaticLibNotFoundError(RuntimeError):
Expand All @@ -32,17 +33,28 @@ class _StaticLibInfo(TypedDict):
site_packages_dirs: tuple[str, ...]


def _cudadevrt_info() -> _StaticLibInfo:
if not IS_WINDOWS:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be risky if non-windows non-linux (RISC-V)? But yes or no I think this is good enough for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, definitely good for now. We have many other existing conditions like this that'd need revisiting.

return {
"filename": "libcudadevrt.a",
"ctk_rel_paths": ("lib64", "lib"),
"conda_rel_paths": ("lib",),
"site_packages_dirs": ("nvidia/cu13/lib", "nvidia/cuda_runtime/lib"),
}

arch_dir = windows_python_arch()
component_wheel_dirs = ("nvidia/cuda_runtime/lib/x64",) if arch_dir == "x64" else ()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect this hardcoded path nvidia/cuda_runtime/lib/x64 and the next path nvidia/cu13/lib/x64 will not be changed in CTK future releases. If the paths are changed, the mock test function would still pass.

conda_fallback_dirs = ("lib",) if arch_dir == "x64" else ()
return {
"filename": "cudadevrt.lib",
"ctk_rel_paths": (os.path.join("lib", arch_dir),),
"conda_rel_paths": (os.path.join("lib", arch_dir), *conda_fallback_dirs),
"site_packages_dirs": (f"nvidia/cu13/lib/{arch_dir}", *component_wheel_dirs),
}


_SUPPORTED_STATIC_LIBS_INFO: dict[str, _StaticLibInfo] = {
"cudadevrt": {
"filename": "cudadevrt.lib" if IS_WINDOWS else "libcudadevrt.a",
"ctk_rel_paths": (os.path.join("lib", "x64"),) if IS_WINDOWS else ("lib64", "lib"),
"conda_rel_paths": ((os.path.join("lib", "x64"), "lib") if IS_WINDOWS else ("lib",)),
"site_packages_dirs": (
("nvidia/cu13/lib/x64", "nvidia/cuda_runtime/lib/x64")
if IS_WINDOWS
else ("nvidia/cu13/lib", "nvidia/cuda_runtime/lib")
),
},
"cudadevrt": _cudadevrt_info(),
}

SUPPORTED_STATIC_LIBS: tuple[str, ...] = tuple(sorted(_SUPPORTED_STATIC_LIBS_INFO.keys()))
Expand Down
5 changes: 5 additions & 0 deletions cuda_pathfinder/docs/source/release/1.6.1-notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ Highlights

* Add ``UnsupportedArchError`` for unsupported Windows Python platform tags.

* Make Windows static-library discovery architecture-aware. Searches now use
the current Python interpreter architecture to select the matching
``lib/x64`` or ``lib/arm64`` CUDA Toolkit and wheel directories. CUDA 12
component-wheel and legacy Conda fallbacks remain x64-only.

Internal maintenance
--------------------

Expand Down
35 changes: 35 additions & 0 deletions cuda_pathfinder/tests/test_find_static_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,41 @@ def test_locate_static_lib_conda_rel_path_fallback(monkeypatch, tmp_path):
assert located_lib.found_via == "conda"


@pytest.mark.parametrize(
("target_arch", "expected_ctk_dirs", "expected_conda_dirs", "expected_site_packages_dirs"),
(
(
"x64",
(os.path.join("lib", "x64"),),
(os.path.join("lib", "x64"), "lib"),
("nvidia/cu13/lib/x64", "nvidia/cuda_runtime/lib/x64"),
),
(
"arm64",
(os.path.join("lib", "arm64"),),
(os.path.join("lib", "arm64"),),
("nvidia/cu13/lib/arm64",),
),
),
)
@pytest.mark.agent_authored(model="gpt-5.6")
def test_cudadevrt_windows_paths_follow_python_arch(
monkeypatch,
target_arch,
expected_ctk_dirs,
expected_conda_dirs,
expected_site_packages_dirs,
):
monkeypatch.setattr(find_static_lib_module, "IS_WINDOWS", True)
monkeypatch.setattr(find_static_lib_module, "windows_python_arch", lambda: target_arch)

info = find_static_lib_module._cudadevrt_info()

assert info["ctk_rel_paths"] == expected_ctk_dirs
assert info["conda_rel_paths"] == expected_conda_dirs
assert info["site_packages_dirs"] == expected_site_packages_dirs


@pytest.mark.usefixtures("clear_find_static_lib_cache")
def test_find_static_lib_not_found_error_includes_cuda_home_directory_listing(monkeypatch, tmp_path):
filename = CUDADEVRT_INFO["filename"]
Expand Down
Loading