[libc-commits] [PATCH] D158365: [libc] Remove 'try_open' from the client interface
Joseph Huber via Phabricator via libc-commits
libc-commits at lists.llvm.org
Sun Aug 20 08:39:31 PDT 2023
jhuber6 updated this revision to Diff 551847.
jhuber6 added a comment.
The hardware resource limit isn't something that's enforced yet. Right now we
just set it to the maximum amount of memory we allocate, which is 512. I believe
most GPUs will need more like 2048 to cover all hardware resources. We'll work
on that later once we have a smarter port allocation scheme. For now we would
probablyt replace the initialize at zero with the sm-id as a cheap way to
stagger them out. The smid can change during execution so it's not a perfect
solution.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D158365/new/
https://reviews.llvm.org/D158365
Files:
libc/src/__support/RPC/rpc.h
Index: libc/src/__support/RPC/rpc.h
===================================================================
--- libc/src/__support/RPC/rpc.h
+++ libc/src/__support/RPC/rpc.h
@@ -348,7 +348,6 @@
LIBC_INLINE ~Client() = default;
using Port = rpc::Port<false, Packet<gpu::LANE_SIZE>>;
- template <uint16_t opcode> LIBC_INLINE cpp::optional<Port> try_open();
template <uint16_t opcode> LIBC_INLINE Port open();
LIBC_INLINE void reset(uint32_t port_count, void *buffer) {
@@ -517,15 +516,19 @@
}
}
-/// Attempts to open a port to use as the client. The client can only open a
-/// port if we find an index that is in a valid sending state. That is, there
-/// are send operations pending that haven't been serviced on this port. Each
-/// port instance uses an associated \p opcode to tell the server what to do.
-template <uint16_t opcode>
-[[clang::convergent]] LIBC_INLINE cpp::optional<Client::Port>
-Client::try_open() {
- // Perform a naive linear scan for a port that can be opened to send data.
- for (uint32_t index = 0; index < process.port_count; ++index) {
+/// Continually attempts to open a port to use as the client. The client can
+/// only open a port if we find an index that is in a valid sending state. That
+/// is, there are send operations pending that haven't been serviced on this
+/// port. Each port instance uses an associated \p opcode to tell the server
+/// what to do.
+template <uint16_t opcode> LIBC_INLINE Client::Port Client::open() {
+ // Repeatedly perform a naive linear scan for a port that can be opened to
+ // send data.
+ for (uint32_t index = 0;; ++index) {
+ // Start from the beginning if we run out of ports to check.
+ if (index >= process.port_count)
+ index = 0;
+
// Attempt to acquire the lock on this index.
uint64_t lane_mask = gpu::get_lane_mask();
if (!process.try_lock(lane_mask, index))
@@ -548,15 +551,6 @@
gpu::sync_lane(lane_mask);
return Port(process, lane_mask, index, out);
}
- return cpp::nullopt;
-}
-
-template <uint16_t opcode> LIBC_INLINE Client::Port Client::open() {
- for (;;) {
- if (cpp::optional<Client::Port> p = try_open<opcode>())
- return cpp::move(p.value());
- sleep_briefly();
- }
}
/// Attempts to open a port to use as the server. The server can only open a
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158365.551847.patch
Type: text/x-patch
Size: 2319 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230820/c54de548/attachment-0001.bin>
More information about the libc-commits
mailing list