[libc-commits] [PATCH] D153897: [libc][hdr-gen] Add special offloading handling for the GPU target

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue Jun 27 10:30:14 PDT 2023


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, JonChesterfield, michaelrj, lntue, sivachandra.
Herald added projects: libc-project, All.
Herald added a subscriber: libc-commits.
jhuber6 requested review of this revision.
Herald added subscribers: jplehr, sstefan1.

The previous patch in D153794 <https://reviews.llvm.org/D153794> provided us with the necessary hooks to
wrap special handling required for GPU headers. As discussed in
https://discourse.llvm.org/t/rfc-implementing-gpu-headers-in-the-llvm-c-library,
we need special handling for the GPU headers if we want them to be
included from a standard offloading lanuage such as CUDA, HIP, or
OpenMP. This is important if we with to actually export the GPU `libc`
as there are the expected users of the interface. The internal
implementation uses a freestanding C++ mode chosen to keep the interface
common.

The requirements summarized for these offloading headers are as follows:

1. The same header must be included by both the host and device as they must agree on definitions
2. We must outline which definitions are provided by the LLVM GPU libc

This means that we need to include the system headers when compiling for
the GPU. Many issues with that are worked around with offloading
language semantics.

It is worth noting that this header mess will not munge the internal
implementation. This is merely a hack required to export these functions
in a way that's compatible with existing offloading languages. The
current use-case for `libc` is a freestanding mode which can use the
standard headers generated by `libc`. If we do not want these headers I
have added an option to disable this.

Depends on D153794 <https://reviews.llvm.org/D153794>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153897

Files:
  libc/cmake/modules/LLVMLibCHeaderRules.cmake
  libc/include/CMakeLists.txt
  libc/include/llvm-libc-macros/CMakeLists.txt
  libc/include/llvm-libc-macros/gpu-macros.h
  libc/utils/HdrGen/BeginCommand.cpp
  libc/utils/HdrGen/BeginCommand.h
  libc/utils/HdrGen/EndCommand.cpp
  libc/utils/HdrGen/EndCommand.h
  libc/utils/HdrGen/Generator.cpp
  libc/utils/HdrGen/Generator.h
  libc/utils/HdrGen/Main.cpp
  libc/utils/HdrGen/PublicAPICommand.cpp
  libc/utils/HdrGen/PublicAPICommand.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153897.535048.patch
Type: text/x-patch
Size: 11610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230627/83d62c72/attachment.bin>


More information about the libc-commits mailing list