Skip to content

[CUDA] Resolve symlinked nvcc before deriving CUDA_HOME - #2839

Open
morluto wants to merge 4 commits into
tile-ai:mainfrom
morluto:audit/cuda-home-symlink
Open

[CUDA] Resolve symlinked nvcc before deriving CUDA_HOME#2839
morluto wants to merge 4 commits into
tile-ai:mainfrom
morluto:audit/cuda-home-symlink

Conversation

@morluto

@morluto morluto commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Fixes #2837.

Problem

CUDA discovery derived the installation root from a symlink on PATH rather than the resolved nvcc binary. Pip-installed NVIDIA CUDA toolchains commonly expose nvcc that way, which selected /home/morluto/.local instead of the package root containing cuda_runtime.h.

Change

Resolve the discovered nvcc path before applying the existing parent-directory discovery logic. Explicit CUDA_HOME and CUDA_PATH retain their existing precedence.

Regression coverage

A deterministic symlink fixture verifies both resolved discovery and explicit-environment precedence.

Validation

  • python -m pytest -q testing/python/components/test_tilelang_env.py — 14 passed, 2 deselected
  • compileall, pre-commit, Ruff format check, and git diff --check — passed

Summary

  • Resolve symlinked nvcc paths before deriving CUDA_HOME.
  • Preserve explicit CUDA_HOME and CUDA_PATH precedence.
  • Prefer a visible toolkit when it contains required CUDA headers.
  • Add deterministic regression tests for these discovery behaviors.
  • Skip symlink fixtures when symlink creation is unavailable.

Validation

  • 14 tests passed.
  • compileall passed.
  • Pre-commit checks passed.
  • Ruff formatting checks passed.
  • git diff --check passed.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown

👋 Hi! Thank you for contributing to the TileLang project.

Please remember to run pre-commit run --all-files in the root directory of the project to ensure your changes are properly linted and formatted. This will help ensure your contribution passes the format check.

We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀

@coderabbitai

coderabbitai Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 8029e043-26d5-444c-a828-c059b475670b

📥 Commits

Reviewing files that changed from the base of the PR and between 4fd3427 and 7981954.

📒 Files selected for processing (1)
  • tilelang/env.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tilelang/env.py

📝 Walkthrough

Walkthrough

_find_cuda_home now derives CUDA roots from visible toolkits or symlink-resolved nvcc paths. Tests cover symlink resolution, explicit path precedence, and toolkit selection.

Changes

CUDA environment detection

Layer / File(s) Summary
Resolve nvcc and select CUDA toolkit
tilelang/env.py, testing/python/components/test_tilelang_env.py
_find_cuda_home preserves a visible prefix when cuda_runtime.h exists and otherwise resolves nvcc symlinks before deriving the CUDA root. Tests cover direct helper access, symlink creation, explicit CUDA_HOME and CUDA_PATH precedence, symlinked nvcc, and complete toolkit selection.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: resolving symlinked nvcc before deriving CUDA_HOME.
Linked Issues check ✅ Passed The changes resolve symlinked nvcc paths, preserve explicit CUDA_HOME and CUDA_PATH precedence, and add regression coverage required by issue #2837.
Out of Scope Changes check ✅ Passed The test and implementation changes are directly related to CUDA discovery behavior and the requirements in issue #2837.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
testing/python/components/test_tilelang_env.py (1)

87-97: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for CUDA_PATH.

_find_cuda_home() also reads CUDA_PATH when CUDA_HOME is absent, but this test only exercises CUDA_HOME set with CUDA_PATH unset. Add the missing CUDA_PATH case, preferably parameterized.

Proposed test adjustment
+@pytest.mark.parametrize("env_var", ["CUDA_HOME", "CUDA_PATH"])
-def test_find_cuda_home_prefers_explicit_environment(monkeypatch, tmp_path):
+def test_find_cuda_home_prefers_explicit_environment(
+    monkeypatch, tmp_path, env_var
+):
     cuda_home = tmp_path / "explicit-cuda"
     cuda_home.mkdir()
 
+    monkeypatch.delenv("CUDA_HOME", raising=False)
+    monkeypatch.delenv("CUDA_PATH", raising=False)
-    monkeypatch.setenv("CUDA_HOME", str(cuda_home))
+    monkeypatch.setenv(env_var, str(cuda_home))
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@testing/python/components/test_tilelang_env.py` around lines 87 - 97, Extend
test_find_cuda_home_prefers_explicit_environment to cover both CUDA_HOME and
CUDA_PATH, preferably by parameterizing the environment-variable name while
keeping the unexpected nvcc lookup assertion. Ensure the test clears the other
variable so each case verifies _find_cuda_home() selects the configured path
when CUDA_HOME is absent for the CUDA_PATH case.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@testing/python/components/test_tilelang_env.py`:
- Around line 87-97: Extend test_find_cuda_home_prefers_explicit_environment to
cover both CUDA_HOME and CUDA_PATH, preferably by parameterizing the
environment-variable name while keeping the unexpected nvcc lookup assertion.
Ensure the test clears the other variable so each case verifies
_find_cuda_home() selects the configured path when CUDA_HOME is absent for the
CUDA_PATH case.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a03cd66f-f273-4e68-b26a-da2581572f0a

📥 Commits

Reviewing files that changed from the base of the PR and between 6b81bb8 and 0dc42e7.

📒 Files selected for processing (2)
  • testing/python/components/test_tilelang_env.py
  • tilelang/env.py

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 0dc42e7ab8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tilelang/env.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 209c57c186

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread testing/python/components/test_tilelang_env.py Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4fd3427f89

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tilelang/env.py
Comment on lines +153 to +154
if "hpc_sdk" in path.lower():
return os.path.dirname(os.path.dirname(os.path.dirname(path)))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve CUDA precedence inside HPC SDK paths

When nvcc is located under an HPC SDK CUDA subtree such as /opt/nvidia/hpc_sdk/Linux_x86_64/25.7/cuda/12.9/bin/nvcc, this condition now takes precedence over recognizing the CUDA layout and strips three components, returning .../cuda instead of .../cuda/12.9. Because the broader directory exists, validation accepts it, but tilelang/contrib/nvcc.py subsequently derives nonexistent include and bin paths from it. Check the CUDA layout before applying the generic HPC SDK parent rule, as the previous ordering did.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Resolve symlinked nvcc before deriving CUDA_HOME

1 participant