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
483 changes: 195 additions & 288 deletions projects/hipsolver/CMakeLists.txt

Large diffs are not rendered by default.

88 changes: 88 additions & 0 deletions projects/hipsolver/CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "base",
"hidden": true,
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_CXX_COMPILER": "/opt/rocm/bin/amdclang++",
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coded compiler paths reduce preset portability

The base preset hard-codes CMAKE_CXX_COMPILER and CMAKE_C_COMPILER to /opt/rocm/bin/amdclang++ and /opt/rocm/bin/amdclang. This makes the preset non-portable across environments where ROCm is installed at a different location or where developers want to use alternative compilers.

Recommended action: Consider one of these approaches:

  1. Remove the compiler variables from the base preset and let CMAKE_PREFIX_PATH guide compiler discovery
  2. Create a separate CMakeUserPresets.json (git-ignored) for developer-specific paths
  3. Add a comment explaining that developers should override these in a user preset

This will make the preset more flexible and portable across different development environments.


Generated by Claude Code

"CMAKE_C_COMPILER": "/opt/rocm/bin/amdclang",
"CMAKE_PREFIX_PATH": "/opt/rocm",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
}
},
{
"name": "dev-hip",
"displayName": "HIP Development",
"description": "HIP backend with tests, benchmarks, and samples enabled",
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"HIPSOLVER_ENABLE_CUDA": "OFF",
"HIPSOLVER_BUILD_TESTING": "ON",
"HIPSOLVER_ENABLE_BENCHMARKS": "ON",
"HIPSOLVER_ENABLE_SAMPLES": "ON",
"HIPSOLVER_ENABLE_VERBOSE": "ON"
}
},
{
"name": "dev-cuda",
"displayName": "CUDA Development",
"description": "CUDA backend with tests, benchmarks, and samples enabled",
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"HIPSOLVER_ENABLE_CUDA": "ON",
"HIPSOLVER_BUILD_TESTING": "ON",
"HIPSOLVER_ENABLE_BENCHMARKS": "ON",
"HIPSOLVER_ENABLE_SAMPLES": "ON",
"HIPSOLVER_ENABLE_VERBOSE": "ON"
}
},
{
"name": "release-hip",
"displayName": "HIP Release",
"description": "HIP backend release build with default options",
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_INSTALL_PREFIX": "/opt/rocm",
"HIPSOLVER_ENABLE_CUDA": "OFF"
}
},
{
"name": "release-cuda",
"displayName": "CUDA Release",
"description": "CUDA backend release build with default options",
"inherits": "base",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"HIPSOLVER_ENABLE_CUDA": "ON"
}
}
],
"buildPresets": [
{
"name": "build-dev-hip",
"configurePreset": "dev-hip"
},
{
"name": "build-dev-cuda",
"configurePreset": "dev-cuda"
},
{
"name": "build-release-hip",
"configurePreset": "release-hip"
},
{
"name": "build-release-cuda",
"configurePreset": "release-cuda"
}
]
}
190 changes: 80 additions & 110 deletions projects/hipsolver/clients/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,126 +1,96 @@
# ########################################################################
# Copyright (C) 2016-2024 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell cop-
# ies of the Software, and to permit persons to whom the Software is furnished
# to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM-
# PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNE-
# CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
# ########################################################################

# Consider removing this in the future
# This should appear before the project command, because it does not use FORCE
if(WIN32)
set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/package" CACHE PATH "Install path prefix, prepended onto install directories")
else()
set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "Install path prefix, prepended onto install directories")
endif()

# This has to be initialized before the project() command appears
# Set the default of CMAKE_BUILD_TYPE to be release, unless user specifies with -D. MSVC_IDE does not use CMAKE_BUILD_TYPE
if(NOT DEFINED CMAKE_CONFIGURATION_TYPES AND NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel.")
endif()

# This project may compile dependencies for clients
project(hipsolver-clients LANGUAGES CXX)
if(UNIX)
enable_language(Fortran)
endif()
# Copyright Advanced Micro Devices, Inc., or its affiliates.
# SPDX-License-Identifier: MIT

# We use C++17 features, this will add compile option: -std=c++17
set(CMAKE_CXX_STANDARD 17)
# --- Client dependencies ---

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)

include(build-options)

# Linking lapack library requires fortran flags
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)

if(HIPSOLVER_FIND_PACKAGE_LAPACK_CONFIG)
find_package(LAPACK 3.7 REQUIRED CONFIG)
find_package(LAPACK 3.7 REQUIRED CONFIG)
else()
find_package(LAPACK 3.7 REQUIRED)
find_package(LAPACK 3.7 REQUIRED)
endif()

if(NOT LAPACK_LIBRARIES)
set(LAPACK_LIBRARIES
${LAPACK_blas_LIBRARIES}
${LAPACK_lapack_LIBRARIES}
)
endif()

if(NOT TARGET hipsolver)
find_package(hipsolver REQUIRED CONFIG PATHS ${ROCM_PATH} /opt/rocm)
set(LAPACK_LIBRARIES
${LAPACK_blas_LIBRARIES}
${LAPACK_lapack_LIBRARIES}
)
endif()

if(BUILD_FORTRAN_BINDINGS)
set(hipsolver_f90_source_clients
include/hipsolver_fortran.f90
)
# --- Fortran client bindings ---

