From 45e9ab0372fab8cdd4ef07acc8c5c8cf104ef850 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 2 Mar 2022 16:46:42 -0500 Subject: Tests: Rename CudaOnly.{All => ArchSpecial} The purpose of the test is to cover special values of `CMAKE_CUDA_ARCHITECTURES`. Prepare to add more than just `all` and `all-major`. While at it, fix the `project()` name in the test to match what we pass to `ctest` with `--build-project`. --- Tests/CudaOnly/All/CMakeLists.txt | 56 ------------------------------- Tests/CudaOnly/All/main.cu | 3 -- Tests/CudaOnly/ArchSpecial/CMakeLists.txt | 56 +++++++++++++++++++++++++++++++ Tests/CudaOnly/ArchSpecial/main.cu | 3 ++ Tests/CudaOnly/CMakeLists.txt | 2 +- 5 files changed, 60 insertions(+), 60 deletions(-) delete mode 100644 Tests/CudaOnly/All/CMakeLists.txt delete mode 100644 Tests/CudaOnly/All/main.cu create mode 100644 Tests/CudaOnly/ArchSpecial/CMakeLists.txt create mode 100644 Tests/CudaOnly/ArchSpecial/main.cu diff --git a/Tests/CudaOnly/All/CMakeLists.txt b/Tests/CudaOnly/All/CMakeLists.txt deleted file mode 100644 index ba32e9a..0000000 --- a/Tests/CudaOnly/All/CMakeLists.txt +++ /dev/null @@ -1,56 +0,0 @@ -cmake_minimum_required(VERSION 3.20) -project(CudaOnlyAll CUDA) - -if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND - CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) - set(compile_options -Wno-deprecated-gpu-targets) -endif() - -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() -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() diff --git a/Tests/CudaOnly/All/main.cu b/Tests/CudaOnly/All/main.cu deleted file mode 100644 index 5047a34..0000000 --- a/Tests/CudaOnly/All/main.cu +++ /dev/null @@ -1,3 +0,0 @@ -int main() -{ -} diff --git a/Tests/CudaOnly/ArchSpecial/CMakeLists.txt b/Tests/CudaOnly/ArchSpecial/CMakeLists.txt new file mode 100644 index 0000000..11f4292 --- /dev/null +++ b/Tests/CudaOnly/ArchSpecial/CMakeLists.txt @@ -0,0 +1,56 @@ +cmake_minimum_required(VERSION 3.20) +project(ArchSpecial CUDA) + +if(CMAKE_CUDA_COMPILER_ID STREQUAL "NVIDIA" AND + CMAKE_CUDA_COMPILER_VERSION VERSION_GREATER_EQUAL 8.0) + set(compile_options -Wno-deprecated-gpu-targets) +endif() + +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() +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(CudaOnlyArchSpecial main.cu) + target_compile_options(CudaOnlyArchSpecial PRIVATE ${compile_options}) +endif() diff --git a/Tests/CudaOnly/ArchSpecial/main.cu b/Tests/CudaOnly/ArchSpecial/main.cu new file mode 100644 index 0000000..5047a34 --- /dev/null +++ b/Tests/CudaOnly/ArchSpecial/main.cu @@ -0,0 +1,3 @@ +int main() +{ +} diff --git a/Tests/CudaOnly/CMakeLists.txt b/Tests/CudaOnly/CMakeLists.txt index cacfb76..aa4755d 100644 --- a/Tests/CudaOnly/CMakeLists.txt +++ b/Tests/CudaOnly/CMakeLists.txt @@ -4,8 +4,8 @@ macro (add_cuda_test_macro name) PROPERTY LABELS "CUDA") endmacro () -add_cuda_test_macro(CudaOnly.All CudaOnlyAll) add_cuda_test_macro(CudaOnly.Architecture Architecture) +add_cuda_test_macro(CudaOnly.ArchSpecial CudaOnlyArchSpecial) add_cuda_test_macro(CudaOnly.CompileFlags CudaOnlyCompileFlags) add_cuda_test_macro(CudaOnly.EnableStandard CudaOnlyEnableStandard) -- cgit v0.12