Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revamp how libomp.so is found #853

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Changes from 2 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
36 changes: 32 additions & 4 deletions clients/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,41 @@ if( BUILD_CLIENTS_BENCHMARKS OR BUILD_CLIENTS_TESTS)

# 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( CMAKE_CXX_COMPILER MATCHES ".*/hipcc$" )
find_package(OpenMP)
Copy link
Contributor

@TorreZuk TorreZuk Apr 22, 2024

Choose a reason for hiding this comment

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

Similar question we shouldn't require NON hipcc to find_package(OpenMP) so can this just be moved two lines above? Sorry I meant other than hipcc we still want find_package to set cmake target etc.

Copy link
Contributor Author

@estewart08 estewart08 Apr 22, 2024

Choose a reason for hiding this comment

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

When the cmake compiler is hipcc find_package finds the correct ROCm libomp.so. Otherwise, gcc will get libgomp.so from gcc installation. I would rather get the libomp from ROCm to be consistent. With your current configuration cmake adds libgomp.so with -L/rpaths -lomp to the ROCm library. So I am fairly certain libgomp is ignored.

if (TARGET OpenMP::OpenMP_CXX)
set( LIBOMP_FOUND OpenMP::OpenMP_CXX)
get_filename_component(LIBOMP_PATH "${OpenMP_omp_LIBRARY}" PATH)
endif()
# Support for using gnu as cmake compiler.
else()
# libomp.so may be in a target subdirectory directory.
execute_process(
OUTPUT_STRIP_TRAILING_WHITESPACE
COMMAND bash -c "${HIP_CLANG_ROOT}/bin/amdclang --version | grep -oP '(?<=Target: ).+'"
OUTPUT_VARIABLE LLVM_TARGET_TRIPLE
)
find_library(LIBOMP_FOUND omp PATHS ${HIP_CLANG_ROOT}/lib PATH_SUFFIXES ${LLVM_TARGET_TRIPLE} NO_DEFAULT_PATH)
if (LIBOMP_FOUND)
get_filename_component(LIBOMP_PATH "${LIBOMP_FOUND}" PATH)
endif()
endif()

if (TARGET OpenMP::OpenMP_CXX)
set( COMMON_LINK_LIBS "OpenMP::OpenMP_CXX")
Comment on lines -121 to -122
Copy link
Contributor

Choose a reason for hiding this comment

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

So aren't we missing the OpenMP::OpenMP_CXX link request on CUDA backend?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I can move set( COMMON_LINK_LIBS ${LIBOMP_FOUND}) outside of the amd guard.

if(LIBOMP_FOUND)
# LIBOMP_FOUND will contain full path to libomp.so
set( COMMON_LINK_LIBS ${LIBOMP_FOUND})
if(HIP_PLATFORM STREQUAL amd AND NOT WIN32)
list( APPEND COMMON_LINK_LIBS "-Wl,-rpath=${LIBOMP_PATH}")
endif()
# If cmake cannot find the proper libomp.so, use HIP_CLANG_ROOT as fallback.
else()
if(HIP_PLATFORM STREQUAL amd)
# Add library search paths.
list( APPEND COMMON_LINK_LIBS "-L\"${HIP_CLANG_ROOT}/lib/${LLVM_TARGET_TRIPLE}\"")
list( APPEND COMMON_LINK_LIBS "-L\"${HIP_CLANG_ROOT}/lib\"")
if (NOT WIN32)
if(NOT WIN32)
# Add rpath.
list( APPEND COMMON_LINK_LIBS "-Wl,-rpath=${HIP_CLANG_ROOT}/lib/${LLVM_TARGET_TRIPLE}")
list( APPEND COMMON_LINK_LIBS "-Wl,-rpath=${HIP_CLANG_ROOT}/lib -lomp")
else()
list( APPEND COMMON_LINK_LIBS "libomp")
Expand Down