mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #4005] [CLOSED] [Engine] prefill: opt-in sparse copied events and deduplicated slot waits (Windows HIP prompt reads +36% at 4K, +15% at 32K) #4873
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#4873
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/4005
Author: @Vop3p
Created: 10/24/2026
Status: ❌ Closed
Base:
main← Head:prefill-copy-events📝 Commits (1)
887796dprefill: opt-in sparse copied events and deduplicated slot waits for the streamed walk📊 Changes
1 file changed (+89 additions, -7 deletions)
View changed files
📝
src/prefill/prefill.cpp(+89 -7)📄 Description
Branch:
Vop3p/Strata:prefill-copy-events(one commit onmain7dd5cf18). Not run on NVIDIA, SYCL or Metal hardware (see Not run). No default changes.Problem and result
On Windows (WDDM) every
cudaEventRecordand every cross-streamcudaStreamWaitEventis a submission of its own. A small HIP probe on an RX 6900 XT (Windows 11, driver 32.0.21045.16010, ROCm 10.2.0a20260930 runtime) against the same card model on Linux (ROCm 10.0), 2.79 MB host-to-device copies from registered memory, µs per copy:cudaEventRecordon the copy streamcudaStreamWaitEventon another streamBandwidth is not the gap: back-to-back copies reach 12.5 GB/s (5.5 µs fixed cost per copy) against 14.1 GB/s (7.5 µs) on Linux.
The streamed walk of the prompt path pays one record and one wait per expert on the copy stream: the issuer records
copied[slot]after every copy and waits on the slot's release event before every copy. The consumer, though, gathers an MMQ group of 16 experts after one wait on its last copy and releases the whole group with one event, so 15 of every 16 records are never waited on, and the copy stream waits on the same release event up to 16 times in a row. WithSTRATA_PREFILL_TIMING=1on Windows this shows aswait copy2.1 s of a 4K prompt (Linux: 0.08 s).This PR adds two opt-in switches. Both off (the default), the walk issues exactly the calls it issued before.
STRATA_PREFILL_COPY_EVENT_EVERY=N(2..64): the issuer records the copied event every N-th entry, and also before it waits (ring full, or the stager behind) and on the last entry; the consumer waits on the first recorded entry at or after the one it needs. The copy stream is in order, so a later entry's event covers the earlier copies.STRATA_PREFILL_COPY_WAIT_DEDUPE=1: the copy stream skips the wait on a slot's release event when the previous slot was released by the same event (one flush releases a whole group), from the second ring round of the walk on.Result on the RX 6900 XT under Windows 11, the same build with the switches off vs
EVERY=16+DEDUPE=1, 10 cold-start pairs at the default--prefill auto(6144 on Windows HIP, #1630):EVERY=16 DEDUPE=1(median of 10)Order B SD SD B, five times, a fresh engine per run; each run is the median of two requests per size (
benchmark.py-style synthetic prompts, a new nonce per request). Decode 44.5 / 44.5 (4K) and 44.2 / 46.2 (32K, different continuations). Every setting both arms share:--prefill auto(6144 here),--expert-cache auto,--vram-reserve-mib 1536,--kv int8 --kv-resident 32768,--max-context 65536,--spec 4 --spec-min-p 0.5,--pcie-frac 0.2,STRATA_IO_THREADS=128,STRATA_HIP_PROMPT_F16=1,STRATA_HIP_ADAPT_KERNEL_COPY=1,STRATA_PREFILL_CPU_SHARE=auto,STRATA_HC_PERSIST=1,STRATA_PIPED_CONCURRENT=1,STRATA_PREFILL_STREAM_MIN=2048, a rocBLAS table tuned on this PC; the display on the iGPU. Every run's numbers are in the table at the end.Decode is unchanged (it does not use this path). On Linux the switches change nothing measurable (below).
Related discussion
--prefill autostops at 6144 on Windows HIP) is why the main table is at 6144; a supplement at--prefill 8192is below.Approach
Only the threaded issuer (
STRATA_PREFILL_ISSUERon, the default) and only the streamed walk change; the staged walk (chunks belowstream_all_min()) and the inline issuer keep their per-slot events.Sparse records: the issuer keeps
rec_of[slot](the entry the slot's event marks) anda_rec(one past the last recorded entry).wait_copied(k)spins untila_rec > k, then waits on the firstrin[k, a_rec)withrec_of[r % ring] == r. That slot cannot be re-recorded beforekis given back, because the issuer stays at most one ring ahead of what was given back andkis not given back yet. The issuer records before every wait of its own, so a consumer never waits on an entry nobody will record. All three consumers ofcopied[]in the streamed walk (the group flush, the per-expert path when group gather is off, the fused path) go throughwait_copied.Deduplicated waits: within one walk, from the second ring round on, two consecutive slots that point at the same release event were released by the same flush (a flush releases contiguous slots, and its event is the group's last slot, which is not re-recorded before the issuer reaches it), so the wait for the previous slot already covers this one.
Compatibility: no file format, API or default changes; the switches are read once. They are meant for WDDM; on Linux they measure as no-ops.
Validation
Passed:
setup.pyHIP options (-DSTRATA_PREFILL_MMQ=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON, plus tests), Qwen3.8-Flash-Next IQ3_S pack, reproducible settingsSTRATA_IQ_MT_MIN=1 --pcie-frac 0 --adapt-every 0 STRATA_PREFILL_CPU_SHARE=0, temperature 0, 4K and 32K prompts x2:main7dd5cf18vs this branch with the switches off vs this branch withEVERY=16 DEDUPE=1: all 4 outputs identical across the three builds. The confirmation linestrata: prompt copies: a copied event every 16 streamed experts ..., one wait per release eventprinted;STRATA_PREFILL_TIMINGreports ~14,100 of ~20,700 slot waits skipped per 32K prompt.ctest -j 1on gfx1030 (Linux, the branch): 128 passed, 13 skipped (not applicable to gfx1030), 3 failed; the same 3 fail onmain7dd5cf18with the same output (see Failed).tools\hip\build_windows.bat(gfx1030, ROCm 10.2.0a20260930) builds; the A/B above;strata bench run(standard track) on this branch with the switches on: 21/21 requests, sanity 12/12 (instruction 4/4, retrieval 4/4, tool calls 4/4), prompt 4K 793 / 16K 979 tok/s.strata_prefillcompiles (-DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=89).Failed (also on
main7dd5cf18, not caused by this change):ple_parity: needs../../Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00002-of-00002.gguf, not on this machine.hip_prefill_mmq_parity: segfault insidelibamdhip64.so.7at the launch ofmmvq_multi_kernel<29,2,true,true>(fromsynthetic_q2).isa_guard_check:iq512x_rowsholds AVX-512 instructions and is not listed; the same class as #3409.Not run:
sycl/CMakeLists.txtcompilesprefill.cpp).Limits
--prefill 8192(3 pairs) the same switches give +35.8% to +37.4% at 4K but only +3.0% to +3.9% at 32K (1,070-1,072 -> 1,103-1,112 tok/s).EVERY=16matchesMMQ_GROUP; other values were not swept.Every run (Windows 11, RX 6900 XT, in run order)
Each cell is the median of the run's two requests of that size. No run failed or was dropped.
Developed with an AI coding assistant; every number above was measured on the RX 6900 XT machines named in it (Windows 11 / i9-10900K and Linux / Ryzen 5 5600X).
🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.