Fix clang CI build: use clang as nvcc host compiler#6004
Conversation
When CC/CXX are set to clang, PyTorch's CMake config adds -fclang-abi-compat=17 to CMAKE_CXX_FLAGS. CMake passes these to nvcc via -Xcompiler, but nvcc defaults to gcc as host compiler which doesn't understand clang-specific flags. Setting CUDAHOSTCXX ensures nvcc uses clang++ as its host compiler, matching CC/CXX. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Review updated until commit 3dac2c5 Description
|
| Relevant files | |||||
|---|---|---|---|---|---|
| Bug fix |
|
PR Reviewer Guide
Here are some key observations to aid the review process:
| 🧪 PR contains tests |
| ⚡ Recommended focus areas for review |
CUDAHOSTCXX path correctness
|
Greptile SummaryFixed the CI Changes:
This fix addresses the root cause where gcc doesn't understand clang-specific compiler flags like Confidence Score: 5/5
Important Files Changed
Last reviewed commit: 3dac2c5 |
CUDAHOSTCXX alone is insufficient because CMake derives CMAKE_CUDA_HOST_COMPILER from CMAKE_CXX_COMPILER, which resolves to "ccache" when CC="ccache clang++". Pass -DCMAKE_CUDA_HOST_COMPILER explicitly in the cmake command to ensure nvcc gets the actual clang++ binary path. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The CC="ccache clang" pattern causes CMake (and PyTorch's TorchConfig)
to resolve the CUDA host compiler to ccache itself, resulting in
`nvcc -ccbin=/usr/bin/ccache` which fails. Instead, set CC/CXX to the
raw clang paths and use CMAKE_{C,CXX,CUDA}_COMPILER_LAUNCHER=ccache,
which is the proper CMake mechanism for compiler launchers and keeps
nvcc's -ccbin pointing to the actual compiler.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The compiler launcher fix resolved the ccache-as-ccbin issue, but nvcc still defaulted to gcc as host compiler. Set CUDAHOSTCXX in setup-env.sh and also set CMAKE_CUDA_HOST_COMPILER in CMakeLists.txt before enable_language(CUDA) to ensure nvcc uses clang++ as its host compiler. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
!build |
| # Tell nvcc to use clang++ as its host compiler. Without this, nvcc defaults | ||
| # to gcc, which fails on clang-specific flags like -fclang-abi-compat that | ||
| # PyTorch adds to CMAKE_CXX_FLAGS. | ||
| export CUDAHOSTCXX=$CLANGXX_PATH |
There was a problem hiding this comment.
Why not export CMAKE_CUDA_HOST_COMPILER=$CLANGXX_PATH? cc @xwang233
Summary
Fix CI
clang-build-23job failure where nvcc used gcc as host compiler but received clang-specific flags (-fclang-abi-compat=17) from PyTorch's CMake config.Two issues were fixed:
setup-env.sh: Switch fromCC="ccache clang"toCC=clang+CMAKE_*_COMPILER_LAUNCHER=ccache. The old pattern caused CMake to resolve the CUDA host compiler (-ccbin) toccacheinstead of clang. SetCUDAHOSTCXXto tell CMake to use clang++ as nvcc's host compiler.CMakeLists.txt: ReadCUDAHOSTCXXintoCMAKE_CUDA_HOST_COMPILERbeforeenable_language(CUDA)to ensure it takes effect before PyTorch's TorchConfig.cmake can override it.Test plan
clang-build-23job passes🤖 Generated with Claude Code