mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4650
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3483
Author: @John-Pi
Created: 10/20/2026
Status: 🔄 Open
Base:
main← Head:fix/stage-fence-per-stream📝 Commits (1)
91f14e1stage: fence a pinned stage buffer's queued copies per stream, not per buffer (#1237)📊 Changes
5 files changed (+294 additions, -29 deletions)
View changed files
📝
CMakeLists.txt(+8 -0)📝
docs/DETAILS.md(+4 -1)📝
include/strata/core/expert_source.hpp(+17 -4)📝
src/core/expert_source.cpp(+66 -24)➕
tests/hip/stage_fence.cpp(+199 -0)📄 Description
Problem and result
With
STRATA_STAGE_PIN=1the stage buffers are page-locked, so the cache fill'scudaMemcpyAsyncis really asynchronous: the DMA reads the buffer after the call returned.f71c5307fenced that by recording an event after each queued copy and havingclaim_stagewait for it before recycling the buffer — but one event per buffer, and a buffer can have copies queued on more than one stream (the hit path, a peer GPU's refill, the startup's refills all read the same blob). The secondcudaEventRecordoverwrote the first, so at recycle timecudaEventQueryanswered for the stream that was already done while the slower stream's copy still had the buffer under the DMA. The refill then overwrote it — the corrupted IQ3_S decode of #1237 (48 tokens of id 0 after a 4096-token prompt).Before: a refill can run under a queued copy on another stream. After: the refill waits for every copy queued out of the buffer, whatever stream it left on.
Related discussion
#1237 is the pinning PR this came out of, and it is where the recycle path was named as the blocker:
This is that recycle path. It is a bug fix in code that is already in
main, so no feature scope to agree on;STRATA_STAGE_PINstays opt-in and no default changes (see Limits).Approach
FileExpertSource::StageFence { stream, event, live }, a fixed table of 4 per buffer.note_async_readreuses the entry of the same stream if there is one (the stream's own order makes the later copy the last to finish), otherwise takes a free entry; if the table is full it waits for the oldest entry and reuses it, so a fence is never dropped.claim_stagewaits for every live entry before it hands the buffer out again, and counts those waits instage_fence_waits_(stage_fence_waits()is new; the test reads it).close()andend_startup_unbuffered()synchronise before destroying events, as before; the startup path now also drops the fence table with the buffers.tests/hip/stage_fence.cppis the deterministic reproduction, registered as ctesthip_stage_fence(skips with 77 without a device or without unbuffered reads).The test builds a synthetic 4-layer × 2-expert pack in the working directory, takes the (0,0) blob into a stage buffer, queues one copy of it behind ~4 GiB of device copies on stream A, queues the same blob on stream B (which completes at once, and whose record is the one a single shared event keeps), lets
kStageAgelayers pass so the buffer is recyclable, then refills the same buffer. It asserts the refill waited, and that both copies still hold the (0,0) bytes.Validation
Passed:
cmake --build build-hip -j$(nproc)— 338 of 338, Release,CMAKE_HIP_ARCHITECTURES=gfx1201, RX 9070 (gfx1201, 16 GB), system ROCm 7.2.4, kernel 7.2.11, engine 0.1.46.1 at9ae93f7b+ this change.ctest --test-dir build-hip -j4— 78 of 80.hip_stage_fencepasses in 0.16 s and 3 of 3 standalone runs:Failed:
hip_stage_fencewithout this change (same tree,9ae93f7b, only the test and thestage_fence_waits()accessor added) fails as designed, which is the reproduction: exit 1. That is the bug: stream B's already-complete copy hid stream A's queued one.ctest:ple_parity(wants../../Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00002-of-00002.gguf, not on this machine) andhip_prefill_mmq_parity(its APR block callsggml_type_name(145)while the TQ overlay leavesGGML_TYPE_COUNTat 43, so the read is out oftype_traits[];basic_string: construction from null is not valid). Both fail identically onorigin/mainin this environment, and neither file is touched here.Not run:
src/core/expert_source.cppis shared with the CUDA build and I have nonvccon this machine; SYCL is untouched by the change. The diff is host-sidecudaEvent*/std::arrayonly, but it is unbuilt there.STRATA_STAGE_PIN=1(1 199-token prompt,--mmap-expertsresident mode): normal prefill and decode,stage_fence_waits()0 for the run.Limits
STAGE_PIN_DEFAULTstays 0 anddocs/DETAILS.mdkeeps saying opt-in. Flipping it is a separate decision with its own numbers; the pinned-vs-pageable decode measurements (R9700, 6 pairs, +2.1% to +3.5%) belong to the pinning change, not to this one. Say the word and I will open that as its own PR.O_DIRECT), so it skips on tmpfs and on machines without a GPU; it is not a substitute for the CUDA-side coverage.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.