This is an archive of the discontinued LLVM Phabricator instance.

[Libomptarget] Build the device runtime as a static library
ClosedPublic

Authored by jhuber6 on May 10 2022, 7:04 AM.

Details

Summary

This patch adds the necessary CMake configuration to build a static
library version of the device runtime, libomptarget.devicertl.a.
Various improvements in how we handle static libraries and generating
offloading code should allow us to treat the device library as a regular
project without needing to invoke the clang front-end directly. Here we
generate a job for each offloading architecture supported. Each
offloading architecture will be embedded into the static library and
used as-needed by the host.

This library will primarily be used to replace the bitcode library when
performing LTO. Currently, we need to manually pass in the bitcode
library which requires foreknowledge of the offloading architecture.
This approach lets us handle that in the linker wrapper instead.
Furthermore this should improve our interface to the device runtime. We
can now build it fully under a release build and have all the expected
entry points, as well as supporting debug builds.

Depends on D125265 D125256 D125260 D125314 D125563

Diff Detail

Event Timeline

jhuber6 created this revision.May 10 2022, 7:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2022, 7:04 AM
Herald added a subscriber: mgorny. · View Herald Transcript
jhuber6 requested review of this revision.May 10 2022, 7:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 10 2022, 7:04 AM

This design is much better because we don't need to have one bc file for each target. What's more, it uses CMake command to compile the library, which has better dependence tracking. Just one comment on the order stuff.

