From ccce1a2860f9ae74d81ee4c998cf4510d7d2f5c9 Mon Sep 17 00:00:00 2001 From: Eduard Valeyev Date: Sun, 17 Sep 2023 20:14:37 -0400 Subject: [PATCH] librett.cmake: support HIP --- external/librett.cmake | 54 +++++++++++++++++++++++++++++------------- 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/external/librett.cmake b/external/librett.cmake index aa1287d90d..9774a84152 100644 --- a/external/librett.cmake +++ b/external/librett.cmake @@ -37,11 +37,6 @@ else() message("** Will clone LibreTT from ${LIBRETT_URL}") - # need to change the separator of list to avoid issues with ExternalProject parsing -# set(CUDA_FLAGS "${CUDA_NVCC_FLAGS}") -# string(REPLACE ";" "::" CUDA_FLAGS "${CUDA_NVCC_FLAGS}") - #message(STATUS "CUDA_FLAGS: " "${CUDA_FLAGS}") - set(LIBRETT_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${EXTERNAL_INSTALL_DIR} -DBUILD_SHARED_LIBS=${BUILD_SHARED_LIBS} @@ -62,22 +57,37 @@ else() -DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} -DCMAKE_CXX_EXTENSIONS=${CMAKE_CXX_EXTENSIONS} -DCMAKE_AR=${CMAKE_AR} - -DCMAKE_CUDA_COMPILER=${CMAKE_CUDA_COMPILER} - -DCMAKE_CUDA_STANDARD=${CMAKE_CUDA_STANDARD} - -DCMAKE_CUDA_EXTENSIONS=${CMAKE_CUDA_EXTENSIONS} -DENABLE_UMPIRE=OFF # N.B. ThreadSafeUMDynamicPool this no longer exists!!! Must teach LibreTT to take allocate/deallocate methods # from the user code -DLIBRETT_USES_THIS_UMPIRE_ALLOCATOR=ThreadSafeUMDynamicPool -DCMAKE_PREFIX_PATH=${_UMPIRE_INSTALL_DIR} -DENABLE_NO_ALIGNED_ALLOC=ON - -DCMAKE_CUDA_HOST_COMPILER=${CMAKE_CUDA_HOST_COMPILER} - -DCUDA_TOOLKIT_ROOT_DIR=${CUDAToolkit_ROOT} - -DENABLE_CUDA=ON ) - if (DEFINED CMAKE_CUDA_ARCHITECTURES) - list(APPEND LIBRETT_CMAKE_ARGS -DCMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES}) - endif(DEFINED CMAKE_CUDA_ARCHITECTURES) + if (ENABLE_CUDA) + list(APPEND LIBRETT_CMAKE_ARGS + -DENABLE_CUDA=ON + -DCMAKE_CUDA_COMPILER=${CMAKE_CUDA_COMPILER} + -DCMAKE_CUDA_STANDARD=${CMAKE_CUDA_STANDARD} + -DCMAKE_CUDA_EXTENSIONS=${CMAKE_CUDA_EXTENSIONS} + -DCMAKE_CUDA_HOST_COMPILER=${CMAKE_CUDA_HOST_COMPILER} + -DCUDA_TOOLKIT_ROOT_DIR=${CUDAToolkit_ROOT} + ) + if (DEFINED CMAKE_CUDA_ARCHITECTURES) + list(APPEND LIBRETT_CMAKE_ARGS -DCMAKE_CUDA_ARCHITECTURES=${CMAKE_CUDA_ARCHITECTURES}) + endif(DEFINED CMAKE_CUDA_ARCHITECTURES) + endif() + if (ENABLE_HIP) + list(APPEND LIBRETT_CMAKE_ARGS + -DENABLE_HIP=ON + -DCMAKE_HIP_COMPILER=${CMAKE_HIP_COMPILER} + -DCMAKE_HIP_STANDARD=${CMAKE_HIP_STANDARD} + -DCMAKE_HIP_EXTENSIONS=${CMAKE_HIP_EXTENSIONS} + ) + if (DEFINED CMAKE_HIP_ARCHITECTURES) + list(APPEND LIBRETT_CMAKE_ARGS -DCMAKE_HIP_ARCHITECTURES=${CMAKE_HIP_ARCHITECTURES}) + endif(DEFINED CMAKE_HIP_ARCHITECTURES) + endif() if (CMAKE_TOOLCHAIN_FILE) set(LIBRETT_CMAKE_ARGS "${LIBRETT_CMAKE_ARGS}" "-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}") @@ -147,9 +157,21 @@ set_target_properties(TiledArray_LIBRETT "$;$" INTERFACE_LINK_LIBRARIES "$;$" - INTERFACE_COMPILE_DEFINITIONS - "LIBRETT_USES_CUDA=1" ) +if (ENABLE_CUDA) + set_target_properties(TiledArray_LIBRETT + PROPERTIES + INTERFACE_COMPILE_DEFINITIONS + "LIBRETT_USES_CUDA=1" + ) +endif() +if (ENABLE_HIP) + set_target_properties(TiledArray_LIBRETT + PROPERTIES + INTERFACE_COMPILE_DEFINITIONS + "LIBRETT_USES_HIP=1" + ) +endif() install(TARGETS TiledArray_LIBRETT EXPORT tiledarray COMPONENT tiledarray)