summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-09-25 20:22:04 (GMT)
committerBrad King <brad.king@kitware.com>2023-09-25 20:23:00 (GMT)
commitfd982eec10840eabcccc1920c7c32eb0a13d65a9 (patch)
tree69c2c825ccf1197f2d39afe38abfdcdcad88ce44
parent8c8b3f1bfaf055910c2764fa710da583a247338a (diff)
downloadCMake-fd982eec10840eabcccc1920c7c32eb0a13d65a9.zip
CMake-fd982eec10840eabcccc1920c7c32eb0a13d65a9.tar.gz
CMake-fd982eec10840eabcccc1920c7c32eb0a13d65a9.tar.bz2
HIP: Add tests for special NVIDIA values of CMAKE_HIP_ARCHITECTURES
-rw-r--r--Tests/HIP/ArchSpecial/CMakeLists.txt66
-rw-r--r--Tests/HIP/ArchSpecial/main.hip3
-rw-r--r--Tests/HIP/CMakeLists.txt3
3 files changed, 72 insertions, 0 deletions
diff --git a/Tests/HIP/ArchSpecial/CMakeLists.txt b/Tests/HIP/ArchSpecial/CMakeLists.txt
new file mode 100644
index 0000000..2bc6bd2
--- /dev/null
+++ b/Tests/HIP/ArchSpecial/CMakeLists.txt
@@ -0,0 +1,66 @@
+cmake_minimum_required(VERSION 3.27)
+project(ArchSpecial HIP)
+
+if(CMAKE_HIP_COMPILER_ID STREQUAL "NVIDIA" AND
+ CMAKE_HIP_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_HIP_ARCHITECTURES_${architectures}}")
+ list(TRANSFORM architectures REPLACE "-real" "")
+
+ if(CMAKE_HIP_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)
+ 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()
+endfunction()
+
+set(try_compile_flags -v ${compile_options})
+
+set(CMAKE_HIP_ARCHITECTURES all)
+try_compile(all_archs_compiles
+ ${CMAKE_CURRENT_BINARY_DIR}/try_compile/all_archs_compiles
+ ${CMAKE_CURRENT_SOURCE_DIR}/main.hip
+ COMPILE_DEFINITIONS ${try_compile_flags}
+ OUTPUT_VARIABLE output
+ )
+verify_output(all)
+
+set(CMAKE_HIP_ARCHITECTURES all-major)
+try_compile(all_major_archs_compiles
+ ${CMAKE_CURRENT_BINARY_DIR}/try_compile/all_major_archs_compiles
+ ${CMAKE_CURRENT_SOURCE_DIR}/main.hip
+ COMPILE_DEFINITIONS ${try_compile_flags}
+ OUTPUT_VARIABLE output
+ )
+verify_output(all-major)
+
+set(CMAKE_HIP_ARCHITECTURES native)
+try_compile(native_archs_compiles
+ ${CMAKE_CURRENT_BINARY_DIR}/try_compile/native_archs_compiles
+ ${CMAKE_CURRENT_SOURCE_DIR}/main.hip
+ 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_HIP_ARCHITECTURES all)
+ add_executable(HIPArchSpecial main.hip)
+ target_compile_options(HIPArchSpecial PRIVATE ${compile_options})
+endif()
diff --git a/Tests/HIP/ArchSpecial/main.hip b/Tests/HIP/ArchSpecial/main.hip
new file mode 100644
index 0000000..5047a34
--- /dev/null
+++ b/Tests/HIP/ArchSpecial/main.hip
@@ -0,0 +1,3 @@
+int main()
+{
+}
diff --git a/Tests/HIP/CMakeLists.txt b/Tests/HIP/CMakeLists.txt
index 26d7459..f1e2e51 100644
--- a/Tests/HIP/CMakeLists.txt
+++ b/Tests/HIP/CMakeLists.txt
@@ -5,6 +5,9 @@ macro (add_hip_test_macro name)
endmacro ()
add_hip_test_macro(HIP.ArchitectureOff HIPOnlyArchitectureOff)
+if(CMake_TEST_HIP STREQUAL "nvidia")
+ add_hip_test_macro(HIP.ArchSpecial HIPArchSpecial)
+endif()
add_hip_test_macro(HIP.CompileFlags HIPOnlyCompileFlags)
add_hip_test_macro(HIP.EnableStandard HIPEnableStandard)
add_hip_test_macro(HIP.InferHipLang1 HIPInferHipLang1)