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

Review CUDA and HIP configuration in CMake #48

Merged
merged 6 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
30 changes: 11 additions & 19 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,31 @@ endif()

option(RESOLVE_TEST_WITH_BSUB "Use `jsrun` instead of `mpirun` commands when running tests" OFF)
option(RESOLVE_USE_KLU "Use KLU, AMD and COLAMD libraries from SuiteSparse" ON)
option(RESOLVE_USE_GPU "Use GPU device for computations" OFF)
option(RESOLVE_USE_CUDA "Use CUDA language and SDK" OFF)
option(RESOLVE_USE_HIP "Use HIP language and ROCm library" OFF)
set(RESOLVE_CTEST_OUTPUT_DIR ${PROJECT_BINARY_DIR} CACHE PATH "Directory where CTest outputs are saved")

option(RESOLVE_USE_GPU "Use GPU device for computations" OFF)
mark_as_advanced(FORCE RESOLVE_USE_GPU)

if(RESOLVE_USE_CUDA)
set(RESOLVE_USE_GPU On CACHE BOOL "Using CUDA GPU!" FORCE)
set(RESOLVE_USE_GPU ON CACHE BOOL "Using CUDA GPU!" FORCE)
endif()

if(RESOLVE_USE_HIP)
set(RESOLVE_USE_GPU On CACHE BOOL "Using HIP GPU!" FORCE)
set(RESOLVE_USE_GPU ON CACHE BOOL "Using HIP GPU!" FORCE)
endif()


# MacOS specific things
set(CMAKE_MACOSX_RPATH 1)
# set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
# https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling#always-full-rpath
# use, i.e. don't skip the full RPATH for the build tree
#set(CMAKE_SKIP_BUILD_RPATH FALSE)

# when building, don't use the install RPATH already
# (but later on when installing)
# Install with RPATH but do not build with it
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)

set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)
#list(APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/lib)

# Add CMake sources from `cmake` dir
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

# Including clang-format cmake files to do automatic checking of formating
# TODO: Set up clang-format
#include(./cmake/clang-format)

if (RESOLVE_USE_KLU)
include(FindKLU)
if(NOT KLU_LIBRARY)
Expand Down Expand Up @@ -100,6 +89,7 @@ if(RESOLVE_USE_HIP)
# This is just an agly hack to make HIP build work
get_target_property(hip_includes hip::device INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "HIP include directories: ${hip_includes}")
# TODO - use targets properly
include_directories(${hip_includes})
else()
message(STATUS "Not using HIP")
Expand All @@ -112,14 +102,15 @@ configure_file(
${CMAKE_BINARY_DIR}/resolve/resolve_defs.hpp)

# include build directory for Fortran name mangling header
# TODO - target based includes
include_directories(${CMAKE_BINARY_DIR})

install(
FILES ${CMAKE_BINARY_DIR}/resolve/resolve_defs.hpp
DESTINATION include/resolve
)


# TODO - fix this
include_directories(${CMAKE_SOURCE_DIR})

# Enable testing
Expand Down Expand Up @@ -158,4 +149,5 @@ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/ReSolveConfig.cmake"
add_subdirectory(examples)

