Skip to content

Commit

Permalink
finish CMake native HIP support
Browse files Browse the repository at this point in the history
  • Loading branch information
SimeonEhrig committed Jan 4, 2024
1 parent e1dfaa1 commit 6d56268
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 7 deletions.
1 change: 0 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"description": "use HIP back-end on AMD GPUs",
"inherits": "develop",
"cacheVariables": {
"CMAKE_CXX_COMPILER": "hipcc",
"alpaka_ACC_CPU_B_SEQ_T_SEQ_ENABLE": "ON",
"alpaka_ACC_GPU_HIP_ENABLE": "ON"
}
Expand Down
1 change: 0 additions & 1 deletion cmake/addExecutable.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ macro(alpaka_add_executable In_Name)
foreach(_file ${ARGN})
if((${_file} MATCHES "\\.cpp$") OR
(${_file} MATCHES "\\.cxx$") OR
(${_file} MATCHES "\\.cu$") OR
(${_file} MATCHES "\\.hip$")
)
set_source_files_properties(${_file} PROPERTIES LANGUAGE HIP)
Expand Down
1 change: 0 additions & 1 deletion cmake/addLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ macro(alpaka_add_library libraryName)
foreach(_file ${ARGN})
if((${_file} MATCHES "\\.cpp$") OR
(${_file} MATCHES "\\.cxx$") OR
(${_file} MATCHES "\\.cu$") OR
(${_file} MATCHES "\\.hip$")
)
set_source_files_properties(${_file} PROPERTIES LANGUAGE HIP)
Expand Down
22 changes: 20 additions & 2 deletions cmake/alpakaCommon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -512,14 +512,32 @@ if(alpaka_ACC_GPU_HIP_ENABLE)
if(CMAKE_HIP_COMPILER)
enable_language(HIP)
find_package(hip REQUIRED)
target_link_libraries(alpaka INTERFACE "$<$<LINK_LANGUAGE:CXX>:hip::host")

set(_alpaka_HIP_MIN_VER 5.1)
set(_alpaka_HIP_MAX_VER 6.0)

# construct hip version only with major and minor level
# cannot use hip_VERSION because of the patch level
# 6.0 is smaller than 6.0.1234, so _alpaka_HIP_MAX_VER would have to be defined with a large patch level or
# the next minor level, e.g. 6.1, would have to be used.
set(_hip_MAJOR_MINOR_VERSION "${hip_VERSION_MAJOR}.${hip_VERSION_MINOR}")

if(${_hip_MAJOR_MINOR_VERSION} VERSION_LESS ${_alpaka_HIP_MIN_VER} OR ${_hip_MAJOR_MINOR_VERSION} VERSION_GREATER ${_alpaka_HIP_MAX_VER})
message(WARNING "HIP ${_hip_MAJOR_MINOR_VERSION} is not official supported by alpaka. Supported versions: ${_alpaka_HIP_MIN_VER} - ${_alpaka_HIP_MAX_VER}")
endif()


target_link_libraries(alpaka INTERFACE "$<$<LINK_LANGUAGE:CXX>:hip::host>")
alpaka_set_compiler_options(HOST_DEVICE target alpaka "$<$<COMPILE_LANGUAGE:CXX>:-D__HIP_PLATFORM_AMD__>")
# only required for HIP 5.1 and maybe older
alpaka_set_compiler_options(HOST_DEVICE target alpaka "$<$<COMPILE_LANGUAGE:CXX>:-D__HIP_PLATFORM_HCC__>")

alpaka_compiler_option(HIP_KEEP_FILES "Keep all intermediate files that are generated during internal compilation steps 'CMakeFiles/<targetname>.dir'" OFF)
if(alpaka_HIP_KEEP_FILES)
alpaka_set_compiler_options(HOST_DEVICE target alpaka "$<$<COMPILE_LANGUAGE:HIP>:SHELL:-save-temps>")
endif()

if(alpaka_FAST_MATH)
if(alpaka_FAST_MATH STREQUAL ON)
alpaka_set_compiler_options(DEVICE target alpaka "$<$<COMPILE_LANGUAGE:HIP>:SHELL:-ffast-math>")
endif()

Expand Down
2 changes: 1 addition & 1 deletion docs/source/advanced/cmake.rst
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ alpaka_ACC_GPU_HIP_ONLY_MODE
Only back-ends using HIP can be enabled in this mode.
GPU_TARGETS
CMAKE_HIP_ARCHITECTURES
.. code-block::
Set the GPU architecture: e.g. "gfx900;gfx906;gfx908".
Expand Down
2 changes: 1 addition & 1 deletion script/install_hip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ fi
if [ -z ${CI_GPU_ARCH+x} ] ; then
# In case the runner is not providing a GPU architecture e.g. a CPU runner set the architecture
# to Radeon VII or MI50/60.
export GPU_TARGETS="gfx906"
export CMAKE_HIP_ARCHITECTURES="gfx906"
fi

# environment overview
Expand Down

0 comments on commit 6d56268

Please sign in to comment.