Skip to content

Commit

Permalink
Fix the static library test_install issues with HIP.
Browse files Browse the repository at this point in the history
  • Loading branch information
tcojean committed Dec 3, 2019
1 parent 67bb138 commit 5315e23
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 19 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ if (GINKGO_WITH_IWYU)
find_program(GINKGO_IWYU_PATH iwyu)
endif()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")

# Find important header files, store the definitions in include/ginkgo/config.h.in
# For details, see https://gitlab.kitware.com/cmake/community/wikis/doc/tutorials/How-To-Write-Platform-Checks
Expand Down Expand Up @@ -166,6 +166,7 @@ endif()
# Load CMake helpers
include(cmake/build_helpers.cmake)
include(cmake/build_type_helpers.cmake)
include(cmake/hip_helpers.cmake)
include(cmake/install_helpers.cmake)

# Try to find the third party packages before using our subdirectories
Expand Down
10 changes: 8 additions & 2 deletions cmake/GinkgoConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ set(GINKGO_INSTALL_LIBRARY_DIR "${GINKGO_INSTALL_PREFIX}/@GINKGO_INSTALL_LIBRARY
set(GINKGO_INSTALL_PKGCONFIG_DIR "${GINKGO_INSTALL_PREFIX}/@GINKGO_INSTALL_PKGCONFIG_DIR@")
set(GINKGO_INSTALL_CONFIG_DIR "${GINKGO_INSTALL_PREFIX}/@GINKGO_INSTALL_CONFIG_DIR@")
set(GINKGO_INSTALL_MODULE_DIR "${GINKGO_INSTALL_PREFIX}/@GINKGO_INSTALL_MODULE_DIR@")
set(CMAKE_MODULE_PATH "${GINKGO_INSTALL_MODULE_DIR}")

# Forward Ginkgo's MODULE PATH and the PREFIX PATH for HIP and more
set(CMAKE_MODULE_PATH "@CMAKE_MODULE_PATH@")
set(CMAKE_MODULE_PATH "${GINKGO_INSTALL_MODULE_DIR}" ${CMAKE_MODULE_PATH})
set(CMAKE_PREFIX_PATH "@CMAKE_PREFIX_PATH@")


set(GINKGO_INTERFACE_LINK_LIBRARIES "@GINKGO_INTERFACE_LINK_LIBRARIES@")
Expand Down Expand Up @@ -123,8 +127,10 @@ set(GINKGO_OPENMP_LIBRARIES @OpenMP_CXX_LIBRARIES@)

set(GINKGO_OPENMP_FLAGS "@OpenMP_CXX_FLAGS@")

# Provide useful HIP helper functions
include(${CMAKE_CURRENT_LIST_DIR}/hip_helpers.cmake)

# NOTE: we do not export benchmarks, examples, tests or devel tools
# so `third_party` libraries are currently unneeded.


include(${CMAKE_CURRENT_LIST_DIR}/GinkgoTargets.cmake)
12 changes: 0 additions & 12 deletions cmake/build_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,3 @@ endmacro()
macro(ginkgo_switch_to_windows_dynamic lang)
ginkgo_switch_windows_link(${lang} "MT" "MD")
endmacro()

macro(ginkgo_hip_ban_link_hcflag target)
get_target_property(GINKGO_TARGET_ILL ${target} INTERFACE_LINK_LIBRARIES)
string(REPLACE "-hc " "" GINKGO_TARGET_NEW_ILL "${GINKGO_TARGET_ILL}")
set_target_properties(${target} PROPERTIES INTERFACE_LINK_LIBRARIES "${GINKGO_TARGET_NEW_ILL}")
endmacro()

macro(ginkgo_hip_ban_compile_hcflag target)
get_target_property(GINKGO_TARGET_ILL ${target} INTERFACE_COMPILE_OPTIONS)
string(REPLACE "-hc" "" GINKGO_TARGET_NEW_ILL "${GINKGO_TARGET_ILL}")
set_target_properties(${target} PROPERTIES INTERFACE_COMPILE_OPTIONS "${GINKGO_TARGET_NEW_ILL}")
endmacro()
11 changes: 11 additions & 0 deletions cmake/hip_helpers.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
macro(ginkgo_hip_ban_link_hcflag target)
get_target_property(GINKGO_TARGET_ILL ${target} INTERFACE_LINK_LIBRARIES)
string(REPLACE "-hc " "" GINKGO_TARGET_NEW_ILL "${GINKGO_TARGET_ILL}")
set_target_properties(${target} PROPERTIES INTERFACE_LINK_LIBRARIES "${GINKGO_TARGET_NEW_ILL}")
endmacro()

macro(ginkgo_hip_ban_compile_hcflag target)
get_target_property(GINKGO_TARGET_ILL ${target} INTERFACE_COMPILE_OPTIONS)
string(REPLACE "-hc" "" GINKGO_TARGET_NEW_ILL "${GINKGO_TARGET_ILL}")
set_target_properties(${target} PROPERTIES INTERFACE_COMPILE_OPTIONS "${GINKGO_TARGET_NEW_ILL}")
endmacro()
1 change: 1 addition & 0 deletions cmake/install_helpers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ function(ginkgo_install)
"${Ginkgo_BINARY_DIR}/GinkgoConfig.cmake"
"${Ginkgo_BINARY_DIR}/GinkgoConfigVersion.cmake"
"${Ginkgo_BINARY_DIR}/GinkgoTargets.cmake"
"${Ginkgo_SOURCE_DIR}/cmake/hip_helpers.cmake"
DESTINATION "${GINKGO_INSTALL_CONFIG_DIR}"
)

