mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-05 21:31:08 -06:00
CUDA: Error on empty/invalid CMAKE_CUDA_ARCHITECTURES set by user
If empty we otherwise treat it the same as unset in most places, but still end up failing eventually with a confusing "Failed to find a working CUDA architecture". This also detects some other basic invalid ones (e.g. "al").
This commit is contained in:
5
Help/release/dev/cuda-invalid-architectures.rst
Normal file
5
Help/release/dev/cuda-invalid-architectures.rst
Normal file
@@ -0,0 +1,5 @@
|
||||
cuda-invalid-architectures
|
||||
--------------------------
|
||||
|
||||
* CUDA compiler detection now tries to detect invalid architectures and issue
|
||||
an error.
|
||||
@@ -257,7 +257,7 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
|
||||
endif()
|
||||
|
||||
# Append user-specified architectures.
|
||||
if(CMAKE_CUDA_ARCHITECTURES)
|
||||
if(DEFINED CMAKE_CUDA_ARCHITECTURES)
|
||||
if("x${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "xall")
|
||||
string(APPEND nvcc_test_flags " -arch=all")
|
||||
set(architectures_mode all)
|
||||
@@ -279,6 +279,13 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
|
||||
set(CMAKE_CUDA_COMPILER_ID_REQUIRE_SUCCESS ON)
|
||||
endif()
|
||||
|
||||
# Rest of the code treats an empty value as equivalent to "use the defaults".
|
||||
# Error out early to prevent confusing errors as a result of this.
|
||||
# Note that this also catches invalid non-numerical values such as "a".
|
||||
if(architectures_mode STREQUAL "explicit" AND "${tested_architectures}" STREQUAL "")
|
||||
message(FATAL_ERROR "CMAKE_CUDA_ARCHITECTURES must be valid if set.")
|
||||
endif()
|
||||
|
||||
if(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")
|
||||
if(NOT CMAKE_CUDA_ARCHITECTURES)
|
||||
# Clang doesn't automatically select an architecture supported by the SDK.
|
||||
|
||||
@@ -534,6 +534,10 @@ add_RunCMake_test(no_install_prefix)
|
||||
add_RunCMake_test(configure_file)
|
||||
add_RunCMake_test(CTestTimeout -DTIMEOUT=${CTestTestTimeout_TIME})
|
||||
add_RunCMake_test(CTestTimeoutAfterMatch)
|
||||
if(CMake_TEST_CUDA)
|
||||
add_RunCMake_test(CUDA_architectures)
|
||||
set_property(TEST RunCMake.CUDA_architectures APPEND PROPERTY LABELS "CUDA")
|
||||
endif()
|
||||
add_RunCMake_test(DependencyGraph -DCMAKE_Fortran_COMPILER=${CMAKE_Fortran_COMPILER})
|
||||
|
||||
# ctresalloc links against CMakeLib and CTestLib, which means it can't be built
|
||||
|
||||
3
Tests/RunCMake/CUDA_architectures/CMakeLists.txt
Normal file
3
Tests/RunCMake/CUDA_architectures/CMakeLists.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
cmake_minimum_required(VERSION 3.22)
|
||||
project(${RunCMake_TEST} NONE)
|
||||
include(${RunCMake_TEST}.cmake)
|
||||
4
Tests/RunCMake/CUDA_architectures/RunCMakeTest.cmake
Normal file
4
Tests/RunCMake/CUDA_architectures/RunCMakeTest.cmake
Normal file
@@ -0,0 +1,4 @@
|
||||
include(RunCMake)
|
||||
|
||||
run_cmake(architectures-empty)
|
||||
run_cmake(architectures-invalid)
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
^CMake Error at .*/Modules/CMakeDetermineCUDACompiler\.cmake:[0-9]+ \(message\):
|
||||
CMAKE_CUDA_ARCHITECTURES must be valid if set\.
|
||||
Call Stack \(most recent call first\):
|
||||
architectures-empty\.cmake:2 \(enable_language\)
|
||||
CMakeLists\.txt:3 \(include\)
|
||||
@@ -0,0 +1,2 @@
|
||||
set(CMAKE_CUDA_ARCHITECTURES "")
|
||||
enable_language(CUDA)
|
||||
@@ -0,0 +1 @@
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
^CMake Error at .*/Modules/CMakeDetermineCUDACompiler\.cmake:[0-9]+ \(message\):
|
||||
CMAKE_CUDA_ARCHITECTURES must be valid if set\.
|
||||
Call Stack \(most recent call first\):
|
||||
architectures-invalid\.cmake:2 \(enable_language\)
|
||||
CMakeLists\.txt:3 \(include\)$
|
||||
@@ -0,0 +1,2 @@
|
||||
set(CMAKE_CUDA_ARCHITECTURES "invalid")
|
||||
enable_language(CUDA)
|
||||
Reference in New Issue
Block a user