summaryrefslogtreecommitdiff
path: root/Modules/CMakeDetermineCUDACompiler.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-03-04 13:51:49 -0500
committerBrad King <brad.king@kitware.com>2022-03-10 09:27:29 -0500
commitd1b48bfabd6157309b3056967e6e30cc0ce07983 (patch)
tree3ce109b078bf5da4d866f6e2994bbce8246e4df1 /Modules/CMakeDetermineCUDACompiler.cmake
parent632752d62e8de2730796f509dbb10551351309c2 (diff)
downloadcmake-d1b48bfabd6157309b3056967e6e30cc0ce07983.tar.gz
CUDA: Add support for CUDA_ARCHITECTURES=native
CUDA 11.6 added the `nvcc -arch=native` flag to automatically compile for the host GPUs' architectures. Add support for specifying this special `native` value in `CMAKE_CUDA_ARCHITECTURES` and `CUDA_ARCHITECTURES`. During the compiler ABI detection step, detect the native architectures so we can pass them explicitly when using Clang or older versions of nvcc. Fixes: #22375
Diffstat (limited to 'Modules/CMakeDetermineCUDACompiler.cmake')
-rw-r--r--Modules/CMakeDetermineCUDACompiler.cmake15
1 files changed, 13 insertions, 2 deletions
diff --git a/Modules/CMakeDetermineCUDACompiler.cmake b/Modules/CMakeDetermineCUDACompiler.cmake
index 4263bed392..f68c4b235f 100644
--- a/Modules/CMakeDetermineCUDACompiler.cmake
+++ b/Modules/CMakeDetermineCUDACompiler.cmake
@@ -249,7 +249,7 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
set(CMAKE_CUDA_COMPILER_TOOLKIT_VERSION "${CMAKE_MATCH_1}")
endif()
- # Make the all and all-major architecture information available.
+ # Make the all, all-major, and native architecture information available.
# FIXME(#23161): Defer architecture detection until compiler testing.
include(${CMAKE_ROOT}/Modules/CUDA/architectures.cmake)
endif()
@@ -291,6 +291,17 @@ if(NOT CMAKE_CUDA_COMPILER_ID_RUN)
set(architectures_test ${CMAKE_CUDA_ARCHITECTURES_ALL_MAJOR})
endif()
endif()
+ elseif(CMAKE_CUDA_ARCHITECTURES STREQUAL "native")
+ # For sufficiently new NVCC we can just use the 'native' value directly.
+ # For VS we don't test since we can't find nvcc this early (see #23161).
+ if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.6)
+ string(APPEND nvcc_test_flags " -arch=${CMAKE_CUDA_ARCHITECTURES}")
+ set(architectures_tested "${CMAKE_CUDA_ARCHITECTURES}")
+ elseif(CMAKE_GENERATOR MATCHES "Visual Studio")
+ set(architectures_tested "${CMAKE_CUDA_ARCHITECTURES}")
+ else()
+ set(architectures_test ${_CUDA_ARCHITECTURES_NATIVE})
+ endif()
elseif(CMAKE_CUDA_ARCHITECTURES OR "${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "")
# Explicit architectures. Test them during detection.
set(architectures_explicit TRUE)
@@ -636,7 +647,7 @@ if("${CMAKE_CUDA_ARCHITECTURES}" STREQUAL "")
message(FATAL_ERROR "Failed to detect a default CUDA architecture.\n\nCompiler output:\n${CMAKE_CUDA_COMPILER_PRODUCED_OUTPUT}")
endif()
endif()
-elseif(CMAKE_CUDA_ARCHITECTURES AND NOT "${architectures_tested}" MATCHES "^(all|all-major)$")
+elseif(CMAKE_CUDA_ARCHITECTURES AND NOT "${architectures_tested}" MATCHES "^(all|all-major|native)$")
# Sort since order mustn't matter.
list(SORT architectures_detected)
list(SORT architectures_tested)