Repository navigation
[Engine] AMD on WSL2: remove a 4 s stall when the cache shrinks - #302
Open
okada-shogo wants to merge 2 commits into
Open
okada-shogo wants to merge 2 commits into
okada-shogo wants to merge 2 commits into
Conversation
ROCm on native Linux gives a released VMM handle's VRAM back only when its addresses are freed, so Engine::vmm_unmap() unmaps every kept piece, frees the reservation, reserves it again at the same place and maps the kept pieces again (STRATA_VMM_RELEASE_WITH_ADDRESSES). Under WSL2 (librocdxg: /dev/dxg without /dev/kfd) the VRAM comes back at the release itself: a 64 MiB handle unmapped and released came back whole, measured on an RX 9060 XT and an RX 9070 XT class card (ROCm 7.2.4). There the cycle only costs time: it was the 4.2 s hipMemUnmap in the first 8K prompt read of a fresh process. So under WSL2 vmm_unmap() releases the pieces past `bytes` and waits (100 ms at most) for the free figure, as the native path does after its cycle, and leaves the kept pieces mapped. Native amdgpu keeps the cycle; STRATA_VMM_READDRESS=1 keeps it under WSL2 too. Same bits: the same pieces at the same addresses. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 24, 2026
Registered as a rollback with its defaults (WSL2 skips the cycle, native Linux keeps it). Co-Authored-By: Claude Sonnet 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.
Problem and result
When strata-poly gives VRAM back (a long prompt takes buffers from the expert cache, the attention caches shrink, or
POST /v1/vramis called), native Linux ROCm only returns a released VMM piece's VRAM once its addresses are freed. Sothe engine unmaps every piece it keeps, frees the whole address reservation, reserves it again at the same place and
maps the kept pieces again.
Under WSL2 (librocdxg) the VRAM comes back as soon as the piece is released, so that cycle only costs time: the first
8K prompt of a fresh engine on an RX 9070 XT spent 4.2 s in
hipMemUnmap. With this PR, the kept pieces stay mappedunder WSL2; native amdgpu keeps the cycle.
The first 8K prompt of a fresh engine now takes 11.9 s instead of 35.5 s, and the second one gets 4% faster.
RX 9070 XT class card (gfx1201, Salad cloud container, WSL2, ROCm 7.2.4), Inkling 2 Mini IQ4_NL, default arguments,
--max-context 16384, no prompt or conversation cache. A fresh process processes the same 8,192-token prompt threetimes. Prompt time in ms (lower is better), mean of 3 fresh processes per side, main and PR interleaved:
Related discussion
none
Approach
/dev/dxgpresent and/dev/kfdabsent (now one shared helper).vmm_unmap()releases the pieces past the cut point, waits (100 ms at most) for the free-VRAM figure torise as the native path does, and returns. A mapping given back whole still gets fresh addresses: nothing is kept, so
that costs nothing, and librocdxg refuses a smaller piece after a larger one in one reservation.
STRATA_VMM_READDRESS=1keeps the cycle under WSL2;=0skips it anywhere (a test switch, with a warning outside WSL2).Each run (ms)
download). Without that run, main's mean first prompt is still 33,493 ms.
this PR 7,919 ms for the first prompt.
Merge note (with #319,
--vram-elastic): both PRs add a check tovmm_unmap()for VRAM that comes back at therelease. They conflict there. Whichever lands second keeps this PR's check (
vmm_release_frees(), every map) first and#319's one-time measure (
readdress, the expert cache with the flag) after it.free0is read when either check needs it.Validation
Passed:
STRATA_VMM_READDRESSis registered as a rollback (the name [Engine] Inkling 2: give expert-cache VRAM back while serving #319 now reads too).python3 tools/settings_register.py --checkandtools/test_settings_register.py: OK at this commit. No engine code changed in this commit.strata-poly.kit.shon the RX 9070 XT container: main = simplex/main 36e654b, this PR = port/wsl-no-remap c1fb2f7).STRATA_FREEZE_EXPERTS=1, 8K prompt, 64 tokens, three requests per process, main vs this branch:SAME, SAME, SAME.
Failed:
Not run:
Limits
hipMallocthat the profile also showed is the settle probe waiting for that remap; with this change it drops to about 20 ms (RX 9070 XT, WSL2). An 8K IQ4_NL prompt in a fresh process measured 711.9 → 1,200.6 tok/s (+68.6%), the same speed as 2K; 32K 949.8 → 1,090.9 (+14.9%); 2K unchanged (median of 3, one process per run).of the measure.
🤖 Generated with Claude Code