summaryrefslogtreecommitdiffstats
path: root/Modules/CUDA
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-03-04 18:51:49 (GMT)
committerBrad King <brad.king@kitware.com>2022-03-10 14:27:29 (GMT)
commitd1b48bfabd6157309b3056967e6e30cc0ce07983 (patch)
tree3ce109b078bf5da4d866f6e2994bbce8246e4df1 /Modules/CUDA
parent632752d62e8de2730796f509dbb10551351309c2 (diff)
downloadCMake-d1b48bfabd6157309b3056967e6e30cc0ce07983.zip
CMake-d1b48bfabd6157309b3056967e6e30cc0ce07983.tar.gz
CMake-d1b48bfabd6157309b3056967e6e30cc0ce07983.tar.bz2
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/CUDA')
-rw-r--r--Modules/CUDA/architectures.cmake40
1 files changed, 40 insertions, 0 deletions
diff --git a/Modules/CUDA/architectures.cmake b/Modules/CUDA/architectures.cmake
index fa3a5a1..521243b 100644
--- a/Modules/CUDA/architectures.cmake
+++ b/Modules/CUDA/architectures.cmake
@@ -44,3 +44,43 @@ if(CMAKE_CUDA_COMPILER_TOOLKIT_VERSION VERSION_GREATER_EQUAL 11.4
AND (NOT CMAKE_CUDA_COMPILER_ID STREQUAL "Clang"))
list(APPEND CMAKE_CUDA_ARCHITECTURES_ALL 87)
endif()
+
+# FIXME(#23161): Detect architectures early since we test them during
+# compiler detection. We already have code to detect them later during
+# compiler testing, so we should not need to do this here.
+if(NOT CMAKE_GENERATOR MATCHES "Visual Studio")
+ set(_CUDA_ARCHS_EXE "${CMAKE_PLATFORM_INFO_DIR}/CMakeDetermineCUDACompilerArchs.bin")
+ execute_process(
+ COMMAND "${_CUDA_NVCC_EXECUTABLE}" -o "${_CUDA_ARCHS_EXE}" --cudart=static "${CMAKE_ROOT}/Modules/CMakeCUDACompilerABI.cu"
+ RESULT_VARIABLE _CUDA_ARCHS_RESULT
+ OUTPUT_VARIABLE _CUDA_ARCHS_OUTPUT
+ ERROR_VARIABLE _CUDA_ARCHS_OUTPUT
+ )
+ if(_CUDA_ARCHS_RESULT EQUAL 0)
+ execute_process(
+ COMMAND "${_CUDA_ARCHS_EXE}"
+ RESULT_VARIABLE _CUDA_ARCHS_RESULT
+ OUTPUT_VARIABLE _CUDA_ARCHS_OUTPUT
+ ERROR_VARIABLE _CUDA_ARCHS_OUTPUT
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ )
+ endif()
+ if(_CUDA_ARCHS_RESULT EQUAL 0)
+ set(_CUDA_ARCHITECTURES_NATIVE "${_CUDA_ARCHS_OUTPUT}")
+ list(REMOVE_DUPLICATES _CUDA_ARCHITECTURES_NATIVE)
+ else()
+ if (NOT _CUDA_ARCHS_RESULT MATCHES "[0-9]+")
+ set(_CUDA_ARCHS_STATUS " (${_CUDA_ARCHS_RESULT})")
+ else()
+ set(_CUDA_ARCHS_STATUS "")
+ endif()
+ string(REPLACE "\n" "\n " _CUDA_ARCHS_OUTPUT " ${_CUDA_ARCHS_OUTPUT}")
+ file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
+ "Detecting the CUDA native architecture(s) failed with "
+ "the following output:\n${_CUDA_ARCHS_OUTPUT}\n\n")
+ set(_CUDA_ARCHS_OUTPUT "")
+ endif()
+ unset(_CUDA_ARCHS_EXE)
+ unset(_CUDA_ARCHS_RESULT)
+ unset(_CUDA_ARCHS_OUTPUT)
+endif()