diff --git a/libc/src/__support/RPC/rpc.h b/libc/src/__support/RPC/rpc.h --- a/libc/src/__support/RPC/rpc.h +++ b/libc/src/__support/RPC/rpc.h @@ -74,7 +74,7 @@ // 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 @@ cpp::Atomic *outbox; Packet *packet; - cpp::Atomic lock[default_port_count] = {0}; + cpp::Atomic 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 --- a/libc/utils/gpu/loader/Server.h +++ b/libc/utils/gpu/loader/Server.h @@ -22,6 +22,8 @@ /// 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 @@ 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 @@ } 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(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(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