[Build] Build tilelang without host toolchain - #1833
Conversation
|
👋 Hi! Thank you for contributing to the TileLang project. Please remember to run We appreciate you taking this step! Our team will review your contribution, and we look forward to your awesome work! 🚀 |
📝 WalkthroughWalkthroughThis PR adds support for detecting and using pip-installed CUDA toolkits alongside traditional host installations. It introduces CMake utilities to dynamically locate CUDA, updates build requirements and documentation, removes obsolete libdevice lookup functions, and adjusts Python version constraints to >=3.9. Changes
Sequence DiagramsequenceDiagram
participant CMake as CMake Build System
participant FindPip as FindPipCUDAToolkit.cmake
participant PythonScript as find_pip_cuda.py
participant HostCUDA as Host CUDA Installation
participant PipCUDA as Pip CUDA Package
participant Compiler as Compiler Config
CMake->>FindPip: Include module, detect CUDA
FindPip->>HostCUDA: find_package(CUDAToolkit)
alt Host CUDA Found
HostCUDA-->>FindPip: Return toolkit paths
FindPip->>Compiler: Set CMAKE_CUDA_COMPILER
else Host CUDA Not Found
FindPip->>PythonScript: Execute find_pip_cuda.py
alt WITH_PIP_CUDA_TOOLCHAIN Set
PythonScript->>PipCUDA: Use explicit path
else
PythonScript->>PipCUDA: Auto-detect from site-packages
end
PipCUDA-->>PythonScript: Return nvcc path & lib dirs
PythonScript->>PythonScript: Ensure symlinks & stubs
PythonScript-->>FindPip: Return JSON config
FindPip->>Compiler: Set CMAKE_CUDA_COMPILER & link dirs
end
Compiler-->>CMake: CUDA toolchain configured
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Fix all issues with AI agents
In `@cmake/find_pip_cuda.py`:
- Around line 58-75: The _ensure_cuda_stub function currently swallows all
exceptions when trying to compile a libcuda.so stub which hides a missing gcc
and causes later cryptic link errors; change the error handling around
subprocess.check_call(["gcc", ...]) to specifically catch FileNotFoundError (or
OSError indicating missing executable) and emit a clear warning to stderr (or
via logging) that gcc is not available and the stub could not be built, while
allowing other exceptions (e.g., permission, disk full) to either be logged with
their details or re-raised so they aren't masked; keep cleanup of src in the
finally block and reference _ensure_cuda_stub, stubs_dir, stub, src, and
subprocess.check_call when making the change.
In `@docs/get_started/Installation.md`:
- Around line 8-9: Update the Installation.md CUDA requirement from ">= 10.0" to
">= 11.0" to reflect the compile-time assertion in src/target/stubs/cudart.cc
that requires CUDART_VERSION >= 11000; change the CUDA host installation line to
state "CUDA Version: >= 11.0 (host installation), or pip-provided CUDA toolchain
(>= 13.0)" so documentation matches the CUDART_VERSION check and prevents
build-time confusion.
In `@requirements-dev.txt`:
- Line 6: Confirm whether cython_wrapper.pyx actually requires Cython >=3.1.0
(check for any 3.1+ specific syntax) and then make the requirement consistent:
either lower the constraint in requirements-dev.txt and pyproject.toml to match
the bare "cython" used in requirements-test.txt, or keep >=3.1.0 and add the
same >=3.1.0 constraint to requirements-test.txt; reference cython_wrapper.pyx,
the language_level=3 directive, requirements-dev.txt, requirements-test.txt, and
pyproject.toml when making the update.
🧹 Nitpick comments (2)
cmake/FindPipCUDAToolkit.cmake (1)
23-26:find_programmay locate a different Python than the one with pip CUDA packages.
find_program(... NAMES python3 python)searches the systemPATH, which in isolated build environments (the default forpip install) may resolve to a different interpreter than the one that has thenvidiapackages installed. This is mitigated by the doc guidance to use--no-build-isolationfor the auto-detect path, but it might be worth adding a comment clarifying this assumption — or preferring${Python_EXECUTABLE}if available (thoughfind_package(Python)hasn't run yet at this point since it's beforeproject()).CMakeLists.txt (1)
337-337: Consider usingtarget_link_directoriesinstead oflink_directories.
link_directoriesis directory-scoped and affects all subsequently defined targets, which can cause unintended side effects. Modern CMake (3.13+) preferstarget_link_directoriesfor more precise scoping. That said, since this is within theUSE_CUDAblock and the targets that need it are defined shortly after, the practical impact is minimal.Suggested change
- link_directories(${CUDAToolkit_LIBRARY_DIR} ${CUDAToolkit_LIBRARY_DIR}/stubs) + # Ensure pip-installed CUDA stubs are discoverable at link time. + set(TILELANG_CUDA_LINK_DIRS ${CUDAToolkit_LIBRARY_DIR} ${CUDAToolkit_LIBRARY_DIR}/stubs)Then apply per-target:
target_link_directories(tilelang_objs PRIVATE ${TILELANG_CUDA_LINK_DIRS})
Motivation
This PR enables building tilelang with CUDA toolchain from pip (
pip install "nvidia-cuda-nvcc>=13" "nvidia-cuda-cccl>=13" "nvidia-cuda-nvrtc>=13"), and would benefit some agentic workflow when e.g. user does not have permission to install cuda toolkit.Summary by CodeRabbit
New Features
Documentation
Dependencies