From d0ff5e40308ee33936bfcc131f33adb4066b946f Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Thu, 13 Apr 2023 21:27:51 -0500 Subject: [libc] Update RPC interface for system utilities on the GPU This patch reworks the RPC interface to allow more generic memory operations using the shared better. This patch decomposes the entire RPC interface into opening a port and calling `send` or `recv` on it. The `send` function sends a single packet of the length of the buffer. The `recv` function is paired with the `send` call to then use the data. So, any aribtrary combination of sending packets is possible. The only restriction is that the client initiates the exchange with a `send` while the server consumes it with a `recv`. The operation of this is driven by two independent state machines that tracks the buffer ownership during loads / stores. We keep track of two so that we can transition between a send state and a recv state without an extra wait. State transitions are observed via bit toggling, e.g. This interface supports an efficient `send -> ack -> send -> ack -> send` interface and allows for the last send to be ignored without checking the ack. A following patch will add some more comprehensive testing to this interface. I I informally made an RPC call that simply incremented an integer and it took roughly 10 microsends to complete an RPC call. Reviewed By: jdoerfert Differential Revision: https://reviews.llvm.org/D148288 --- libc/startup/gpu/amdgpu/start.cpp | 4 +++- libc/startup/gpu/nvptx/start.cpp | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'libc/startup') diff --git a/libc/startup/gpu/amdgpu/start.cpp b/libc/startup/gpu/amdgpu/start.cpp index 9915dff..66f06b0 100644 --- a/libc/startup/gpu/amdgpu/start.cpp +++ b/libc/startup/gpu/amdgpu/start.cpp @@ -8,12 +8,14 @@ #include "src/__support/RPC/rpc_client.h" +static __llvm_libc::cpp::Atomic lock; + extern "C" int main(int argc, char **argv, char **envp); extern "C" [[gnu::visibility("protected"), clang::amdgpu_kernel]] void _start(int argc, char **argv, char **envp, int *ret, void *in, void *out, void *buffer) { - __llvm_libc::rpc::client.reset(in, out, buffer); + __llvm_libc::rpc::client.reset(&lock, in, out, buffer); __atomic_fetch_or(ret, main(argc, argv, envp), __ATOMIC_RELAXED); } diff --git a/libc/startup/gpu/nvptx/start.cpp b/libc/startup/gpu/nvptx/start.cpp index b09d6f6..9939c6e 100644 --- a/libc/startup/gpu/nvptx/start.cpp +++ b/libc/startup/gpu/nvptx/start.cpp @@ -8,12 +8,14 @@ #include "src/__support/RPC/rpc_client.h" +static __llvm_libc::cpp::Atomic lock; + extern "C" int main(int argc, char **argv, char **envp); extern "C" [[gnu::visibility("protected")]] __attribute__((nvptx_kernel)) void _start(int argc, char **argv, char **envp, int *ret, void *in, void *out, void *buffer) { - __llvm_libc::rpc::client.reset(in, out, buffer); + __llvm_libc::rpc::client.reset(&lock, in, out, buffer); __atomic_fetch_or(ret, main(argc, argv, envp), __ATOMIC_RELAXED); } -- cgit v1.1