From 191a313f3ebfe332f9cd5bd06c9f798ef4f71fe5 Mon Sep 17 00:00:00 2001 From: "David J. Gardner" Date: Thu, 30 Nov 2023 18:26:41 -0500 Subject: [PATCH] use cmake HIP language support --- CMakeLists.txt | 2 +- benchmarks/advection_reaction_3D/raja/CMakeLists.txt | 11 ++++++++++- benchmarks/diffusion_2D/mpi_gpu/CMakeLists.txt | 9 ++++++--- cmake/SundialsSetupCompilers.cmake | 4 +++- cmake/SundialsSetupCuda.cmake | 5 ----- cmake/tpl/FindSUPERLUDIST.cmake | 2 +- examples/arkode/CXX_parallel/CMakeLists.txt | 8 ++++---- examples/cvode/hip/CMakeLists.txt | 4 +++- src/nvector/CMakeLists.txt | 8 +------- src/nvector/hip/CMakeLists.txt | 9 +++++++-- src/nvector/raja/CMakeLists.txt | 4 ++-- src/sunlinsol/magmadense/CMakeLists.txt | 4 ++-- src/sunmatrix/magmadense/CMakeLists.txt | 4 ++-- src/sunmemory/hip/CMakeLists.txt | 8 +++++++- test/unit_tests/sunmemory/hip/CMakeLists.txt | 4 +++- 15 files changed, 52 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dbd1230512..ed64223e6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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. diff --git a/benchmarks/advection_reaction_3D/raja/CMakeLists.txt b/benchmarks/advection_reaction_3D/raja/CMakeLists.txt index a697577573..7a22f129b5 100644 --- a/benchmarks/advection_reaction_3D/raja/CMakeLists.txt +++ b/benchmarks/advection_reaction_3D/raja/CMakeLists.txt @@ -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 @@ -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 @@ -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}) diff --git a/benchmarks/diffusion_2D/mpi_gpu/CMakeLists.txt b/benchmarks/diffusion_2D/mpi_gpu/CMakeLists.txt index 42dee3e3ad..8e9a8d1bbf 100644 --- a/benchmarks/diffusion_2D/mpi_gpu/CMakeLists.txt +++ b/benchmarks/diffusion_2D/mpi_gpu/CMakeLists.txt @@ -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() @@ -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() @@ -115,8 +119,7 @@ foreach(test_tuple ${tests}) PRIVATE sundials_${package} sundials_nvecmpiplusx - sundials_nvechip - hip::device) + sundials_nvechip) endif() diff --git a/cmake/SundialsSetupCompilers.cmake b/cmake/SundialsSetupCompilers.cmake index 3e5420f63d..34a4134797 100644 --- a/cmake/SundialsSetupCompilers.cmake +++ b/cmake/SundialsSetupCompilers.cmake @@ -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() diff --git a/cmake/SundialsSetupCuda.cmake b/cmake/SundialsSetupCuda.cmake index aa41f5a117..6a6d89a321 100644 --- a/cmake/SundialsSetupCuda.cmake +++ b/cmake/SundialsSetupCuda.cmake @@ -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 # =============================================================== diff --git a/cmake/tpl/FindSUPERLUDIST.cmake b/cmake/tpl/FindSUPERLUDIST.cmake index 3ba69b3e83..fa22e0ab79 100644 --- a/cmake/tpl/FindSUPERLUDIST.cmake +++ b/cmake/tpl/FindSUPERLUDIST.cmake @@ -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 diff --git a/examples/arkode/CXX_parallel/CMakeLists.txt b/examples/arkode/CXX_parallel/CMakeLists.txt index d40c99decd..2d353332a9 100644 --- a/examples/arkode/CXX_parallel/CMakeLists.txt +++ b/examples/arkode/CXX_parallel/CMakeLists.txt @@ -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")) @@ -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() # --------------------- diff --git a/examples/cvode/hip/CMakeLists.txt b/examples/cvode/hip/CMakeLists.txt index 8a217bcceb..c6d2cf1f85 100644 --- a/examples/cvode/hip/CMakeLists.txt +++ b/examples/cvode/hip/CMakeLists.txt @@ -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}) @@ -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 diff --git a/src/nvector/CMakeLists.txt b/src/nvector/CMakeLists.txt index 3639014b00..b111bcf3fe 100644 --- a/src/nvector/CMakeLists.txt +++ b/src/nvector/CMakeLists.txt @@ -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 $ $ diff --git a/src/nvector/hip/CMakeLists.txt b/src/nvector/hip/CMakeLists.txt index 248d20d752..fde427c5b1 100644 --- a/src/nvector/hip/CMakeLists.txt +++ b/src/nvector/hip/CMakeLists.txt @@ -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 @@ -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 diff --git a/src/nvector/raja/CMakeLists.txt b/src/nvector/raja/CMakeLists.txt index ca4ee237b4..335c311e95 100644 --- a/src/nvector/raja/CMakeLists.txt +++ b/src/nvector/raja/CMakeLists.txt @@ -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) @@ -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 $<$:--expt-extended-lambda> COMPILE_DEFINITIONS diff --git a/src/sunlinsol/magmadense/CMakeLists.txt b/src/sunlinsol/magmadense/CMakeLists.txt index 55e78fb138..4fe808e059 100644 --- a/src/sunlinsol/magmadense/CMakeLists.txt +++ b/src/sunlinsol/magmadense/CMakeLists.txt @@ -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 diff --git a/src/sunmatrix/magmadense/CMakeLists.txt b/src/sunmatrix/magmadense/CMakeLists.txt index c575d0709d..d0b356b11a 100644 --- a/src/sunmatrix/magmadense/CMakeLists.txt +++ b/src/sunmatrix/magmadense/CMakeLists.txt @@ -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 diff --git a/src/sunmemory/hip/CMakeLists.txt b/src/sunmemory/hip/CMakeLists.txt index 6f63cc4ce8..ab13e932c2 100644 --- a/src/sunmemory/hip/CMakeLists.txt +++ b/src/sunmemory/hip/CMakeLists.txt @@ -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 @@ -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 ) diff --git a/test/unit_tests/sunmemory/hip/CMakeLists.txt b/test/unit_tests/sunmemory/hip/CMakeLists.txt index 92e78ecb7a..ec38029150 100644 --- a/test/unit_tests/sunmemory/hip/CMakeLists.txt +++ b/test/unit_tests/sunmemory/hip/CMakeLists.txt @@ -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) @@ -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()