From 47ddbc9dedfac4d78e67ab67c5284c007d17d65d Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 22 Apr 2025 09:47:33 -0400 Subject: [PATCH] CUDA/Clang: Prefer NVCC's default architecture for each CUDA Toolkit version This makes the default CUDA architecture consistent across compilers, and makes it more likely that the resulting binary will run on the user's hardware. This also makes hardware requirements for CI builds more consistent. See commit 4f2178c4a8 (ci: add tags to tie CUDA jobs to runners with hardware supporting them, 2025-04-21). --- Modules/CMakeDetermineCUDACompiler.cmake | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index 70528da3d0..cad26da4e1 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -112,9 +112,14 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) cmake_cuda_architectures_validate(CUDA) if(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang") - # Clang doesn't automatically select an architecture supported by the SDK. - # Try in reverse order of deprecation with the most recent at front (i.e. the most likely to work for new setups). - foreach(arch "52" "30" "20") + # Clang does not automatically select an architecture supported by the SDK. + # Prefer NVCC's default for each SDK version, and fall back to older archs. + set(archs "") + if(NOT CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_LESS 11.0) + list(APPEND archs 52) + endif() + list(APPEND archs 30 20) + foreach(arch IN LISTS archs) list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags} --cuda-gpu-arch=sm_${arch}") endforeach() elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")