Skip to content

Commit 29762e3

Browse files
authored
[libc][NFCI] Remove lane size template argument on RPC server (#84557)
Summary: We previously changed the data layout for the RPC buffer to make it lane size agnostic. I put off changing the size for the server case to make the patch smaller. This patch simply reorganizes code by making the lane size an argument to the port rather than a templtae size. Heavily simplifies a lot of code, no more `std::variant`.
1 parent 8d85cd3 commit 29762e3

File tree

2 files changed

+234
-273
lines changed

2 files changed

+234
-273
lines changed

libc/src/__support/RPC/rpc.h

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ template <bool T> struct Port {
310310
LIBC_INLINE Port &operator=(Port &&) = default;
311311

312312
friend struct Client;
313-
template <uint32_t U> friend struct Server;
313+
friend struct Server;
314314
friend class cpp::optional<Port<T>>;
315315

316316
public:
@@ -369,7 +369,7 @@ static_assert(cpp::is_trivially_copyable<Client>::value &&
369369
"The client is not trivially copyable from the server");
370370

371371
/// The RPC server used to respond to the client.
372-
template <uint32_t lane_size> struct Server {
372+
struct Server {
373373
LIBC_INLINE Server() = default;
374374
LIBC_INLINE Server(const Server &) = delete;
375375
LIBC_INLINE Server &operator=(const Server &) = delete;
@@ -379,10 +379,12 @@ template <uint32_t lane_size> struct Server {
379379
: process(port_count, buffer) {}
380380

381381
using Port = rpc::Port<true>;
382-
LIBC_INLINE cpp::optional<Port> try_open(uint32_t start = 0);
383-
LIBC_INLINE Port open();
382+
LIBC_INLINE cpp::optional<Port> try_open(uint32_t lane_size,
383+
uint32_t start = 0);
384+
LIBC_INLINE Port open(uint32_t lane_size);
384385

385-
LIBC_INLINE static uint64_t allocation_size(uint32_t port_count) {
386+
LIBC_INLINE static uint64_t allocation_size(uint32_t lane_size,
387+
uint32_t port_count) {
386388
return Process<true>::allocation_size(port_count, lane_size);
387389
}
388390

@@ -556,10 +558,8 @@ template <uint16_t opcode>
556558

557559
/// Attempts to open a port to use as the server. The server can only open a
558560
/// port if it has a pending receive operation
559-
template <uint32_t lane_size>
560-
[[clang::convergent]] LIBC_INLINE
561-
cpp::optional<typename Server<lane_size>::Port>
562-
Server<lane_size>::try_open(uint32_t start) {
561+
[[clang::convergent]] LIBC_INLINE cpp::optional<typename Server::Port>
562+
Server::try_open(uint32_t lane_size, uint32_t start) {
563563
// Perform a naive linear scan for a port that has a pending request.
564564
for (uint32_t index = start; index < process.port_count; ++index) {
565565
uint64_t lane_mask = gpu::get_lane_mask();
@@ -588,10 +588,9 @@ template <uint32_t lane_size>
588588
return cpp::nullopt;
589589
}
590590

591-
template <uint32_t lane_size>
592-
LIBC_INLINE typename Server<lane_size>::Port Server<lane_size>::open() {
591+
LIBC_INLINE Server::Port Server::open(uint32_t lane_size) {
593592
for (;;) {
594-
if (cpp::optional<Server::Port> p = try_open())
593+
if (cpp::optional<Server::Port> p = try_open(lane_size))
595594
return cpp::move(p.value());
596595
sleep_briefly();
597596
}

0 commit comments

Comments
 (0)