Skip to content

Commit

Permalink
getting started with HIP support
Browse files Browse the repository at this point in the history
  • Loading branch information
evaleev committed Sep 17, 2023
1 parent 881bb5a commit fa52e10
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
11 changes: 6 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,8 @@ add_feature_info(TBB ENABLE_TBB "Intel Thread-Building Blocks (TBB) supports pro
option(ENABLE_CUDA "Enable use of CUDA with TiledArray" OFF)
add_feature_info(CUDA ENABLE_CUDA "NVIDIA CUDA support for GPU")

if(ENABLE_CUDA)
option(ENABLE_CUDA_ERROR_CHECK "TiledArray will always check errors in CUDA calls" ON)
add_feature_info(CUDA_ERROR_CHECK ENABLE_CUDA_ERROR_CHECK "Checks CUDA Error")
endif()
option(ENABLE_HIP "Enable use of HIP with TiledArray" OFF)
add_feature_info(HIP ENABLE_HIP "AMD HIP/ROCm support for GPU")

option(ENABLE_GPERFTOOLS "Enable linking with Gperftools" OFF)
add_feature_info(GPERFTOOLS ENABLE_GPERFTOOLS "Google Performance Tools provide fast memory allocation and performance profiling")
Expand Down Expand Up @@ -306,10 +304,13 @@ include_directories(${PROJECT_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}/src)
add_custom_target(External-tiledarray)

# required deps:
# 1. CUDA first since others may depend on it
# 1. derive runtime (CUDA/HIP/...) first since others may depend on it
if(ENABLE_CUDA)
include(external/cuda.cmake)
endif()
if(ENABLE_HIP)
include(external/hip.cmake)
endif()
if (TA_TTG)
include(${PROJECT_SOURCE_DIR}/cmake/modules/FindOrFetchTTG.cmake)
endif(TA_TTG)
Expand Down
2 changes: 1 addition & 1 deletion INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ Support for execution on CUDA-enabled hardware is controlled by the following va

* `ENABLE_CUDA` -- Set to `ON` to turn on CUDA support. [Default=OFF].
* `CMAKE_CUDA_HOST_COMPILER` -- Set to the path to the host C++ compiler to be used by CUDA compiler. CUDA compilers used to be notorious for only being able to use specific C++ host compilers, but support for more recent C++ host compilers has improved. The default is determined by the CUDA compiler and the user environment variables (`PATH` etc.).
* `ENABLE_CUDA_ERROR_CHECK` -- Set to `ON` to turn on assertions for successful completion of calls to CUDA runtime and libraries. [Default=OFF].
* `ENABLE_HIP` -- Set to `ON` to turn on HIP support. [Default=OFF].
* `LIBRETT_INSTALL_DIR` -- the installation prefix of the pre-installed LibreTT library. This should not be normally needed; it is strongly recommended to let TiledArray build and install LibreTT.
* `UMPIRE_INSTALL_DIR` -- the installation prefix of the pre-installed Umpire library. This should not be normally needed; it is strongly recommended to let TiledArray build and install Umpire.

Expand Down
5 changes: 1 addition & 4 deletions external/cuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ enable_language(CUDA)

set(CUDA_FOUND TRUE)
set(TILEDARRAY_HAS_CUDA 1 CACHE BOOL "Whether TiledArray has CUDA support")

if(ENABLE_CUDA_ERROR_CHECK)
set (TILEDARRAY_CHECK_CUDA_ERROR 1)
endif(ENABLE_CUDA_ERROR_CHECK)
set(TILEDARRAY_CHECK_CUDA_ERROR 1 CACHE BOOL "Whether TiledArray will check CUDA errors")

# find CUDA toolkit
# NB CUDAToolkit does NOT have COMPONENTS
Expand Down
36 changes: 36 additions & 0 deletions external/hip.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# cmake 3.21 introduced HIP language support
cmake_minimum_required(VERSION 3.21.0)
set(CMAKE_HIP_STANDARD 17)
set(CMAKE_HIP_EXTENSIONS OFF)
set(CMAKE_HIP_STANDARD_REQUIRED ON)
# N.B. need relaxed constexpr for std::complex
# see https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#constexpr-functions%5B/url%5D:
if (DEFINED CMAKE_HIP_FLAGS)
set(CMAKE_HIP_FLAGS "--expt-relaxed-constexpr ${CMAKE_HIPE_FLAGS}")
else()
set(CMAKE_HIP_FLAGS "--expt-relaxed-constexpr")
endif()
enable_language(HIP)

set(HIP_FOUND TRUE)
set(TILEDARRAY_HAS_HIP 1 CACHE BOOL "Whether TiledArray has HIP support")
set(TILEDARRAY_CHECK_HIP_ERROR 1 CACHE BOOL "Whether TiledArray will check HIP errors")

# find HIP components
find_package(hipblas REQUIRED)

foreach (library hipblas)
if (NOT TARGET roc::${library})
message(FATAL_ERROR "roc::${library} not found")
endif()
endforeach()

##
## Umpire
##
include(external/umpire.cmake)

##
## LibreTT
##
include(external/librett.cmake)

0 comments on commit fa52e10

Please sign in to comment.