From 1461db3a3327edac5d5435727eb9580eecf6d60b Mon Sep 17 00:00:00 2001 From: Aaron Enye Shi Date: Fri, 24 Aug 2018 15:46:13 +0000 Subject: [PATCH 1/4] Add HIP-Clang CMake changes Add ifdefs to remove usage of hcc in cmake files, and remove hc tests on the hip path if using HIP-Clang as the compiler. Enable detection of the compiler into HIP_COMPILER cmake variable. --- CMakeLists.txt | 15 +++++++++++++++ benchmark/CMakeLists.txt | 2 ++ cmake/VerifyCompiler.cmake | 6 +++--- rocprim/CMakeLists.txt | 8 ++++++++ test/CMakeLists.txt | 25 +++++++++++++++++-------- test/rocprim/CMakeLists.txt | 2 ++ 6 files changed, 47 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 126fc7099..0447a0471 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,6 +52,21 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") +# Determine if CXX Compiler is hcc, hip-clang or other +execute_process(COMMAND ${CMAKE_CXX_COMPILER} "--version" OUTPUT_VARIABLE CXX_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE) +string(REGEX MATCH "[A-Za-z]* ?clang version" TMP_CXX_VERSION ${CXX_OUTPUT}) +string(REGEX MATCH "[A-Za-z]+" CXX_VERSION_STRING ${TMP_CXX_VERSION}) + if(CXX_VERSION_STRING MATCHES "HCC") + set(HIP_COMPILER "hcc" CACHE STRING "HIP Compiler") +elseif(CXX_VERSION_STRING MATCHES "clang") + set(HIP_COMPILER "clang" CACHE STRING "HIP Compiler") +else() + message(FATAL_ERROR "CXX Compiler version ${CXX_VERSION_STRING} unsupported.") +endif() +message(STATUS "HIP Compiler: " ${HIP_COMPILER}) + # Build options option(BUILD_TEST "Build tests (requires googletest)" ON) option(BUILD_BENCHMARK "Build benchmarks" OFF) diff --git a/benchmark/CMakeLists.txt b/benchmark/CMakeLists.txt index a3745417b..071bf94cd 100644 --- a/benchmark/CMakeLists.txt +++ b/benchmark/CMakeLists.txt @@ -79,6 +79,7 @@ add_rocprim_benchmark_hip(benchmark_hip_warp_sort.cpp) add_rocprim_benchmark_hip(benchmark_hip_device_memory.cpp) # rocPRIM HC benchmarks +if(HIP_COMPILER STREQUAL "HCC") add_rocprim_benchmark_hc(benchmark_hc_block_discontinuity.cpp) add_rocprim_benchmark_hc(benchmark_hc_block_exchange.cpp) add_rocprim_benchmark_hc(benchmark_hc_block_histogram.cpp) @@ -95,3 +96,4 @@ add_rocprim_benchmark_hc(benchmark_hc_device_select.cpp) add_rocprim_benchmark_hc(benchmark_hc_device_transform.cpp) add_rocprim_benchmark_hc(benchmark_hc_warp_scan.cpp) add_rocprim_benchmark_hc(benchmark_hc_warp_sort.cpp) +endif() diff --git a/cmake/VerifyCompiler.cmake b/cmake/VerifyCompiler.cmake index b8b10be3e..ea81a8fee 100644 --- a/cmake/VerifyCompiler.cmake +++ b/cmake/VerifyCompiler.cmake @@ -32,8 +32,8 @@ if(HIP_PLATFORM STREQUAL "nvcc") include(cmake/SetupNVCC.cmake) message(STATUS "rocPRIM does not support NVCC. Only hipCUB will be available.") elseif(HIP_PLATFORM STREQUAL "hcc") - if(NOT (CMAKE_CXX_COMPILER MATCHES ".*/hcc$")) - message(FATAL_ERROR "On ROCm platform 'hcc' must be used as C++ compiler.") + if(NOT (CMAKE_CXX_COMPILER MATCHES ".*/hcc$" OR CMAKE_CXX_COMPILER MATCHES ".*/hipcc$")) + message(FATAL_ERROR "On ROCm platform 'hcc' or 'clang' must be used as C++ compiler.") else() # Workaround until hcc & hip cmake modules fixes symlink logic in their config files. # (Thanks to rocBLAS devs for finding workaround for this problem.) @@ -44,5 +44,5 @@ elseif(HIP_PLATFORM STREQUAL "hcc") find_package(hip REQUIRED CONFIG PATHS /opt/rocm) endif() else() - message(FATAL_ERROR "HIP_PLATFORM must be 'hcc' (AMD ROCm platform) or `nvcc` (NVIDIA CUDA platform).") + message(FATAL_ERROR "HIP_PLATFORM must be 'hcc' or 'clang' (AMD ROCm platform) or `nvcc` (NVIDIA CUDA platform).") endif() diff --git a/rocprim/CMakeLists.txt b/rocprim/CMakeLists.txt index 0aae2ef9b..671b27e0e 100644 --- a/rocprim/CMakeLists.txt +++ b/rocprim/CMakeLists.txt @@ -42,12 +42,20 @@ target_include_directories(rocprim # This target allows using only HC interface, links only # against HC/HSA library, doesn't require HIP add_library(rocprim_hc INTERFACE) +if(HIP_COMPILER STREQUAL "HCC") target_link_libraries(rocprim_hc INTERFACE rocprim hcc::hccrt hcc::hc_am ) +elseif(HIP_COMPILER STREQUAL "clang") +target_link_libraries(rocprim_hc + INTERFACE + rocprim +) +endif() + target_compile_definitions(rocprim_hc INTERFACE ROCPRIM_HC_API=1 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 26faae8ab..72c4eecbf 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -61,12 +61,19 @@ function(add_hc_test TEST_NAME TEST_SOURCES) PUBLIC ${GTEST_INCLUDE_DIRS} ) - target_link_libraries(${TEST_TARGET} - PRIVATE - hcc::hccrt - hcc::hc_am - ${GTEST_BOTH_LIBRARIES} - ) + if(HIP_COMPILER STREQUAL "HCC") + target_link_libraries(${TEST_TARGET} + PRIVATE + hcc::hccrt + hcc::hc_am + ${GTEST_BOTH_LIBRARIES} + ) + elseif(HIP_COMPILER STREQUAL "clang") + target_link_libraries(${TEST_TARGET} + PRIVATE + ${GTEST_BOTH_LIBRARIES} + ) + endif() foreach(amdgpu_target ${AMDGPU_TARGETS}) target_link_libraries(${TEST_TARGET} PRIVATE @@ -86,8 +93,10 @@ endfunction() # HC and HIP tests without using rocPRIM if(HIP_PLATFORM STREQUAL "hcc") - add_hip_test("hc.device_api" test_hip_api.cpp) - add_hc_test ("hip.device_api" test_hc_api.cpp) + add_hip_test("hip.device_api" test_hip_api.cpp) + if(HIP_COMPILER STREQUAL "HCC") + add_hc_test ("hc.device_api" test_hc_api.cpp) + endif() endif() # rocPRIM test (run only on ROCm/hcc) diff --git a/test/rocprim/CMakeLists.txt b/test/rocprim/CMakeLists.txt index cace5b347..c3e0d0433 100644 --- a/test/rocprim/CMakeLists.txt +++ b/test/rocprim/CMakeLists.txt @@ -63,6 +63,7 @@ endfunction() # # HCP basic test, which also checks if there are no linkage problems when there are multiple sources +if(HIP_COMPILER STREQUAL "HCC") add_rocprim_test_hc("rocprim.hc.basic_test" "test_hc_basic.cpp;detail/get_rocprim_version_hc.cpp") add_rocprim_test_hc("rocprim.hc.arg_index_iterator" test_hc_arg_index_iterator.cpp) @@ -98,6 +99,7 @@ add_rocprim_test_hc("rocprim.hc.warp_reduce" test_hc_warp_reduce.cpp) add_rocprim_test_hc("rocprim.hc.warp_scan" test_hc_warp_scan.cpp) add_rocprim_test_hc("rocprim.hc.warp_sort" test_hc_warp_sort.cpp) add_rocprim_test_hc("rocprim.hc.zip_iterator" test_hc_zip_iterator.cpp) +endif() # # rocPRIM HIP API tests From ffd862aa9d4815b7e40b2a1be54a3b766064b9e7 Mon Sep 17 00:00:00 2001 From: Aaron Enye Shi Date: Mon, 27 Aug 2018 20:39:28 +0000 Subject: [PATCH 2/4] Create rocprim_hc if hcc PACKAGE / targets found Requiring HCC only if the compiler is HCC. However if using HIP-Clang, but HCC packages are found, proceed with creating a meaningful rocprim_hc target which can be used later. --- cmake/VerifyCompiler.cmake | 6 +++++- rocprim/CMakeLists.txt | 29 ++++++++++++----------------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/cmake/VerifyCompiler.cmake b/cmake/VerifyCompiler.cmake index ea81a8fee..458730c37 100644 --- a/cmake/VerifyCompiler.cmake +++ b/cmake/VerifyCompiler.cmake @@ -40,7 +40,11 @@ elseif(HIP_PLATFORM STREQUAL "hcc") list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hcc /opt/rocm/hip) # Ignore hcc warning: argument unused during compilation: '-isystem /opt/rocm/hip/include' set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unused-command-line-argument") - find_package(hcc REQUIRED CONFIG PATHS /opt/rocm) + if(HIP_COMPILER STREQUAL "HCC") + find_package(hcc REQUIRED CONFIG PATHS /opt/rocm) + else() + find_package(hcc QUIET CONFIG PATHS /opt/rocm) + endif() find_package(hip REQUIRED CONFIG PATHS /opt/rocm) endif() else() diff --git a/rocprim/CMakeLists.txt b/rocprim/CMakeLists.txt index 671b27e0e..4f8f97976 100644 --- a/rocprim/CMakeLists.txt +++ b/rocprim/CMakeLists.txt @@ -41,25 +41,20 @@ target_include_directories(rocprim # This target allows using only HC interface, links only # against HC/HSA library, doesn't require HIP -add_library(rocprim_hc INTERFACE) -if(HIP_COMPILER STREQUAL "HCC") -target_link_libraries(rocprim_hc - INTERFACE - rocprim - hcc::hccrt - hcc::hc_am -) -elseif(HIP_COMPILER STREQUAL "clang") -target_link_libraries(rocprim_hc - INTERFACE - rocprim -) +if(HIP_COMPILER STREQUAL "HCC" OR (hcc_FOUND AND TARGET hcc::hccrt AND TARGET hcc::hc_am)) + add_library(rocprim_hc INTERFACE) + target_link_libraries(rocprim_hc + INTERFACE + rocprim + hcc::hccrt + hcc::hc_am + ) + target_compile_definitions(rocprim_hc + INTERFACE + ROCPRIM_HC_API=1 + ) endif() -target_compile_definitions(rocprim_hc - INTERFACE - ROCPRIM_HC_API=1 -) # This target allows using both HIP and HC interfaces, # links against HIP library (which depends on HC) From 1dc3cb1ef1559636645e0a5f1d0b2205f0490aa5 Mon Sep 17 00:00:00 2001 From: Aaron Enye Shi Date: Mon, 27 Aug 2018 21:42:30 +0000 Subject: [PATCH 3/4] Clean up HCC check on HIP-Clang --- CMakeLists.txt | 15 --------------- cmake/VerifyCompiler.cmake | 15 +++++++++++++++ rocprim/CMakeLists.txt | 13 ++++++++++++- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0447a0471..126fc7099 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,21 +52,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") -# Determine if CXX Compiler is hcc, hip-clang or other -execute_process(COMMAND ${CMAKE_CXX_COMPILER} "--version" OUTPUT_VARIABLE CXX_OUTPUT - OUTPUT_STRIP_TRAILING_WHITESPACE - ERROR_STRIP_TRAILING_WHITESPACE) -string(REGEX MATCH "[A-Za-z]* ?clang version" TMP_CXX_VERSION ${CXX_OUTPUT}) -string(REGEX MATCH "[A-Za-z]+" CXX_VERSION_STRING ${TMP_CXX_VERSION}) - if(CXX_VERSION_STRING MATCHES "HCC") - set(HIP_COMPILER "hcc" CACHE STRING "HIP Compiler") -elseif(CXX_VERSION_STRING MATCHES "clang") - set(HIP_COMPILER "clang" CACHE STRING "HIP Compiler") -else() - message(FATAL_ERROR "CXX Compiler version ${CXX_VERSION_STRING} unsupported.") -endif() -message(STATUS "HIP Compiler: " ${HIP_COMPILER}) - # Build options option(BUILD_TEST "Build tests (requires googletest)" ON) option(BUILD_BENCHMARK "Build benchmarks" OFF) diff --git a/cmake/VerifyCompiler.cmake b/cmake/VerifyCompiler.cmake index 458730c37..0d99d56b9 100644 --- a/cmake/VerifyCompiler.cmake +++ b/cmake/VerifyCompiler.cmake @@ -35,6 +35,21 @@ elseif(HIP_PLATFORM STREQUAL "hcc") if(NOT (CMAKE_CXX_COMPILER MATCHES ".*/hcc$" OR CMAKE_CXX_COMPILER MATCHES ".*/hipcc$")) message(FATAL_ERROR "On ROCm platform 'hcc' or 'clang' must be used as C++ compiler.") else() + # Determine if CXX Compiler is hcc, hip-clang or other + execute_process(COMMAND ${CMAKE_CXX_COMPILER} "--version" OUTPUT_VARIABLE CXX_OUTPUT + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_STRIP_TRAILING_WHITESPACE) + string(REGEX MATCH "[A-Za-z]* ?clang version" TMP_CXX_VERSION ${CXX_OUTPUT}) + string(REGEX MATCH "[A-Za-z]+" CXX_VERSION_STRING ${TMP_CXX_VERSION}) + if(CXX_VERSION_STRING MATCHES "HCC") + set(HIP_COMPILER "hcc" CACHE STRING "HIP Compiler") + elseif(CXX_VERSION_STRING MATCHES "clang") + set(HIP_COMPILER "clang" CACHE STRING "HIP Compiler") + else() + message(FATAL_ERROR "CXX Compiler version ${CXX_VERSION_STRING} unsupported.") + endif() + message(STATUS "HIP Compiler: " ${HIP_COMPILER}) + # Workaround until hcc & hip cmake modules fixes symlink logic in their config files. # (Thanks to rocBLAS devs for finding workaround for this problem.) list(APPEND CMAKE_PREFIX_PATH /opt/rocm/hcc /opt/rocm/hip) diff --git a/rocprim/CMakeLists.txt b/rocprim/CMakeLists.txt index 4f8f97976..5902b543e 100644 --- a/rocprim/CMakeLists.txt +++ b/rocprim/CMakeLists.txt @@ -41,7 +41,7 @@ target_include_directories(rocprim # This target allows using only HC interface, links only # against HC/HSA library, doesn't require HIP -if(HIP_COMPILER STREQUAL "HCC" OR (hcc_FOUND AND TARGET hcc::hccrt AND TARGET hcc::hc_am)) +if(HIP_COMPILER STREQUAL "HCC" OR hcc_FOUND) add_library(rocprim_hc INTERFACE) target_link_libraries(rocprim_hc INTERFACE @@ -79,6 +79,7 @@ set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) # We need to install headers manually as rocm_install_targets # does not support header-only libraries (INTERFACE targets) +if(rocprim_hc) rocm_install_targets( TARGETS rocprim rocprim_hip rocprim_hc # INCLUDE @@ -86,6 +87,16 @@ rocm_install_targets( # ${CMAKE_BINARY_DIR}/rocprim/include PREFIX rocprim ) +else() +rocm_install_targets( + TARGETS rocprim rocprim_hip +# INCLUDE +# ${CMAKE_SOURCE_DIR}/rocprim/include +# ${CMAKE_BINARY_DIR}/rocprim/include + PREFIX rocprim +) +endif() + install( DIRECTORY "include/" From b191bddabf73f84c3ced22d6876403ffc5112b49 Mon Sep 17 00:00:00 2001 From: Aaron Enye Shi Date: Mon, 27 Aug 2018 22:05:12 +0000 Subject: [PATCH 4/4] Disable hc examples for HIP-Clang --- example/CMakeLists.txt | 4 +++- rocprim/CMakeLists.txt | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index 61f84f51b..010aa4ede 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -50,6 +50,8 @@ endfunction() # **************************************************************************** # rocPRIM examples # **************************************************************************** - + add_rocprim_example_hip(example_hip_temporary_storage.cpp) +if(HIP_COMPILER STREQUAL "HCC") add_rocprim_example_hc(example_hc_temporary_storage.cpp) +endif() diff --git a/rocprim/CMakeLists.txt b/rocprim/CMakeLists.txt index 5902b543e..bfe2ae792 100644 --- a/rocprim/CMakeLists.txt +++ b/rocprim/CMakeLists.txt @@ -79,7 +79,7 @@ set(INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_INCLUDEDIR}) # We need to install headers manually as rocm_install_targets # does not support header-only libraries (INTERFACE targets) -if(rocprim_hc) +if(TARGET rocprim_hc) rocm_install_targets( TARGETS rocprim rocprim_hip rocprim_hc # INCLUDE