Skip to content

fix(cmake): support CUDA 13 Clang toolchains - #39

Open
aegioscy wants to merge 1 commit into
2026-08-11from
fix/cuda13-clang-toolchain-20260811
Open

fix(cmake): support CUDA 13 Clang toolchains#39
aegioscy wants to merge 1 commit into
2026-08-11from
fix/cuda13-clang-toolchain-20260811

Conversation

@aegioscy

@aegioscy aegioscy commented Sep 8, 2026

Copy link
Copy Markdown

What problem does this PR solve?

On Linux hosts with more than one CUDA installation, CMake could select an older nvcc from PATH instead of the intended CUDA 13 toolkit. CUDA 13 also installs runtime headers below targets/<platform>/include, which can leave FindCUDAToolkit without the include path it needs. Finally, Clang-based builds required callers to wire NVCC's host compiler manually.

How does it solve it?

  • Prefer /usr/local/cuda/bin/nvcc on Linux, then fall back to CUDA_PATH, CUDA_HOME, and PATH; an explicitly supplied CMAKE_CUDA_COMPILER remains authoritative.
  • Detect CUDA 13 target-layout runtime headers and provide the corresponding toolkit root and include location before GGML resolves CUDAToolkit.
  • When Clang is the selected C++ compiler, use it as NVCC's host compiler unless CMAKE_CUDA_HOST_COMPILER is already set.
  • Preserve explicit CUDAToolkit_ROOT, CMAKE_CUDA_COMPILER, and CMAKE_CUDA_HOST_COMPILER settings.
  • Document the normal CUDA build and explicit toolkit/compiler override paths.

How was it tested?

  • Configured and built the branch directly on NV5090 with CUDA 13.3.73 and Clang 20.1.8. The build emitted the expected Blackwell-capable CUDA architecture set, including 120a and 121a.
  • Ran ctest: 8/8 tests passed.
  • Ran CUDA inference smoke tests for SD 2.1, SDXL, SD3, and Flux.2 Klein.
  • Ran MiniMax-H3 Q2 and Q4 prompt-to-audio-video inference; both completed and produced valid 480×288, 24-FPS AVI files with audio.

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.

@aegioscy
aegioscy force-pushed the fix/cuda13-clang-toolchain-20260811 branch 2 times, most recently from d11dcba to 5d98e76 Compare September 8, 2026 09:48
@aegioscy
aegioscy force-pushed the fix/cuda13-clang-toolchain-20260811 branch from 5d98e76 to 9b23aae Compare September 8, 2026 09:49
Comment thread CMakeLists.txt
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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.

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.

2 participants