This is an archive of the discontinued LLVM Phabricator instance.

[Libomptarget] Make libomptarget an LLVM library
ClosedPublic

Authored by jhuber6 on Jul 15 2022, 9:18 AM.

Details

Summary

This patch makes libomptarget depend on LLVM libraries to be built. The
reason for this is because we already have an implicit dependency on
LLVM headers for ELF identification and extraction as well as an
optional dependenly on the LLVMSupport library for time tracing
information. Furthermore, there are changes in the future that require
using more LLVM libraries, and will heavily simplify some future code as
well as open up the large amount of useful LLVM libraries to
libomptarget.

This will make "standalone" builds of `libomptarget' more difficult for
vendors wishing to ship their own. This will require a sufficiently new
version of LLVM to be installed on the system that should be picked up
by the existing handling for the implicit headers.

The things this patch changes are as follows:

  • libomptarget.so links against LLVMSupport and LLVMObject
  • libomptarget.so is a symbolic link to libomptarget.so.15
  • If using a shared library build, user applications will depend on LLVM libraries as well
  • We can now use LLVM resources in Libomptarget.

Note that this patch only changes this to apply to libomptarget itself,
not the plugins. Additional patches will be necessary for that.

Diff Detail

Event Timeline

jhuber6 created this revision.Jul 15 2022, 9:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2022, 9:18 AM
Herald added a subscriber: mgorny. · View Herald Transcript
jhuber6 requested review of this revision.Jul 15 2022, 9:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 15 2022, 9:18 AM

It's going to be difficult to tell which vendors or CI systems are affected without landing this. I remember objections to that strategy in the past, anyone have an alternative suggestion?

jhuber6 updated this revision to Diff 445123.Jul 15 2022, 1:56 PM

Change link libraries to LINK_LIBS.

It's going to be difficult to tell which vendors or CI systems are affected without landing this. I remember objections to that strategy in the past, anyone have an alternative suggestion?

I didn't have any problems locally doing either a LLVM_ENABLE_PROJECTS=openmp or a LLVM_ENABLE_RUNTIMES=openmp build. However it seems the pre-merge checks end up with a lot of failures. It may just require rebuilding properly.

Another advantage of this is that we should be able to drop the dl, libelf, and libffi dependencies and use some LLVM libraries instead.

Prefer additional dependency remains optional.

Prefer additional dependency remains optional.

That's the problem really. It means reimplementing a bunch of object format handling and sticking with raw dlopen etc. The return on the investment of DIY or copy/pasting blocks of llvm source is really poor relative to requiring llvm to build the library from llvm.

Prefer additional dependency remains optional.

The only downsides I see from this approach is that user code will depend on LLVM libraries if LLVM is build using shared libraries. But I'm pretty sure the default build method in LLVM is to use static libraries so that shouldn't propagate to users just wishing to build libomptarget alone. We may have some vendors complain about the extra dependency, but I'm personally not aware of anyone using Clang/LLVM for OpenMP offloading that isn't building it with LLVM or getting it through a release that was build with LLVM.

Prefer additional dependency remains optional.

The only downsides I see from this approach is that user code will depend on LLVM libraries if LLVM is build using shared libraries. But I'm pretty sure the default build method in LLVM is to use static libraries so that shouldn't propagate to users just wishing to build libomptarget alone. We may have some vendors complain about the extra dependency, but I'm personally not aware of anyone using Clang/LLVM for OpenMP offloading that isn't building it with LLVM or getting it through a release that was build with LLVM.

That is exactly my concern. Won't be happy to see llvm libraries on the application side. If it is internal to the libomptarget, that is fine. It seems all the llvm libraries are static in my builds. Then it is likely OK.

Prefer additional dependency remains optional.

The only downsides I see from this approach is that user code will depend on LLVM libraries if LLVM is build using shared libraries. But I'm pretty sure the default build method in LLVM is to use static libraries so that shouldn't propagate to users just wishing to build libomptarget alone. We may have some vendors complain about the extra dependency, but I'm personally not aware of anyone using Clang/LLVM for OpenMP offloading that isn't building it with LLVM or getting it through a release that was build with LLVM.

That is exactly my concern. Won't be happy to see llvm libraries on the application side. If it is internal to the libomptarget, that is fine. It seems all the llvm libraries are static in my builds. Then it is likely OK.

If you want to make extra sure you can apply this patch and use the new clang to compile any offloading application. Run ldd on it and see if there are any LLVM libraries listed in the dependencies.

If you want to make extra sure you can apply this patch and use the new clang to compile any offloading application. Run ldd on it and see if there are any LLVM libraries listed in the dependencies.

Tried it. It was clean.

JonChesterfield accepted this revision.Jul 18 2022, 3:29 PM

Static linking llvm libs into libomptarget should remove any deployment concerns. The binary is then very similar to what we'd have if we copy/paste/reimplement instead of reuse.

This revision is now accepted and ready to land.Jul 18 2022, 3:29 PM

If you want to make extra sure you can apply this patch and use the new clang to compile any offloading application. Run ldd on it and see if there are any LLVM libraries listed in the dependencies.

Tried it. It was clean.

Thanks, I will try to land this tomorrow and see what falls over.

This revision was landed with ongoing or failed builds.Jul 19 2022, 9:33 AM
This revision was automatically updated to reflect the committed changes.
JonChesterfield added a comment.EditedJul 19 2022, 10:00 AM

Immediately took down the amdgpu buildbot with error while loading shared libraries: libomptarget.so.15, cannot open shared object file: No such file or directory, reverted while trying to guess why

@ronlieb thoughts?

jhuber6 reopened this revision.Jul 20 2022, 6:50 AM

Going to try to land this again, I believe the problems caused on the AMDGPU buildbot are primarily because the LLVM library installs things to ./lib in the build directory while the old library lived at ./openmp/libomptarget/ or similar.

This revision is now accepted and ready to land.Jul 20 2022, 6:50 AM
jhuber6 updated this revision to Diff 446141.Jul 20 2022, 6:51 AM

Adding another installation directory. This will install the library at the previous location as well as the standard LLVM one. This isn't the ideal solution, but it's much less noisy until we totally migrate all the plugins and libraries. Once we do that we can just update the LIBOMPTARGET_LIBRARY_DIR variable to be LLVM_LIBRARY_DIR.

This revision was landed with ongoing or failed builds.Jul 20 2022, 6:52 AM
This revision was automatically updated to reflect the committed changes.
jhuber6 reopened this revision.Jul 20 2022, 12:57 PM

Opening again, hopefully third time's the charm.

This revision is now accepted and ready to land.Jul 20 2022, 12:57 PM
jhuber6 updated this revision to Diff 446240.Jul 20 2022, 12:57 PM

Updating with new extra lit variables for the LLVM library rpath.

This revision was landed with ongoing or failed builds.Jul 20 2022, 12:58 PM
This revision was automatically updated to reflect the committed changes.
kaz7 added a subscriber: kaz7.EditedAug 6 2022, 5:18 AM

Hi, I am having configuration error after this patch like it cannot find zlib and terminfo to compile libomptarget. Why those are required for libomptarget is that those libraries are listed in install/lib/cmake/llvm/LLVMConfig.cmake like below if I compile llvm with default setting. it's clear that libomptarget doesn't require them, but this patch change it to require similar libraries as llvm itself. I would like to disable them for only libomptarget compiling. Do you know how to do that? Please let me know any way to solve this situation. Thank you!

set(LLVM_ENABLE_TERMINFO TRUE)
if(LLVM_ENABLE_TERMINFO)
  find_package(Terminfo)
endif()

set(LLVM_ENABLE_ZLIB 1)
if(LLVM_ENABLE_ZLIB)
  set(ZLIB_ROOT )
  find_package(ZLIB)
endif()

Hi, I am having configuration error after this patch like it cannot find zlib and terminfo to compile libomptarget. Why those are required for libomptarget is that those libraries are listed in install/lib/cmake/llvm/LLVMConfig.cmake like below if I compile llvm with default setting. it's clear that libomptarget doesn't require them, but this patch change it to require similar libraries as llvm itself. I would like to disable them for only libomptarget compiling. Do you know how to do that? Please let me know any way to solve this situation. Thank you!

set(LLVM_ENABLE_TERMINFO TRUE)
if(LLVM_ENABLE_TERMINFO)
  find_package(Terminfo)
endif()

set(LLVM_ENABLE_ZLIB 1)
if(LLVM_ENABLE_ZLIB)
  set(ZLIB_ROOT )
  find_package(ZLIB)
endif()

Libomptarget now depends on the LLVM libraries , so whatever dependencies LLVM has libomptarget needs to have as well. Is it possible for you to build with -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_ZLIB=OFF? I'd assume that would stop LLVM from looking for it and prevent libomptarget from picking it up either.

kaz7 added a comment.Aug 6 2022, 6:44 PM

Libomptarget now depends on the LLVM libraries , so whatever dependencies LLVM has libomptarget needs to have as well. Is it possible for you to build with -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_ZLIB=OFF? I'd assume that would stop LLVM from looking for it and prevent libomptarget from picking it up either.

Yes. Adding those options to not only libomptarget but also whole llvm solves this problem. Thank you.

But, do you really want to make libomptarget depends on LLVM libraries including terminfo and zlib although libomptarget is running on accelarators? Isn't it possible to separate LLVM libraries for hosts and for targets somehow? Just a thought.

Libomptarget now depends on the LLVM libraries , so whatever dependencies LLVM has libomptarget needs to have as well. Is it possible for you to build with -DLLVM_ENABLE_TERMINFO=OFF -DLLVM_ENABLE_ZLIB=OFF? I'd assume that would stop LLVM from looking for it and prevent libomptarget from picking it up either.

Yes. Adding those options to not only libomptarget but also whole llvm solves this problem. Thank you.

But, do you really want to make libomptarget depends on LLVM libraries including terminfo and zlib although libomptarget is running on accelarators? Isn't it possible to separate LLVM libraries for hosts and for targets somehow? Just a thought.

LLVM builds and links static libraries by default, so unless changed by the user the LLVM libraries shouldn't be required by user applications using libomptarget. Is the problem here that LLVM is pulling in dependencies for libz and terminfo that aren't statically removed in the default build configuration? If that's the case it would be a good idea to try to remove those unless we explicitly need them.

JonChesterfield added a comment.EditedAug 7 2022, 12:26 AM

libomptarget is running on accelarators

Libomptarget is host code. There's another library called DeviceRTL which runs on the accelerator and that won't be linking in llvm libs or zlib.

We could audit which llvm libs are transitively depended on and see whether they use zlib or terminfo and try to avoid them if necessary, but that's really better solved at the llvm libs level. Only declare the dependency on libs that use them. I'd guess that hasn't been worth doing so far so using any llvm lib is taken as a sign that you may as well link those two as well, unless you opted out using the top level defines. Doesn't look especially worth the cmake complexity and maintenance cost to me.

kaz7 added a comment.Aug 8 2022, 1:06 AM

Libomptarget is host code. There's another library called DeviceRTL which runs on the accelerator and that won't be linking in llvm libs or zlib.

Thank you for the correction! Then, I'm not sure why cmake for libomptarget fails to find terminfo and zlib although those are used by llvm itself.

We could audit which llvm libs are transitively depended on and see whether they use zlib or terminfo and try to avoid them if necessary, but that's really better solved at the llvm libs level. Only declare the dependency on libs that use them. I'd guess that hasn't been worth doing so far so using any llvm lib is taken as a sign that you may as well link those two as well, unless you opted out using the top level defines. Doesn't look especially worth the cmake complexity and maintenance cost to me.

That's true. It's much easier and I agree with you. Ok. Thanks!

efocht added a subscriber: efocht.Aug 9 2022, 6:29 AM