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

Conversation

estewart08
Copy link
Contributor

An upstream llvm change enables
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR by default for the openmp build. This installs the openmp libraries into
/opt/rocm-ver/llvm/lib/x86_64-unknown-linux-gnu instead of /opt/rocm-ver/llvm/lib. Currenty, hipBLAS only uses /lib.

Since hipBLAS uses gcc by default, find_package(OpenMP) will locate libgomp from the gnu installation. We would prefer to use libomp from the ROCm install. Query amdclang to find LLVM_TARGET_TRIPLE and use as a suffix for find_library(omp).

On the other hand, the user can choose to use hipcc, which allows find_package(OpenMP) to properly locate libomp inside ROCm llvm.

To include legacy support, I left the hardcoded -L HIP_CLANG_ROOT as a fallback.

This would be much simpler if hipBLAS defaulted to hipcc as the cmake compiler.

Summary of proposed changes:

  • If compiler is gcc, query amdclang for LLVM_TARGET_TRIPLE and use as suffix for find_library(omp).
  • If compiler is hipcc, use find_package(OpenMP).
  • If cmake cannot find libomp.so then fallback to using -L HIP_CLANG_ROOT/lib.
  • Allow proper detection of new lib installation subdirectory (i.e. x86_64-unknown-linux-gnu).
  • Removed dependency on find_package(LLVM) due to rocm-llvm-dev/devel not being installed by default on various operating systems, which would not have the cmake config files.

An upstream llvm change enables
LLVM_ENABLE_PER_TARGET_RUNTIME_DIR by default for the openmp
build. This installs the openmp libraries into
/opt/rocm-ver/llvm/lib/x86_64-unknown-linux-gnu instead of
/opt/rocm-ver/llvm/lib. Currenty, hipBLAS only uses /lib.

Since hipBLAS uses gcc by default, find_package(OpenMP) will
locate libgomp from the gnu installation. We would prefer
to use libomp from the ROCm install. Query amdclang to find
LLVM_TARGET_TRIPLE and use as a suffix for find_library(omp).

On the other hand, the user can choose to use hipcc, which
allows find_package(OpenMP) to properly locate libomp
inside ROCm llvm.

To include legacy support, I left the hardcoded -L with
use of HIP_CLANG_ROOT as a fallback.

This would be much simpler if hipBLAS defaulted to hipcc
as the cmake compiler.
Comment on lines -121 to -122
if (TARGET OpenMP::OpenMP_CXX)
set( COMMON_LINK_LIBS "OpenMP::OpenMP_CXX")
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.

@@ -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

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.

Remove amd check for rpath addtion. If we use the libomp.so from
ROCm we need the rpath.
@TorreZuk
Copy link
Contributor

Hi @estewart08 are you still active on this?

@estewart08
Copy link
Contributor Author

I am going to pick this effort back up, so I would prefer it to stay open for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants