summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2021-11-02 12:54:57 (GMT)
committerKitware Robot <kwrobot@kitware.com>2021-11-02 12:55:13 (GMT)
commit4e84a4763d702590fb06d62540e35a614dcd5133 (patch)
tree7e296b09c62be920fb89e93997743463842e1250 /Modules
parentd273175157efcdcd5d114ee6e79e61e9bb7a26b6 (diff)
parent14d8a2768d8b8c2ba0f341b4bd59a875aaf6c2f4 (diff)
downloadCMake-4e84a4763d702590fb06d62540e35a614dcd5133.zip
CMake-4e84a4763d702590fb06d62540e35a614dcd5133.tar.gz
CMake-4e84a4763d702590fb06d62540e35a614dcd5133.tar.bz2
Merge topic 'support_nvcc_native_flag'
14d8a2768d CUDA: Support nvcc 11.5 new -arch=all|all-major flags Acked-by: Kitware Robot <kwrobot@kitware.com> Reviewed-by: Raul Tambre <raul@tambre.ee> Merge-request: !6652
Diffstat (limited to 'Modules')
-rw-r--r--Modules/CMakeDetermineCUDACompiler.cmake38
1 files changed, 30 insertions, 8 deletions
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake
index d06315e..8479831 100644
--- a/Modules/CMakeDetermineCUDACompiler.cmake
+++ b/Modules/CMakeDetermineCUDACompiler.cmake
@@ -258,13 +258,22 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
# Append user-specified architectures.
if(CMAKE_CUDA_ARCHITECTURES)
- foreach(arch ${CMAKE_CUDA_ARCHITECTURES})
- # Strip specifiers as PTX vs binary doesn't matter.
- string(REGEX MATCH "[0-9]+" arch_name "${arch}")
- string(APPEND clang_test_flags " --cuda-gpu-arch=sm_${arch_name}")
- string(APPEND nvcc_test_flags " -gencode=arch=compute_${arch_name},code=sm_${arch_name}")
- list(APPEND tested_architectures "${arch_name}")
- endforeach()
+ if("x${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "xall")
+ string(APPEND nvcc_test_flags " -arch=all")
+ set(architectures_mode all)
+ elseif("x${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "xall-major")
+ string(APPEND nvcc_test_flags " -arch=all-major")
+ set(architectures_mode all-major)
+ else()
+ set(architectures_mode explicit)
+ foreach(arch ${CMAKE_CUDA_ARCHITECTURES})
+ # Strip specifiers as PTX vs binary doesn't matter.
+ string(REGEX MATCH "[0-9]+" arch_name "${arch}")
+ string(APPEND clang_test_flags " --cuda-gpu-arch=sm_${arch_name}")
+ string(APPEND nvcc_test_flags " -gencode=arch=compute_${arch_name},code=sm_${arch_name}")
+ list(APPEND tested_architectures "${arch_name}")
+ endforeach()
+ endif()
# If the user has specified architectures we'll want to fail during compiler detection if they don't work.
set(CMAKE_CUDA_COMPILER_ID_REQUIRE_SUCCESS ON)
@@ -597,7 +606,18 @@ if(DEFINED detected_architecture AND "${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "")
if(NOT CMAKE_CUDA_ARCHITECTURES)
message(FATAL_ERROR "Failed to find a working CUDA architecture.")
endif()
-elseif(architectures)
+elseif(architectures AND (architectures_mode STREQUAL "xall" OR
+ architectures_mode STREQUAL "xall-major"))
+ if(NOT CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
+ message(FATAL_ERROR
+ "The CMAKE_CUDA_ARCHITECTURES:\n"
+ " ${CMAKE_CUDA_ARCHITECTURES}\n"
+ "is not supported with the ${CMAKE_CUDA_COMPILER_ID} compiler. Try:\n"
+ " ${architectures}\n"
+ "instead.")
+ endif()
+
+elseif(architectures AND architectures_mode STREQUAL "xexplicit")
# Sort since order mustn't matter.
list(SORT architectures)
list(SORT tested_architectures)
@@ -630,5 +650,7 @@ unset(_CUDA_LIBRARY_DIR)
unset(_CUDA_TARGET_DIR)
unset(_CUDA_TARGET_NAME)
+unset(architectures_mode)
+
set(CMAKE_CUDA_COMPILER_ENV_VAR "CUDACXX")
set(CMAKE_CUDA_HOST_COMPILER_ENV_VAR "CUDAHOSTCXX")