Skip to content

Simplify the CMake ROCm detection #419

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

Merged
merged 44 commits into from
Feb 4, 2021
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
924c0f7
Add FindHIP.cmake module
haampie Jan 12, 2021
b27dc5f
wip: simplify finding rocm through find_package and config files
haampie Jan 12, 2021
0d7b68e
Do not use device compiler openmp, since it's only relevant on the host
haampie Jan 13, 2021
24d3218
Fix C interface (todo: check when this was introduced)
haampie Jan 13, 2021
972d4c9
Force looking in config mode
haampie Jan 13, 2021
e894221
Add a CMAKE_PREFIX_PATH for ROCm in CI
haampie Jan 13, 2021
c11b65a
Enable examples in CI, cause they caused linking issues previously
haampie Jan 13, 2021
0eac0b7
Drop local FindHIP module, just temporarily add external CMAKE_MODULE…
haampie Jan 13, 2021
57789d2
Format cmake
haampie Jan 13, 2021
940ff7c
Enable PIC for object lib only
haampie Jan 13, 2021
a6015be
Only compile *.cu with device compiler
haampie Jan 13, 2021
5961cb7
Prepend C api with c_dbsr_*
haampie Jan 14, 2021
4a69f6c
use hip::host to get the proper defines etc
haampie Jan 14, 2021
48bb7a9
so... we don't have device code at compile time, no need to use a dev…
haampie Jan 14, 2021
00b49f9
No need to find HIP anymore, since we don't need the device compiler …
haampie Jan 15, 2021
f1c1aa2
use STATUS
haampie Jan 15, 2021
fae8cee
Remove more of hipcc
haampie Jan 15, 2021
746423d
Update workaround issues
haampie Jan 18, 2021
ee457a7
Fixes for HIP_ROCclr not defining __HIP
haampie Jan 18, 2021
05495f2
Simplify architecture flag
haampie Jan 18, 2021
cb89c35
Use .cu to help clang detect language
haampie Jan 18, 2021
f43ed99
Use -Wno-error=deprecated-declarations to make CI pass. Deprecations …
haampie Jan 18, 2021
99214ac
Ignore spack-* for spack dev-build
haampie Jan 27, 2021
9f8cb27
Merge hip / cuda cmake stuff
haampie Jan 28, 2021
cad249a
Drop openmp linking from cpp tests
haampie Jan 28, 2021
59aec5b
just move everything to the sources of dbcsr
haampie Jan 28, 2021
72d5d01
Fix deprecation warning / error
haampie Jan 29, 2021
5fa6178
Drop -Werror in Release
haampie Jan 29, 2021
b1f0efc
Fix some comments
haampie Jan 29, 2021
33b4138
Get things to compile
haampie Feb 2, 2021
b9e2109
make dbcsr_acc_test use include acc/acc.h
haampie Feb 3, 2021
708fc2d
wip fix cmake opencl
haampie Feb 3, 2021
4c2bdaf
Prefix acc_* with c_dbcsr_* to avoid clashes with potential openacc f…
haampie Feb 3, 2021
0a01c25
Only generate header file in smm/cmakelists.txt, don't add sources
haampie Feb 3, 2021
423c571
Fix disturbing curly-brace
haampie Feb 3, 2021
4a5be4e
just use Openmp::OpenMP instead of language specific targets
haampie Feb 3, 2021
70825c3
Fix an issue for AMD OpenCL where TA is the string "long" instead of …
haampie Feb 3, 2021
746861c
Turns out there is no OpenMP::OpenMP, so specify all languages
haampie Feb 3, 2021
c585373
Bump CMake version in CI
haampie Feb 3, 2021
ef06ce2
Bump required CMake version to 3.17
haampie Feb 3, 2021
5d89b94
Fix comment
haampie Feb 4, 2021
65dc8c5
Fix test names
haampie Feb 4, 2021
e9bcce3
Fix tests
haampie Feb 4, 2021
f415150
Sprinkle REQUIRED and make OpenCL require libxsmm
haampie Feb 4, 2021
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
2 changes: 1 addition & 1 deletion .ci/daint.cscs.ch/cray.build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set -o errexit
set -o nounset
set -o pipefail

