[libc-commits] [PATCH] D151735: [libc] Implement basic `malloc` and `free` support on the GPU

Joseph Huber via Phabricator via libc-commits libc-commits at lists.llvm.org
Tue May 30 10:16:58 PDT 2023


jhuber6 created this revision.
jhuber6 added reviewers: jdoerfert, tianshilei1992, yaxunl, JonChesterfield, tra, carlo.bertolli, jplehr, sivachandra, lntue, michaelrj.
Herald added subscribers: libc-commits, mattd, asavonic, kerbowa, tschuett, jvesely.
Herald added projects: libc-project, All.
jhuber6 requested review of this revision.

This patch adds support for the `malloc` and `free` functions. These
currently aren't implemented in-tree so we first add the interface
filies.

This patch provides the most basic support for a true `malloc` and
`free` by using the RPC interface. This is functional, but in the future
we will want to implement a more intelligent system and primarily use
the RPC interface more as a `brk()` or `sbrk()` interface only called
when absolutely necessary. We will need to design an intelligent
allocator in the future.

The semantics of these memory allocations will need to be checked. I am
somewhat iffy on the details. I've heard that HSA can allocate
asynchronously which seems to work with my tests at least. CUDA uses an
implicit synchronization scheme so we need to use an explicitly separate
stream from the one launching the kernel or the default stream. I will
need to test the NVPTX case.

I would appreciate if anyone more experienced with the implementation details
here could chime in for the HSA and CUDA cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D151735

Files:
  libc/src/__support/RPC/rpc.h
  libc/src/stdlib/CMakeLists.txt
  libc/src/stdlib/free.h
  libc/src/stdlib/gpu/CMakeLists.txt
  libc/src/stdlib/gpu/free.cpp
  libc/src/stdlib/gpu/malloc.cpp
  libc/src/stdlib/malloc.h
  libc/test/src/stdlib/CMakeLists.txt
  libc/test/src/stdlib/malloc_test.cpp
  libc/utils/gpu/loader/Server.h
  libc/utils/gpu/loader/amdgpu/Loader.cpp
  libc/utils/gpu/loader/nvptx/Loader.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151735.526701.patch
Type: text/x-patch
Size: 13442 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230530/a010ccb6/attachment-0001.bin>


More information about the libc-commits mailing list