Expand Down
7 changes: 4 additions & 3 deletions hip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@ endif()


## Setup all CMAKE variables to find HIP and its dependencies
set(CMAKE_MODULE_PATH "${HIP_PATH}/cmake" ${CMAKE_MODULE_PATH})
list(APPEND CMAKE_MODULE_PATH "${HIP_PATH}/cmake")
list(APPEND CMAKE_PREFIX_PATH
"${HIPBLAS_PATH}/lib/cmake"
"${HIPSPARSE_PATH}/lib/cmake"
)
# Set CMAKE_MODULE_PATH in PARENT_SCOPE for benchmark
# Set CMAKE_MODULE_PATH and CMAKE_PREFIX_PATH as PARENT_SCOPE to easily find HIP again
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" PARENT_SCOPE)
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH}" PARENT_SCOPE)

find_package(HIP REQUIRED)
find_package(hipblas REQUIRED)
Expand Down Expand Up @@ -150,7 +151,7 @@ endif()
if(GINKGO_HIP_PLATFORM MATCHES "hcc")
# Fix the exception thrown bug with `hcc` backend and shared libraries
set_target_properties(ginkgo_hip PROPERTIES LINKER_LANGUAGE HIP)

# Ban `-hc` flag as INTERFACE_LINK_LIBRARIES since that is propagated when building
# a static library, and it's definitely not a known option to any compiler.
ginkgo_hip_ban_link_hcflag(hcc::hccrt)
Expand Down
15 changes: 14 additions & 1 deletion test_install/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.8)
cmake_minimum_required(VERSION 3.9)

project(TestInstall LANGUAGES CXX)

Expand All @@ -17,6 +17,19 @@ if((NOT GINKGO_BUILD_SHARED_LIBS) AND GINKGO_BUILD_CUDA)
enable_language(CUDA)
endif()

if((NOT GINKGO_BUILD_SHARED_LIBS) AND GINKGO_BUILD_HIP)
find_package(HIP REQUIRED)
find_package(hipblas REQUIRED)
find_package(hipsparse REQUIRED)
if(GINKGO_HIP_PLATFORM MATCHES "hcc")
ginkgo_hip_ban_link_hcflag(hcc::hccrt)
ginkgo_hip_ban_link_hcflag(hcc::hc_am)
ginkgo_hip_ban_link_hcflag(hcc::mcwamp)
ginkgo_hip_ban_compile_hcflag(hcc::hccrt)
ginkgo_hip_ban_compile_hcflag(hcc::hc_am)
ginkgo_hip_ban_compile_hcflag(hcc::mcwamp)
endif()
endif()

add_executable(test_install test_install.cpp)
target_compile_features(test_install PUBLIC cxx_std_11)
Expand Down

0 comments on commit 5315e23

Please sign in to comment.