From 2e86e50c2fb2897dc1a0612676c5bd26eb7924a9 Mon Sep 17 00:00:00 2001 From: Robert Maynard Date: Sun, 25 Oct 2020 14:34:18 -0400 Subject: HIP: Add HIP to all the Check* modules --- Modules/CheckLinkerFlag.cmake | 2 ++ Modules/Internal/CheckCompilerFlag.cmake | 3 +++ Modules/Internal/CheckSourceCompiles.cmake | 3 +++ Modules/Internal/CheckSourceRuns.cmake | 3 +++ Tests/RunCMake/CMakeLists.txt | 18 +++++++++++---- .../CheckCompilerFlag/CheckHIPCompilerFlag.cmake | 13 +++++++++++ .../RunCMake/CheckCompilerFlag/RunCMakeTest.cmake | 4 ++++ .../CheckLinkerFlag/CheckHIPLinkerFlag.cmake | 3 +++ Tests/RunCMake/CheckLinkerFlag/RunCMakeTest.cmake | 4 ++++ .../CheckHIPSourceCompiles.cmake | 27 ++++++++++++++++++++++ .../CheckSourceCompiles/RunCMakeTest.cmake | 4 ++++ .../CheckSourceRuns/CheckHIPSourceRuns.cmake | 21 +++++++++++++++++ Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake | 4 ++++ 13 files changed, 105 insertions(+), 4 deletions(-) create mode 100644 Tests/RunCMake/CheckCompilerFlag/CheckHIPCompilerFlag.cmake create mode 100644 Tests/RunCMake/CheckLinkerFlag/CheckHIPLinkerFlag.cmake create mode 100644 Tests/RunCMake/CheckSourceCompiles/CheckHIPSourceCompiles.cmake create mode 100644 Tests/RunCMake/CheckSourceRuns/CheckHIPSourceRuns.cmake diff --git a/Modules/CheckLinkerFlag.cmake b/Modules/CheckLinkerFlag.cmake index 3c7a828..28ac2e3 100644 --- a/Modules/CheckLinkerFlag.cmake +++ b/Modules/CheckLinkerFlag.cmake @@ -65,6 +65,8 @@ function(CHECK_LINKER_FLAG _lang _flag _var) set (_source " program test\n stop\n end program") elseif (_lang MATCHES "CUDA") set (_source "__host__ int main() { return 0; }") + elseif (_lang MATCHES "HIP") + set (_source "__host__ int main() { return 0; }") elseif (_lang MATCHES "^(OBJC|OBJCXX)$") set (_source "#ifndef __OBJC__\n# error \"Not an Objective-C++ compiler\"\n#endif\nint main(void) { return 0; }") else() diff --git a/Modules/Internal/CheckCompilerFlag.cmake b/Modules/Internal/CheckCompilerFlag.cmake index 6b2a11e..9eb1bf0 100644 --- a/Modules/Internal/CheckCompilerFlag.cmake +++ b/Modules/Internal/CheckCompilerFlag.cmake @@ -24,6 +24,9 @@ function(CMAKE_CHECK_COMPILER_FLAG _lang _flag _var) elseif(_lang STREQUAL "Fortran") set(_lang_src " program test\n stop\n end program") set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for Fortran") + elseif(_lang STREQUAL "HIP") + set(_lang_src "__host__ int main() { return 0; }") + set(_lang_fail_regex FAIL_REGEX "argument unused during compilation: .*") # Clang elseif(_lang STREQUAL "OBJC") set(_lang_src [=[ #ifndef __OBJC__ diff --git a/Modules/Internal/CheckSourceCompiles.cmake b/Modules/Internal/CheckSourceCompiles.cmake index 3b2152a..8c3a418 100644 --- a/Modules/Internal/CheckSourceCompiles.cmake +++ b/Modules/Internal/CheckSourceCompiles.cmake @@ -22,6 +22,9 @@ function(CMAKE_CHECK_SOURCE_COMPILES _lang _source _var) elseif(_lang STREQUAL "Fortran") set(_lang_textual "Fortran") set(_lang_ext "F90") + elseif(_lang STREQUAL "HIP") + set(_lang_textual "HIP") + set(_lang_ext "hip") elseif(_lang STREQUAL "ISPC") set(_lang_textual "ISPC") set(_lang_ext "ispc") diff --git a/Modules/Internal/CheckSourceRuns.cmake b/Modules/Internal/CheckSourceRuns.cmake index 676f3d0..75e9896 100644 --- a/Modules/Internal/CheckSourceRuns.cmake +++ b/Modules/Internal/CheckSourceRuns.cmake @@ -22,6 +22,9 @@ function(CMAKE_CHECK_SOURCE_RUNS _lang _source _var) elseif(_lang STREQUAL "Fortran") set(_lang_textual "Fortran") set(_lang_ext "F90") + elseif(_lang STREQUAL "HIP") + set(_lang_textual "HIP") + set(_lang_ext "hip") elseif(_lang STREQUAL "OBJC") set(_lang_textual "Objective-C") set(_lang_ext "m") diff --git a/Tests/RunCMake/CMakeLists.txt b/Tests/RunCMake/CMakeLists.txt index 16487f3..dcf1e72 100644 --- a/Tests/RunCMake/CMakeLists.txt +++ b/Tests/RunCMake/CMakeLists.txt @@ -452,6 +452,7 @@ function(add_RunCMake_test_try_compile) CMAKE_CXX_STANDARD_DEFAULT CMake_TEST_CUDA CMake_TEST_ISPC + CMake_TEST_HIP CMake_TEST_FILESYSTEM_1S CMAKE_OBJC_STANDARD_DEFAULT CMAKE_OBJCXX_STANDARD_DEFAULT @@ -600,12 +601,15 @@ add_RunCMake_test(target_include_directories) add_RunCMake_test(target_sources) add_RunCMake_test(CheckCompilerFlag -DCMake_TEST_CUDA=${CMake_TEST_CUDA} -DCMake_TEST_ISPC=${CMake_TEST_ISPC} - -DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID}) + -DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID} + -DCMake_TEST_HIP=${CMake_TEST_HIP}) add_RunCMake_test(CheckSourceCompiles -DCMake_TEST_CUDA=${CMake_TEST_CUDA} -DCMake_TEST_ISPC=${CMake_TEST_ISPC} - -DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID}) + -DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID} + -DCMake_TEST_HIP=${CMake_TEST_HIP}) add_RunCMake_test(CheckSourceRuns -DCMake_TEST_CUDA=${CMake_TEST_CUDA} - -DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID}) + -DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID} + -DCMake_TEST_HIP=${CMake_TEST_HIP}) set_property(TEST RunCMake.CheckCompilerFlag RunCMake.CheckSourceCompiles RunCMake.CheckSourceRuns @@ -613,14 +617,20 @@ set_property(TEST RunCMake.CheckCompilerFlag set_property(TEST RunCMake.CheckSourceCompiles RunCMake.CheckCompilerFlag APPEND PROPERTY LABELS "ISPC") +set_property(TEST RunCMake.CheckCompilerFlag + RunCMake.CheckSourceCompiles + RunCMake.CheckSourceRuns + APPEND PROPERTY LABELS "HIP") add_RunCMake_test(CheckModules) add_RunCMake_test(CheckIPOSupported) if (CMAKE_SYSTEM_NAME MATCHES "(Linux|Darwin)" AND (CMAKE_C_COMPILER_ID MATCHES "Clang|GNU" OR CMAKE_Fortran_COMPILER_ID MATCHES "GNU")) add_RunCMake_test(CheckLinkerFlag -DCMAKE_C_COMPILER_ID=${CMAKE_C_COMPILER_ID} -DCMAKE_Fortran_COMPILER_ID=${CMAKE_Fortran_COMPILER_ID} - -DCMake_TEST_CUDA=${CMake_TEST_CUDA}) + -DCMake_TEST_CUDA=${CMake_TEST_CUDA} + -DCMake_TEST_HIP=${CMake_TEST_HIP}) set_property(TEST RunCMake.CheckLinkerFlag APPEND PROPERTY LABELS "CUDA") + set_property(TEST RunCMake.CheckLinkerFlag APPEND PROPERTY LABELS "HIP") endif() diff --git a/Tests/RunCMake/CheckCompilerFlag/CheckHIPCompilerFlag.cmake b/Tests/RunCMake/CheckCompilerFlag/CheckHIPCompilerFlag.cmake new file mode 100644 index 0000000..339ce18 --- /dev/null +++ b/Tests/RunCMake/CheckCompilerFlag/CheckHIPCompilerFlag.cmake @@ -0,0 +1,13 @@ + +enable_language (HIP) +include(CheckCompilerFlag) + +check_compiler_flag(HIP "-_this_is_not_a_flag_" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "invalid HIP compile flag didn't fail.") +endif() + +check_compiler_flag(HIP "-DFOO" SHOULD_WORK) +if(NOT SHOULD_WORK) + message(SEND_ERROR "${CMAKE_HIP_COMPILER_ID} compiler flag '-DFOO' check failed") +endif() diff --git a/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake b/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake index 7a4e2ce..7ef1860 100644 --- a/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake +++ b/Tests/RunCMake/CheckCompilerFlag/RunCMakeTest.cmake @@ -22,3 +22,7 @@ endif() if(CMake_TEST_ISPC) run_cmake(CheckISPCCompilerFlag) endif() + +if(CMake_TEST_HIP) + run_cmake(CheckHIPCompilerFlag) +endif() diff --git a/Tests/RunCMake/CheckLinkerFlag/CheckHIPLinkerFlag.cmake b/Tests/RunCMake/CheckLinkerFlag/CheckHIPLinkerFlag.cmake new file mode 100644 index 0000000..3bf3b30 --- /dev/null +++ b/Tests/RunCMake/CheckLinkerFlag/CheckHIPLinkerFlag.cmake @@ -0,0 +1,3 @@ + +set (CHECK_LANGUAGE HIP) +include ("${CMAKE_CURRENT_SOURCE_DIR}/CheckLinkerFlag.cmake") diff --git a/Tests/RunCMake/CheckLinkerFlag/RunCMakeTest.cmake b/Tests/RunCMake/CheckLinkerFlag/RunCMakeTest.cmake index 6ec9148..5e5bff6 100644 --- a/Tests/RunCMake/CheckLinkerFlag/RunCMakeTest.cmake +++ b/Tests/RunCMake/CheckLinkerFlag/RunCMakeTest.cmake @@ -16,3 +16,7 @@ endif() if (CMake_TEST_CUDA) run_cmake(CheckCUDALinkerFlag) endif() + +if (CMake_TEST_HIP) + run_cmake(CheckHIPLinkerFlag) +endif() diff --git a/Tests/RunCMake/CheckSourceCompiles/CheckHIPSourceCompiles.cmake b/Tests/RunCMake/CheckSourceCompiles/CheckHIPSourceCompiles.cmake new file mode 100644 index 0000000..911a0d7 --- /dev/null +++ b/Tests/RunCMake/CheckSourceCompiles/CheckHIPSourceCompiles.cmake @@ -0,0 +1,27 @@ + +enable_language (HIP) +include(CheckSourceCompiles) + +check_source_compiles(HIP "I don't build" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "invalid HIP source didn't fail.") +endif() + +check_source_compiles(HIP [=[ + #include + __device__ int d_func() { } + int main() { + return 0; + } +]=] + SHOULD_BUILD) +if(NOT SHOULD_BUILD) + message(SEND_ERROR "Test fail for valid HIP source.") +endif() + +check_source_compiles(HIP "void l(char const (&x)[2]){}; int main() { l(\"\\n\"); return 0;}" + SHOULD_BUILD_COMPLEX) + +if(NOT SHOULD_BUILD_COMPLEX) + message(SEND_ERROR "Test fail for valid HIP complex source.") +endif() diff --git a/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake b/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake index 6e9088f..530f133 100644 --- a/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake +++ b/Tests/RunCMake/CheckSourceCompiles/RunCMakeTest.cmake @@ -23,3 +23,7 @@ endif() if(CMake_TEST_ISPC) run_cmake(CheckISPCSourceCompiles) endif() + +if(CMake_TEST_HIP) + run_cmake(CheckHIPSourceCompiles) +endif() diff --git a/Tests/RunCMake/CheckSourceRuns/CheckHIPSourceRuns.cmake b/Tests/RunCMake/CheckSourceRuns/CheckHIPSourceRuns.cmake new file mode 100644 index 0000000..d9fb8c2 --- /dev/null +++ b/Tests/RunCMake/CheckSourceRuns/CheckHIPSourceRuns.cmake @@ -0,0 +1,21 @@ + +enable_language (HIP) +include(CheckSourceRuns) + +check_source_runs(HIP "int main() {return 2;}" SHOULD_FAIL) +if(SHOULD_FAIL) + message(SEND_ERROR "HIP check_source_runs succeeded, but should have failed.") +endif() + +check_source_runs(HIP +[=[ + #include + __device__ __host__ void fake_function(); + __host__ int main() { + return 0; + } +]=] + SHOULD_RUN) +if(NOT SHOULD_RUN) + message(SEND_ERROR "HIP check_source_runs failed for valid HIP executable.") +endif() diff --git a/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake b/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake index c99ac8b..4784103 100644 --- a/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake +++ b/Tests/RunCMake/CheckSourceRuns/RunCMakeTest.cmake @@ -19,3 +19,7 @@ endif() if (CMake_TEST_CUDA) run_cmake(CheckCUDASourceRuns) endif() + +if (CMake_TEST_HIP) + run_cmake(CheckHIPSourceRuns) +endif() -- cgit v0.12