summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorRaul Tambre <raul@tambre.ee>2020-06-05 12:04:23 (GMT)
committerRaul Tambre <raul@tambre.ee>2020-06-05 12:04:23 (GMT)
commit4eaf1ef4257de10ad8711df77510ceda93f6ccff (patch)
treec41a91b1f216af088e2b241aa8be40084626468b /Modules
parent4af04586303da6fe0755423728c979aa8c84c301 (diff)
downloadCMake-4eaf1ef4257de10ad8711df77510ceda93f6ccff.zip
CMake-4eaf1ef4257de10ad8711df77510ceda93f6ccff.tar.gz
CMake-4eaf1ef4257de10ad8711df77510ceda93f6ccff.tar.bz2
CUDA: Fix checking working architectures with specifiers
We don't distinguish real/virtual architectures during compiler detection. If the user passes -DCMAKE_CUDA_ARCHITECTURES="70-virtual" we'll test with only the real architecture. If it works "architectures" will end up as "70". We check equality using strings, so this fails and we incorrectly throw an error. Fix this by comparing against CMAKE_CUDA_ARCHITECTURES with the specifiers stripped. We need to deduplicate tested_architectures for the same reason in case the user specified something like "70-real;70-virtual".
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CMakeDetermineCUDACompiler.cmake12
1 files changed, 10 insertions, 2 deletions
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake
index 1601e83..5ae3908 100644
--- a/Modules/CMakeDetermineCUDACompiler.cmake
+++ b/Modules/CMakeDetermineCUDACompiler.cmake
@@ -89,6 +89,7 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
string(REGEX MATCH "[0-9]+" arch_name "${arch}")
string(APPEND clang_archs " --cuda-gpu-arch=sm_${arch_name}")
string(APPEND nvcc_archs " -gencode=arch=compute_${arch_name},code=sm_${arch_name}")
+ list(APPEND tested_architectures "${arch_name}")
endforeach()
list(APPEND CMAKE_CUDA_COMPILER_ID_TEST_FLAGS_FIRST "${clang_archs}")
@@ -349,6 +350,8 @@ if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
endif()
endif()
+# If the user didn't set the architectures, then set them to a default.
+# If the user did, then make sure those architectures worked.
if(DEFINED detected_architecture)
set(CMAKE_CUDA_ARCHITECTURES "${detected_architecture}" CACHE STRING "CUDA architectures")
@@ -357,10 +360,15 @@ if(DEFINED detected_architecture)
endif()
elseif(architectures)
# Sort since order mustn't matter.
- list(SORT CMAKE_CUDA_ARCHITECTURES)
list(SORT architectures)
+ list(SORT tested_architectures)
- if(NOT "${architectures}" STREQUAL "${CMAKE_CUDA_ARCHITECTURES}")
+ # We don't distinguish real/virtual architectures during testing.
+ # For "70-real;70-virtual" we detect "70" as working and tested_architectures is "70;70".
+ # Thus we need to remove duplicates before checking if they're equal.
+ list(REMOVE_DUPLICATES tested_architectures)
+
+ if(NOT "${architectures}" STREQUAL "${tested_architectures}")
message(FATAL_ERROR
"The CMAKE_CUDA_ARCHITECTURES:\n"
" ${CMAKE_CUDA_ARCHITECTURES}\n"