Skip to content
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
83 changes: 80 additions & 3 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,13 @@ set(HIPFORT_ARCH "nvptx")
# nvptx
set(HIPFORT_LIB "hipfort-${HIPFORT_ARCH}")
set(CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/include/hipfort/${HIPFORT_ARCH})
ADD_LIBRARY(${HIPFORT_LIB} STATIC
${HIPFORT_SRC_HIP}
ADD_LIBRARY(${HIPFORT_LIB} STATIC
${HIPFORT_SRC_HIP}
)
target_include_directories(${HIPFORT_LIB}
PUBLIC
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/hipfort/nvptx>
)
IF(HIPFORT_USE_FPOINTER_INTERFACES)
target_compile_definitions(${HIPFORT_LIB} PRIVATE USE_FPOINTER_INTERFACES)
ENDIF(HIPFORT_USE_FPOINTER_INTERFACES)
Expand All @@ -82,6 +86,11 @@ set(HIPFORT_ARCH "nvptx")
# Install Target hipfort-nvptx
rocm_install_targets(
TARGETS ${HIPFORT_LIB}
EXPORT hipfort-nvptx-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
INCLUDE
${CMAKE_Fortran_MODULE_DIRECTORY}
)
Expand All @@ -101,14 +110,21 @@ rocm_install(
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hipfort
)

rocm_install(
EXPORT hipfort-nvptx-targets
FILE hipfort-nvptx-targets.cmake
NAMESPACE hipfort::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hipfort
)

macro(hipfort_add_component name imported_target)
add_library(hipfort-${name} INTERFACE)
add_library(hipfort::${name} ALIAS hipfort-${name})
set_target_properties(hipfort-${name}
PROPERTIES
EXPORT_NAME ${name}
)
target_link_libraries(hipfort-${name} INTERFACE hipfort-amdgcn ${imported_target})
target_link_libraries(hipfort-${name} INTERFACE ${HIPFORT_BASE_LIB} ${imported_target})
rocm_install(
TARGETS
hipfort-${name}
Expand All @@ -128,6 +144,10 @@ endmacro()

find_package(hip PATHS ${ROCM_PATH} /opt/rocm)
if(HIP_PLATFORM STREQUAL "amd")
# Components link the AMD (amdgcn) library and use the ROCm imported targets.
set(HIPFORT_BASE_LIB hipfort-amdgcn)
set(HIPFORT_ARCH_EXPORT amdgcn)

if(hip_FOUND)
hipfort_add_component(hip hip::host)
else()
Expand Down Expand Up @@ -219,6 +239,63 @@ if(HIP_PLATFORM STREQUAL "amd")
message(STATUS "Skipping hipfort::hipsparse target export")
endif()

elseif(HIP_PLATFORM STREQUAL "nvidia")
# NVIDIA/CUDA backend: components link the nvptx (USE_CUDA_NAMES) library.
# Only the HIP-based libraries exist on NVIDIA; the roc* libraries and roctx
# (ROCm-only) are not wired here.
set(HIPFORT_BASE_LIB hipfort-nvptx)
set(HIPFORT_ARCH_EXPORT nvptx)

if(hip_FOUND)
hipfort_add_component(hip hip::host)
else()
message(STATUS "Skipping hipfort::hip target export")
endif()

find_package(hipblas PATHS ${ROCM_PATH} /opt/rocm)
if(hipblas_FOUND)
hipfort_add_component(hipblas roc::hipblas)
else()
message(STATUS "Skipping hipfort::hipblas target export")
endif()

find_package(hipfft PATHS ${ROCM_PATH} /opt/rocm)
if(hipfft_FOUND)
hipfort_add_component(hipfft hip::hipfft)
if(TARGET hip::hipfftw)
hipfort_add_component(hipfftw hip::hipfftw)
else()
hipfort_add_component(hipfftw hip::hipfft)
endif()
else()
message(STATUS "Skipping hipfort::hipfft target export")
endif()

find_package(hiprand PATHS ${ROCM_PATH} /opt/rocm)
if(hiprand_FOUND)
hipfort_add_component(hiprand hip::hiprand)
else()
message(STATUS "Skipping hipfort::hiprand target export")
endif()

find_package(hipsolver PATHS ${ROCM_PATH} /opt/rocm)
if(hipsolver_FOUND)
hipfort_add_component(hipsolver roc::hipsolver)
else()
message(STATUS "Skipping hipfort::hipsolver target export")
endif()

find_package(hipsparse PATHS ${ROCM_PATH} /opt/rocm)
if(hipsparse_FOUND)
hipfort_add_component(hipsparse roc::hipsparse)
else()
message(STATUS "Skipping hipfort::hipsparse target export")
endif()
endif()

# Generate and install the package config for whichever platform was selected.
# hipfort-config.cmake.in includes hipfort-@HIPFORT_ARCH_EXPORT@-targets.cmake.
if(DEFINED HIPFORT_BASE_LIB)
include(CMakePackageConfigHelpers)

configure_package_config_file(
Expand Down
2 changes: 1 addition & 1 deletion lib/hipfort-config.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ set(_hipfort_supported_components hip roctx
set(_hipfort_hipfftw_dependency hipfft)
set(_hipfort_roctx_dependency rocprofiler-sdk-roctx)

include("${CMAKE_CURRENT_LIST_DIR}/hipfort-amdgcn-targets.cmake")
include("${CMAKE_CURRENT_LIST_DIR}/hipfort-@HIPFORT_ARCH_EXPORT@-targets.cmake")
foreach(_comp ${hipfort_FIND_COMPONENTS})
if (NOT _comp IN_LIST _hipfort_supported_components)
set(hipfort_FOUND False)
Expand Down