summaryrefslogtreecommitdiff
path: root/Modules/CMakeDetermineCUDACompiler.cmake
diff options
context:
space:
mode:
authorRobert Maynard <rmaynard@nvidia.com>2021-08-17 12:28:23 -0400
committerRobert Maynard <rmaynard@nvidia.com>2021-11-01 14:57:58 -0400
commit14d8a2768d8b8c2ba0f341b4bd59a875aaf6c2f4 (patch)
tree2074643d278024f89622b959a7795ee57438c222 /Modules/CMakeDetermineCUDACompiler.cmake
parente1acb03cd9b53fe81dd9e1696ac293ae5ba468cc (diff)
downloadcmake-14d8a2768d8b8c2ba0f341b4bd59a875aaf6c2f4.tar.gz
CUDA: Support nvcc 11.5 new -arch=all|all-major flags
Diffstat (limited to 'Modules/CMakeDetermineCUDACompiler.cmake')
-rw-r--r--Modules/CMakeDetermineCUDACompiler.cmake38
1 files changed, 30 insertions, 8 deletions
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake
index d06315e479..8479831b0b 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")