mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-19 11:18:40 +08:00
CUDA: Fail fast if CMAKE_CUDA_ARCHITECTURES doesn't work during detection
Also re-ordered the code to avoid testing flags for other compilers, since we know the vendor before full detection.
This commit is contained in:
@@ -2,4 +2,5 @@ cuda-fail-fast
|
|||||||
--------------
|
--------------
|
||||||
|
|
||||||
* If ``CUDA`` compiler detection fails with user-specified
|
* If ``CUDA`` compiler detection fails with user-specified
|
||||||
:variable:`CMAKE_CUDA_ARCHITECTURES` an error is raised.
|
:variable:`CMAKE_CUDA_ARCHITECTURES` or :variable:`CMAKE_CUDA_HOST_COMPILER`
|
||||||
|
an error is raised.
|
||||||
|
@@ -206,34 +206,35 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
|
|||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# First try with the user-specified architectures.
|
# Append user-specified architectures.
|
||||||
if(CMAKE_CUDA_ARCHITECTURES)
|
if(CMAKE_CUDA_ARCHITECTURES)
|
||||||
set(clang_archs "${clang_test_flags}")
|
|
||||||
set(nvcc_archs "${nvcc_test_flags}")
|
|
||||||
|
|
||||||
foreach(arch ${CMAKE_CUDA_ARCHITECTURES})
|
foreach(arch ${CMAKE_CUDA_ARCHITECTURES})
|
||||||
# Strip specifiers as PTX vs binary doesn't matter.
|
# Strip specifiers as PTX vs binary doesn't matter.
|
||||||
string(REGEX MATCH "[0-9]+" arch_name "${arch}")
|
string(REGEX MATCH "[0-9]+" arch_name "${arch}")
|
||||||
string(APPEND clang_archs " --cuda-gpu-arch=sm_${arch_name}")
|
string(APPEND clang_test_flags " --cuda-gpu-arch=sm_${arch_name}")
|
||||||
string(APPEND nvcc_archs " -gencode=arch=compute_${arch_name},code=sm_${arch_name}")
|
string(APPEND nvcc_test_flags " -gencode=arch=compute_${arch_name},code=sm_${arch_name}")
|
||||||
list(APPEND tested_architectures "${arch_name}")
|
list(APPEND tested_architectures "${arch_name}")
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_archs}")
|
# If the user has specified architectures we'll want to fail during compiler detection if they don't work.
|
||||||
list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${nvcc_archs}")
|
set(CMAKE_CUDA_COMPILER_ID_REQUIRE_SUCCESS ON)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
# Fallback default NVCC flags.
|
if(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")
|
||||||
list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST ${nvcc_test_flags})
|
if(NOT CMAKE_CUDA_ARCHITECTURES)
|
||||||
|
# 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 "20" "30" "52")
|
||||||
|
list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags} --cuda-gpu-arch=sm_${arch}")
|
||||||
|
endforeach()
|
||||||
|
endif()
|
||||||
|
|
||||||
# Clang doesn't automatically select an architecture supported by the SDK.
|
# If the user specified CMAKE_CUDA_ARCHITECTURES this will include all the architecture flags.
|
||||||
# Try in reverse order of deprecation with the most recent at front (i.e. the most likely to work for new setups).
|
# Otherwise this won't include any architecture flags and we'll fallback to Clang's defaults.
|
||||||
foreach(arch "20" "30" "52")
|
list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags}")
|
||||||
list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags} --cuda-gpu-arch=sm_${arch}")
|
elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
|
||||||
endforeach()
|
list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${nvcc_test_flags}")
|
||||||
|
endif()
|
||||||
# Finally also try the default.
|
|
||||||
list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_test_flags}")
|
|
||||||
|
|
||||||
# We perform compiler identification for a second time to extract implicit linking info and host compiler for NVCC.
|
# We perform compiler identification for a second time to extract implicit linking info and host compiler for NVCC.
|
||||||
# We also use it to verify that CMAKE_CUDA_ARCHITECTURES and additionally on Clang that CUDA toolkit path works.
|
# We also use it to verify that CMAKE_CUDA_ARCHITECTURES and additionally on Clang that CUDA toolkit path works.
|
||||||
|
Reference in New Issue
Block a user