diff --git a/CMakeLists.txt b/CMakeLists.txt index 802f5c63b..53140e8a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,37 @@ endif() # Note: C is required here for dependencies project(rocthrust LANGUAGES CXX C) +# Set CXX flags +if (NOT DEFINED CMAKE_CXX_STANDARD) + set(CMAKE_CXX_STANDARD 17) +endif() +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +# Set HIP flags +set(CMAKE_HIP_STANDARD 14) +set(CMAKE_HIP_STANDARD_REQUIRED ON) +set(CMAKE_HIP_EXTENSIONS OFF) + +include(CheckLanguage) +include(CMakeDependentOption) + +# Build options +# Disable -Werror +option(DISABLE_WERROR "Disable building with Werror" ON) +option(BUILD_TEST "Build tests" OFF) +option(BUILD_HIPSTDPAR_TEST "Build hipstdpar tests" OFF) +option(BUILD_EXAMPLES "Build examples" OFF) +option(BUILD_BENCHMARKS "Build benchmarks" OFF) +option(DOWNLOAD_ROCPRIM "Download rocPRIM and do not search for rocPRIM package" OFF) +option(BUILD_ADDRESS_SANITIZER "Build with address sanitizer enabled" OFF) +cmake_dependent_option(ENABLE_UPSTREAM_TESTS "Enable upstream (thrust) tests" ON BUILD_TEST OFF) +#Set the header wrapper OFF by default. +option(BUILD_FILE_REORG_BACKWARD_COMPATIBILITY "Build with file/folder reorg with backward compatibility enabled" OFF) + +check_language(HIP) +cmake_dependent_option(USE_HIPCXX "Use CMake HIP language support" OFF CMAKE_HIP_COMPILER OFF) + #Adding CMAKE_PREFIX_PATH list( APPEND CMAKE_PREFIX_PATH /opt/rocm/llvm /opt/rocm ${ROCM_PATH} ) @@ -34,7 +65,6 @@ endif() set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE CACHE BOOL "Add paths to linker search and installed rpath") -include(CMakeDependentOption) # rocm-cmake contains common cmake code for rocm projects to help # setup and install include( cmake/FindROCMCmake.cmake ) @@ -47,26 +77,30 @@ include( ROCMHeaderWrapper ) include( ROCMCheckTargetIds ) include( ROCMClients ) -# Use target ID syntax if supported for GPU_TARGETS -if (NOT DEFINED AMDGPU_TARGETS) - set(GPU_TARGETS "all" CACHE STRING "GPU architectures to compile for") +if(USE_HIPCXX) + enable_language(HIP) else() - set(GPU_TARGETS "${AMDGPU_TARGETS}" CACHE STRING "GPU architectures to compile for") -endif() -set_property(CACHE GPU_TARGETS PROPERTY STRINGS "all") - -if(GPU_TARGETS STREQUAL "all") - if(BUILD_ADDRESS_SANITIZER) - # ASAN builds require xnack - rocm_check_target_ids(DEFAULT_AMDGPU_TARGETS - TARGETS "gfx908:xnack+;gfx90a:xnack+;gfx942:xnack+" - ) + # Use target ID syntax if supported for GPU_TARGETS + if (NOT DEFINED AMDGPU_TARGETS) + set(GPU_TARGETS "all" CACHE STRING "GPU architectures to compile for") else() - rocm_check_target_ids(DEFAULT_AMDGPU_TARGETS - TARGETS "gfx803;gfx900:xnack-;gfx906:xnack-;gfx908:xnack-;gfx90a:xnack-;gfx90a:xnack+;gfx942;gfx1030;gfx1100;gfx1101;gfx1102;gfx1151;gfx1200;gfx1201" - ) + set(GPU_TARGETS "${AMDGPU_TARGETS}" CACHE STRING "GPU architectures to compile for") + endif() + set_property(CACHE GPU_TARGETS PROPERTY STRINGS "all") + + if(GPU_TARGETS STREQUAL "all") + if(BUILD_ADDRESS_SANITIZER) + # ASAN builds require xnack + rocm_check_target_ids(DEFAULT_AMDGPU_TARGETS + TARGETS "gfx908:xnack+;gfx90a:xnack+;gfx942:xnack+" + ) + else() + rocm_check_target_ids(DEFAULT_AMDGPU_TARGETS + TARGETS "gfx803;gfx900:xnack-;gfx906:xnack-;gfx908:xnack-;gfx90a:xnack-;gfx90a:xnack+;gfx942;gfx1030;gfx1100;gfx1101;gfx1102;gfx1151;gfx1200;gfx1201" + ) + endif() + set(GPU_TARGETS "${DEFAULT_AMDGPU_TARGETS}" CACHE STRING "GPU architectures to compile for" FORCE) endif() - set(GPU_TARGETS "${DEFAULT_AMDGPU_TARGETS}" CACHE STRING "GPU architectures to compile for" FORCE) endif() # Get dependencies @@ -76,18 +110,6 @@ include(cmake/Dependencies.cmake) if (NOT WIN32) include(cmake/VerifyCompiler.cmake) endif() -# Build options -# Disable -Werror -option(DISABLE_WERROR "Disable building with Werror" ON) -option(BUILD_TEST "Build tests" OFF) -option(BUILD_HIPSTDPAR_TEST "Build hipstdpar tests" OFF) -option(BUILD_EXAMPLES "Build examples" OFF) -option(BUILD_BENCHMARKS "Build benchmarks" OFF) -option(DOWNLOAD_ROCPRIM "Download rocPRIM and do not search for rocPRIM package" OFF) -option(BUILD_ADDRESS_SANITIZER "Build with address sanitizer enabled" OFF) -cmake_dependent_option(ENABLE_UPSTREAM_TESTS "Enable upstream (thrust) tests" ON BUILD_TEST OFF) -#Set the header wrapper OFF by default. -option(BUILD_FILE_REORG_BACKWARD_COMPATIBILITY "Build with file/folder reorg with backward compatibility enabled" OFF) set(RNG_SEED_COUNT 0 CACHE STRING "Number of true random sequences to test each input size for") set(PRNG_SEEDS 1 CACHE STRING "Seeds of pseudo random sequences to test each input size for") @@ -106,17 +128,10 @@ if (NOT THRUST_HOST_SYSTEM IN_LIST THRUST_HOST_SYSTEM_OPTIONS) ) endif () -# Set CXX flags -if (NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) -endif() -set(CMAKE_CXX_STANDARD_REQUIRED ON) -set(CMAKE_CXX_EXTENSIONS OFF) - if(DISABLE_WERROR) - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra ") + add_compile_options(-Wall -Wextra) else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror") + add_compile_options(-Wall -Wextra -Werror) endif() if (CMAKE_CXX_STANDARD EQUAL 14) diff --git a/cmake/Benchmarks.cmake b/cmake/Benchmarks.cmake index 7e9a3d5bd..e74f9bb43 100644 --- a/cmake/Benchmarks.cmake +++ b/cmake/Benchmarks.cmake @@ -37,10 +37,17 @@ endfunction() # Registers a .cu as C++ rocThrust benchmark function(add_thrust_benchmark BENCHMARK_NAME BENCHMARK_SOURCE NOT_INTERNAL) set(BENCHMARK_TARGET "benchmark_thrust_${BENCHMARK_NAME}") - set_source_files_properties(${BENCHMARK_SOURCE} - PROPERTIES - LANGUAGE CXX - ) + if(USE_HIPCXX) + set_source_files_properties(${BENCHMARK_SOURCE} + PROPERTIES + LANGUAGE HIP + ) + else() + set_source_files_properties(${BENCHMARK_SOURCE} + PROPERTIES + LANGUAGE CXX + ) + endif() add_executable(${BENCHMARK_TARGET} ${BENCHMARK_SOURCE}) target_link_libraries(${BENCHMARK_TARGET} diff --git a/cmake/Summary.cmake b/cmake/Summary.cmake index 62ccfbc3f..6c68f49da 100644 --- a/cmake/Summary.cmake +++ b/cmake/Summary.cmake @@ -26,14 +26,25 @@ function (print_configuration_summary) message(STATUS "General:") message(STATUS " System : ${CMAKE_SYSTEM_NAME}") message(STATUS " HIP ROOT : ${HIP_ROOT_DIR}") +if(USE_HIPCXX) + message(STATUS " HIP compiler : ${CMAKE_HIP_COMPILER}") + message(STATUS " HIP compiler version : ${CMAKE_HIP_COMPILER_VERSION}") + string(STRIP "${CMAKE_HIP_FLAGS}" CMAKE_HIP_FLAGS_STRIP) + message(STATUS " HIP flags : ${CMAKE_HIP_FLAGS_STRIP}") +else() message(STATUS " C++ compiler : ${CMAKE_CXX_COMPILER}") message(STATUS " C++ compiler version : ${CMAKE_CXX_COMPILER_VERSION}") string(STRIP "${CMAKE_CXX_FLAGS}" CMAKE_CXX_FLAGS_STRIP) message(STATUS " CXX flags : ${CMAKE_CXX_FLAGS_STRIP}") +endif() message(STATUS " Build type : ${CMAKE_BUILD_TYPE}") message(STATUS " Install prefix : ${CMAKE_INSTALL_PREFIX}") if(HIP_COMPILER STREQUAL "clang") +if(USE_HIPCXX) + message(STATUS " Device targets : ${CMAKE_HIP_ARCHITECTURES}") +else() message(STATUS " Device targets : ${GPU_TARGETS}") +endif() endif() message(STATUS "") message(STATUS " DISABLE_WERROR : ${DISABLE_WERROR}") diff --git a/cmake/VerifyCompiler.cmake b/cmake/VerifyCompiler.cmake index 13749152d..0930d6132 100644 --- a/cmake/VerifyCompiler.cmake +++ b/cmake/VerifyCompiler.cmake @@ -26,8 +26,14 @@ find_package(hip REQUIRED CONFIG PATHS /opt/rocm) if(HIP_COMPILER STREQUAL "nvcc") message(FATAL_ERROR "rocThrust does not support the CUDA backend.") elseif(HIP_COMPILER STREQUAL "clang") - if(NOT (CMAKE_CXX_COMPILER MATCHES ".*hipcc$" OR CMAKE_CXX_COMPILER MATCHES ".*clang\\+\\+")) - message(FATAL_ERROR "On ROCm platform 'hipcc' or HIP-aware Clang must be used as C++ compiler.") + if(USE_HIPCXX) + if(NOT (CMAKE_HIP_COMPILER MATCHES ".*hipcc$" OR CMAKE_HIP_COMPILER MATCHES ".*clang\\+\\+")) + message(FATAL_ERROR "On ROCm platform 'hipcc' or HIP-aware Clang must be used as HIP compiler.") + endif() + else() + if(NOT (CMAKE_CXX_COMPILER MATCHES ".*hipcc$" OR CMAKE_CXX_COMPILER MATCHES ".*clang\\+\\+")) + message(FATAL_ERROR "On ROCm platform 'hipcc' or HIP-aware Clang must be used as C++ compiler.") + endif() endif() else() message(FATAL_ERROR "HIP_COMPILER must be `clang` (AMD ROCm platform)") diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 27c959fad..b36063ce4 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -9,10 +9,17 @@ endif() function(add_thrust_example EXAMPLE) set(EXAMPLE_SOURCE "${EXAMPLE}.cu") set(EXAMPLE_TARGET "example_thrust_${EXAMPLE}") - set_source_files_properties(${EXAMPLE_SOURCE} + if(USE_HIPCXX) + set_source_files_properties(${EXAMPLE_SOURCE} PROPERTIES - LANGUAGE CXX - ) + LANGUAGE HIP + ) + else() + set_source_files_properties(${EXAMPLE_SOURCE} + PROPERTIES + LANGUAGE CXX + ) + endif() add_executable(${EXAMPLE_TARGET} ${EXAMPLE_SOURCE}) target_link_libraries(${EXAMPLE_TARGET} @@ -45,7 +52,7 @@ function(add_thrust_example EXAMPLE) foreach( file_i ${third_party_dlls}) add_custom_command( TARGET ${EXAMPLE_TARGET} POST_BUILD COMMAND ${CMAKE_COMMAND} ARGS -E copy_if_different ${file_i} ${PROJECT_BINARY_DIR}/examples ) endforeach( file_i ) - endif() + endif() endfunction() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1bd8a8bdd..8af7d09e3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -49,6 +49,10 @@ endfunction() function(add_rocthrust_test TEST) set(TEST_SOURCE "test_${TEST}.cpp") + if(USE_HIPCXX) + set_source_files_properties(${TEST_SOURCE} PROPERTIES LANGUAGE HIP) + endif() + set(TEST_TARGET "${TEST}.hip") add_executable(${TEST_TARGET} ${TEST_SOURCE}) target_include_directories(${TEST_TARGET} SYSTEM BEFORE diff --git a/test/hipstdpar/CMakeLists.txt b/test/hipstdpar/CMakeLists.txt index c93ca7222..faf301837 100644 --- a/test/hipstdpar/CMakeLists.txt +++ b/test/hipstdpar/CMakeLists.txt @@ -4,6 +4,9 @@ function(add_hipstdpar_test TEST TEST_TYPE INTERPOSE_ALLOC) set(TEST_SOURCE "test_${TEST}.cpp") + if(USE_HIPCXX) + set_source_files_properties(${TEST_SOURCE} PROPERTIES LANGUAGE HIP) + endif() set(TEST_TARGET "${TEST}_${TEST_TYPE}.hip") add_executable(${TEST_TARGET} ${TEST_SOURCE}) diff --git a/testing/CMakeLists.txt b/testing/CMakeLists.txt index 03aa0a39b..0eae4066c 100644 --- a/testing/CMakeLists.txt +++ b/testing/CMakeLists.txt @@ -53,10 +53,17 @@ if(HIP_COMPILER STREQUAL "nvcc") ) target_sources(testframework PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/unittest/cuda/testframework.cu) elseif(HIP_COMPILER STREQUAL "clang") - set_source_files_properties(unittest/hip/testframework.cu - PROPERTIES - LANGUAGE CXX - ) + if(USE_HIPCXX) + set_source_files_properties(unittest/hip/testframework.cu + PROPERTIES + LANGUAGE HIP + ) + else() + set_source_files_properties(unittest/hip/testframework.cu + PROPERTIES + LANGUAGE CXX + ) + endif() target_sources(testframework PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/unittest/hip/testframework.cu) endif() @@ -76,10 +83,17 @@ function(add_thrust_test TEST) # This code path used to add "-x c++" to the compiler flags too, but that was # superfluous as "-x hip" was already present on the command-line due to linking to # hip::device transitively from roc::rocprim_hip. - set_source_files_properties(${TEST_SOURCE} - PROPERTIES - LANGUAGE CXX - ) + if(USE_HIPCXX) + set_source_files_properties(${TEST_SOURCE} + PROPERTIES + LANGUAGE HIP + ) + else() + set_source_files_properties(${TEST_SOURCE} + PROPERTIES + LANGUAGE CXX + ) + endif() if(NOT CMAKE_VERSION VERSION_LESS 3.13) add_executable(${TEST_TARGET} ${TEST_SOURCE} $) target_link_libraries(${TEST_TARGET}