module load daint-gpu cudatoolkit CMake/3.14.5
module load daint-gpu cudatoolkit CMake/3.18.4
module unload cray-libsci_acc
# make sure a recent GCC is available as NVCC backend:
# nvcc does not automatically use Cray's CC as backend
Expand Down
2 changes: 1 addition & 1 deletion .ci/daint.cscs.ch/cray.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ set -o errexit
set -o nounset
set -o pipefail

module load daint-gpu cudatoolkit CMake/3.14.5
module load daint-gpu cudatoolkit CMake/3.18.4
module unload cray-libsci_acc
module list

Expand Down
2 changes: 1 addition & 1 deletion .ci/daint.cscs.ch/gnu.build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set -o nounset
set -o pipefail

module swap PrgEnv-cray PrgEnv-gnu
module load daint-gpu cudatoolkit CMake/3.14.5
module load daint-gpu cudatoolkit CMake/3.18.4
module unload cray-libsci_acc
module list

Expand Down
2 changes: 1 addition & 1 deletion .ci/daint.cscs.ch/gnu.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set -o nounset
set -o pipefail

module swap PrgEnv-cray PrgEnv-gnu
module load daint-gpu cudatoolkit CMake/3.14.5
module load daint-gpu cudatoolkit CMake/3.18.4
module unload cray-libsci_acc
module list

Expand Down
2 changes: 1 addition & 1 deletion .ci/daint.cscs.ch/intel.build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set -o nounset
set -o pipefail

module swap PrgEnv-cray PrgEnv-intel
module load daint-gpu cudatoolkit CMake/3.14.5
module load daint-gpu cudatoolkit CMake/3.18.4
module unload cray-libsci_acc
# make sure a recent GCC is available as NVCC backend:
# nvcc does not automatically use Cray's CC as backend
Expand Down
2 changes: 1 addition & 1 deletion .ci/daint.cscs.ch/intel.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set -o nounset
set -o pipefail

module swap PrgEnv-cray PrgEnv-intel
module load daint-gpu cudatoolkit CMake/3.14.5
module load daint-gpu cudatoolkit CMake/3.18.4
module unload cray-libsci_acc
module list

Expand Down
2 changes: 1 addition & 1 deletion .ci/daint.cscs.ch/ocl.build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set -o nounset
set -o pipefail

module swap PrgEnv-cray PrgEnv-gnu
module load daint-gpu cudatoolkit CMake/3.14.5
module load daint-gpu cudatoolkit CMake/3.18.4
module unload cray-libsci_acc
module list

Expand Down
2 changes: 1 addition & 1 deletion .ci/daint.cscs.ch/ocl.test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ set -o nounset
set -o pipefail

module swap PrgEnv-cray PrgEnv-gnu
module load daint-gpu cudatoolkit CMake/3.14.5
module load daint-gpu cudatoolkit CMake/3.18.4
module unload cray-libsci_acc
module list

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/testing-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ jobs:
-DUSE_${{ matrix.use_openmp }} \
-DUSE_ACCEL=hip \
-DWITH_GPU=Mi50 \
-DWITH_EXAMPLES=ON \
-DCMAKE_PREFIX_PATH=/opt/rocm \
..
- name: Build
run: cmake --build build -- --verbose
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -223,3 +223,5 @@ tags
.tags

# End of https://www.gitignore.io/api/vim,emacs,python,fortran

spack-*
124 changes: 16 additions & 108 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.12)
cmake_minimum_required(VERSION 3.17)

