[libc-commits] [libc] [libc] Fix chunk calculation in GPU allocator (PR #221583)
via libc-commits
libc-commits at lists.llvm.org
Sun Sep 6 08:25:16 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-libc
Author: Joseph Huber (jhuber6)
<details>
<summary>Changes</summary>
Summary:
This would pesismistically round up 48 to 64 and the previous s0 case
was unused.
---
Full diff: https://github.com/llvm/llvm-project/pull/221583.diff
1 Files Affected:
- (modified) libc/src/__support/GPU/allocator.cpp (+7-10)
``````````diff
diff --git a/libc/src/__support/GPU/allocator.cpp b/libc/src/__support/GPU/allocator.cpp
index c88a70708b964..75b9ea73e609c 100644
--- a/libc/src/__support/GPU/allocator.cpp
+++ b/libc/src/__support/GPU/allocator.cpp
@@ -94,24 +94,21 @@ static inline uint32_t xorshift32(uint32_t &state) {
}
// Rounds the input value to the closest permitted chunk size. Here we accept
-// the sum of the closest three powers of two. For a 2MiB slab size this is 48
+// the sum of the closest three powers of two. For a 2MiB slab size this is 46
// different chunk sizes. This gives us average internal fragmentation of 87.5%.
static inline constexpr uint32_t get_chunk_size(uint32_t x) {
uint32_t y = x < MIN_SIZE ? MIN_SIZE : x;
uint32_t pow2 = BITS_IN_WORD - cpp::countl_zero(y - 1);
- uint32_t s0 = 0b0100 << (pow2 - 3);
- uint32_t s1 = 0b0110 << (pow2 - 3);
- uint32_t s2 = 0b0111 << (pow2 - 3);
- uint32_t s3 = 0b1000 << (pow2 - 3);
+ uint32_t s0 = 0b0110 << (pow2 - 3);
+ uint32_t s1 = 0b0111 << (pow2 - 3);
+ uint32_t s2 = 0b1000 << (pow2 - 3);
- if (s0 > y)
+ if (s0 >= y)
return (s0 + MIN_ALIGNMENT) & ~MIN_ALIGNMENT;
- if (s1 > y)
+ if (s1 >= y)
return (s1 + MIN_ALIGNMENT) & ~MIN_ALIGNMENT;
- if (s2 > y)
- return (s2 + MIN_ALIGNMENT) & ~MIN_ALIGNMENT;
- return (s3 + MIN_ALIGNMENT) & ~MIN_ALIGNMENT;
+ return (s2 + MIN_ALIGNMENT) & ~MIN_ALIGNMENT;
}
// Converts a chunk size into an index suitable for a statically sized array.
``````````
</details>
https://github.com/llvm/llvm-project/pull/221583
More information about the libc-commits
mailing list