Skip to content

Commit

Permalink
use cmake HIP language support
Browse files Browse the repository at this point in the history
  • Loading branch information
gardner48 committed Nov 30, 2023
1 parent 12d8fb3 commit 191a313
Show file tree
Hide file tree
Showing 15 changed files with 52 additions and 34 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
# Initial setup.
# ===============================================================

cmake_minimum_required(VERSION 3.18)
cmake_minimum_required(VERSION 3.22)

# Project SUNDIALS (initially only C supported)
# sets PROJECT_SOURCE_DIR and PROJECT_BINARY_DIR variables.
Expand Down
11 changes: 10 additions & 1 deletion benchmarks/advection_reaction_3D/raja/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ if(BUILD_ARKODE AND BUILD_CVODE AND BUILD_IDA)

if(BUILD_NVECTOR_HIP)

set_source_files_properties(advection_reaction_3D.cpp
PROPERTIES LANGUAGE HIP)
set_source_files_properties(arkode_driver.cpp PROPERTIES LANGUAGE HIP)
set_source_files_properties(cvode_driver.cpp PROPERTIES LANGUAGE HIP)
set_source_files_properties(ida_driver.cpp PROPERTIES LANGUAGE HIP)

add_executable(advection_reaction_3D_raja_mpihip
advection_reaction_3D.cpp
advection_reaction_3D.hpp
Expand All @@ -152,6 +158,10 @@ if(BUILD_ARKODE AND BUILD_CVODE AND BUILD_IDA)
check_retval.h
backends.hpp)

# ensure the linker language is reset to CXX
# set_target_properties(advection_reaction_3D_raja_mpihip
# PROPERTIES LINKER_LANGUAGE CXX)

target_include_directories(advection_reaction_3D_raja_mpihip
PRIVATE
${PROJECT_SOURCE_DIR}/utilities
Expand All @@ -165,7 +175,6 @@ if(BUILD_ARKODE AND BUILD_CVODE AND BUILD_IDA)
sundials_nvecmpiplusx
sundials_nvechip
RAJA
hip::device
${MPI_CXX_LIBRARIES}
${OTHER_LIBS})

Expand Down
9 changes: 6 additions & 3 deletions benchmarks/diffusion_2D/mpi_gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ foreach(test_tuple ${tests})

else()

foreach(file ${sources})
set_source_files_properties(${file} PROPERTIES LANGUAGE HIP)
endforeach()

set(target ${package}_diffusion_2D_mpihip)

endif()
Expand All @@ -77,7 +81,7 @@ foreach(test_tuple ${tests})
# if("${backend}" STREQUAL "USE_CUDA")
# sundials_add_benchmark(${target} ${target} diffusion_2D
# ENABLE_GPU
# NUM_CORES ${SUNDIALS_BENCHMARK_NUM_GPUS}
# NUM_CORES ${SUNDIALS_BENCHMARK_NUM_GPUS}
# )
#endif()

Expand Down Expand Up @@ -115,8 +119,7 @@ foreach(test_tuple ${tests})
PRIVATE
sundials_${package}
sundials_nvecmpiplusx
sundials_nvechip
hip::device)
sundials_nvechip)

endif()

Expand Down
4 changes: 3 additions & 1 deletion cmake/SundialsSetupCompilers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,9 @@ endif()
# ===============================================================

if(ENABLE_HIP)
include(SundialsSetupHIP)
#include(SundialsSetupHIP)
enable_language(HIP)
set(HIP_FOUND TRUE)
# we treat HIP as both a TPL and a language
list(APPEND SUNDIALS_TPL_LIST "HIP")
endif()
Expand Down
5 changes: 0 additions & 5 deletions cmake/SundialsSetupCuda.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@
# Setup the CUDA languge and CUDA libraries.
# ---------------------------------------------------------------

# For CUDA support, require CMake 3.18 so we can use FindCUDAToolkit
# FindCUDAToolkit was introduced in 3.17, but 3.18 fixes a lot
# of issues with it and CUDA as a native language.
cmake_minimum_required(VERSION 3.18.0)

# ===============================================================
# Configure options needed prior to enabling the CUDA language
# ===============================================================
Expand Down
2 changes: 1 addition & 1 deletion cmake/tpl/FindSUPERLUDIST.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ if(SUPERLUDIST_ROCM)
find_package(hipblas REQUIRED)
find_package(rocsolver REQUIRED)
find_package(rocblas REQUIRED)
list(APPEND SUPERLUDIST_LINK_LIBRARIES hip::device roc::hipblas roc::rocblas roc::rocsolver)
list(APPEND SUPERLUDIST_LINK_LIBRARIES roc::hipblas roc::rocblas roc::rocsolver)
endif()

