aboutsummaryrefslogtreecommitdiff
path: root/libc/src/gpu/rpc_host_call.cpp
diff options
context:
space:
mode:
authorJoseph Huber <jhuber6@vols.utk.edu>2023-07-11 14:14:08 -0500
committerJoseph Huber <jhuber6@vols.utk.edu>2023-07-19 10:11:46 -0500
commite537c839757c6bae91bd5adbf65eb4e06a040840 (patch)
tree207463a9bfa36bcbffc343046a7843b8e16b9fca /libc/src/gpu/rpc_host_call.cpp
parent68cd1dbc2ec97e20306694a7cdc480584295e62c (diff)
downloadllvm-e537c839757c6bae91bd5adbf65eb4e06a040840.zip
llvm-e537c839757c6bae91bd5adbf65eb4e06a040840.tar.gz
llvm-e537c839757c6bae91bd5adbf65eb4e06a040840.tar.bz2
[libc] Add basic support for calling host functions from the GPU
This patch adds the `rpc_host_call` function as a GPU extension. This is exported from the `libc` project to use the RPC interface to call a function pointer via RPC any copying the arguments by-value. The interface can only support a single void pointer argument much like pthreads. The function call here is the bare-bones version of what's required for OpenMP reverse offloading. Full support will require interfacing with the mapping table, nowait support, etc. I decided to test this interface in `libomptarget` as that will be the primary consumer and it would be more difficult to make a test in `libc` due to the testing infrastructure not really having a concept of the "host" as it runs directly on the GPU as if it were a CPU target. Reviewed By: jplehr Differential Revision: https://reviews.llvm.org/D155003
Diffstat (limited to 'libc/src/gpu/rpc_host_call.cpp')
-rw-r--r--libc/src/gpu/rpc_host_call.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/libc/src/gpu/rpc_host_call.cpp b/libc/src/gpu/rpc_host_call.cpp
new file mode 100644
index 0000000..67b839d
--- /dev/null
+++ b/libc/src/gpu/rpc_host_call.cpp
@@ -0,0 +1,30 @@
+//===---------- GPU implementation of the external RPC call function ------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/gpu/rpc_host_call.h"
+
+#include "llvm-libc-types/rpc_opcodes_t.h"
+#include "src/__support/GPU/utils.h"
+#include "src/__support/RPC/rpc_client.h"
+#include "src/__support/common.h"
+
+namespace __llvm_libc {
+
+// This calls the associated function pointer on the RPC server with the given
+// arguments. We expect that the pointer here is a valid pointer on the server.
+LLVM_LIBC_FUNCTION(void, rpc_host_call, (void *fn, void *data, size_t size)) {
+ rpc::Client::Port port = rpc::client.open<RPC_HOST_CALL>();
+ port.send_n(data, size);
+ port.send([=](rpc::Buffer *buffer) {
+ buffer->data[0] = reinterpret_cast<uintptr_t>(fn);
+ });
+ port.recv([](rpc::Buffer *) {});
+ port.close();
+}
+
+} // namespace __llvm_libc