if(HIPSOLVER_ENABLE_FORTRAN)
if(HIPSOLVER_BUILD_TESTING OR HIPSOLVER_ENABLE_BENCHMARKS)
add_library(hipsolver_fortran_client STATIC)
target_sources(hipsolver_fortran_client PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/include/hipsolver_fortran.f90"
)
target_link_libraries(hipsolver_fortran_client PUBLIC hipsolver_fortran)
target_include_directories(hipsolver_fortran_client PUBLIC
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include/hipsolver>
$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/include/hipsolver/internal>
)
target_compile_definitions(hipsolver_fortran_client INTERFACE HAVE_HIPSOLVER_FORTRAN_CLIENT)
endif()
endif()

if(BUILD_CLIENTS_TESTS OR BUILD_CLIENTS_BENCHMARKS)
if(BUILD_FORTRAN_BINDINGS)
add_library(hipsolver_fortran_client STATIC ${hipsolver_f90_source_clients})
target_link_libraries(hipsolver_fortran_client hipsolver_fortran)
include_directories(${CMAKE_BINARY_DIR}/include/hipsolver)
include_directories(${CMAKE_BINARY_DIR}/include/hipsolver/internal)
target_compile_definitions(hipsolver_fortran_client INTERFACE HAVE_HIPSOLVER_FORTRAN_CLIENT)
endif()

add_library(clients-common INTERFACE)
target_include_directories(clients-common INTERFACE
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}/include
)
target_link_libraries(clients-common INTERFACE
$<$<PLATFORM_ID:Linux>:stdc++fs>
)
set(common_source_files
common/clients_utility.cpp
common/hipsolver_datatype2string.cpp
common/lapack_host_reference.cpp
common/utility.cpp
rocsolvercommon/rocsolver_test.cpp
)

prepend_path("${CMAKE_CURRENT_SOURCE_DIR}/" common_source_files common_source_paths)
target_sources(clients-common INTERFACE ${common_source_paths})

# Copy and point to sparse test data
file(COPY
${CMAKE_CURRENT_SOURCE_DIR}/sparsedata/
DESTINATION ${PROJECT_BINARY_DIR}/staging/sparsedata/
)
install(DIRECTORY
${CMAKE_CURRENT_SOURCE_DIR}/sparsedata/
DESTINATION ${CMAKE_INSTALL_DATADIR}/hipsolver/test
COMPONENT tests
)

if(BUILD_CLIENTS_TESTS)
add_subdirectory(gtest)
endif()

if(BUILD_CLIENTS_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
# --- Common client library ---

if(HIPSOLVER_BUILD_TESTING OR HIPSOLVER_ENABLE_BENCHMARKS)
add_library(hipsolver-clients-common OBJECT)

target_compile_features(hipsolver-clients-common PRIVATE cxx_std_17)

target_sources(hipsolver-clients-common PRIVATE
"${CMAKE_CURRENT_SOURCE_DIR}/common/clients_utility.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/hipsolver_datatype2string.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/lapack_host_reference.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/common/utility.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/rocsolvercommon/rocsolver_test.cpp"
)

target_include_directories(hipsolver-clients-common
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
)

target_link_libraries(hipsolver-clients-common
PUBLIC roc::hipsolver
PRIVATE Threads::Threads
)
Comment on lines +60 to +63
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarify linking strategy for roc::hipsolver on OBJECT library

hipsolver-clients-common is an OBJECT library whose compiled objects are incorporated into the final executables (hipsolver-test, hipsolver-bench). Linking roc::hipsolver PUBLIC here means every consumer of this OBJECT library inherits roc::hipsolver transitively, which creates redundancy since downstream targets (hipsolver-bench and hipsolver-test) also explicitly link roc::hipsolver.

Recommended action: Choose one of these approaches for consistency:

  • Option A (preferred): Keep roc::hipsolver PUBLIC on hipsolver-clients-common and remove the redundant explicit links from hipsolver-bench and hipsolver-test
  • Option B: Change to PRIVATE here and keep the explicit links in the downstream targets

Option A is cleaner and reduces duplication noted in other comments.


Generated by Claude Code


target_link_libraries(hipsolver-clients-common PUBLIC
$<$<PLATFORM_ID:Linux>:stdc++fs>
)

# Ensure PIC for shared library builds
set_target_properties(hipsolver-clients-common PROPERTIES
POSITION_INDEPENDENT_CODE ON
)

# Copy and point to sparse test data
file(COPY
"${CMAKE_CURRENT_SOURCE_DIR}/sparsedata/"
DESTINATION "${PROJECT_BINARY_DIR}/staging/sparsedata/"
)
install(DIRECTORY
"${CMAKE_CURRENT_SOURCE_DIR}/sparsedata/"
DESTINATION "${CMAKE_INSTALL_DATADIR}/hipsolver/test"
COMPONENT tests
)

if(HIPSOLVER_BUILD_TESTING)
add_subdirectory(gtest)
endif()

if(HIPSOLVER_ENABLE_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
endif()

if(BUILD_CLIENTS_SAMPLES)
add_subdirectory(samples)
if(HIPSOLVER_ENABLE_SAMPLES)
add_subdirectory(samples)
endif()
Loading
Loading