Skip to content

Reuse exactly-sized free blocks in the custom GPU allocator (#1225) - #1369

Merged
biochem-fan merged 1 commit into
3dem:ver5.1from
arcusbuilds:fix/allocator-exact-fit-block
Sep 16, 2026
Merged

biochem-fan merged 1 commit into
3dem:ver5.1from
arcusbuilds:fix/allocator-exact-fit-block

Conversation

@arcusbuilds

Copy link
Copy Markdown
Contributor

Fixes #1225, reported by @fengxiaoshuai.

_getFirstSuitedFree() skips a free block whose size is exactly the requested size:

while (a != NULL && ( a->size <= size || ! a->free ) )

That makes the curAlloc->size == size branch in alloc() unreachable, and a request the pool can satisfy exactly instead aborts with CRITICAL(ERRGPUCAOOM). It also stops a freed block from being reused by a request of the same size, which fragments the pool. Since requests are rounded up to alignmentSize first, exact fits are common.

Changed <= to <. The HIP port has an identical copy of the function, so both are updated.

Not compiled against CUDA/HIP here (the build workflow is CPU-only, so it does not cover these headers) — checked by running the free-list logic standalone with the CUDA calls stubbed out.

…em#1225)

_getFirstSuitedFree() skipped every free block whose size was equal to
the requested size, so an exact fit was never returned. Three
consequences:

- the "curAlloc->size == size" branch in alloc() is unreachable, even
  though it is written to handle precisely that case;
- a request the pool can satisfy exactly still fails, and alloc() aborts
  with ERRGPUCAOOM after exhausting its retry loop;
- a freed block is never reused by a request of the same size, so the
  pool fragments under the common free-then-reallocate pattern.

Requests are rounded up to alignmentSize before the search, which makes
exact fits common rather than rare.

The HIP port carries an identical copy of the function, so both are
changed.

Reported by @fengxiaoshuai.
@biochem-fan
biochem-fan changed the base branch from ver5.0 to ver5.1 September 16, 2026 05:55
@biochem-fan

Copy link
Copy Markdown
Member

Thank you very much. I merged this into the ver5.1 (beta version) branch to let others test the code.

@biochem-fan
biochem-fan merged commit 95017d2 into 3dem:ver5.1 Sep 16, 2026
@arcusbuilds

Copy link
Copy Markdown
Contributor Author

@biochem-fan hey, quick one, is there any CUDA related work coming up in the repo? wanted to see if there's something in that area I could jump in on.

@biochem-fan

Copy link
Copy Markdown
Member

@arcusbuilds we have already did a big refactoring of the GPU code path but it is still being tested internally and not public yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants