diff options
author | Brad King <brad.king@kitware.com> | 2022-03-04 18:51:49 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-03-10 14:27:29 (GMT) |
commit | d1b48bfabd6157309b3056967e6e30cc0ce07983 (patch) | |
tree | 3ce109b078bf5da4d866f6e2994bbce8246e4df1 /Tests/CudaOnly | |
parent | 632752d62e8de2730796f509dbb10551351309c2 (diff) | |
download | CMake-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 'Tests/CudaOnly')
-rw-r--r-- | Tests/CudaOnly/ArchSpecial/CMakeLists.txt | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/Tests/CudaOnly/ArchSpecial/CMakeLists.txt b/Tests/CudaOnly/ArchSpecial/CMakeLists.txt index 11f4292..46f4ada 100644 --- a/Tests/CudaOnly/ArchSpecial/CMakeLists.txt +++ b/Tests/CudaOnly/ArchSpecial/CMakeLists.txt @@ -25,6 +25,7 @@ function(verify_output flag) endforeach() list(SORT command_archs) + list(REMOVE_DUPLICATES command_archs) if(NOT "${command_archs}" STREQUAL "${architectures}") message(FATAL_ERROR "Architectures used for \"${flag}\" don't match the reference (\"${command_archs}\" != \"${architectures}\").") endif() @@ -50,7 +51,17 @@ try_compile(all_major_archs_compiles ) verify_output(all-major) -if(all_archs_compiles AND all_major_archs_compiles) +set(CMAKE_CUDA_ARCHITECTURES native) +try_compile(native_archs_compiles + ${CMAKE_CURRENT_BINARY_DIR}/try_compile/native_archs_compiles + ${CMAKE_CURRENT_SOURCE_DIR}/main.cu + COMPILE_DEFINITIONS ${try_compile_flags} + OUTPUT_VARIABLE output + ) +verify_output(native) + +if(all_archs_compiles AND all_major_archs_compiles AND native_archs_compiles) + set(CMAKE_CUDA_ARCHITECTURES all) add_executable(CudaOnlyArchSpecial main.cu) target_compile_options(CudaOnlyArchSpecial PRIVATE ${compile_options}) endif() |