[libc-commits] [PATCH] D149107: [libc] Ignore 'errno' on the GPU and support 'atoi'

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Mon Apr 24 16:33:16 PDT 2023


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

The 'errno' value is most likely not useful on the GPU and it prevents
us from providing certain functions on the GPU that depend on it, like
`atoi`. This patch makes the necessary changes to support `errno` by
simple replacing it with a consumer class.

Supporting `errno` on the GPU is possible in some aspects. The first
approach would be to use a buffer of shared memory that has enough space
for all threads. Another option would be to change code generation to
support `thread_local` using `address_space(5)` memory allocated at
kernel launch. The former could look like the following, which could be
implemented in a later patch:

  template <typename T>
  using SharedBuffer = T[gpu::MAX_THREADS] [[clang::address_space(3)]];
  template <typename T> struct ErrnoSetter {
    constexpr ErrnoSetter(SharedBuffer<T> &storage) : storage(storage) {}
    SharedBuffer<T> &storage;
    void operator=(const T &val) { storage[gpu::get_thread_id()] = val; }
  };
  
  static SharedBuffer<int> thread_local_buffer [[clang::loader_uninitialized]];
  ErrnoSetter<int> __llvmlibc_internal_errno(thread_local_buffer);


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149107

Files:
  libc/config/gpu/entrypoints.txt
  libc/config/gpu/headers.txt
  libc/include/errno.h.def
  libc/src/errno/libc_errno.cpp
  libc/src/errno/libc_errno.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149107.516573.patch
Type: text/x-patch
Size: 3602 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230424/08f4283b/attachment.bin>


More information about the libc-commits mailing list