[libc-commits] [libc] 4a2e50e - [libc][NFC] Clean up some code in the RPC implementation.

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Thu May 11 06:23:03 PDT 2023


Author: Joseph Huber
Date: 2023-05-11T08:22:55-05:00
New Revision: 4a2e50e4f4e0eab20bdb4f5bfd3c1db3e900c5ec

URL: https://github.com/llvm/llvm-project/commit/4a2e50e4f4e0eab20bdb4f5bfd3c1db3e900c5ec
DIFF: https://github.com/llvm/llvm-project/commit/4a2e50e4f4e0eab20bdb4f5bfd3c1db3e900c5ec.diff

LOG: [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

Added: 
    

Modified: 
    libc/src/__support/RPC/rpc.h
    libc/utils/gpu/loader/Server.h

Removed: 
    


################################################################################
diff  --git a/libc/src/__support/RPC/rpc.h b/libc/src/__support/RPC/rpc.h
index 2304b4d9b2423..84177abaad249 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 c79277dd8fdca..2419de53a5cd2 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


        


More information about the libc-commits mailing list