summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorJoseph Huber <jhuber6@vols.utk.edu>2023-05-11 08:21:12 -0500
committerJoseph Huber <jhuber6@vols.utk.edu>2023-05-11 08:22:55 -0500
commit4a2e50e4f4e0eab20bdb4f5bfd3c1db3e900c5ec (patch)
treedaa8f35112ba74c56ee2abb6bb97f5c1f9434224 /libc
parent9dd2af0b4caeaa3d19d9f48891e59bc5e0877544 (diff)
downloadllvm-4a2e50e4f4e0eab20bdb4f5bfd3c1db3e900c5ec.tar.gz
[libc][NFC] Clean up some code in the RPC implementation.
Small cleanup of the server code and fixes a constant name not following the naming convention. Differential Revision: https://reviews.llvm.org/D150361
Diffstat (limited to 'libc')
-rw-r--r--libc/src/__support/RPC/rpc.h4
-rw-r--r--libc/utils/gpu/loader/Server.h63
2 files changed, 27 insertions, 40 deletions
diff --git a/libc/src/__support/RPC/rpc.h b/libc/src/__support/RPC/rpc.h
index 2304b4d9b242..84177abaad24 100644
--- a/libc/src/__support/RPC/rpc.h
+++ b/libc/src/__support/RPC/rpc.h
@@ -74,7 +74,7 @@ struct alignas(64) Packet {
// of thumb is that you should have at least as many ports as possible
// concurrent work items on the GPU to mitigate the lack offorward
// progress guarantees on the GPU.
-constexpr uint64_t default_port_count = 64;
+constexpr uint64_t DEFAULT_PORT_COUNT = 64;
/// A common process used to synchronize communication between a client and a
/// server. The process contains an inbox and an outbox used for signaling
@@ -111,7 +111,7 @@ template <bool InvertInbox> struct Process {
cpp::Atomic<uint32_t> *outbox;
Packet *packet;
- cpp::Atomic<uint32_t> lock[default_port_count] = {0};
+ cpp::Atomic<uint32_t> lock[DEFAULT_PORT_COUNT] = {0};
/// Initialize the communication channels.
LIBC_INLINE void reset(uint64_t port_count, uint32_t lane_size, void *state) {
diff --git a/libc/utils/gpu/loader/Server.h b/libc/utils/gpu/loader/Server.h
index c79277dd8fdc..2419de53a5cd 100644
--- a/libc/utils/gpu/loader/Server.h
+++ b/libc/utils/gpu/loader/Server.h
@@ -22,6 +22,8 @@ static __llvm_libc::rpc::Server server;
/// Queries the RPC client at least once and performs server-side work if there
/// are any active requests.
void handle_server() {
+ using namespace __llvm_libc;
+
// Continue servicing the client until there is no work left and we return.
for (;;) {
auto port = server.try_open();
@@ -29,15 +31,15 @@ void handle_server() {
return;
switch (port->get_opcode()) {
- case __llvm_libc::rpc::Opcode::PRINT_TO_STDERR: {
- uint64_t str_size[__llvm_libc::rpc::MAX_LANE_SIZE] = {0};
- char *strs[__llvm_libc::rpc::MAX_LANE_SIZE] = {nullptr};
+ case rpc::Opcode::PRINT_TO_STDERR: {
+ uint64_t str_size[rpc::MAX_LANE_SIZE] = {0};
+ char *strs[rpc::MAX_LANE_SIZE] = {nullptr};
port->recv_n([&](uint64_t size, uint32_t id) {
str_size[id] = size;
strs[id] = new char[size];
return strs[id];
});
- for (uint64_t i = 0; i < __llvm_libc::rpc::MAX_LANE_SIZE; ++i) {
+ for (uint64_t i = 0; i < rpc::MAX_LANE_SIZE; ++i) {
if (strs[i]) {
fwrite(strs[i], str_size[i], 1, stderr);
delete[] strs[i];
@@ -45,57 +47,42 @@ void handle_server() {
}
break;
}
- case __llvm_libc::rpc::Opcode::EXIT: {
- port->recv([](__llvm_libc::rpc::Buffer *buffer) {
+ case rpc::Opcode::EXIT: {
+ port->recv([](rpc::Buffer *buffer) {
exit(reinterpret_cast<uint32_t *>(buffer->data)[0]);
});
break;
}
- case __llvm_libc::rpc::Opcode::TEST_INCREMENT: {
- port->recv_and_send([](__llvm_libc::rpc::Buffer *buffer) {
+ case rpc::Opcode::TEST_INCREMENT: {
+ port->recv_and_send([](rpc::Buffer *buffer) {
reinterpret_cast<uint64_t *>(buffer->data)[0] += 1;
});
break;
}
- case __llvm_libc::rpc::Opcode::TEST_INTERFACE: {
+ case rpc::Opcode::TEST_INTERFACE: {
uint64_t cnt = 0;
bool end_with_recv;
- port->recv([&](__llvm_libc::rpc::Buffer *buffer) {
- end_with_recv = buffer->data[0];
- });
- port->recv(
- [&](__llvm_libc::rpc::Buffer *buffer) { cnt = buffer->data[0]; });
- port->send([&](__llvm_libc::rpc::Buffer *buffer) {
- buffer->data[0] = cnt = cnt + 1;
- });
- port->recv(
- [&](__llvm_libc::rpc::Buffer *buffer) { cnt = buffer->data[0]; });
- port->send([&](__llvm_libc::rpc::Buffer *buffer) {
- buffer->data[0] = cnt = cnt + 1;
- });
- port->recv(
- [&](__llvm_libc::rpc::Buffer *buffer) { cnt = buffer->data[0]; });
- port->recv(
- [&](__llvm_libc::rpc::Buffer *buffer) { cnt = buffer->data[0]; });
- port->send([&](__llvm_libc::rpc::Buffer *buffer) {
- buffer->data[0] = cnt = cnt + 1;
- });
- port->send([&](__llvm_libc::rpc::Buffer *buffer) {
- buffer->data[0] = cnt = cnt + 1;
- });
+ port->recv([&](rpc::Buffer *buffer) { end_with_recv = buffer->data[0]; });
+ port->recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; });
+ port->send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; });
+ port->recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; });
+ port->send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; });
+ port->recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; });
+ port->recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; });
+ port->send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; });
+ port->send([&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; });
if (end_with_recv)
- port->recv(
- [&](__llvm_libc::rpc::Buffer *buffer) { cnt = buffer->data[0]; });
+ port->recv([&](rpc::Buffer *buffer) { cnt = buffer->data[0]; });
else
- port->send([&](__llvm_libc::rpc::Buffer *buffer) {
- buffer->data[0] = cnt = cnt + 1;
- });
+ port->send(
+ [&](rpc::Buffer *buffer) { buffer->data[0] = cnt = cnt + 1; });
break;
}
default:
- port->recv([](__llvm_libc::rpc::Buffer *buffer) {});
+ port->recv([](rpc::Buffer *buffer) {});
}
port->close();
}
}
+
#endif