fix(cmake): support CUDA 13 Clang toolchains - #39
Conversation
d11dcba to
5d98e76
Compare
5d98e76 to
9b23aae
Compare
| if(DEFINED CMAKE_CUDA_COMPILER AND NOT CMAKE_CUDA_COMPILER STREQUAL "") | ||
| set(SD_NVCC_EXECUTABLE "${CMAKE_CUDA_COMPILER}") | ||
| else() | ||
| find_program(SD_NVCC_EXECUTABLE NAMES nvcc |
There was a problem hiding this comment.
[P1] Honor CUDAToolkit_ROOT when selecting NVCC. When CMAKE_CUDA_COMPILER is unset, this search ignores an explicit toolkit root and can force nvcc from /usr/local/cuda or PATH. GGML then runs FindCUDAToolkit, which prioritizes CMAKE_CUDA_COMPILER over CUDAToolkit_ROOT; for example, -DCUDAToolkit_ROOT=/opt/cuda-13 with CUDA 12 on PATH resolves the compiler/toolkit search to CUDA 12 and can fail or mix installations. I reproduced this with separate explicit-root and PATH toolkit locations. Please search ${CUDAToolkit_ROOT}/bin first (including the environment form), or leave CMAKE_CUDA_COMPILER unset so FindCUDAToolkit can honor the explicit root.
There was a problem hiding this comment.
You are right: an explicit CUDAToolkit_ROOT must take precedence over the convenience probe. I will change the order to honor an explicit CMAKE_CUDA_COMPILER, then CUDAToolkit_ROOT/bin (including its environment form), before /usr/local/cuda, CUDA_PATH/CUDA_HOME, and PATH; I will validate it with an explicit-root/PATH-version mismatch.
The need for this PR is independently reproducible on the NV5090 host. The unmodified 2026-08-11 branch, configured with Clang 20 and CUDA 13.3 installed, found CUDA 13.3 headers but selected /usr/bin/nvcc from CUDA 12.4 with GNU 13.4 as NVCC's host compiler. It then failed while building GGML CUDA with nvcc fatal: Unsupported gpu architecture 'compute_120a'. #39 makes the intended CUDA 13.3 compiler and Clang host compiler selection deterministic; after that selection, the engine builds and the CUDA smoke runs complete.
What problem does this PR solve?
On Linux hosts with more than one CUDA installation, CMake could select an older
nvccfromPATHinstead of the intended CUDA 13 toolkit. CUDA 13 also installs runtime headers belowtargets/<platform>/include, which can leaveFindCUDAToolkitwithout the include path it needs. Finally, Clang-based builds required callers to wire NVCC's host compiler manually.How does it solve it?
/usr/local/cuda/bin/nvccon Linux, then fall back toCUDA_PATH,CUDA_HOME, andPATH; an explicitly suppliedCMAKE_CUDA_COMPILERremains authoritative.CUDAToolkit.CMAKE_CUDA_HOST_COMPILERis already set.CUDAToolkit_ROOT,CMAKE_CUDA_COMPILER, andCMAKE_CUDA_HOST_COMPILERsettings.How was it tested?
120aand121a.ctest: 8/8 tests passed.Compatibility
This is a build-configuration change only. It retains GGML's CUDA backend and architecture policy, while making CUDA 13.3 and Clang selection reproducible for the stable-diffusion.cpp engine.