[libc-commits] [libc] ec40c8d - [libc] Only back off GPU allocation under high contention (#197170)
via libc-commits
libc-commits at lists.llvm.org
Wed May 13 06:07:06 PDT 2026
Author: Joseph Huber
Date: 2026-05-13T08:07:02-05:00
New Revision: ec40c8d3ce6869ef8c4016d34e33c808886585ee
URL: https://github.com/llvm/llvm-project/commit/ec40c8d3ce6869ef8c4016d34e33c808886585ee
DIFF: https://github.com/llvm/llvm-project/commit/ec40c8d3ce6869ef8c4016d34e33c808886585ee.diff
LOG: [libc] Only back off GPU allocation under high contention (#197170)
Summary:
Right now this sleeps if any threads failed, this is inefficient. We
want the sleep to stop livelock, though that is less common since the FW
progress bit was set by default. But we should only do this when the
bitfield is full to minimize sleeping when there's plenty of space
available.
Added:
Modified:
libc/src/__support/GPU/allocator.cpp
Removed:
################################################################################
diff --git a/libc/src/__support/GPU/allocator.cpp b/libc/src/__support/GPU/allocator.cpp
index 2146cd3808716..9f95e6d15fa3e 100644
--- a/libc/src/__support/GPU/allocator.cpp
+++ b/libc/src/__support/GPU/allocator.cpp
@@ -327,15 +327,16 @@ struct Slab {
uint32_t after = before | bitmask;
uint64_t waiting = gpu::ballot(lane_mask, !result);
- if (!result)
+ if (!result) {
start =
gpu::shuffle(waiting, cpp::countr_zero(waiting),
~after ? __builtin_align_down(index, BITS_IN_WORD) +
cpp::countr_zero(~after)
: __builtin_align_down(
impl::xorshift32(state), BITS_IN_WORD));
- if (!result)
- sleep_briefly();
+ if (!gpu::shuffle(waiting, cpp::countr_zero(waiting), ~after))
+ sleep_briefly();
+ }
}
}
return result;
More information about the libc-commits
mailing list