# Add tests
set(RESOLVE_CTEST_OUTPUT_DIR ${PROJECT_BINARY_DIR} CACHE PATH "Directory where CTest outputs are saved")
add_subdirectory(tests)
12 changes: 6 additions & 6 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
"description": "Base config to build with CUDA",
"binaryDir": "${sourceDir}/build",
"installDir": "${sourceDir}/install",
"generator": "Unix Makefiles"
"generator": "Unix Makefiles",
"cacheVariables": {
"RESOLVE_USE_CUDA": "ON",
"RESOLVE_USE_GPU": "ON"
pelesh marked this conversation as resolved.
Show resolved Hide resolved
}
},
{
"name": "cpu",
"displayName": "CPU only build",
"description": "Base config to build without GPUs",
"binaryDir": "${sourceDir}/build",
"installDir": "${sourceDir}/install",
"generator": "Unix Makefiles",
"cacheVariables": {
"RESOLVE_USE_CUDA": "OFF",
"RESOLVE_USE_GPU": "OFF"
}
"generator": "Unix Makefiles"
},
{
"name": "ascent",
Expand Down
12 changes: 12 additions & 0 deletions cmake/ReSolveConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ if(@RESOLVE_USE_CUDA@)
check_language(CUDA)
set(CMAKE_CUDA_FLAGS "@CMAKE_CUDA_FLAGS@")
find_package(CUDAToolkit REQUIRED)
add_library(ReSolve::CUDA ALIAS ReSolve::resolve_backend_cuda)
endif()
if(@RESOLVE_USE_HIP@)
enable_language(HIP)
check_language(HIP)
find_package(hip REQUIRED)
find_package(hipblas REQUIRED)
# This is just an agly hack to make HIP build work
get_target_property(hip_includes hip::device INTERFACE_INCLUDE_DIRECTORIES)
message(STATUS "HIP include directories: ${hip_includes}")
include_directories(${hip_includes})
add_library(ReSolve::HIP ALIAS ReSolve::resolve_backend_hip)
endif()

# Compute installation prefix relative to this file.
Expand Down
6 changes: 0 additions & 6 deletions cmake/ReSolveFindHipLibraries.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,4 @@ target_link_libraries(resolve_hip INTERFACE
#roc::hipblas
)

# get_target_property(hip_includes hip::device INTERFACE_INCLUDE_DIRECTORIES)
# message(STATUS "HIP include directories: ${hip_includes}")

# get_target_property(resolve_hip_includes resolve_hip INTERFACE_INCLUDE_DIRECTORIES)
# message(STATUS "ReSolve HIP include directories: ${resolve_hip_includes}")

install(TARGETS resolve_hip EXPORT ReSolveTargets)
30 changes: 5 additions & 25 deletions resolve/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,45 +37,20 @@ set(ReSolve_HEADER_INSTALL
MemoryUtils.hpp
)

# If GPU support is not enabled, add dummy device backend
if(NOT RESOLVE_USE_GPU)
add_subdirectory(cpu)
endif()

# If CUDA support is enabled, create CUDA backend
# (this should really be CUDA _API_ backend, separate backend will be needed for CUDA SDK)
if(RESOLVE_USE_CUDA)
add_subdirectory(cuda)
endif()

if(RESOLVE_USE_HIP)
add_subdirectory(hip)
endif()

# Now, build workspaces
add_subdirectory(workspace)

# Next build vector and matrix objects that may use this backend.
add_subdirectory(vector)
add_subdirectory(matrix)


# Build shared library ReSolve
add_library(resolve_tpl INTERFACE)

if(RESOLVE_USE_KLU)
target_link_libraries(resolve_tpl INTERFACE KLU)
pelesh marked this conversation as resolved.
Show resolved Hide resolved
endif(RESOLVE_USE_KLU)

if(RESOLVE_USE_CUDA)
target_link_libraries(resolve_tpl INTERFACE resolve_cuda)
endif(RESOLVE_USE_CUDA)

if(RESOLVE_USE_HIP)
target_link_libraries(resolve_tpl INTERFACE resolve_hip)
endif(RESOLVE_USE_HIP)


set(ReSolve_Targets_List
resolve_matrix
resolve_vector
Expand All @@ -86,17 +61,22 @@ set(ReSolve_Targets_List

# If CUDA support is enabled add CUDA SDK specific code and dependencies
if(RESOLVE_USE_CUDA)
add_subdirectory(cuda)
target_link_libraries(resolve_tpl INTERFACE resolve_cuda)
set(ReSolve_SRC ${ReSolve_SRC} ${ReSolve_CUDASDK_SRC})
set(ReSolve_Targets_List ${ReSolve_Targets_List} resolve_backend_cuda)
endif()

# If HIP support is enabled add HIP SDK specific code and dependencies
if(RESOLVE_USE_HIP)
add_subdirectory(hip)
target_link_libraries(resolve_tpl INTERFACE resolve_hip)
set(ReSolve_Targets_List ${ReSolve_Targets_List} resolve_backend_hip)
endif()

# If no GPU support is enabled, link to dummy device backend
if(NOT RESOLVE_USE_GPU)
add_subdirectory(cpu)
set(ReSolve_Targets_List ${ReSolve_Targets_List} resolve_backend_cpu)
pelesh marked this conversation as resolved.
Show resolved Hide resolved
endif()

Expand Down