[libc-commits] [PATCH] D158774: [libc] Add GPU support for `printf` and `fprintf`

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Aug 24 13:33:48 PDT 2023


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

This patch adds support for calling the `printf` and `fprintf` functions
from the GPU. The overall goal is to provide an implementation of
`printf` that is light-weight enough to be used on the GPU without
straining resources or being too slow.

The RPC interface allows for streaming arbitrary bytes from the client to
the server. To implement `printf`, we first stream the format string to
the server. Then, both sides use an extremely minimal parser to identify
the sizes and number of arguments that will be exchanged. The client will
then use this information to traverse through the variadic list with the
appropriate sizes and send the argument to the server. The server uses
this to build an array of all the argument to `printf`.

Once the server has these arguments, we can re-use the LLVM C library
handling of `printf`. With a custom argument list we can instead
traverse this array of pointers instead of a varadic list.

This patch depends on correct codegen and implementation of variadics on
the GPU, which is being handled by @JonChesterfield.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158774

Files:
  libc/config/gpu/entrypoints.txt
  libc/include/llvm-libc-types/rpc_opcodes_t.h
  libc/src/__support/arg_list.h
  libc/src/stdio/CMakeLists.txt
  libc/src/stdio/fprintf.cpp
  libc/src/stdio/generic/CMakeLists.txt
  libc/src/stdio/generic/fprintf.cpp
  libc/src/stdio/generic/printf.cpp
  libc/src/stdio/generic/vfprintf.cpp
  libc/src/stdio/generic/vprintf.cpp
  libc/src/stdio/gpu/CMakeLists.txt
  libc/src/stdio/gpu/file.h
  libc/src/stdio/gpu/fprintf.cpp
  libc/src/stdio/gpu/parser.h
  libc/src/stdio/gpu/printf.cpp
  libc/src/stdio/gpu/printf_impl.h
  libc/src/stdio/printf.cpp
  libc/src/stdio/printf_core/parser.h
  libc/src/stdio/vfprintf.cpp
  libc/src/stdio/vprintf.cpp
  libc/test/integration/startup/gpu/CMakeLists.txt
  libc/test/integration/startup/gpu/rpc_printf_test.cpp
  libc/test/src/stdio/CMakeLists.txt
  libc/utils/gpu/server/CMakeLists.txt
  libc/utils/gpu/server/rpc_server.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158774.553245.patch
Type: text/x-patch
Size: 29383 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230824/129b032f/attachment-0001.bin>


More information about the libc-commits mailing list