# include our cmake snippets
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
Expand Down Expand Up @@ -152,8 +152,6 @@ endif ()
# =================================== MPI
if (USE_MPI)
get_property(REQUIRED_MPI_COMPONENTS GLOBAL PROPERTY ENABLED_LANGUAGES)
list(REMOVE_ITEM REQUIRED_MPI_COMPONENTS CUDA) # CUDA does not have an MPI
# component
if (NOT CMAKE_CROSSCOMPILING) # when cross compiling, assume the users know
# what they are doing
set(MPI_DETERMINE_LIBRARY_VERSION TRUE)
Expand Down Expand Up @@ -183,24 +181,18 @@ endif ()

# =================================== SMM (Small Matrix-Matrix multiplication)
if (USE_SMM MATCHES "blas")
message("-- Using BLAS for Small Matrix Multiplication")
message(STATUS "Using BLAS for Small Matrix Multiplication")
elseif (USE_SMM MATCHES "libxsmm")
if (LIBXSMM_FOUND)
message("-- Using LIBXSMM for Small Matrix Multiplication")
else ()
message(
FATAL_ERROR
"LIBXSMM is not found but requested (USE_SMM). "
"Please install PkgConfig, build LIBXSMM, and "
"set PKG_CONFIG_PATH=/path/to/libxsmm/lib")
endif ()
# rely on pkg-config in order to link against libxsmm
pkg_check_modules(deps REQUIRED IMPORTED_TARGET GLOBAL libxsmmf)
message(STATUS "Using libxsmm for Small Matrix Multiplication")
else ()
message(FATAL_ERROR "Unknown SMM library specified")
endif ()

# =================================== GPU backends
if (USE_ACCEL MATCHES "opencl")
if (NOT LIBXSMM_FOUND)
if (NOT USE_SMM)
message(
FATAL_ERROR
"LIBXSMM is not found but required for "
Expand All @@ -224,8 +216,9 @@ if (USE_ACCEL MATCHES "cuda|hip")
endif ()

if (USE_ACCEL MATCHES "cuda")
enable_language(CUDA)
if (CMAKE_CUDA_COMPILER_VERSION LESS 5.5)
find_package(CUDAToolkit REQUIRED)

if (CUDAToolkit_VERSION LESS 5.5)
message(FATAL_ERROR "CUDA version >= 5.5 is required.")
endif ()

Expand All @@ -237,43 +230,14 @@ if (USE_ACCEL MATCHES "cuda")
"Please choose from: ${SUPPORTED_CUDA_ARCHITECTURES}")
endif ()

# assume that the backend compiler for nvcc understands the -std=c++11
set(CMAKE_CUDA_STANDARD 11)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)

# set cuda architecture number and compilation flags
set(ACC_ARCH_NUMBER ${GPU_ARCH_NUMBER_${WITH_GPU}})
# TODO: use CMAKE_CUDA_RUNTIME_LIBRARY with CMake 3.17+ and CUDA_ARCHITECTURES
# with CMake 3.18+
string(APPEND CMAKE_CUDA_FLAGS " -arch=sm_${ACC_ARCH_NUMBER} --cudart static")
add_compile_definitions($<$<COMPILE_LANGUAGE:CUDA>:__CUDA>)

message(STATUS "GPU target architecture: " ${WITH_GPU})
message(STATUS "GPU architecture number: " ${ACC_ARCH_NUMBER})
message(STATUS "GPU profiling enabled: " ${WITH_CUDA_PROFILING})

# =================================== BLAS on GPU backend
find_library(CUBLAS cublas HINT ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES})
if (NOT CUBLAS)
message(
FATAL_ERROR
"cuBLAS library not found but support required for DBCSR's CUDA backend"
)
else ()
message(STATUS "Found cuBLAS: ${CUBLAS}")
endif ()
if (WITH_CUDA_PROFILING)
find_library(
CUDA_NVTOOLSEXT nvToolsExt
PATHS ${CMAKE_CUDA_IMPLICIT_LINK_DIRECTORIES}
DOC "Building with CUDA profiling requires the nvToolsExt CUDA library"
REQUIRED)
message(STATUS "Found nvToolsExt: ${CUDA_NVTOOLSEXT}")
endif ()

