From 47632a902c283d46d42f09bc59d70b8f9d09868a Mon Sep 17 00:00:00 2001 From: Patrick Stotko Date: Sun, 14 Dec 2025 15:04:48 +0100 Subject: [PATCH] General: Bump HIP backend to ROCm 7.1+ --- cmake/hip/Findthrust.cmake | 32 ++++++++++++++++++++ cmake/hip/determine_thrust_paths.cmake | 11 ------- cmake/hip/set_device_flags.cmake | 4 --- docs/CMakeLists.txt | 2 +- docs/getting_started/building_from_source.md | 4 +-- src/stdgpu/hip/CMakeLists.txt | 21 +++++++------ src/stdgpu/hip/impl/memory_detail.h | 3 +- tools/backend/configure_hip.sh | 2 +- 8 files changed, 48 insertions(+), 31 deletions(-) create mode 100644 cmake/hip/Findthrust.cmake delete mode 100644 cmake/hip/determine_thrust_paths.cmake diff --git a/cmake/hip/Findthrust.cmake b/cmake/hip/Findthrust.cmake new file mode 100644 index 000000000..9d6bf0514 --- /dev/null +++ b/cmake/hip/Findthrust.cmake @@ -0,0 +1,32 @@ +find_package(rocthrust) + +if(rocthrust_INCLUDE_DIR) + file(STRINGS "${rocthrust_INCLUDE_DIR}/thrust/version.h" + THRUST_VERSION_STRING + REGEX "#define THRUST_VERSION[ \t]+([0-9x]+)") + + string(REGEX REPLACE "#define THRUST_VERSION[ \t]+([0-9]+).*" "\\1" THRUST_VERSION_STRING ${THRUST_VERSION_STRING}) + + math(EXPR THRUST_VERSION_MAJOR "${THRUST_VERSION_STRING} / 100000") + math(EXPR THRUST_VERSION_MINOR "(${THRUST_VERSION_STRING} / 100) % 1000") + math(EXPR THRUST_VERSION_PATCH "${THRUST_VERSION_STRING} % 100") + unset(THRUST_VERSION_STRING) + + set(THRUST_VERSION "${THRUST_VERSION_MAJOR}.${THRUST_VERSION_MINOR}.${THRUST_VERSION_PATCH}") +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(thrust + REQUIRED_VARS rocthrust_INCLUDE_DIR + VERSION_VAR THRUST_VERSION) + +if(thrust_FOUND) + add_library(thrust::thrust INTERFACE IMPORTED) + target_link_libraries(thrust::thrust INTERFACE roc::rocthrust) + + mark_as_advanced(THRUST_INCLUDE_DIR + THRUST_VERSION + THRUST_VERSION_MAJOR + THRUST_VERSION_MINOR + THRUST_VERSION_PATCH) +endif() diff --git a/cmake/hip/determine_thrust_paths.cmake b/cmake/hip/determine_thrust_paths.cmake deleted file mode 100644 index 8db8e51fe..000000000 --- a/cmake/hip/determine_thrust_paths.cmake +++ /dev/null @@ -1,11 +0,0 @@ -function(stdgpu_determine_thrust_paths STDGPU_OUTPUT_THRUST_PATHS) - # Clear list before appending flags - unset(${STDGPU_OUTPUT_THRUST_PATHS}) - - find_package(hip QUIET) - - set(${STDGPU_OUTPUT_THRUST_PATHS} "${hip_INCLUDE_DIRS}") - - # Make output variable visible - set(${STDGPU_OUTPUT_THRUST_PATHS} ${${STDGPU_OUTPUT_THRUST_PATHS}} PARENT_SCOPE) -endfunction() diff --git a/cmake/hip/set_device_flags.cmake b/cmake/hip/set_device_flags.cmake index 943b4aca6..23ffa2d41 100644 --- a/cmake/hip/set_device_flags.cmake +++ b/cmake/hip/set_device_flags.cmake @@ -21,10 +21,6 @@ function(stdgpu_set_device_flags STDGPU_OUTPUT_DEVICE_FLAGS) endif() endif() - if(CMAKE_HIP_COMPILER_ID STREQUAL "Clang") - list(APPEND ${STDGPU_OUTPUT_DEVICE_FLAGS} "-Wno-pass-failed") - endif() - set(${STDGPU_OUTPUT_DEVICE_FLAGS} "$<$:${${STDGPU_OUTPUT_DEVICE_FLAGS}}>") # Make output variable visible diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 2efd94881..b0672fbc1 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -30,7 +30,7 @@ endif() # - The dark mode switch and the respective variables of the sphinx-book-theme will be used # # Therefore, use the modified stylesheet from ROCm released under the MIT license: -# https://github.com/RadeonOpenCompute/rocm-docs-core/blob/develop/src/rocm_docs/data/_doxygen/extra_stylesheet.css +# https://github.com/ROCm/rocm-docs-core/blob/develop/src/rocm_docs/data/_doxygen/extra_stylesheet.css set(STDGPU_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../src") diff --git a/docs/getting_started/building_from_source.md b/docs/getting_started/building_from_source.md index 8ab2594fc..f58a81374 100644 --- a/docs/getting_started/building_from_source.md +++ b/docs/getting_started/building_from_source.md @@ -48,7 +48,7 @@ Before building the library, please make sure that all required development tool - Clang 10: `sudo apt install clang` - HIP compiler - Clang (Already included in ROCm) -- ROCm 5.1 +- ROCm 7.1 - CMake 3.21.3: `sudo apt install cmake` ::: @@ -91,7 +91,7 @@ Before building the library, please make sure that all required development tool - MSVC 19.20 (Visual Studio 2019) - HIP compiler - Clang (Already included in ROCm) -- ROCm 5.1 +- ROCm 7.1 - CMake 3.21.3: ::: diff --git a/src/stdgpu/hip/CMakeLists.txt b/src/stdgpu/hip/CMakeLists.txt index c84bc883c..dbb1cdb6a 100644 --- a/src/stdgpu/hip/CMakeLists.txt +++ b/src/stdgpu/hip/CMakeLists.txt @@ -1,8 +1,8 @@ -find_package(hip 5.1 REQUIRED) +#find_package(hip 7.1 REQUIRED) -set(STDGPU_DEPENDENCIES_BACKEND_INIT " -find_dependency(hip 5.1 REQUIRED) -" PARENT_SCOPE) +#set(STDGPU_DEPENDENCIES_BACKEND_INIT " +#find_dependency(hip 7.1 REQUIRED) +#" PARENT_SCOPE) target_sources(stdgpu PRIVATE impl/device.cpp impl/memory.cpp) @@ -29,10 +29,11 @@ target_compile_features(stdgpu PUBLIC hip_std_17) target_compile_definitions(stdgpu PUBLIC THRUST_DEVICE_SYSTEM=THRUST_DEVICE_SYSTEM_HIP) -# CMake always links libraries and executables involving HIP with the device linker, even if only host code is used. -# Suppress the linker warning about unused HIP architectures *globally* via a public linker flag. -set(STDGPU_HIP_DEVICE_LINKER_FLAGS "$<$:-Wno-unused-command-line-argument>") -message(STATUS "Created HIP device linker flags : ${STDGPU_HIP_DEVICE_LINKER_FLAGS}") -target_link_options(stdgpu PUBLIC "${STDGPU_HIP_DEVICE_LINKER_FLAGS}") +# thrust (rocthrust) already links against hip::device, which in turn links against hip::host +#target_link_libraries(stdgpu PUBLIC hip::host) -target_link_libraries(stdgpu PUBLIC hip::host) + +# Install custom thrust module +install(FILES "${stdgpu_SOURCE_DIR}/cmake/${STDGPU_BACKEND_DIRECTORY}/Findthrust.cmake" + DESTINATION "${STDGPU_CMAKE_INSTALL_DIR}/${STDGPU_BACKEND_DIRECTORY}" + COMPONENT stdgpu) diff --git a/src/stdgpu/hip/impl/memory_detail.h b/src/stdgpu/hip/impl/memory_detail.h index fb945bc6d..362430047 100644 --- a/src/stdgpu/hip/impl/memory_detail.h +++ b/src/stdgpu/hip/impl/memory_detail.h @@ -33,8 +33,7 @@ memcpy_impl(ExecutionPolicy&& policy, hipMemcpyKind kind, bool needs_sychronization) { - cudaStream_t stream = - thrust::hip_rocprim::stream(thrust::detail::derived_cast(thrust::detail::strip_const(policy))); + hipStream_t stream = thrust::hip_rocprim::stream(thrust::detail::derived_cast(thrust::detail::strip_const(policy))); STDGPU_HIP_SAFE_CALL(hipMemcpyAsync(destination, source, static_cast(bytes), kind, stream)); if (needs_sychronization) diff --git a/tools/backend/configure_hip.sh b/tools/backend/configure_hip.sh index 533c3c483..e35a3d383 100644 --- a/tools/backend/configure_hip.sh +++ b/tools/backend/configure_hip.sh @@ -12,4 +12,4 @@ fi sh tools/backend/helper/create_empty_directory.sh build # Configure project -sh tools/backend/helper/configure.sh $CONFIG -DSTDGPU_BACKEND=STDGPU_BACKEND_HIP -DSTDGPU_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_VERIFY_INTERFACE_HEADER_SETS=ON $@ +sh tools/backend/helper/configure.sh $CONFIG -DSTDGPU_BACKEND=STDGPU_BACKEND_HIP -DSTDGPU_COMPILE_WARNING_AS_ERROR=ON -DCMAKE_VERIFY_INTERFACE_HEADER_SETS=ON -DCMAKE_CXX_COMPILER=hipcc $@