[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
Wed Jun 28 09:47:20 PDT 2023


jhuber6 added a comment.

In D153897#4456220 <https://reviews.llvm.org/D153897#4456220>, @jdoerfert wrote:

> Localizing the hacks seems reasonable. Putting it in clang/lib/headers might not be the best idea though but I won't fight it. I was hoping to have it self contained in libc, but again, that is debatable.

I'll mirror a comment I made on the original RFC what the alternate approach will look like.

  #ifndef __ATTRS
  #define __ATTRS
  #endif
  
  int fputs(const char *__restrict, FILE *__restrict) __ATTRS;
  extern FILE * stderr __ATTRS;

This would then be included by a wrapper header in clang/ilb/Headers/__libc_wrappers/stdio.h which looks like the following,

  #ifndef __CLANG_LIBC_WRAPPERS_STDIO_H__
  #define __CLANG_LIBC_WRAPPERS_STDIO_H__
  #include_next <stdio.h>
  
  #if defined(__CUDA__) || defined(__HIP__)
  #define __ATTRS __attribiute__((device))
  #endif
  
  #pragma omp begin declare target
  #include <llvm-gpu-none/llvm-libc-declarations/stdlib.h>
  #pragma omp end declare target
  
  #endif

The downside is that we don't get these nice unified headers, but I think with the extent of hacks for each language it may be better to shuttle that next to where `clang` is. This would pretty much be a separate mode for `libc-hdrgen` that just spits out the entrypoints, so it's much less intrusive to `libc` and it gives us a hook that we can add whatever workarounds we'll require for the offloading case. I think I'm favoring this approach having thought through it, because in my head I can already imagine a large number of `#undefs` we'll need to do, and I don't think we should mash those into the `libc` implementation itself.

I'll try to make a new patch to illustrate this after lunch that's hopefully agreeable with everyone involved. Getting this done would be a major milestone in being able to ship the `libc` so I'm eager to make progress. So thanks for everyone's continued involvement.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D153897/new/

https://reviews.llvm.org/D153897



More information about the libc-commits mailing list