openmp/libomptarget/CMakeLists.txt
41 ↗(On Diff #428363)

The order here is critical because both openmp/libomptarget/include and openmp/libomptarget/DeviceRTL/include has Debug.h. However, I don't think that's a good practice to use order to guard that. IMO, we need to move the global include to where it is actually being used.

jhuber6 added inline comments.May 10 2022, 7:45 AM
openmp/libomptarget/CMakeLists.txt
41 ↗(On Diff #428363)

We need to change the include_directories to target_include_directories and specify it for each target. I wasn't sure if I should bother doing that for this patch.

tianshilei1992 added inline comments.May 10 2022, 7:49 AM
openmp/libomptarget/CMakeLists.txt
41 ↗(On Diff #428363)

That is the better way. No need to do it here but worth another patch. However, using order is not a good idea.

jhuber6 updated this revision to Diff 429288.May 13 2022, 10:23 AM

Rebase to not change the include directories.

This revision is now accepted and ready to land.May 13 2022, 10:23 AM
nikic added a subscriber: nikic.May 16 2022, 1:33 AM

This change has broken the build of libomp with gcc, as it appears to be using clang-specific options:

g++: error: unrecognized command-line option '-Xopenmp-target=nvptx64-nvidia-cuda'
g++: error: unrecognized command-line option '--cuda-feature=+ptx61'
g++: error: unrecognized command-line option '-nocudalib'; did you mean '-nostdlib'?
g++: error: unrecognized command-line option '-nogpulib'
g++: error: unrecognized command-line option '--offload-arch=sm_35'
g++: error: unrecognized command-line option '--offload-arch=sm_37'
g++: error: unrecognized command-line option '--offload-arch=sm_50'
g++: error: unrecognized command-line option '--offload-arch=sm_52'
g++: error: unrecognized command-line option '--offload-arch=sm_53'
g++: error: unrecognized command-line option '--offload-arch=sm_60'; did you mean '--offload-abi=lp64'?
g++: error: unrecognized command-line option '--offload-arch=sm_61'; did you mean '--offload-abi=lp64'?
g++: error: unrecognized command-line option '--offload-arch=sm_62'
g++: error: unrecognized command-line option '--offload-arch=sm_70'
g++: error: unrecognized command-line option '--offload-arch=sm_72'
g++: error: unrecognized command-line option '--offload-arch=sm_75'
g++: error: unrecognized command-line option '--offload-arch=sm_80'
g++: error: unrecognized command-line option '--offload-arch=sm_86'
g++: error: unrecognized command-line option '--offload-arch=gfx700'
g++: error: unrecognized command-line option '--offload-arch=gfx701'
g++: error: unrecognized command-line option '--offload-arch=gfx801'
g++: error: unrecognized command-line option '--offload-arch=gfx803'
g++: error: unrecognized command-line option '--offload-arch=gfx900'
g++: error: unrecognized command-line option '--offload-arch=gfx902'
g++: error: unrecognized command-line option '--offload-arch=gfx906'
g++: error: unrecognized command-line option '--offload-arch=gfx908'
g++: error: unrecognized command-line option '--offload-arch=gfx90a'
g++: error: unrecognized command-line option '--offload-arch=gfx90c'
g++: error: unrecognized command-line option '--offload-arch=gfx940'
g++: error: unrecognized command-line option '--offload-arch=gfx1010'
g++: error: unrecognized command-line option '--offload-arch=gfx1030'
g++: error: unrecognized command-line option '--offload-arch=gfx1031'
g++: error: unrecognized command-line option '--offload-arch=gfx1032'
g++: error: unrecognized command-line option '--offload-arch=gfx1033'
g++: error: unrecognized command-line option '--offload-arch=gfx1034'
g++: error: unrecognized command-line option '--offload-arch=gfx1035'
g++: error: unrecognized command-line option '--offload-arch=gfx1036'

This change has broken the build of libomp with gcc, as it appears to be using clang-specific options:

g++: error: unrecognized command-line option '-Xopenmp-target=nvptx64-nvidia-cuda'
g++: error: unrecognized command-line option '--cuda-feature=+ptx61'
g++: error: unrecognized command-line option '-nocudalib'; did you mean '-nostdlib'?
g++: error: unrecognized command-line option '-nogpulib'
g++: error: unrecognized command-line option '--offload-arch=sm_35'
g++: error: unrecognized command-line option '--offload-arch=sm_37'
g++: error: unrecognized command-line option '--offload-arch=sm_50'
g++: error: unrecognized command-line option '--offload-arch=sm_52'
g++: error: unrecognized command-line option '--offload-arch=sm_53'
g++: error: unrecognized command-line option '--offload-arch=sm_60'; did you mean '--offload-abi=lp64'?
g++: error: unrecognized command-line option '--offload-arch=sm_61'; did you mean '--offload-abi=lp64'?
g++: error: unrecognized command-line option '--offload-arch=sm_62'
g++: error: unrecognized command-line option '--offload-arch=sm_70'
g++: error: unrecognized command-line option '--offload-arch=sm_72'
g++: error: unrecognized command-line option '--offload-arch=sm_75'
g++: error: unrecognized command-line option '--offload-arch=sm_80'
g++: error: unrecognized command-line option '--offload-arch=sm_86'
g++: error: unrecognized command-line option '--offload-arch=gfx700'
g++: error: unrecognized command-line option '--offload-arch=gfx701'
g++: error: unrecognized command-line option '--offload-arch=gfx801'
g++: error: unrecognized command-line option '--offload-arch=gfx803'
g++: error: unrecognized command-line option '--offload-arch=gfx900'
g++: error: unrecognized command-line option '--offload-arch=gfx902'
g++: error: unrecognized command-line option '--offload-arch=gfx906'
g++: error: unrecognized command-line option '--offload-arch=gfx908'
g++: error: unrecognized command-line option '--offload-arch=gfx90a'
g++: error: unrecognized command-line option '--offload-arch=gfx90c'
g++: error: unrecognized command-line option '--offload-arch=gfx940'
g++: error: unrecognized command-line option '--offload-arch=gfx1010'
g++: error: unrecognized command-line option '--offload-arch=gfx1030'
g++: error: unrecognized command-line option '--offload-arch=gfx1031'
g++: error: unrecognized command-line option '--offload-arch=gfx1032'
g++: error: unrecognized command-line option '--offload-arch=gfx1033'
g++: error: unrecognized command-line option '--offload-arch=gfx1034'
g++: error: unrecognized command-line option '--offload-arch=gfx1035'
g++: error: unrecognized command-line option '--offload-arch=gfx1036'

The OpenMP offloading runtime was always intended to be built with a newly-built Clang, either through a two-phase build or with -DLLVM_ENABLE_RUNTIMES=openmp. This patch added some code that uses standard CMake to build the library, rather than locating the clang binary directly. I could add some code to skip building this static library, or the device runtime entirely, if the compiler isn't an up-to-date Clang. I'm not sure what the best solution to this is, since we always required that this was to be built with Clang, this patch just made it a more strict requirement.