Skip to content

Commit c4ee96b

Browse files
TorreZukassistant-librarian[bot]
authored andcommitted
[rocm-libraries] ROCm/rocm-libraries#624 (commit 2f44be4)
hotfix 7.0 use omp config (#565) find OpenMP config (#517) First search for ROCm's libomp.so via openmp-config.cmake. This is what we would prefer instead of searching for a system libomp.so/libgomp.so and then manually adding in a ROCm lib path. This methodology should still be RHEL-10 RPATH compliant. (cherry picked from commit 408affb61fe3a97d7eecc458f6314da8418035d5)
1 parent 0aa044b commit c4ee96b

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

clients/CMakeLists.txt

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@
2222

2323
cmake_minimum_required( VERSION 3.16.8 )
2424

25+
function( apply_omp_settings lib_target_ )
26+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND TARGET OpenMP::OpenMP_CXX)
27+
set_target_properties( ${lib_target_} PROPERTIES
28+
BUILD_RPATH "${HIP_CLANG_ROOT}/lib"
29+
)
30+
set_target_properties( ${lib_target_} PROPERTIES
31+
INSTALL_RPATH "$ORIGIN/../llvm/lib"
32+
)
33+
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND TARGET OpenMP::omp)
34+
set_target_properties( ${lib_target_} PROPERTIES
35+
BUILD_RPATH "${HIP_CLANG_ROOT}/${openmp_LIB_DIR}"
36+
)
37+
set_target_properties( ${lib_target_} PROPERTIES
38+
INSTALL_RPATH "$ORIGIN/../llvm/${openmp_LIB_DIR}"
39+
)
40+
endif()
41+
endfunction()
42+
2543
# This has to be initialized before the project() command appears
2644
# Set the default of CMAKE_BUILD_TYPE to be release, unless user specifies with -D. MSVC_IDE does not use CMAKE_BUILD_TYPE
2745
if( NOT DEFINED CMAKE_CONFIGURATION_TYPES AND NOT DEFINED CMAKE_BUILD_TYPE )
@@ -69,20 +87,21 @@ endif()
6987
set(THREADS_PREFER_PTHREAD_FLAG ON)
7088
find_package(Threads REQUIRED)
7189

72-
# if it fails to find OpenMP compile and link flags in strange configurations it can just use non-parallel reference computation
73-
# if there is no omp.h to find the client compilation will fail and this should be obvious, used to be REQUIRED
74-
find_package(OpenMP)
75-
76-
if (TARGET OpenMP::OpenMP_CXX)
77-
set( COMMON_LINK_LIBS "OpenMP::OpenMP_CXX")
78-
get_filename_component(LIBOMP_PATH "${OpenMP_omp_LIBRARY}" PATH)
79-
if (NOT WIN32)
80-
list( APPEND COMMON_LINK_LIBS "-Wl,-rpath=${LIBOMP_PATH}")
81-
endif()
90+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
91+
# Look for openmp config in ROCm install to populate openmp_LIB_DIR and openmp_LIB_INSTALL_DIR
92+
find_package(OpenMP CONFIG PATHS "${HIP_CLANG_ROOT}/lib/cmake")
8293
endif()
8394

84-
if (WIN32)
85-
list( APPEND COMMON_LINK_LIBS "libomp")
95+
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND TARGET OpenMP::omp)
96+
set( COMMON_LINK_LIBS "OpenMP::omp")
97+
message(STATUS "Found openmp-config.cmake at ${OpenMP_DIR}")
98+
else()
99+
# if it fails to find OpenMP compile and link flags in strange configurations it can just use non-parallel reference computation
100+
# if there is no omp.h to find the client compilation will fail and this should be obvious, used to be REQUIRED
101+
find_package(OpenMP)
102+
if (TARGET OpenMP::OpenMP_CXX)
103+
set( COMMON_LINK_LIBS "OpenMP::OpenMP_CXX")
104+
endif()
86105
endif()
87106

88107
if (TARGET Threads::Threads)

clients/benchmarks/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ endif()
7373

7474

7575
target_link_libraries( rocblas-bench PRIVATE ${COMMON_LINK_LIBS} )
76+
apply_omp_settings( rocblas-bench )
7677
if( BUILD_WITH_TENSILE )
7778
target_link_libraries( rocblas-gemm-tune PRIVATE ${COMMON_LINK_LIBS} )
79+
apply_omp_settings( rocblas-gemm-tune )
7880
endif()
7981

8082
target_compile_options(rocblas-bench PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${COMMON_CXX_OPTIONS}>)

clients/gtest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ if (NOT WIN32)
131131
list( APPEND COMMON_LINK_LIBS "-lm -lstdc++fs" )
132132
endif()
133133
target_link_libraries( rocblas-test PRIVATE ${COMMON_LINK_LIBS} )
134+
apply_omp_settings( rocblas-test )
134135

135136
target_compile_options(rocblas-test PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${COMMON_CXX_OPTIONS}>)
136137

0 commit comments

Comments
 (0)