Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pvelesko committed Oct 9, 2024
1 parent 06cddf6 commit fae9755
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 33 deletions.
34 changes: 29 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,38 @@
cmake_minimum_required(VERSION 3.20)
include (${CMAKE_SOURCE_DIR}/CMake/HipSOLVERVersion.cmake)
project(HipSOLVER
VERSION ${HipSOLVER_VERSION}
LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
set(STANDALONE_BUILD ON)
else()
set(STANDALONE_BUILD OFF)
endif()

# set the default CMAKE_INSTALL_PREFIX to the current directory/install
if(STANDALONE_BUILD AND CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/install" CACHE PATH "..." FORCE)
endif()

find_package(hip REQUIRED)
# print where the library will be installed
message(STATUS "HipSOLVER will be installed to: ${CMAKE_INSTALL_PREFIX}")

# Find HIP
if(STANDALONE_BUILD)
# Build H4I-MKLShim from submodule first
add_subdirectory(H4I-MKLShim REQUIRED)

# Find hip package, but exclude its H4I-MKLShim
set(CMAKE_IGNORE_PATH ${CMAKE_IGNORE_PATH} ${hip_DIR}/../H4I-MKLShim)
find_package(hip CONFIG REQUIRED)

# Explicitly set the path to our built H4I-MKLShim
set(H4I_MKLShim_DIR ${CMAKE_CURRENT_BINARY_DIR}/H4I-MKLShim)
endif()

include(GNUInstallDirs)
file(RELATIVE_PATH relRPath
Expand All @@ -14,8 +41,6 @@ file(RELATIVE_PATH relRPath
)
set(CMAKE_INSTALL_RPATH $ORIGIN $ORIGIN/${relRPath})

set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
add_library(HipSOLVERCommonConfig INTERFACE)
target_compile_features(HipSOLVERCommonConfig
INTERFACE
Expand All @@ -28,4 +53,3 @@ if(NOT H4I_USE_ROCM_HIPBLAS)
# Build our library.
add_subdirectory(src)
endif()

75 changes: 47 additions & 28 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
find_package(MKLShim REQUIRED)
# Find HIP
if(STANDALONE_BUILD)
# Build H4I-MKLShim from submodule first
add_subdirectory(H4I-MKLShim REQUIRED)

# Find hip package, but exclude its H4I-MKLShim
set(CMAKE_IGNORE_PATH ${CMAKE_IGNORE_PATH} ${hip_DIR}/../H4I-MKLShim)
find_package(hip CONFIG REQUIRED)

# Explicitly set the path to our built H4I-MKLShim
set(H4I_MKLShim_DIR ${CMAKE_CURRENT_BINARY_DIR}/H4I-MKLShim)
endif()

include(ExternalProject)
option(H4I_ROCM_HIPSOLVER_TAG "Tag to use from the ROCm hipBLAS repository when obtaining its hipsolver.h header" "rocm-5.3.3")
Expand All @@ -10,24 +21,44 @@ ExternalProject_Add(ROCmHipsolver
PATCH_COMMAND ""
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND sh ${CMAKE_SOURCE_DIR}/Scripts/install-hipsolver-header.sh <SOURCE_DIR> ${CMAKE_BINARY_DIR} ${CMAKE_INSTALL_PREFIX}
INSTALL_COMMAND ${CMAKE_COMMAND} -E env SHELL=/bin/bash
bash ${CMAKE_CURRENT_SOURCE_DIR}/../Scripts/install-hipsolver-header.sh
<SOURCE_DIR> ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_INSTALL_PREFIX}
)

# Add a custom target that depends on the external project
add_custom_target(ROCmHipsolverHeaders
DEPENDS ROCmHipsolver
)

set(PROJECT_VERSION_MAJOR 5)
set(PROJECT_VERSION_MINOR 3)
set(PROJECT_VERSION_PATCH 3)

configure_file(
${CMAKE_SOURCE_DIR}/include/internal/hipsolver-version.h.in
${CMAKE_BINARY_DIR}/include/internal/hipsolver-version.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/internal/hipsolver-version.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/internal/hipsolver-version.h
@ONLY)

add_library(hipsolver SHARED
util.cpp
hipsolver.cpp)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../include)
# Add dependency on the custom target
add_dependencies(hipsolver ROCmHipsolverHeaders)
target_include_directories(hipsolver
PUBLIC
"$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include;${CMAKE_BINARY_DIR}/include>"
$<INSTALL_INTERFACE:include>)
# Check if hip::host target exists
if(NOT TARGET hip::host)
message(FATAL_ERROR "hip::host target not found. Please ensure HIP is properly installed and found by CMake.")
endif()

target_link_libraries(hipsolver
PRIVATE
H4I::MKLShim
MKLShim
PUBLIC
hip::host
)
Expand All @@ -37,35 +68,23 @@ install(TARGETS hipsolver
EXPORT hipsolver
)
install(FILES
${CMAKE_BINARY_DIR}/include/hipsolver.h
${CMAKE_CURRENT_BINARY_DIR}/include/hipsolver.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/
)

install(FILES
${CMAKE_BINARY_DIR}/include/internal/hipsolver-version.h
${CMAKE_BINARY_DIR}/include/internal/hipsolver-types.h
${CMAKE_BINARY_DIR}/include/internal/hipsolver-functions.h
${CMAKE_BINARY_DIR}/include/internal/hipsolver-compat.h
${CMAKE_SOURCE_DIR}/include/internal/hipsolver-export.h
${CMAKE_BINARY_DIR}/include/internal/hipsolver-refactor.h
${CMAKE_CURRENT_BINARY_DIR}/include/internal/hipsolver-version.h
${CMAKE_CURRENT_BINARY_DIR}/include/internal/hipsolver-types.h
${CMAKE_CURRENT_BINARY_DIR}/include/internal/hipsolver-functions.h
${CMAKE_CURRENT_BINARY_DIR}/include/internal/hipsolver-compat.h
${CMAKE_CURRENT_SOURCE_DIR}/../include/internal/hipsolver-export.h
${CMAKE_CURRENT_BINARY_DIR}/include/internal/hipsolver-refactor.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/internal/
)


install(EXPORT hipsolver
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hipsolver
NAMESPACE H4I::
)

include(CMakePackageConfigHelpers)

configure_package_config_file(${CMAKE_SOURCE_DIR}/CMake/HipSOLVERConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/hipsolverConfig.cmake
PATH_VARS CMAKE_INSTALL_INCLUDEDIR
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hipsolver
)
# install(EXPORT hipsolver
# DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hipsolver
# NAMESPACE H4I::
# )

install(FILES
${CMAKE_CURRENT_BINARY_DIR}/hipsolverConfig.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hipsolver
)

0 comments on commit fae9755

Please sign in to comment.