-
Notifications
You must be signed in to change notification settings - Fork 235
Initial version of cuda.pathfinder._find_nvidia_headers for nvshmem
#661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
d174f5a
find_nvidia_headers.py initial version (untested).
rwgk 5ed86c5
Add tests/test_path_finder_find_headers.py, with hard-coded paths.
rwgk a98de70
Better error message: UNKNOWN libname='unknown-libname'
rwgk 6a93fe7
if libname == "nvshmem" and IS_WINDOWS: return None
rwgk 3ab9643
Merge branch 'main' into find_nvidia_headers_nvshmem and move/adjust/…
rwgk c1e9385
Move find_nvidia_headers.py → _headers/find_nvidia_headers.py
rwgk c3464b3
test_find_nvidia_headers.py: removed hard-wired paths, comments with …
rwgk 627f6d0
Merge branch 'main' into find_nvidia_headers_nvshmem
rwgk 26f94d1
Make _find_nvidia_header_directory private for now.
rwgk 6adddb0
test_find_nvidia_headers.py: Move comments with installation commands…
rwgk 363b649
Add `have_nvidia_nvshmem_package()` function to enable `assert hdr_di…
rwgk 2dd448c
Merge branch 'main' into find_nvidia_headers_nvshmem
rwgk d3f97e4
Add nvidia-nvshmem-cu12,13 in pyproject.toml
rwgk 6f4d762
assert site-packages or dist-packages
rwgk dfa3384
Add CUDA_PATHFINDER_TEST_FIND_NVIDIA_HEADERS_STRICTNESS
rwgk 673c38c
Transfer `ci/`, `.github/` changes from PR #864
rwgk 80cece3
Add CUDA_PATHFINDER_TEST_FIND_NVIDIA_HEADERS_STRICTNESS in `ci/`, `.g…
rwgk 7c30292
reverse=True in sorting of "/usr/include/nvshmem_*" (find newest first)
rwgk a300419
Fix: assert site-packages or dist-packages only if have_nvidia_nvshme…
rwgk 3ae15e0
pytest.skip("nvshmem has no Windows support.")
rwgk e855155
Merge branch 'main' into find_nvidia_headers_nvshmem
rwgk dc4de43
Merge branch 'main' into find_nvidia_headers_nvshmem
rwgk eb2e78a
Add new cuda/pathfinder/_utils/conda_env.py and use from find_nvidia_…
rwgk c90c393
Add new cuda/pathfinder/_utils/env_vars_for_include.py and use from f…
rwgk cee717a
Revert "Add new cuda/pathfinder/_utils/env_vars_for_include.py and us…
rwgk a50da30
Revert "Add new cuda/pathfinder/_utils/conda_env.py and use from find…
rwgk a185f03
Merge branch 'main' into find_nvidia_headers_nvshmem
rwgk 7cfcbfe
Bump pathfinder version to 1.2.2 and add release/1.2.2-notes.rst
rwgk 510f470
Remove os.path.isdir() tests that are not strictly needed.
rwgk 2426260
test_find_nvidia_headers.py: remove check for `dist-packages` because…
rwgk b74a84c
Additional testing
rwgk 6ee6529
Merge branch 'main' into find_nvidia_headers_nvshmem
rwgk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
cuda_pathfinder/cuda/pathfinder/_headers/find_nvidia_headers.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import functools | ||
| import glob | ||
| import os | ||
| from typing import Optional | ||
|
|
||
| from cuda.pathfinder._dynamic_libs.supported_nvidia_libs import IS_WINDOWS | ||
| from cuda.pathfinder._utils.find_sub_dirs import find_sub_dirs_all_sitepackages | ||
|
|
||
|
|
||
| @functools.cache | ||
| def find_nvidia_header_directory(libname: str) -> Optional[str]: | ||
| if libname != "nvshmem": | ||
| raise RuntimeError(f"UNKNOWN {libname=}") | ||
|
|
||
| if libname == "nvshmem" and IS_WINDOWS: | ||
| # nvshmem has no Windows support. | ||
| return None | ||
|
|
||
| # Installed from a wheel | ||
| nvidia_sub_dirs = ("nvidia", "nvshmem", "include") | ||
| hdr_dir: str # help mypy | ||
| for hdr_dir in find_sub_dirs_all_sitepackages(nvidia_sub_dirs): | ||
| nvshmem_h_path = os.path.join(hdr_dir, "nvshmem.h") | ||
| if os.path.isfile(nvshmem_h_path): | ||
| return hdr_dir | ||
|
|
||
| conda_prefix = os.environ.get("CONDA_PREFIX") | ||
leofang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if conda_prefix and os.path.isdir(conda_prefix): | ||
| hdr_dir = os.path.join(conda_prefix, "include") | ||
| nvshmem_h_path = os.path.join(hdr_dir, "nvshmem.h") | ||
| if os.path.isfile(nvshmem_h_path): | ||
| return hdr_dir | ||
|
|
||
| for hdr_dir in sorted(glob.glob("/usr/include/nvshmem_*"), reverse=True): | ||
leofang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| nvshmem_h_path = os.path.join(hdr_dir, "nvshmem.h") | ||
| if os.path.isfile(nvshmem_h_path): | ||
kkraus14 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return hdr_dir | ||
|
|
||
| return None | ||
rwgk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| __version__ = "1.2.2a0" | ||
| __version__ = "1.2.2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| .. SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| .. SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| .. module:: cuda.pathfinder | ||
|
|
||
| ``cuda-pathfinder`` 1.2.2 Release notes | ||
| ======================================= | ||
|
|
||
| Released on Sep 8, 2025 | ||
|
|
||
|
|
||
| Highlights | ||
| ---------- | ||
|
|
||
| * Support nccl library (`PR #945 <https://github.com/NVIDIA/cuda-python/pull/945>`_) | ||
|
|
||
| * Add experimental ``cuda.pathfinder._find_nvidia_headers`` API, | ||
| currently limited to supporting ``nvshmem`` | ||
| (`PR #661 <https://github.com/NVIDIA/cuda-python/pull/661>`_) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Currently these installations are only manually tested: | ||
|
|
||
| # conda create -y -n nvshmem python=3.12 | ||
| # conda activate nvshmem | ||
| # conda install -y conda-forge::libnvshmem3 conda-forge::libnvshmem-dev | ||
|
|
||
| # wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb | ||
| # sudo dpkg -i cuda-keyring_1.1-1_all.deb | ||
| # sudo apt update | ||
| # sudo apt install libnvshmem3-cuda-12 libnvshmem3-dev-cuda-12 | ||
| # sudo apt install libnvshmem3-cuda-13 libnvshmem3-dev-cuda-13 | ||
|
|
||
| import functools | ||
| import importlib.metadata | ||
| import os | ||
| import re | ||
|
|
||
| import pytest | ||
|
|
||
| from cuda.pathfinder import _find_nvidia_header_directory as find_nvidia_header_directory | ||
| from cuda.pathfinder._dynamic_libs.supported_nvidia_libs import IS_WINDOWS | ||
|
|
||
| STRICTNESS = os.environ.get("CUDA_PATHFINDER_TEST_FIND_NVIDIA_HEADERS_STRICTNESS", "see_what_works") | ||
| assert STRICTNESS in ("see_what_works", "all_must_work") | ||
|
|
||
|
|
||
| @functools.cache | ||
| def have_nvidia_nvshmem_package() -> bool: | ||
| pattern = re.compile(r"^nvidia-nvshmem-.*$") | ||
| return any( | ||
| pattern.match(dist.metadata["Name"]) for dist in importlib.metadata.distributions() if "Name" in dist.metadata | ||
| ) | ||
|
|
||
|
|
||
| def test_unknown_libname(): | ||
| with pytest.raises(RuntimeError, match=r"^UNKNOWN libname='unknown-libname'$"): | ||
| find_nvidia_header_directory("unknown-libname") | ||
|
|
||
|
|
||
| def test_find_libname_nvshmem(info_summary_append): | ||
| hdr_dir = find_nvidia_header_directory("nvshmem") | ||
| info_summary_append(f"{hdr_dir=!r}") | ||
| if IS_WINDOWS: | ||
| assert hdr_dir is None | ||
| pytest.skip("nvshmem has no Windows support.") | ||
| if hdr_dir: | ||
| assert os.path.isdir(hdr_dir) | ||
| assert os.path.isfile(os.path.join(hdr_dir, "nvshmem.h")) | ||
| if STRICTNESS == "all_must_work" or have_nvidia_nvshmem_package(): | ||
| assert hdr_dir is not None | ||
| if have_nvidia_nvshmem_package(): | ||
| hdr_dir_parts = hdr_dir.split(os.path.sep) | ||
| assert "site-packages" in hdr_dir_parts | ||
| elif conda_prefix := os.getenv("CONDA_PREFIX"): | ||
| assert hdr_dir.startswith(conda_prefix) | ||
| else: | ||
| assert hdr_dir.startswith("/usr/include/nvshmem_") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should do it in a follow up, but I think we should really move towards using an
importlibbased resolution method instead of walking the sitepackages ourselves.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we discussed and agreed walking the paths is acceptable since on the PyPI side they are predictable? Any reason to prefer
importlib?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, tx, I created issue #949 to track this.
(I wrote this code before @ZzEeKkAa pointed me to
importlibwhile working on PR #864)Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines crossed here. Let's review under #949 when we get to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
864?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, sorry, copy-paste mishap. Corrected (949).