endif ()

# inspired from
# https://github.com/ROCm-Developer-Tools/HIP/tree/master/samples/2_Cookbook/12_cmake_hip_add_executable
if (USE_ACCEL MATCHES "hip")
# Make sure the GPU required is supported
list(FIND SUPPORTED_HIP_ARCHITECTURES ${WITH_GPU} GPU_SUPPORTED)
Expand All @@ -283,20 +247,8 @@ if (USE_ACCEL MATCHES "hip")
"Please choose from: ${SUPPORTED_HIP_ARCHITECTURES}")
endif ()

# Set path to HIP installation, include HIP cmake utilities
if (NOT DEFINED HIP_PATH)
if (NOT DEFINED ENV{HIP_PATH})
set(HIP_PATH
"/opt/rocm/hip"
CACHE PATH "Path to HIP installation")
else ()
set(HIP_PATH
$ENV{HIP_PATH}
CACHE PATH "Path to HIP installation")
endif ()
endif ()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${HIP_PATH}/cmake")

# ROCm is typically installed in /opt/rocm; otherwise let the user set
# ROCM_PATH as an environment variable or define.
if (NOT DEFINED ROCM_PATH)
if (NOT DEFINED ENV{ROCM_PATH})
set(ROCM_PATH
Expand All @@ -309,60 +261,16 @@ if (USE_ACCEL MATCHES "hip")
endif ()
endif ()

# Find HIP package
find_package(HIP)
if (HIP_FOUND)
message(STATUS "Found HIP: " ${HIP_VERSION})
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 ()

# Find hiprtc library (adds support for JIT-ing in HIP)
find_library(ROCM_HIPRTC_LIB amdhip64 HINTS ${HIP_PATH}/lib)
if (NOT ROCM_HIPRTC_LIB)
message(
FATAL_ERROR "HIPRTC (HIP library for just-in-time compilation) not found")
endif ()
set(ENV{HIP_PATH} /opt/rocm/hip) # workaround bug in hiprtc.cpp
# Notice: this is not FindHIP.cmake for hip language support, but
# hip-config.cmake which contains targets like hip::host for jitting.
find_package(hip CONFIG REQUIRED HINTS ${ROCM_PATH})

# Set platform to compile for (NVIDIA-nvcc or ROCm-hcc) as well as
# corresponding architecture and flags adapted from:
# https://github.com/ROCmSoftwarePlatform/hipDNN/blob/master/CMakeLists.txt
execute_process(COMMAND ${HIP_PATH}/bin/hipconfig -P
OUTPUT_VARIABLE HIP_PLATFORM)
message(STATUS "Compiling for platform: " ${HIP_PLATFORM})

# set appropriate compilation flags depending on platform
set(ACC_ARCH_NUMBER ${GPU_ARCH_NUMBER_${WITH_GPU}})
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -D__HIP -O3")
if (${HIP_PLATFORM} STREQUAL "nvcc")
set(HIP_HIPCC_FLAGS
"${HIP_HIPCC_FLAGS} -std=c++11 -arch=sm_${ACC_ARCH_NUMBER} --cudart static"
)
else ()
set(HIP_HIPCC_FLAGS "${HIP_HIPCC_FLAGS} -fPIC")
endif ()
message(STATUS "GPU target architecture: " ${WITH_GPU})
message(STATUS "GPU architecture number: " ${ACC_ARCH_NUMBER})
message(STATUS "HIPCC flags: " ${HIP_HIPCC_FLAGS})
if (USE_OPENMP)
set(HIP_OpenMP_FLAGS "-L${ROCM_PATH}/llvm/lib -lomp")
message(STATUS "HIP OpenMP linking flags: ${HIP_OpenMP_FLAGS}")
endif ()

# =================================== BLAS on GPU backend
find_library(HIPBLAS hipblas HINTS ${HIP_PATH}/../lib) # /opt/rocm/lib
if (NOT HIPBLAS)
message(
FATAL_ERROR
"hipBLAS library not found but support required for DBCSR's HIP backend"
)
else ()
message(STATUS "Found hipBLAS: ${HIPBLAS}")
endif ()
find_package(hipblas CONFIG REQUIRED HINTS ${ROCM_PATH})
endif ()

# =================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion cmake/CompilerConfiguration.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Please open an issue at https://github.com/cp2k/dbcsr/issues with the reported c
endif ()

if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g -funroll-loops -Wall -Werror")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g -funroll-loops -Wall")
set(CMAKE_CXX_FLAGS_COVERAGE "-O0 -g --coverage -Wall -Werror")
set(CMAKE_CXX_FLAGS_DEBUG "-O2 -ggdb -Wall -Werror -fsanitize=undefined -fsanitize=address -fsanitize-recover=all")
if ((NOT (USE_MPI)) OR (NOT ("${MPI_Fortran_LIBRARY_VERSION_STRING}" MATCHES "Open MPI")))
Expand Down
7 changes: 5 additions & 2 deletions docs/guide/2-user-guide/1-installation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ If MPI support is enabled (the default), the C API is automatically built.

