Skip to content
Merged
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
48 changes: 36 additions & 12 deletions projects/rocsparse/clients/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@
# The ROCm platform requires Ubuntu 16.04 or Fedora 24, which has cmake 3.5
cmake_minimum_required(VERSION 3.5 FATAL_ERROR)

function( apply_omp_settings lib_target_ )
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND TARGET OpenMP::OpenMP_CXX)
set_target_properties( ${lib_target_} PROPERTIES
BUILD_RPATH "${HIP_CLANG_ROOT}/lib"
)
set_target_properties( ${lib_target_} PROPERTIES
INSTALL_RPATH "$ORIGIN/../llvm/lib"
)
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND TARGET OpenMP::omp)
set_target_properties( ${lib_target_} PROPERTIES
BUILD_RPATH "${HIP_CLANG_ROOT}/${openmp_LIB_DIR}"
)
set_target_properties( ${lib_target_} PROPERTIES
INSTALL_RPATH "$ORIGIN/../llvm/${openmp_LIB_DIR}"
)
endif()
endfunction()

if (rocblas_FOUND)
message("Build rocSPARSE client with rocBLAS")
add_compile_options(-DROCSPARSE_WITH_ROCBLAS)
Expand Down Expand Up @@ -69,6 +87,24 @@ if ( BUILD_FORTRAN_CLIENTS )

endif()

if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
# Look for openmp config in ROCm install to populate openmp_LIB_DIR and openmp_LIB_INSTALL_DIR
find_package(OpenMP CONFIG PATHS "${HIP_CLANG_ROOT}/lib/cmake")
endif()

# OpenMP
Comment thread
ntrost57 marked this conversation as resolved.
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND TARGET OpenMP::omp)
set(ROCSPARSE_CLIENT_LIBS "OpenMP::omp")
message(STATUS "Found openmp-config.cmake at ${OpenMP_DIR}")
else()
# if it fails to find OpenMP compile and link flags in strange configurations it can just use non-parallel reference computation
# if there is no omp.h to find the client compilation will fail and this should be obvious, used to be REQUIRED
find_package(OpenMP)
if (TARGET OpenMP::OpenMP_CXX)
set(ROCSPARSE_CLIENT_LIBS "OpenMP::OpenMP_CXX")
endif()
endif()

# Determine if CXX Compiler is hip-clang
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
message(STATUS "Using hip-clang to build for amdgpu backend")
Expand Down Expand Up @@ -108,18 +144,6 @@ elseif(NOT CMAKE_CXX_STANDARD EQUAL 17)
message(FATAL_ERROR "Only C++14 and C++17 are supported")
endif()

# If OpenMP is available, we can use it to speed up some tests
find_package(OpenMP QUIET)

if(OPENMP_FOUND)
if(NOT TARGET OpenMP::OpenMP_CXX)
# OpenMP cmake fix for cmake <= 3.9
add_library(OpenMP::OpenMP_CXX IMPORTED INTERFACE)
set_property(TARGET OpenMP::OpenMP_CXX PROPERTY INTERFACE_COMPILE_OPTIONS ${OpenMP_CXX_FLAGS})
set_property(TARGET OpenMP::OpenMP_CXX PROPERTY INTERFACE_LINK_LIBRARIES ${OpenMP_CXX_FLAGS} Threads::Threads)
endif()
endif()

if(BUILD_CLIENTS_SAMPLES)
add_subdirectory(samples)
endif()
Expand Down
14 changes: 4 additions & 10 deletions projects/rocsparse/clients/benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -215,21 +215,15 @@ target_compile_options(rocsparse-bench PRIVATE -Wno-deprecated -Wno-unused-comma
# Internal common header
target_include_directories(rocsparse-bench PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)

# Add OpenMP if available
apply_omp_settings(rocsparse-bench)

# Target link libraries
target_link_libraries(rocsparse-bench PRIVATE roc::rocsparse hip::host hip::device)
target_link_libraries(rocsparse-bench PRIVATE roc::rocsparse hip::host hip::device ${ROCSPARSE_CLIENT_LIBS})
if (rocsparseio_FOUND)
target_link_libraries(rocsparse-bench PRIVATE roc::rocsparseio)
endif()

# Add OpenMP if available
if(OPENMP_FOUND)
if (NOT WIN32)
target_link_libraries(rocsparse-bench PRIVATE OpenMP::OpenMP_CXX -Wl,-rpath=${HIP_CLANG_ROOT}/lib)
else()
target_link_libraries(rocsparse-bench PRIVATE libomp)
endif()
endif()

Comment on lines -219 to -232
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This broke building rocSPARSE on Windows as amd-llvm doesn't provide OpenMP on Windows. See #1173.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks. Possible fixing PR #1373

Copy link
Copy Markdown
Contributor

@jsandham jsandham Aug 27, 2025

Choose a reason for hiding this comment

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

Oh I see you already have a PR #1352. Ill close mine.

if (NOT WIN32)
if (BUILD_WITH_ROCTX)

Expand Down
14 changes: 4 additions & 10 deletions projects/rocsparse/clients/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -403,17 +403,11 @@ target_compile_options(rocsparse-test PRIVATE -ffp-contract=on -mfma -Wno-deprec
# Internal common header
target_include_directories(rocsparse-test PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)

# Target link libraries
target_link_libraries(rocsparse-test PRIVATE GTest::gtest roc::rocsparse hip::host hip::device)

# Add OpenMP if available
if(OPENMP_FOUND)
if (NOT WIN32)
target_link_libraries(rocsparse-test PRIVATE OpenMP::OpenMP_CXX -Wl,-rpath=${HIP_CLANG_ROOT}/lib)
else()
target_link_libraries(rocsparse-test PRIVATE libomp)
endif()
endif()
apply_omp_settings(rocsparse-test)

# Target link libraries
target_link_libraries(rocsparse-test PRIVATE GTest::gtest roc::rocsparse hip::host hip::device ${ROCSPARSE_CLIENT_LIBS})

if (NOT WIN32)
if (BUILD_WITH_ROCTX)
Expand Down
14 changes: 1 addition & 13 deletions projects/rocsparse/clients/tools/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,7 @@ foreach(app ${ROCSPARSEIO_TOOLS_SOURCES})
add_executable(${app} ${app}.cpp ${ROCSPARSEIO_SOURCES})

# Internal common header
target_include_directories(${app} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include ${CMAKE_CURRENT_SOURCE_DIR}/../common)

# Target link libraries
target_link_libraries(${app} PRIVATE roc::rocsparse hip::host ${EXTRA_LIBS})

# Add OpenMP if available
if(OPENMP_FOUND)
if (NOT WIN32)
target_link_libraries(${app} PRIVATE OpenMP::OpenMP_CXX -Wl,-rpath=${HIP_CLANG_ROOT}/lib)
else()
target_link_libraries(${app} PRIVATE libomp)
endif()
endif()
Comment thread
ntrost57 marked this conversation as resolved.
target_include_directories(${app} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../common>)

# Set tools output directory
set_target_properties(${app} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging")
Expand Down
Loading