Repository navigation
Reuse large arrays across repeats - #25
Open
AdvaitTahilyani wants to merge 12 commits into
Open
AdvaitTahilyani wants to merge 12 commits into
AdvaitTahilyani wants to merge 12 commits into
Conversation
Retired arrays were keyed by dtype, local and global shape and the decomposition, so an array of the same size from another DAG with a different tile or offset missed the free list and paid a cudaMalloc (and the surplus a cudaFree). The reuse path already rewrites region, shape and decomposition, so the key is now the dtype and the local element count. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
black_scholes -n 400000 and scan -s 1e9 allocate 6-8 GB of arrays per repeat, more than the 1/8-of-the-device free-list budget (4.9 GB on an A100-40GB). Every repeat freed the surplus (13-15 cudaFree, ~2 ms each, a device sync) and allocated it again; the cudaMallocs got slower as the process freed more large blocks (up to 70 ms per call, 200-280 ms per repeat), so repeats ranged 50-320 ms (nsys, CNUM_MEM_STATS). - Retired arrays and large message/scratch blocks may now use up to 1/2 of the device per sharing process (CNUM_FREE_LIST_MB, CNUM_DEVICE_CACHE_MB). Up to 1/8 is kept unconditionally; beyond that a block is kept only while CNUM_DEVICE_RESERVE_MB (default 1/4 of the device) stays free. - Before a fresh array or large block is allocated, cached blocks and this PE's retired arrays are evicted, least recently freed first, until it fits with 1/32 of the device to spare. A failed allocation still releases everything and retries once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Scratch from the stream-ordered pool is allocated outside the array and message caches; with those caches allowed to grow, ds_alloc first evicts cached blocks for what the pool cannot serve from memory it holds, and a failed cudaMallocAsync releases the caches and retries instead of aborting. Releasing the caches on OOM also trims the pool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cudaMemGetInfo costs ~24 us on an A100. Caches up to 1/8 of the device (per sharing process) are kept without asking, and a fresh allocation only evicts while the caches hold more than that; below it a failed allocation still releases everything and retries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Allocations outside these caches (cuBLAS, the stream-ordered pool, Kokkos scratch, JIT temporaries) cannot release them. A fresh array or large block now evicts cached ones until it fits with CNUM_DEVICE_RESERVE_MB still free, not just a 1/32 margin, but never below the always-kept 1/8. A test that fills the caches with one size and then allocates 25-28 GB of others peaked at 38.9 of 40.4 GB used before this change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
adityapb
reviewed
Nov 6, 2026
adityapb
left a comment
Member
There was a problem hiding this comment.
Verdict: approve with nits.
This is a static review. Line numbers are at this PR's head.
These are correct:
- Reuse: matching by (dtype, size) is sound because storage is a flat 1-D view, and reuse is ordered after the old readers.
- Accounting:
retired_bytesandlarge_cachedare updated symmetrically. - Eviction: it is truly least-recently-freed and always terminates.
- [minor] Eviction and the OOM fallback are per PE, but the raised budgets are per process.
- Where:
backend.hpp:1237-1281.evict_oldest_cachedscans only thethread_localpartitions. - Scenario (SMP, 2 PEs on a 40 GB GPU): PE A retires about 15 GB, then PE B allocates 12 GB. B owns nothing evictable, so
device_oomaborts while 15 GB of freeable cache sits in A's free lists. - Same root cause as my note on #17. Still at #44.
- Where:
- Nits:
- Unguarded allocations: allocations outside the three guarded allocators (
Kokkos::Viewtemporaries, cuBLAS/cuSOLVER workspaces, cuFFT plans) get no make-room or retry, and the caches may now grow until only 1/4 of the device is free. - Budget size: "up to half the GPU" is really 1/2 per cache, about 3/4 combined.
- Eviction cost: there's a
cudaMemGetInfocall plus a full scan for every evicted object.
- Unguarded allocations: allocations outside the three guarded allocators (
…ess under a lock; fix budget doc Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Author
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #24.
black_scholes: 174 ms (50–320 spread) → 41 ms flat; scan: ~45 → 22 ms (1 A100).
Tested (full stack): CPU +p1/+p2 15/15 originals, 25/25 ports, 30/30 ops; A100 1 GPU 15/15, 25/25, 30/30 and 4 GPUs (one process per GPU) 15/15, 25/25.
🤖 Generated with Claude Code