xref: /aosp_15_r20/external/llvm-libc/src/gpu/rpc_host_call.cpp (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===---------- GPU implementation of the external RPC call function ------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "src/gpu/rpc_host_call.h"
10 
11 #include "src/__support/GPU/utils.h"
12 #include "src/__support/RPC/rpc_client.h"
13 #include "src/__support/common.h"
14 #include "src/__support/macros/config.h"
15 
16 namespace LIBC_NAMESPACE_DECL {
17 
18 // This calls the associated function pointer on the RPC server with the given
19 // arguments. We expect that the pointer here is a valid pointer on the server.
20 LLVM_LIBC_FUNCTION(unsigned long long, rpc_host_call,
21                    (void *fn, void *data, size_t size)) {
22   rpc::Client::Port port = rpc::client.open<RPC_HOST_CALL>();
23   port.send_n(data, size);
__anon8a305a380102(rpc::Buffer *buffer, uint32_t) 24   port.send([=](rpc::Buffer *buffer, uint32_t) {
25     buffer->data[0] = reinterpret_cast<uintptr_t>(fn);
26   });
27   unsigned long long ret;
__anon8a305a380202(rpc::Buffer *buffer, uint32_t) 28   port.recv([&](rpc::Buffer *buffer, uint32_t) {
29     ret = static_cast<unsigned long long>(buffer->data[0]);
30   });
31   port.close();
32   return ret;
33 }
34 
35 } // namespace LIBC_NAMESPACE_DECL
36