This is an archive of the discontinued LLVM Phabricator instance.

[libc] Remove OpenMP and build the GPU libc directly
ClosedPublic

Authored by jhuber6 on Feb 1 2023, 9:47 AM.

Details

Summary

The current libcgpu.a is actually an archive of fatbinaries. The host
file contains nothing but a section called LLVM_OFFLOADING that
contains embedded device code. This used to be handled implicitly by
borrowing the OpenMP toolchain, which did this packaging internally.
Passing the OpenMP flags causes problems with trying to move to testing.
This patch pulls this logic out into the CMake and handles it manually.

This patch is a lot of noise, but it fundamentally comes down to the
following changes.

  1. Build the source for every GPU architecture (GPU architectures are generally not backwards compatible)
  2. Combine all of these files into a single binary blob
  3. Embed that binary blob into a host file
  4. Package these host files into a .a archive.
  5. The device code will be extracted and managed by the offloading linker.

Another important point. Right now we are maintaining an important
distinction with the GPU build. That is, when we build the exported
library we will build for many GPU architectures. However, the internal
version will only be built for a single GPU architecture, one that was
found on the user's system. This is intended to be used for internal
testing, very similar to the current path where libc is compiled for a
single target triple.

Diff Detail

Event Timeline

jhuber6 created this revision.Feb 1 2023, 9:47 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptFeb 1 2023, 9:47 AM
jhuber6 requested review of this revision.Feb 1 2023, 9:47 AM

Mostly LGTM but I have left a few nits and request for one TODO. I will approve as soon as I can see the TODO comment.

libc/cmake/modules/LLVMLibCObjectRules.cmake
157

gpu can potentially be directory name. So, can we use a suffix like, .__gpu__?

158

Can this be given a suffix of .gpu.bin?

163

Can this be moved into the foreach block above?

175

Can you add a TODO explaining how this will evolve?

204

Can this be moved to the if block where the internal target is actually added?

jhuber6 updated this revision to Diff 494271.Feb 2 2023, 5:37 AM

Addressing comments.

jhuber6 marked 5 inline comments as done.Feb 2 2023, 5:37 AM
sivachandra accepted this revision.Feb 2 2023, 7:04 AM
This revision is now accepted and ready to land.Feb 2 2023, 7:04 AM
This revision was automatically updated to reflect the committed changes.