From 5c1f5357b0335158aa7b31990d1df26fd04114f2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 2 Mar 2022 15:45:47 -0500 Subject: VS: Fix CUDA compiler id with CMAKE_CUDA_ARCHITECTURES={all,all-major} Skip the architecture verification check for these values on Visual Studio. It cannot be implemented correctly until future work delays the check to the main compiler test step. Issue: #23164, #23161 --- Modules/CMakeDetermineCUDACompiler.cmake | 4 +++- Modules/CMakeDetermineCompilerId.cmake | 10 ++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake index f491c79..8c01ea4 100644 --- a/Modules/CMakeDetermineCUDACompiler.cmake +++ b/Modules/CMakeDetermineCUDACompiler.cmake @@ -280,7 +280,9 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN) if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.5) string(APPEND nvcc_test_flags " -arch=${CMAKE_CUDA_ARCHITECTURES}") set(architectures_tested "${CMAKE_CUDA_ARCHITECTURES}") - elseif(NOT CMAKE_GENERATOR MATCHES "Visual Studio") + elseif(CMAKE_GENERATOR MATCHES "Visual Studio") + set(architectures_tested "${CMAKE_CUDA_ARCHITECTURES}") + else() if(CMAKE_CUDA_ARCHITECTURES STREQUAL "all") set(architectures_test ${CMAKE_CUDA_ARCHITECTURES_ALL}) elseif(CMAKE_CUDA_ARCHITECTURES STREQUAL "all-major") diff --git a/Modules/CMakeDetermineCompilerId.cmake b/Modules/CMakeDetermineCompilerId.cmake index 3ea146c..e0aa483 100644 --- a/Modules/CMakeDetermineCompilerId.cmake +++ b/Modules/CMakeDetermineCompilerId.cmake @@ -495,10 +495,12 @@ Id flags: ${testflags} ${CMAKE_${lang}_COMPILER_ID_FLAGS_ALWAYS} if(CMAKE_VS_PLATFORM_NAME STREQUAL x64) set(cuda_target "64") endif() - foreach(arch ${CMAKE_CUDA_ARCHITECTURES}) - string(REGEX MATCH "[0-9]+" arch_name "${arch}") - string(APPEND cuda_codegen "compute_${arch_name},sm_${arch_name};") - endforeach() + if(NOT CMAKE_CUDA_ARCHITECTURES MATCHES "^(all|all-major)$") + foreach(arch ${CMAKE_CUDA_ARCHITECTURES}) + string(REGEX MATCH "[0-9]+" arch_name "${arch}") + string(APPEND cuda_codegen "compute_${arch_name},sm_${arch_name};") + endforeach() + endif() set(id_ItemDefinitionGroup_entry "${cuda_target}%(AdditionalOptions)-v${cuda_codegen}") set(id_PostBuildEvent_Command [[echo CMAKE_CUDA_COMPILER=$(CudaToolkitBinDir)\nvcc.exe]]) if(CMAKE_VS_PLATFORM_TOOLSET_CUDA_CUSTOM_DIR) -- cgit v0.12 From dae3ad08fa1fe3078bf2fd3e949a078ca24e5636 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 2 Mar 2022 15:28:27 -0500 Subject: Tests: Add cases for CMAKE_CUDA_ARCHITECTURES={all,all-major} The `CudaOnly.All` test only sets these in project code after CUDA is enabled. Add another case to test the values during compiler detection. Issue: #23161 --- Tests/RunCMake/CUDA_architectures/RunCMakeTest.cmake | 2 ++ Tests/RunCMake/CUDA_architectures/architectures-all-major-stdout.txt | 3 +++ Tests/RunCMake/CUDA_architectures/architectures-all-major.cmake | 5 +++++ Tests/RunCMake/CUDA_architectures/architectures-all-stdout.txt | 3 +++ Tests/RunCMake/CUDA_architectures/architectures-all.cmake | 5 +++++ 5 files changed, 18 insertions(+) create mode 100644 Tests/RunCMake/CUDA_architectures/architectures-all-major-stdout.txt create mode 100644 Tests/RunCMake/CUDA_architectures/architectures-all-major.cmake create mode 100644 Tests/RunCMake/CUDA_architectures/architectures-all-stdout.txt create mode 100644 Tests/RunCMake/CUDA_architectures/architectures-all.cmake diff --git a/Tests/RunCMake/CUDA_architectures/RunCMakeTest.cmake b/Tests/RunCMake/CUDA_architectures/RunCMakeTest.cmake index cbbf57c..d16156e 100644 --- a/Tests/RunCMake/CUDA_architectures/RunCMakeTest.cmake +++ b/Tests/RunCMake/CUDA_architectures/RunCMakeTest.cmake @@ -1,4 +1,6 @@ include(RunCMake) +run_cmake(architectures-all) +run_cmake(architectures-all-major) run_cmake(architectures-empty) run_cmake(architectures-invalid) diff --git a/Tests/RunCMake/CUDA_architectures/architectures-all-major-stdout.txt b/Tests/RunCMake/CUDA_architectures/architectures-all-major-stdout.txt new file mode 100644 index 0000000..c5cde8f --- /dev/null +++ b/Tests/RunCMake/CUDA_architectures/architectures-all-major-stdout.txt @@ -0,0 +1,3 @@ +-- CMAKE_CUDA_ARCHITECTURES='all-major' +-- CMAKE_CUDA_ARCHITECTURES_ALL='[0-9;]+' +-- CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR='[0-9;]+' diff --git a/Tests/RunCMake/CUDA_architectures/architectures-all-major.cmake b/Tests/RunCMake/CUDA_architectures/architectures-all-major.cmake new file mode 100644 index 0000000..5112473 --- /dev/null +++ b/Tests/RunCMake/CUDA_architectures/architectures-all-major.cmake @@ -0,0 +1,5 @@ +set(CMAKE_CUDA_ARCHITECTURES "all-major") +enable_language(CUDA) +message(STATUS "CMAKE_CUDA_ARCHITECTURES='${CMAKE_CUDA_ARCHITECTURES}'") +message(STATUS "CMAKE_CUDA_ARCHITECTURES_ALL='${CMAKE_CUDA_ARCHITECTURES_ALL}'") +message(STATUS "CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR='${CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR}'") diff --git a/Tests/RunCMake/CUDA_architectures/architectures-all-stdout.txt b/Tests/RunCMake/CUDA_architectures/architectures-all-stdout.txt new file mode 100644 index 0000000..aba26b9 --- /dev/null +++ b/Tests/RunCMake/CUDA_architectures/architectures-all-stdout.txt @@ -0,0 +1,3 @@ +-- CMAKE_CUDA_ARCHITECTURES='all' +-- CMAKE_CUDA_ARCHITECTURES_ALL='[0-9;]+' +-- CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR='[0-9;]+' diff --git a/Tests/RunCMake/CUDA_architectures/architectures-all.cmake b/Tests/RunCMake/CUDA_architectures/architectures-all.cmake new file mode 100644 index 0000000..32175f6 --- /dev/null +++ b/Tests/RunCMake/CUDA_architectures/architectures-all.cmake @@ -0,0 +1,5 @@ +set(CMAKE_CUDA_ARCHITECTURES "all") +enable_language(CUDA) +message(STATUS "CMAKE_CUDA_ARCHITECTURES='${CMAKE_CUDA_ARCHITECTURES}'") +message(STATUS "CMAKE_CUDA_ARCHITECTURES_ALL='${CMAKE_CUDA_ARCHITECTURES_ALL}'") +message(STATUS "CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR='${CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR}'") -- cgit v0.12