### Workaround issue in HIP

HIP is a relatively new language, and some issues still need to be ironed out. As a workaround to an [issue](https://github.com/ROCm-Developer-Tools/HIP/pull/1543) in HIP's JIT infrastructure, please set the following if you've built HIP from source:
For custom installs of HIP 3.9.0 and above, some paths have to be configured to ensure the JIT compiler can locate the HIP runtime and compiler tools

```bash
export HIP_PATH=/opt/rocm/hip
export ROCM_PATH=/path/to/hip-3.9.0
export HIP_PATH=$ROCM_PATH
export LLVM_PATH=/path/to/llvm-amdgpu-3.9.0
export HIP_DEVICE_LIB_PATH=/path/to/rocm-device-libs-3.9.0/amdgcn/bitcode
```

before running on an AMD GPU.
12 changes: 2 additions & 10 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ set(DBCSR_PROGRAM_SRCS_CPP dbcsr_example_3.cpp dbcsr_tensor_example_2.cpp)
# Compile Fortran examples
foreach (dbcsr_program_src ${DBCSR_PROGRAM_SRCS_FTN})
get_filename_component(dbcsr_program_name ${dbcsr_program_src} NAME_WE)
if (USE_ACCEL MATCHES "hip")
hip_add_executable(${dbcsr_program_name} ${dbcsr_program_src})
else ()
add_executable(${dbcsr_program_name} ${dbcsr_program_src})
endif ()
add_executable(${dbcsr_program_name} ${dbcsr_program_src})
target_link_libraries(${dbcsr_program_name} dbcsr)

# with the Intel compiler CMake 3.12 seems to forget that the source is
Expand All @@ -24,11 +20,7 @@ if (WITH_C_API)
foreach (dbcsr_program_src ${DBCSR_PROGRAM_SRCS_CPP})
get_filename_component(dbcsr_program_name ${dbcsr_program_src} NAME_WE)
set(dbcsr_program_name ${dbcsr_program_name}_cpp)
if (USE_ACCEL MATCHES "hip")
hip_add_executable(${dbcsr_program_name} ${dbcsr_program_src})
else ()
add_executable(${dbcsr_program_name} ${dbcsr_program_src})
endif ()
add_executable(${dbcsr_program_name} ${dbcsr_program_src})
target_link_libraries(${dbcsr_program_name} dbcsr_c MPI::MPI_CXX)

if (CMAKE_CXX_COMPILER_ID STREQUAL "Cray")
Expand Down
Loading