[libc-commits] [libc] [libc] Only back off GPU allocation under high contention (PR #197170)
via libc-commits
libc-commits at lists.llvm.org
Tue May 12 05:22:24 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Joseph Huber (jhuber6)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/197170.diff
1 Files Affected:
- (modified) libc/src/__support/GPU/allocator.cpp (+4-3)
``````````diff
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;
``````````
</details>
https://github.com/llvm/llvm-project/pull/197170
More information about the libc-commits
mailing list