From be94ee749ea84780099de4caaef2d12a9f5c5579 Mon Sep 17 00:00:00 2001 From: rcrutherford Date: Tue, 31 Oct 2023 12:55:22 -0700 Subject: [PATCH] Add first pass CMake cleanup - need to fix include_directories and add custom library macro. --- CMakeLists.txt | 30 +++++++++++------------------ CMakePresets.json | 12 ++++++------ cmake/ReSolveConfig.cmake.in | 12 ++++++++++++ cmake/ReSolveFindHipLibraries.cmake | 6 ------ resolve/CMakeLists.txt | 30 +++++------------------------ 5 files changed, 34 insertions(+), 56 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f802231..db4e8e74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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") @@ -112,6 +102,7 @@ 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( @@ -119,7 +110,7 @@ install( DESTINATION include/resolve ) - +# TODO - fix this include_directories(${CMAKE_SOURCE_DIR}) # Enable testing @@ -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) diff --git a/CMakePresets.json b/CMakePresets.json index e4784095..40092da1 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -12,7 +12,11 @@ "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" + } }, { "name": "cpu", @@ -20,11 +24,7 @@ "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", diff --git a/cmake/ReSolveConfig.cmake.in b/cmake/ReSolveConfig.cmake.in index 7a162d90..47f9fe35 100644 --- a/cmake/ReSolveConfig.cmake.in +++ b/cmake/ReSolveConfig.cmake.in @@ -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. diff --git a/cmake/ReSolveFindHipLibraries.cmake b/cmake/ReSolveFindHipLibraries.cmake index e754da0d..d25c36aa 100644 --- a/cmake/ReSolveFindHipLibraries.cmake +++ b/cmake/ReSolveFindHipLibraries.cmake @@ -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) diff --git a/resolve/CMakeLists.txt b/resolve/CMakeLists.txt index fa6c9cd5..81613aa0 100644 --- a/resolve/CMakeLists.txt +++ b/resolve/CMakeLists.txt @@ -37,21 +37,6 @@ 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) @@ -59,7 +44,6 @@ add_subdirectory(workspace) add_subdirectory(vector) add_subdirectory(matrix) - # Build shared library ReSolve add_library(resolve_tpl INTERFACE) @@ -67,15 +51,6 @@ if(RESOLVE_USE_KLU) target_link_libraries(resolve_tpl INTERFACE KLU) 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 @@ -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) endif()