# set package variables including SUPERLUDIST_FOUND
Expand Down
8 changes: 4 additions & 4 deletions examples/arkode/CXX_parallel/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ if(ENABLE_RAJA AND (SUNDIALS_PRECISION MATCHES "DOUBLE") AND
set(OTHER_LIBS RAJA ${OTHER_LIBS})

# If RAJA has HIP enabled, we have to link to HIP even if we dont use it
if(RAJA_BACKENDS MATCHES "HIP")
set(OTHER_LIBS hip::device ${OTHER_LIBS})
endif()
# if(RAJA_BACKENDS MATCHES "HIP")
# set(OTHER_LIBS hip::device ${OTHER_LIBS})
# endif()

# If RAJA has OpenMP enabled, we have to link to OpenMP even if we dont use it
if((RAJA_BACKENDS MATCHES "TARGET_OPENMP") OR (RAJA_BACKENDS MATCHES "OPENMP"))
Expand Down Expand Up @@ -205,7 +205,7 @@ if(ENABLE_RAJA AND (SUNDIALS_PRECISION MATCHES "DOUBLE") AND
set(hip_raja_examples
"ark_brusselator1D_task_local_nls.cpp\;USE_HIP_NVEC\;--monitor\;1\;4\;exclude\;2")
set(SUNDIALS_LIBS sundials_arkode sundials_nvecmpiplusx sundials_nvechip)
build_examples(hip_raja_examples CXX)
build_examples(hip_raja_examples HIP)
endif()

# ---------------------
Expand Down
4 changes: 3 additions & 1 deletion examples/cvode/hip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ foreach(example_tuple ${all_examples})
# extract the file name without extension
get_filename_component(example_target ${example} NAME_WE)

set_source_files_properties(${example} PROPERTIES LANGUAGE HIP)

if (NOT TARGET ${example_target})
# example source files
add_executable(${example_target} ${example})
Expand All @@ -56,7 +58,7 @@ foreach(example_tuple ${all_examples})
set_target_properties(${example_target} PROPERTIES FOLDER "Examples")

# libraries to link against
target_link_libraries(${example_target} PRIVATE hip::device ${SUNDIALS_LIBS} ${EXE_EXTRA_LINK_LIBS})
target_link_libraries(${example_target} PRIVATE ${SUNDIALS_LIBS} ${EXE_EXTRA_LINK_LIBS})
endif()

# check if example args are provided and set the test name
Expand Down
8 changes: 1 addition & 7 deletions src/nvector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,7 @@ if(BUILD_NVECTOR_KOKKOS)
message(STATUS "Added BUILD_NVECTOR_KOKKOS module")
add_library(sundials_nveckokkos INTERFACE)
target_link_libraries(sundials_nveckokkos INTERFACE sundials_core)
if(ENABLE_HIP)
target_link_libraries(sundials_nveckokkos INTERFACE
Kokkos::kokkos hip::device)
else()
target_link_libraries(sundials_nveckokkos INTERFACE
Kokkos::kokkos)
endif()
target_link_libraries(sundials_nveckokkos INTERFACE Kokkos::kokkos)
target_include_directories(sundials_nveckokkos INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}/include>
Expand Down
9 changes: 7 additions & 2 deletions src/nvector/hip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

install(CODE "MESSAGE(\"\nInstall NVECTOR_HIP\n\")")

set_source_files_properties(nvector_hip.hip.cpp PROPERTIES LANGUAGE HIP)

if(ENABLE_MPI)
set(_link_mpi_if_needed PUBLIC MPI::MPI_CXX)
endif()

# Create the library
sundials_add_library(sundials_nvechip
SOURCES
Expand All @@ -26,10 +32,9 @@ sundials_add_library(sundials_nvechip
nvector
LINK_LIBRARIES
PUBLIC sundials_core
${_link_mpi_if_needed}
OBJECT_LIBRARIES
sundials_sunmemhip_obj
LINK_LIBRARIES
PUBLIC hip::device
OUTPUT_NAME
sundials_nvechip
VERSION
Expand Down
4 changes: 2 additions & 2 deletions src/nvector/raja/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ if(SUNDIALS_RAJA_BACKENDS MATCHES "CUDA")
elseif(SUNDIALS_RAJA_BACKENDS MATCHES "HIP")
set(_sunmemlib sundials_sunmemhip_obj)
set(_lib_output_name sundials_nvechipraja)
set(_hip_lib_or_not hip::device)
set_source_files_properties(nvector_raja.cpp PROPERTIES LANGUAGE HIP)
set(_cxx_std cxx_std_14)
elseif(SUNDIALS_RAJA_BACKENDS MATCHES "SYCL")
set(_sunmemlib sundials_sunmemsycl_obj)
Expand All @@ -45,7 +45,7 @@ sundials_add_library(sundials_nvecraja
OBJECT_LIBRARIES
${_sunmemlib}
LINK_LIBRARIES
PUBLIC ${_hip_lib_or_not} RAJA
PUBLIC RAJA
COMPILE_OPTIONS
PUBLIC $<$<COMPILE_LANGUAGE:CUDA>:--expt-extended-lambda>
COMPILE_DEFINITIONS
Expand Down
4 changes: 2 additions & 2 deletions src/sunlinsol/magmadense/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ if(SUNDIALS_MAGMA_BACKENDS MATCHES "CUDA")
set_source_files_properties(sunlinsol_magmadense.cpp PROPERTIES LANGUAGE CUDA)
set(_libs_needed sundials_sunmatrixmagmadense sundials_nveccuda)
elseif(SUNDIALS_MAGMA_BACKENDS MATCHES "HIP")
set_source_files_properties(sunlinsol_magmadense.cpp PROPERTIES LANGUAGE CXX)
set(_libs_needed sundials_sunmatrixmagmadense sundials_nvechip hip::device)
set_source_files_properties(sunlinsol_magmadense.cpp PROPERTIES LANGUAGE HIP)
set(_libs_needed sundials_sunmatrixmagmadense sundials_nvechip)
endif()

# Add the sunlinsol_magmadense library
Expand Down
4 changes: 2 additions & 2 deletions src/sunmatrix/magmadense/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ if(SUNDIALS_MAGMA_BACKENDS MATCHES "CUDA")
set_source_files_properties(sunmatrix_magmadense.cpp PROPERTIES LANGUAGE CUDA)
set(_libs_needed sundials_nveccuda)
elseif(SUNDIALS_MAGMA_BACKENDS MATCHES "HIP")
set_source_files_properties(sunmatrix_magmadense.cpp PROPERTIES LANGUAGE CXX)
set(_libs_needed sundials_nvechip hip::device)
set_source_files_properties(sunmatrix_magmadense.cpp PROPERTIES LANGUAGE HIP)
set(_libs_needed sundials_nvechip)
endif()

# Add the sunmatrix_magmadense library
Expand Down
8 changes: 7 additions & 1 deletion src/sunmemory/hip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
# SUNDIALS Copyright End
# ---------------------------------------------------------------

set_source_files_properties(sundials_hip_memory.hip.cpp PROPERTIES LANGUAGE HIP)

if(ENABLE_MPI)
set(_link_mpi_if_needed PUBLIC MPI::MPI_CXX)
endif()

# Create a library out of the generic sundials modules
sundials_add_library(sundials_sunmemhip
SOURCES
Expand All @@ -22,6 +28,6 @@ sundials_add_library(sundials_sunmemhip
sunmemory
LINK_LIBRARIES
PUBLIC sundials_core
PRIVATE hip::device
${_link_mpi_if_needed}
OBJECT_LIB_ONLY
)
4 changes: 3 additions & 1 deletion test/unit_tests/sunmemory/hip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ foreach(test_tuple ${unit_tests})
# test source files once for testing with different inputs
if(NOT TARGET ${test})

set_source_files_properties(${test}.cpp PROPERTIES LANGUAGE HIP)

# test source files
add_executable(${test} ${test}.cpp)

Expand All @@ -36,7 +38,7 @@ foreach(test_tuple ${unit_tests})
${CMAKE_SOURCE_DIR}/src)

# libraries to link against
target_link_libraries(${test} PRIVATE sundials_core sundials_sunmemhip_obj hip::device ${EXE_EXTRA_LINK_LIBS})
target_link_libraries(${test} PRIVATE sundials_core sundials_sunmemhip_obj ${EXE_EXTRA_LINK_LIBS})

endif()

Expand Down

0 comments on commit 191a313

Please sign in to comment.