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 @@ /// - The client will always start with a 'send' operation. /// - The server will always start with a 'recv' operation. /// - Every 'send' or 'recv' call is mirrored by the other process. -template struct Process { +template struct Process { LIBC_INLINE Process() = default; LIBC_INLINE Process(const Process &) = delete; LIBC_INLINE Process &operator=(const Process &) = delete; @@ -85,7 +85,7 @@ uint64_t port_count; cpp::Atomic *inbox; cpp::Atomic *outbox; - Packet *packet; + Packet *packet; cpp::Atomic lock[DEFAULT_PORT_COUNT] = {0}; @@ -96,8 +96,8 @@ advance(buffer, inbox_offset(port_count))); this->outbox = reinterpret_cast *>( advance(buffer, outbox_offset(port_count))); - this->packet = reinterpret_cast *>( - advance(buffer, buffer_offset(port_count))); + this->packet = + reinterpret_cast(advance(buffer, buffer_offset(port_count))); } /// Returns the beginning of the unified buffer. Intended for initializing the @@ -221,30 +221,6 @@ gpu::sync_lane(lane_mask); } - /// Invokes a function accross every active buffer across the total lane size. - LIBC_INLINE void invoke_rpc(cpp::function fn, - Packet &packet) { - if constexpr (is_process_gpu()) { - fn(&packet.payload.slot[gpu::get_lane_id()]); - } else { - for (uint32_t i = 0; i < lane_size; i += gpu::get_lane_size()) - if (packet.header.mask & 1ul << i) - fn(&packet.payload.slot[i]); - } - } - - /// Alternate version that also provides the index of the current lane. - LIBC_INLINE void invoke_rpc(cpp::function fn, - Packet &packet) { - if constexpr (is_process_gpu()) { - fn(&packet.payload.slot[gpu::get_lane_id()], gpu::get_lane_id()); - } else { - for (uint32_t i = 0; i < lane_size; i += gpu::get_lane_size()) - if (packet.header.mask & 1ul << i) - fn(&packet.payload.slot[i], i); - } - } - /// Number of bytes to allocate for an inbox or outbox. LIBC_INLINE static constexpr uint64_t mailbox_bytes(uint64_t port_count) { return port_count * sizeof(cpp::Atomic); @@ -252,7 +228,7 @@ /// Number of bytes to allocate for the buffer containing the packets. LIBC_INLINE static constexpr uint64_t buffer_bytes(uint64_t port_count) { - return port_count * sizeof(Packet); + return port_count * sizeof(Packet); } /// Offset of the inbox in memory. This is the same as the outbox if inverted. @@ -267,10 +243,40 @@ /// Offset of the buffer containing the packets after the inbox and outbox. LIBC_INLINE static constexpr uint64_t buffer_offset(uint64_t port_count) { - return align_up(2 * mailbox_bytes(port_count), alignof(Packet)); + return align_up(2 * mailbox_bytes(port_count), alignof(Packet)); } }; +namespace { + +/// Invokes a function accross every active buffer across the total lane size. +template +LIBC_INLINE void invoke_rpc(cpp::function fn, + Packet &packet) { + if constexpr (is_process_gpu()) { + fn(&packet.payload.slot[gpu::get_lane_id()]); + } else { + for (uint32_t i = 0; i < lane_size; i += gpu::get_lane_size()) + if (packet.header.mask & 1ul << i) + fn(&packet.payload.slot[i]); + } +} + +/// Alternate version that also provides the index of the current lane. +template +LIBC_INLINE void invoke_rpc(cpp::function fn, + Packet &packet) { + if constexpr (is_process_gpu()) { + fn(&packet.payload.slot[gpu::get_lane_id()], gpu::get_lane_id()); + } else { + for (uint32_t i = 0; i < lane_size; i += gpu::get_lane_size()) + if (packet.header.mask & 1ul << i) + fn(&packet.payload.slot[i], i); + } +} + +} // namespace + /// The port provides the interface to communicate between the multiple /// processes. A port is conceptually an index into the memory provided by the /// underlying process that is guarded by a lock bit. @@ -339,7 +345,7 @@ } private: - Process process; + Process> process; }; /// The RPC server used to respond to the client. @@ -362,11 +368,11 @@ } LIBC_INLINE static uint64_t allocation_size(uint64_t port_count) { - return Process::allocation_size(port_count); + return Process>::allocation_size(port_count); } private: - Process process; + Process> process; }; /// Applies \p fill to the shared buffer and initiates a send operation.