Skip to content

Commit 62f57bc

Browse files
committed
[libc] Add other RPC callback methods to the RPC server
This patch adds the other two methods to the server so the external users can use the interface through the obfuscated interface. Reviewed By: JonChesterfield Differential Revision: https://reviews.llvm.org/D154224
1 parent 58a16d8 commit 62f57bc

File tree

2 files changed

+50
-19
lines changed

2 files changed

+50
-19
lines changed

libc/utils/gpu/server/rpc_server.cpp

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -320,25 +320,50 @@ const void *rpc_get_client_buffer(uint32_t device_id) {
320320

321321
uint64_t rpc_get_client_size() { return sizeof(rpc::Client); }
322322

323+
using ServerPort = std::variant<rpc::Server<1>::Port *, rpc::Server<32>::Port *,
324+
rpc::Server<64>::Port *>;
325+
326+
ServerPort getPort(rpc_port_t ref) {
327+
if (ref.lane_size == 1)
328+
return reinterpret_cast<rpc::Server<1>::Port *>(ref.handle);
329+
else if (ref.lane_size == 32)
330+
return reinterpret_cast<rpc::Server<32>::Port *>(ref.handle);
331+
else if (ref.lane_size == 64)
332+
return reinterpret_cast<rpc::Server<64>::Port *>(ref.handle);
333+
else
334+
__builtin_unreachable();
335+
}
336+
337+
void rpc_send(rpc_port_t ref, rpc_port_callback_ty callback, void *data) {
338+
auto port = getPort(ref);
339+
std::visit(
340+
[=](auto &port) {
341+
port->send([=](rpc::Buffer *buffer) {
342+
callback(reinterpret_cast<rpc_buffer_t *>(buffer), data);
343+
});
344+
},
345+
port);
346+
}
347+
348+
void rpc_recv(rpc_port_t ref, rpc_port_callback_ty callback, void *data) {
349+
auto port = getPort(ref);
350+
std::visit(
351+
[=](auto &port) {
352+
port->recv([=](rpc::Buffer *buffer) {
353+
callback(reinterpret_cast<rpc_buffer_t *>(buffer), data);
354+
});
355+
},
356+
port);
357+
}
358+
323359
void rpc_recv_and_send(rpc_port_t ref, rpc_port_callback_ty callback,
324360
void *data) {
325-
if (ref.lane_size == 1) {
326-
rpc::Server<1>::Port *port =
327-
reinterpret_cast<rpc::Server<1>::Port *>(ref.handle);
328-
port->recv_and_send([=](rpc::Buffer *buffer) {
329-
callback(reinterpret_cast<rpc_buffer_t *>(buffer), data);
330-
});
331-
} else if (ref.lane_size == 32) {
332-
rpc::Server<32>::Port *port =
333-
reinterpret_cast<rpc::Server<32>::Port *>(ref.handle);
334-
port->recv_and_send([=](rpc::Buffer *buffer) {
335-
callback(reinterpret_cast<rpc_buffer_t *>(buffer), data);
336-
});
337-
} else if (ref.lane_size == 64) {
338-
rpc::Server<64>::Port *port =
339-
reinterpret_cast<rpc::Server<64>::Port *>(ref.handle);
340-
port->recv_and_send([=](rpc::Buffer *buffer) {
341-
callback(reinterpret_cast<rpc_buffer_t *>(buffer), data);
342-
});
343-
}
361+
auto port = getPort(ref);
362+
std::visit(
363+
[=](auto &port) {
364+
port->recv_and_send([=](rpc::Buffer *buffer) {
365+
callback(reinterpret_cast<rpc_buffer_t *>(buffer), data);
366+
});
367+
},
368+
port);
344369
}

libc/utils/gpu/server/rpc_server.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ const void *rpc_get_client_buffer(uint32_t device_id);
9797
/// Returns the size of the client in bytes to be used for a memory copy.
9898
uint64_t rpc_get_client_size();
9999

100+
/// Use the \p port to send a buffer using the \p callback.
101+
void rpc_send(rpc_port_t port, rpc_port_callback_ty callback, void *data);
102+
103+
/// Use the \p port to recieve a buffer using the \p callback.
104+
void rpc_recv(rpc_port_t port, rpc_port_callback_ty callback, void *data);
105+
100106
/// Use the \p port to receive and send a buffer using the \p callback.
101107
void rpc_recv_and_send(rpc_port_t port, rpc_port_callback_ty callback,
102108
void *data);

0 commit comments

Comments
 (0)