summaryrefslogtreecommitdiffstats
path: root/Tests
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-02-02 13:23:05 (GMT)
committerKitware Robot <kwrobot@kitware.com>2022-02-02 13:23:19 (GMT)
commit92459258108c0036808f29f83a8503fea18ccee9 (patch)
treec2f302d41c63a149b510c97c74a664f980aa0808 /Tests
parent0f316675cfb572058b2077e72a8ecbb6b5c7b534 (diff)
parent8f64df0a7c2c9126017847f2bb8d37bc54ea0338 (diff)
downloadCMake-92459258108c0036808f29f83a8503fea18ccee9.zip
CMake-92459258108c0036808f29f83a8503fea18ccee9.tar.gz
CMake-92459258108c0036808f29f83a8503fea18ccee9.tar.bz2
Merge topic 'cuda_generic_arch_all'
8f64df0a7c CUDA: Generic all and all-major support Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Alex <leha-bot@yandex.ru> Merge-request: !6816
Diffstat (limited to 'Tests')
-rw-r--r--Tests/CudaOnly/All/CMakeLists.txt80
1 files changed, 46 insertions, 34 deletions
diff --git a/Tests/CudaOnly/All/CMakeLists.txt b/Tests/CudaOnly/All/CMakeLists.txt
index fe29bb0..ba32e9a 100644
--- a/Tests/CudaOnly/All/CMakeLists.txt
+++ b/Tests/CudaOnly/All/CMakeLists.txt
@@ -2,43 +2,55 @@ cmake_minimum_required(VERSION 3.20)
project(CudaOnlyAll CUDA)
if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND
- CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 11.5.0)
-
+ CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0)
set(compile_options -Wno-deprecated-gpu-targets)
- function(verify_output flag output_var)
- string(REGEX MATCHALL "-arch compute_([0-9]+)" target_archs "${${output_var}}")
- list(LENGTH target_archs count)
- if(count LESS 2)
- message(FATAL_ERROR "${flag} failed to map to multiple architectures")
- endif()
- endfunction()
endif()
-if(COMMAND verify_output)
- set(try_compile_flags -v ${compile_options})
-
- set(CMAKE_CUDA_ARCHITECTURES all)
- try_compile(all_archs_compiles
- ${CMAKE_CURRENT_BINARY_DIR}/try_compile/all_archs_compiles
- ${CMAKE_CURRENT_SOURCE_DIR}/main.cu
- COMPILE_DEFINITIONS ${try_compile_flags}
- OUTPUT_VARIABLE output
- )
- verify_output(all output)
-
- set(CMAKE_CUDA_ARCHITECTURES all-major)
- try_compile(all_major_archs_compiles
- ${CMAKE_CURRENT_BINARY_DIR}/try_compile/all_major_archs_compiles
- ${CMAKE_CURRENT_SOURCE_DIR}/main.cu
- COMPILE_DEFINITIONS ${try_compile_flags}
- OUTPUT_VARIABLE output
- )
- verify_output(all-major output)
-
- if(all_archs_compiles AND all_major_archs_compiles)
- add_executable(CudaOnlyAll main.cu)
- target_compile_options(CudaOnlyAll PRIVATE ${compile_options})
+function(verify_output flag)
+ string(REPLACE "-" "_" architectures "${flag}")
+ string(TOUPPER "${architectures}" architectures)
+ set(architectures "${CMAKE_CUDA_ARCHITECTURES_${architectures}}")
+
+ if(CMAKE_CUDA_COMPILER_ID STREQUAL "Clang")
+ set(match_regex "-target-cpu sm_([0-9]+)")
+ elseif(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA")
+ set(match_regex "-arch compute_([0-9]+)")
+ endif()
+
+ string(REGEX MATCHALL "${match_regex}" target_cpus "${output}")
+
+ foreach(cpu ${target_cpus})
+ string(REGEX MATCH "${match_regex}" dont_care "${cpu}")
+ list(APPEND command_archs "${CMAKE_MATCH_1}")
+ endforeach()
+
+ list(SORT command_archs)
+ if(NOT "${command_archs}" STREQUAL "${architectures}")
+ message(FATAL_ERROR "Architectures used for \"${flag}\" don't match the reference (\"${command_archs}\" != \"${architectures}\").")
endif()
-else()
+endfunction()
+
+set(try_compile_flags -v ${compile_options})
+
+set(CMAKE_CUDA_ARCHITECTURES all)
+try_compile(all_archs_compiles
+ ${CMAKE_CURRENT_BINARY_DIR}/try_compile/all_archs_compiles
+ ${CMAKE_CURRENT_SOURCE_DIR}/main.cu
+ COMPILE_DEFINITIONS ${try_compile_flags}
+ OUTPUT_VARIABLE output
+ )
+verify_output(all)
+
+set(CMAKE_CUDA_ARCHITECTURES all-major)
+try_compile(all_major_archs_compiles
+ ${CMAKE_CURRENT_BINARY_DIR}/try_compile/all_major_archs_compiles
+ ${CMAKE_CURRENT_SOURCE_DIR}/main.cu
+ COMPILE_DEFINITIONS ${try_compile_flags}
+ OUTPUT_VARIABLE output
+ )
+verify_output(all-major)
+
+if(all_archs_compiles AND all_major_archs_compiles)
add_executable(CudaOnlyAll main.cu)
+ target_compile_options(CudaOnlyAll PRIVATE ${compile_options})
endif()