Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: add HIP support #1316

Merged
merged 77 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
886c4d1
CMake: first basic attempt at HIP support
mic84 Aug 26, 2020
bb1a732
Update Tools/CMake/AMReXParallelBackends.cmake
mic84 Sep 3, 2020
99fcf6f
CI: Add HIP-Clang
ax3l Sep 3, 2020
a70eaef
fix typo: GCC 9.3 on focal
ax3l Sep 3, 2020
37f99b0
Fix sources: set two lists
ax3l Sep 3, 2020
3a49fd7
fix target properties: append two lists
ax3l Sep 3, 2020
eab4262
Merge branch 'development' into mr/cmake-hip-support
mic84 Sep 15, 2020
1746fc9
CMake: some changes to debug issue with generated files
mic84 Sep 15, 2020
7b60320
CI: only run HIP check for now
mic84 Sep 15, 2020
10631a1
CMake: fix typo
mic84 Sep 15, 2020
dba7fb5
Merge remote-tracking branch 'upstream/development' into mr/cmake-hip…
mic84 Sep 16, 2020
f1df1eb
CMake: let's try this
mic84 Sep 16, 2020
cf08282
CMake: other small modifications
mic84 Sep 16, 2020
6adaa30
Merge branch 'development' into mr/cmake-hip-support
mic84 Sep 16, 2020
c94a81c
CMake: attemp #1
mic84 Sep 16, 2020
2c5f683
CMake: attemp #2
mic84 Sep 16, 2020
9c8421c
CI: build just the bare minimum for now
mic84 Sep 16, 2020
2f6b512
CMake: attempt #3
mic84 Sep 16, 2020
abb0a68
CMake: missing defines for HIP builds
mic84 Sep 16, 2020
423f712
CMake: defines were still missing :-P
mic84 Sep 16, 2020
b93bb8a
CMake: AMREX_HIP_PLATFORM is actually the HIP_COMPILER
mic84 Sep 16, 2020
3dc551e
CMake: let's see if this works
mic84 Sep 16, 2020
8c39963
Install rocRAND
ax3l Sep 16, 2020
20ecb32
CMake: re-factor and update defines for HIP compilation
mic84 Sep 16, 2020
df3ab64
Merge branch 'mr/cmake-hip-support' of https://github.com/mic84/amrex…
mic84 Sep 16, 2020
545006c
CMake: list against hiprand too
mic84 Sep 16, 2020
d7e7cc4
CMake: find and link to hiprand
mic84 Sep 16, 2020
e77896d
CMake: add -DNDEBUG to any type of build when HIP is on
mic84 Sep 17, 2020
c0ec20e
CMake: we must manually add rocrand too
mic84 Sep 17, 2020
0650715
CMake: let's see if it works with Fortran enabled
mic84 Sep 17, 2020
6a92adc
Revert "CMake: let's see if it works with Fortran enabled"
mic84 Sep 17, 2020
5055e23
CMake: try this
mic84 Sep 17, 2020
59e3102
CMake: this should work too
mic84 Sep 17, 2020
090373a
Revert "Revert "CMake: let's see if it works with Fortran enabled""
mic84 Sep 17, 2020
02402cc
CMake: no fortran for now
mic84 Sep 17, 2020
c723560
CI: turn on linear solvers in HIP check
mic84 Sep 17, 2020
fb3fe4d
CI: turn on particles in HIP checks
mic84 Sep 17, 2020
957292b
Revert "CI: turn on linear solvers in HIP check"
mic84 Sep 17, 2020
f7360b9
CMake: hipify tutorials
mic84 Sep 17, 2020
bd6724e
CMake: temporary fix
mic84 Sep 17, 2020
6c0d6ad
Revert "CMake: temporary fix"
mic84 Sep 17, 2020
397025f
CMake: fix HIP compilation for Tutorials
mic84 Sep 17, 2020
ba066ee
CMake: some cleanup
mic84 Sep 17, 2020
e1a5119
CMake: add HIP options to pass in architecture and extra flags
mic84 Sep 17, 2020
1b132cf
CMake: oops
mic84 Sep 17, 2020
dcf068f
Merge remote-tracking branch 'upstream/development' into mr/cmake-hip…
mic84 Sep 22, 2020
e9dd41b
CMake: try to enable linear solvers
mic84 Sep 22, 2020
06571e3
CMake: update ROCm version number in CI check name
mic84 Sep 22, 2020
34c1327
Merge remote-tracking branch 'upstream/development' into mr/cmake-hip…
mic84 Sep 22, 2020
2b342dd
CMake: enable Fortran
mic84 Sep 22, 2020
885b911
CMake: disable tutorials for the time being
mic84 Sep 22, 2020
42d33bc
CMake: commit custom FindHIP.cmake to debug the issue
mic84 Sep 22, 2020
44b28b1
CMake: trying this
mic84 Sep 22, 2020
667ff84
CMake: now it should use the local FindHIP.cmake
mic84 Sep 22, 2020
d833855
CMake: now custom FindHIP.cmake should be able to find helper files
mic84 Sep 22, 2020
537aa3a
CMake: let's see if we really need this
mic84 Sep 22, 2020
0624090
CMake: let's try this
mic84 Sep 22, 2020
fe9c8c8
CMake: temporary fix
mic84 Sep 23, 2020
3065d2c
Revert "CMake: disable tutorials for the time being"
mic84 Sep 23, 2020
0155f99
CMake: Tutorials/Particles/CellSortedParticles do not work with HIP
mic84 Sep 23, 2020
31224a5
Merge remote-tracking branch 'upstream/development' into mr/cmake-hip…
mic84 Sep 26, 2020
6027cfd
CMake: remove local FindHIP.cmake.
mic84 Sep 26, 2020
7f49730
CMake: HIP arch flags are now PUBLIC and inheritable
mic84 Sep 26, 2020
f85dd52
CMake: no use for setup_target_for_hip_compilation anymore
mic84 Sep 26, 2020
1ecf913
CMake: remove unnecessary options for HIP
mic84 Sep 28, 2020
e2a90f4
CMake: check that HIP_COMPILER is the same as CMAKE_CXX_COMPILER
mic84 Sep 28, 2020
bdfa79c
CMake: better this
mic84 Sep 28, 2020
acd9a29
Merge branch 'development' into mr/cmake-hip-support
mic84 Sep 28, 2020
a5ef075
CI: uncomment all checks
mic84 Sep 28, 2020
6958531
Merge remote-tracking branch 'upstream/development' into mr/cmake-hip…
mic84 Sep 30, 2020
970498c
CMake: fix visibility of arch flags for HIP
mic84 Sep 30, 2020
cee5b29
Doc: add subsection on HIP+CMake
mic84 Sep 30, 2020
b270884
Merge branch 'mr/cmake-hip-support' of https://github.com/mic84/amrex…
mic84 Sep 30, 2020
f2f52c1
Update Docs/sphinx_documentation/source/GPU.rst
mic84 Sep 30, 2020
a21b031
Merge remote-tracking branch 'upstream/development' into mr/cmake-hip…
mic84 Oct 13, 2020
2d20303
CMake: fix incorrect configuration option passed to cmake
mic84 Oct 13, 2020
e343ef4
CI: target 'tutorials' no longer exists
mic84 Oct 13, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions .github/workflows/dependencies/dependencies_hip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
#
# Copyright 2020 The AMReX Community
#
# License: BSD-3-Clause-LBNL
# Authors: Axel Huebl

