Skip to content
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

Fix CMake dependencies generated for hypre #1203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
55 changes: 49 additions & 6 deletions src/config/HYPREConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ set(HYPRE_ENABLE_HIP @HYPRE_ENABLE_HIP@)
set(HYPRE_ENABLE_SYCL @HYPRE_ENABLE_SYCL@)
set(HYPRE_ENABLE_UNIFIED_MEMORY @HYPRE_ENABLE_UNIFIED_MEMORY@)
set(HYPRE_ENABLE_CUDA_STREAMS @HYPRE_ENABLE_CUDA_STREAMS@)
set(HYPRE_ENABLE_CUSPARSE @HYPRE_ENABLE_CUSPARSE@)
set(HYPRE_ENABLE_DEVICE_POOL @HYPRE_ENABLE_DEVICE_POOL@)
set(HYPRE_ENABLE_DEVICE_MALLOC_ASYNC @HYPRE_ENABLE_DEVICE_MALLOC_ASYNC@)
set(HYPRE_ENABLE_THRUST_ASYNC @HYPRE_ENABLE_THRUST_ASYNC@)
set(HYPRE_ENABLE_CUSPARSE @HYPRE_ENABLE_CUSPARSE@)
set(HYPRE_ENABLE_CUBLAS @HYPRE_ENABLE_CUBLAS@)
set(HYPRE_ENABLE_CURAND @HYPRE_ENABLE_CURAND@)
set(HYPRE_ENABLE_CUSOLVER @HYPRE_ENABLE_CUSOLVER@)
set(HYPRE_ENABLE_GPU_AWARE_MPI @HYPRE_ENABLE_GPU_AWARE_MPI@)
set(HYPRE_ENABLE_GPU_PROFILING @HYPRE_ENABLE_GPU_PROFILING@)
set(HYPRE_ENABLE_ROCSPARSE @HYPRE_ENABLE_ROCSPARSE@)
set(HYPRE_ENABLE_ROCBLAS @HYPRE_ENABLE_ROCBLAS@)
set(HYPRE_ENABLE_ROCRAND @HYPRE_ENABLE_ROCRAND@)
set(HYPRE_ENABLE_ROCSOLVER @HYPRE_ENABLE_ROCSOLVER@)
Expand Down Expand Up @@ -96,6 +98,7 @@ find_hypre_dependency(magma)
find_hypre_dependency(umpire)

if(HYPRE_ENABLE_CUDA OR HYPRE_ENABLE_HIP OR HYPRE_ENABLE_SYCL)
# List of required GPU libraries
set(REQUIRED_GPU_COMPONENTS)

if(HYPRE_ENABLE_CUDA)
Expand All @@ -110,6 +113,10 @@ if(HYPRE_ENABLE_CUDA OR HYPRE_ENABLE_HIP OR HYPRE_ENABLE_SYCL)
if(HYPRE_ENABLE_CURAND)
list(APPEND REQUIRED_GPU_COMPONENTS curand)
endif()

if(HYPRE_ENABLE_CUSOLVER)
list(APPEND REQUIRED_GPU_COMPONENTS cusolver)
endif()
elseif(HYPRE_ENABLE_HIP)
if(HYPRE_ENABLE_ROCSPARSE)
list(APPEND REQUIRED_GPU_COMPONENTS rocsparse)
Expand All @@ -122,6 +129,10 @@ if(HYPRE_ENABLE_CUDA OR HYPRE_ENABLE_HIP OR HYPRE_ENABLE_SYCL)
if(HYPRE_ENABLE_ROCRAND)
list(APPEND REQUIRED_GPU_COMPONENTS rocrand)
endif()

if(HYPRE_ENABLE_ROCSOLVER)
list(APPEND REQUIRED_GPU_COMPONENTS rocsolver)
endif()
elseif(HYPRE_ENABLE_SYCL)
if(HYPRE_ENABLE_ONEMKLSPARSE)
list(APPEND REQUIRED_GPU_COMPONENTS onemklsparse)
Expand All @@ -138,24 +149,56 @@ if(HYPRE_ENABLE_CUDA OR HYPRE_ENABLE_HIP OR HYPRE_ENABLE_SYCL)

if(REQUIRED_GPU_COMPONENTS)
if(HYPRE_ENABLE_CUDA)
set(GPU_TOOLKIT_NAME "CUDA")
message(STATUS "Finding CUDA Toolkit components: ${REQUIRED_GPU_COMPONENTS}")
find_dependency(CUDAToolkit REQUIRED COMPONENTS ${REQUIRED_GPU_COMPONENTS})
set(GPU_TOOLKIT_FOUND ${CUDAToolkit_FOUND})
set(GPU_TOOLKIT_VERSION ${CUDAToolkit_VERSION})

