-
Notifications
You must be signed in to change notification settings - Fork 669
[Fix] Discover flat CUDA includes for NVRTC #2829
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
Open
morluto
wants to merge
2
commits into
tile-ai:main
Choose a base branch
from
morluto:audit/nvrtc-layout
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+107
−21
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
56 changes: 56 additions & 0 deletions
56
testing/python/jit/test_tilelang_jit_nvrtc_include_paths.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,56 @@ | ||
| from pathlib import Path | ||
|
|
||
| from tilelang.jit.adapter.nvrtc.include_paths import discover_cuda_include_paths | ||
|
|
||
|
|
||
| def _make_include_tree(cuda_home: Path, relative_paths: list[str]) -> list[str]: | ||
| paths = [] | ||
| for relative_path in relative_paths: | ||
| path = cuda_home / relative_path | ||
| path.mkdir(parents=True) | ||
| paths.append(str(path)) | ||
| return paths | ||
|
|
||
|
|
||
| def test_discovers_flat_pip_include_layout(tmp_path): | ||
| expected = _make_include_tree(tmp_path, ["include", "include/cccl"]) | ||
|
|
||
| assert discover_cuda_include_paths(str(tmp_path), machine="x86_64", system="linux") == expected | ||
|
|
||
|
|
||
| def test_discovers_target_specific_system_include_layout(tmp_path): | ||
| expected = _make_include_tree( | ||
| tmp_path, | ||
| ["targets/x86_64-linux/include", "targets/x86_64-linux/include/cccl"], | ||
| ) | ||
|
|
||
| assert discover_cuda_include_paths(str(tmp_path), machine="x86_64", system="linux") == expected | ||
|
|
||
|
|
||
| def test_discovers_flat_and_target_specific_include_layouts(tmp_path): | ||
| expected = _make_include_tree( | ||
| tmp_path, | ||
| [ | ||
| "include", | ||
| "include/cccl", | ||
| "targets/sbsa-linux/include", | ||
| "targets/sbsa-linux/include/cccl", | ||
| ], | ||
| ) | ||
|
|
||
| assert discover_cuda_include_paths(str(tmp_path), machine="aarch64", system="linux") == expected | ||
|
|
||
|
|
||
| def test_preserves_legacy_paths_when_cuda_layout_is_missing(tmp_path): | ||
| assert discover_cuda_include_paths(str(tmp_path), machine="x86_64", system="linux") == [ | ||
| str(tmp_path / "include"), | ||
| str(tmp_path / "targets/x86_64-linux/include"), | ||
| str(tmp_path / "targets/x86_64-linux/include/cccl"), | ||
| ] | ||
|
|
||
|
|
||
| def test_preserves_flat_windows_include_layout(tmp_path): | ||
| assert discover_cuda_include_paths(str(tmp_path), system="win32") == [ | ||
| str(tmp_path / "include"), | ||
| str(tmp_path / "include/cccl"), | ||
| ] | ||
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,43 @@ | ||
| """CUDA include-path discovery for NVRTC compilation.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os.path as osp | ||
| import platform | ||
| import sys | ||
|
|
||
|
|
||
| def _target_include_path(cuda_home: str, machine: str | None = None) -> str: | ||
| machine = machine or platform.machine() | ||
| target_arch = "sbsa-linux" if machine in ("aarch64", "arm64") else "x86_64-linux" | ||
| return osp.join(cuda_home, "targets", target_arch, "include") | ||
|
|
||
|
|
||
| def discover_cuda_include_paths(cuda_home: str, machine: str | None = None, system: str | None = None) -> list[str]: | ||
| """Return NVRTC include paths supported by the CUDA layout at ``cuda_home``. | ||
|
|
||
| CUDA pip packages may install headers in a flat ``include`` tree, while | ||
| system toolkits commonly use ``targets/<arch>-linux/include``. Include both | ||
| layouts when present so split or overlaid installations continue to work. | ||
| """ | ||
| flat_include = osp.join(cuda_home, "include") | ||
| system = system or sys.platform | ||
| if system.startswith("win32"): | ||
| return [flat_include, osp.join(flat_include, "cccl")] | ||
|
|
||
| target_include = _target_include_path(cuda_home, machine) | ||
| include_paths = [] | ||
|
|
||
| for include_path in (flat_include, target_include): | ||
| if osp.isdir(include_path): | ||
| include_paths.append(include_path) | ||
| cccl_include = osp.join(include_path, "cccl") | ||
| if osp.isdir(cccl_include): | ||
| include_paths.append(cccl_include) | ||
|
|
||
| if include_paths: | ||
| return include_paths | ||
|
|
||
| # Preserve the previous Linux search paths when probing an incomplete or | ||
| # not-yet-mounted toolkit. NVRTC will then report the missing headers. | ||
| return [flat_include, target_include, osp.join(target_include, "cccl")] |
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
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.
Uh oh!
There was an error while loading. Please reload this page.