# search recursive inside a folder if a file contains tabs
#
# @result 0 if no files are found, else 1
#

set -eu -o pipefail

# Ref.: https://rocmdocs.amd.com/en/latest/Installation_Guide/Installation-Guide.html#ubuntu
wget -q -O - http://repo.radeon.com/rocm/rocm.gpg.key \
| sudo apt-key add -
echo 'deb [arch=amd64] http://repo.radeon.com/rocm/apt/debian/ xenial main' \
| sudo tee /etc/apt/sources.list.d/rocm.list

echo 'export PATH=$PATH:/opt/rocm/bin:/opt/rocm/profiler/bin:/opt/rocm/opencl/bin' \
| sudo tee -a /etc/profile.d/rocm.sh
# we should not need to export HIP_PATH=/opt/rocm/hip with those installs

sudo apt-get update

# Ref.: https://rocmdocs.amd.com/en/latest/Installation_Guide/Installation-Guide.html#installing-development-packages-for-cross-compilation
# meta-package: rocm-dkms
# OpenCL: rocm-opencl
# other: rocm-dev rocm-utils
sudo apt-get install -y --no-install-recommends \
build-essential \
gfortran \
libnuma-dev \
libopenmpi-dev \
openmpi-bin \
rocm-dev

23 changes: 23 additions & 0 deletions .github/workflows/linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,29 @@ jobs:
-DCMAKE_Fortran_COMPILER=$(which gfortran)
make -j 2 tutorials

tutorials-hip:
name: HIP ROCm@3.7 GFortran@9.3 C++17 [tutorials]
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Dependencies
run: .github/workflows/dependencies/dependencies_hip.sh
- name: Build & Install
run: |
source /etc/profile.d/rocm.sh
hipcc --version
mkdir build
cd build
cmake .. \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DENABLE_TUTORIALS=ON \
-DENABLE_PARTICLES=ON \
-DENABLE_HIP=ON \
-DCMAKE_C_COMPILER=$(which hipcc) \
-DCMAKE_CXX_COMPILER=$(which hipcc) \
-DCMAKE_Fortran_COMPILER=$(which gfortran)
make -j 2 tutorials