elseif(HYPRE_ENABLE_HIP)
message(STATUS "Finding ROCm Toolkit components: ${REQUIRED_GPU_COMPONENTS}")
find_dependency(rocm REQUIRED COMPONENTS ${REQUIRED_GPU_COMPONENTS})
set(GPU_TOOLKIT_FOUND ${rocm_FOUND})
set(GPU_TOOLKIT_VERSION ${rocm_VERSION})
# Add HIP root to prefix path to find ROCm components
if(DEFINED ROCM_PATH)
set(HIP_PATH ${ROCM_PATH})
elseif(DEFINED ENV{ROCM_PATH})
set(HIP_PATH $ENV{ROCM_PATH})
elseif(DEFINED rocm_ROOT)
set(HIP_PATH ${rocm_ROOT})
elseif(DEFINED ENV{ROCM_ROOT})
set(HIP_PATH $ENV{ROCM_ROOT})
elseif(DEFINED hip_ROOT)
set(HIP_PATH ${hip_ROOT})
elseif(DEFINED ENV{hip_ROOT})
set(HIP_PATH $ENV{hip_ROOT})
elseif(EXISTS "/opt/rocm")
set(HIP_PATH "/opt/rocm")
else()
message(WARNING "ROCM_PATH or HIP_PATH not set. Linking to ROCm libraries may not work.")
endif()

# Add HIP path to prefix path to find ROCm components
list(APPEND CMAKE_PREFIX_PATH "${HIP_PATH}")

set(GPU_TOOLKIT_NAME "HIP")
message(STATUS "Finding HIP Toolkit components: ${REQUIRED_GPU_COMPONENTS}")
find_dependency(hip REQUIRED)
set(GPU_TOOLKIT_FOUND ${hip_FOUND})
set(GPU_TOOLKIT_VERSION ${hip_VERSION})

# Find ROCm components
foreach(component ${REQUIRED_GPU_COMPONENTS})
find_dependency(${component} REQUIRED)
endforeach()

elseif(HYPRE_ENABLE_SYCL)
set(GPU_TOOLKIT_NAME "Intel DPC++")
message(STATUS "Finding Intel DPC++ Toolkit components: ${REQUIRED_GPU_COMPONENTS}")
find_dependency(IntelDPCPP REQUIRED)
set(GPU_TOOLKIT_FOUND ${IntelDPCPP_FOUND})
set(GPU_TOOLKIT_VERSION ${IntelDPCPP_VERSION})
endif()

if(GPU_TOOLKIT_FOUND)
message(STATUS "GPU Toolkit found: ${GPU_TOOLKIT_VERSION}")
message(STATUS "GPU Toolkit found: ${GPU_TOOLKIT_NAME} ${GPU_TOOLKIT_VERSION}")
set(MISSING_COMPONENTS)
foreach(component ${REQUIRED_GPU_COMPONENTS})
if(HYPRE_ENABLE_CUDA AND NOT TARGET CUDA::${component})
Expand Down
22 changes: 22 additions & 0 deletions src/config/cmake/HYPRE_SetupGPUToolkit.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,29 @@ else()
set(CMAKE_CXX_STANDARD 14)
endif()
endif()

# Set C++ standard for HYPRE
set_property(TARGET HYPRE PROPERTY CXX_STANDARD ${CMAKE_CXX_STANDARD})

# Add C++ standard library to interface
if(MSVC OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND WIN32))
# MSVC and Intel on Windows link the C++ standard library automatically
message(STATUS "${CMAKE_CXX_COMPILER_ID} on Windows: C++ standard library linked automatically")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang" AND APPLE)
# Apple Clang specifically uses c++
target_link_libraries(HYPRE INTERFACE "-lc++")
else()
# Most other compilers use stdc++
if(NOT (MSVC OR (CMAKE_CXX_COMPILER_ID MATCHES "Intel" AND WIN32)))
target_link_libraries(HYPRE INTERFACE "-lstdc++")
if(NOT CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang|Intel|PGI|NVHPC|XL|XLClang")
message(WARNING "Unknown compiler: ${CMAKE_CXX_COMPILER_ID}. Attempting to link -lstdc++")
endif()
endif()
endif()
message(STATUS "C++ standard library configuration completed for ${CMAKE_CXX_COMPILER_ID}")

# Print C++ info
message(STATUS "Enabling support for CXX.")
message(STATUS "Using CXX standard: C++${CMAKE_CXX_STANDARD}")

Expand Down