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:
Raul Tambre
2021-12-27 20:40:29 +02:00
parent d19273bc7b
commit 7a0d098352
11 changed files with 40 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
cuda-invalid-architectures
--------------------------
* CUDA compiler detection now tries to detect invalid architectures and issue
an error.

View File

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

View File

@@ -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

View File

@@ -0,0 +1,3 @@
cmake_minimum_required(VERSION 3.22)
project(${RunCMake_TEST} NONE)
include(${RunCMake_TEST}.cmake)

View File

@@ -0,0 +1,4 @@
include(RunCMake)
run_cmake(architectures-empty)
run_cmake(architectures-invalid)

View File

@@ -0,0 +1 @@
1

View File

@@ -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\)

View File

@@ -0,0 +1,2 @@
set(CMAKE_CUDA_ARCHITECTURES "")
enable_language(CUDA)

View File

@@ -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\)$

View File

@@ -0,0 +1,2 @@
set(CMAKE_CUDA_ARCHITECTURES "invalid")
enable_language(CUDA)