# Build 1D libamrex with configure
configure-1d:
name: GNU@7.5 Release [configure 1D]
Expand Down
9 changes: 8 additions & 1 deletion Src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Fist, define the library we want to add
# First, define the library we want to add
# Think of this as a constructor for object "amrex"
# In the following, we will use setters to change
# the properties of this object, like setting the sources,
Expand Down Expand Up @@ -178,6 +178,13 @@ if (ENABLE_CUDA)
setup_target_for_cuda_compilation( amrex )
endif ()

#
# If ENABLE_HIP, target 'amrex' requires a special treatment
#
if (ENABLE_HIP)
setup_target_for_hip_compilation( amrex )
endif ()


#
# Install amrex -- Export
Expand Down
35 changes: 35 additions & 0 deletions Tools/CMake/AMReXParallelBackends.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,38 @@ if (ENABLE_DPCPP)
include(AMReXSYCL)
target_link_libraries(amrex PUBLIC SYCL)
endif ()


#
#
# HIP
#
#
if (ENABLE_HIP)
if(NOT DEFINED HIP_PATH)
if(NOT DEFINED ENV{HIP_PATH})
set(HIP_PATH "/opt/rocm/hip" CACHE PATH "Path to which HIP has been installed")
else()
set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
endif()
endif()

set(CMAKE_MODULE_PATH "${HIP_PATH}/cmake" ${CMAKE_MODULE_PATH})

find_package(HIP REQUIRED)
if("${HIP_COMPILER}" STREQUAL "hcc")
message(FATAL_ERROR "Using (deprecated) HCC compiler: please update ROCm")
endif()

if(HIP_FOUND)
message(STATUS "Found HIP: ${HIP_VERSION}")
message(STATUS "HIP: Platform=${HIP_PLATFORM} Compiler=${HIP_COMPILER}")
else()
message(FATAL_ERROR "Could not find HIP."
" Ensure that HIP is either installed in /opt/rocm/hip or the variable HIP_PATH is set to point to the right location.")
endif()

# Let's put the defines here for the time being
target_compile_definitions( amrex PUBLIC AMREX_USE_HIP AMREX_HIP_PLATFORM=${HIP_PLATFORM} )

endif ()
37 changes: 37 additions & 0 deletions Tools/CMake/AMReXTargetHelpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,40 @@ function (setup_target_for_cuda_compilation _target)
)
set_cpp_sources_to_cuda_language(${_target})
endfunction ()


#
# Create target 'amrex-hip' by "cloning" target 'amrex' and
# adding HIP specific settings
#
function (setup_target_for_hip_compilation _target)

# Make C++ files with HIP_SOURCE_PROPERTY_FORMAT
# This will trigger HIP compilation of those files
get_target_property(_sources ${_target} SOURCES)
list(FILTER _sources INCLUDE REGEX "\\.cpp")
set_source_files_properties(${_sources} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)

# Separate the sources from the options
# HIP_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _hipcc_options _hcc_options _nvcc_options ${ARGN})
set(_cmake_options)
set(_hipcc_options)
set(_hcc_options)
set(_nvcc_options)
hip_prepare_target_commands(${_target}
OBJ _generated_files _source_files ${_sources} ${_cmake_options}
HIPCC_OPTIONS ${_hipcc_options}
HCC_OPTIONS ${_hcc_options}
NVCC_OPTIONS ${_nvcc_options})

if (_source_files)
list(REMOVE_ITEM _sources ${_source_files})
endif ()

# overwrite sources of _target with "new" sources
set_target_properties(${_target} PROPERTIES SOURCES "${_generated_files};${_sources}")

# set linker language
set_target_properties(${_target} PROPERTIES LINKER_LANGUAGE ${HIP_C_OR_CXX})

endfunction ()
4 changes: 4 additions & 0 deletions Tools/CMake/AMReX_Options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ cmake_dependent_option( ENABLE_CUDA "Enable GPU support via CUDA" OFF
"NOT ENABLE_DPCPP" OFF)
print_option( ENABLE_CUDA )

cmake_dependent_option( ENABLE_HIP "Enable GPU support via HIP" OFF
"NOT ENABLE_DPCPP;NOT ENABLE_CUDA" OFF)
print_option( ENABLE_HIP )

option( ENABLE_ACC "Enable GPU support via OpenACC" OFF )
print_option( ENABLE_ACC )

Expand Down