[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

Closed
opened 2026-11-07 16:31:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 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)

  • 887796d prefill: 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 on main 7dd5cf18). Not run on NVIDIA, SYCL or Metal hardware (see Not run). No default changes.

Problem and result

On Windows (WDDM) every cudaEventRecord and every cross-stream cudaStreamWaitEvent is 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:

per copy Windows Linux
copy only 222 205
+ cudaEventRecord on the copy stream 301 (+79) 208 (+3)
+ cudaStreamWaitEvent on another stream 343 (+42) 208 (+0)
record + wait + small kernel, one event per copy 352 209
the same, one event per 8 copies 239 205

Bandwidth 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. With STRATA_PREFILL_TIMING=1 on Windows this shows as wait copy 2.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):

prompt switches off (median of 10) EVERY=16 DEDUPE=1 (median of 10) per pair faster in
4K 589.2 tok/s 803.5 tok/s +35.5% to +36.8% (median +36.4%) 10/10
32K 828.7 tok/s 951.3 tok/s +14.3% to +15.0% (median +14.9%) 10/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).

  • #3767 (launch batching on Windows HIP: a launch can sit in the runtime's batch until something submits) is the same WDDM submission model seen from the other side.
  • #1630 (why --prefill auto stops at 6144 on Windows HIP) is why the main table is at 6144; a supplement at --prefill 8192 is below.
  • No issue was opened for this change: it is opt-in and small.

Approach

Only the threaded issuer (STRATA_PREFILL_ISSUER on, the default) and only the streamed walk change; the staged walk (chunks below stream_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) and a_rec (one past the last recorded entry). wait_copied(k) spins until a_rec > k, then waits on the first r in [k, a_rec) with rec_of[r % ring] == r. That slot cannot be re-recorded before k is given back, because the issuer stays at most one ring ahead of what was given back and k is 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 of copied[] in the streamed walk (the group flush, the per-expert path when group gather is off, the fused path) go through wait_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:

  • Default path byte-identical and switches output-identical, Linux, RX 6900 XT (gfx1030), ROCm 10.0, built with the setup.py HIP options (-DSTRATA_PREFILL_MMQ=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON, plus tests), Qwen3.8-Flash-Next IQ3_S pack, reproducible settings STRATA_IQ_MT_MIN=1 --pcie-frac 0 --adapt-every 0 STRATA_PREFILL_CPU_SHARE=0, temperature 0, 4K and 32K prompts x2: main 7dd5cf18 vs this branch with the switches off vs this branch with EVERY=16 DEDUPE=1: all 4 outputs identical across the three builds. The confirmation line strata: prompt copies: a copied event every 16 streamed experts ..., one wait per release event printed; STRATA_PREFILL_TIMING reports ~14,100 of ~20,700 slot waits skipped per 32K prompt.
  • Linux speed, same runs: prompt 4K 915 / 907 / 913, 32K 1,101 / 1,102 / 1,099 tok/s (main / off / on).
  • ctest -j 1 on gfx1030 (Linux, the branch): 128 passed, 13 skipped (not applicable to gfx1030), 3 failed; the same 3 fail on main 7dd5cf18 with the same output (see Failed).
  • Windows 11, RX 6900 XT: 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.
  • CUDA 13.2.86 (GCC 15.2): strata_prefill compiles (-DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=89).

Failed (also on main 7dd5cf18, 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 inside libamdhip64.so.7 at the launch of mmvq_multi_kernel<29,2,true,true> (from synthetic_q2).
  • isa_guard_check: iq512x_rows holds AVX-512 instructions and is not listed; the same class as #3409.

Not run:

  • Not executed on NVIDIA hardware (CUDA compile only). Not built for SYCL or Metal (no toolchain here; sycl/CMakeLists.txt compiles prefill.cpp).
  • No other Windows GPU; no gfx11/gfx12.
  • The ctest suite does not reach the streamed walk with the issuer thread for most tests; the switches' correctness check is the end-to-end comparison above.

Limits

  • Measured on one card (RX 6900 XT, PCIe 3.0 x16, i9-10900K, 64 GB) under Windows 11 with HIP. NVIDIA under WDDM likely has a smaller per-call cost; not measured.
  • The gain shrinks with bigger chunks (fewer streamed passes): at --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=16 matches MMQ_GROUP; other values were not swept.
Every run (Windows 11, RX 6900 XT, in run order)
# arm --prefill 4K prompt tok/s 32K prompt tok/s 4K decode 32K decode
1 off auto (6144) 587.7 828.6 44.5 43.7
2 on auto (6144) 803.8 951.8 44.4 43.8
3 on auto (6144) 804.6 951.3 44.4 47.9
4 off auto (6144) 589.1 829.1 45.2 43.8
5 off auto (6144) 589.4 827.7 44.4 46.6
6 on auto (6144) 802.9 950.7 44.4 46.6
7 on auto (6144) 802.8 950.8 44.5 43.6
8 off auto (6144) 587.6 829.1 45.1 43.6
9 off auto (6144) 590.2 828.7 44.3 43.7
10 on auto (6144) 805.6 952.6 44.6 44.5
11 on auto (6144) 805.4 950.8 44.4 46.5
12 off auto (6144) 594.4 831.8 44.5 43.9
13 off auto (6144) 588.6 828.6 44.5 45.3
14 on auto (6144) 802.7 952.3 44.5 46.6
15 on auto (6144) 805.1 952.5 44.5 43.2
16 off auto (6144) 590.3 829.3 44.5 44.7
17 off auto (6144) 588.4 827.6 44.8 44.5
18 on auto (6144) 802.1 951.0 44.5 47.2
19 on auto (6144) 803.2 951.3 44.8 45.8
20 off auto (6144) 589.7 827.5 44.4 46.0
21 off 8192 586.9 1071.7 44.3 42.4
22 on 8192 804.9 1103.7 43.9 45.2
23 on 8192 804.2 1103.4 44.5 42.7
24 off 8192 592.2 1070.7 44.6 44.6
25 off 8192 590.1 1070.0 44.4 43.4
26 on 8192 811.0 1112.1 47.2 43.1

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.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/4005 **Author:** [@Vop3p](https://github.com/Vop3p) **Created:** 10/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `prefill-copy-events` --- ### 📝 Commits (1) - [`887796d`](https://github.com/Niko1221/Strata/commit/887796debca1fa20ee0f3ab11d8571d8dcbb2f10) prefill: opt-in sparse copied events and deduplicated slot waits for the streamed walk ### 📊 Changes **1 file changed** (+89 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `src/prefill/prefill.cpp` (+89 -7) </details> ### 📄 Description Branch: `Vop3p/Strata:prefill-copy-events` (one commit on `main` 7dd5cf18). Not run on NVIDIA, SYCL or Metal hardware (see Not run). No default changes. ## Problem and result On Windows (WDDM) every `cudaEventRecord` and every cross-stream `cudaStreamWaitEvent` is 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: | per copy | Windows | Linux | |---|---|---| | copy only | 222 | 205 | | + `cudaEventRecord` on the copy stream | 301 (+79) | 208 (+3) | | + `cudaStreamWaitEvent` on another stream | 343 (+42) | 208 (+0) | | record + wait + small kernel, one event per copy | 352 | 209 | | the same, one event per 8 copies | 239 | 205 | Bandwidth 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. With `STRATA_PREFILL_TIMING=1` on Windows this shows as `wait copy` 2.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): | prompt | switches off (median of 10) | `EVERY=16 DEDUPE=1` (median of 10) | per pair | faster in | |---|---|---|---|---| | 4K | 589.2 tok/s | 803.5 tok/s | +35.5% to +36.8% (median +36.4%) | 10/10 | | 32K | 828.7 tok/s | 951.3 tok/s | +14.3% to +15.0% (median +14.9%) | 10/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 - #3767 (launch batching on Windows HIP: a launch can sit in the runtime's batch until something submits) is the same WDDM submission model seen from the other side. - #1630 (why `--prefill auto` stops at 6144 on Windows HIP) is why the main table is at 6144; a supplement at `--prefill 8192` is below. - No issue was opened for this change: it is opt-in and small. ## Approach Only the threaded issuer (`STRATA_PREFILL_ISSUER` on, the default) and only the streamed walk change; the staged walk (chunks below `stream_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) and `a_rec` (one past the last recorded entry). `wait_copied(k)` spins until `a_rec > k`, then waits on the first `r` in `[k, a_rec)` with `rec_of[r % ring] == r`. That slot cannot be re-recorded before `k` is given back, because the issuer stays at most one ring ahead of what was given back and `k` is 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 of `copied[]` in the streamed walk (the group flush, the per-expert path when group gather is off, the fused path) go through `wait_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: - Default path byte-identical and switches output-identical, Linux, RX 6900 XT (gfx1030), ROCm 10.0, built with the `setup.py` HIP options (`-DSTRATA_PREFILL_MMQ=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON`, plus tests), Qwen3.8-Flash-Next IQ3_S pack, reproducible settings `STRATA_IQ_MT_MIN=1 --pcie-frac 0 --adapt-every 0 STRATA_PREFILL_CPU_SHARE=0`, temperature 0, 4K and 32K prompts x2: `main` 7dd5cf18 vs this branch with the switches off vs this branch with `EVERY=16 DEDUPE=1`: all 4 outputs identical across the three builds. The confirmation line `strata: prompt copies: a copied event every 16 streamed experts ..., one wait per release event` printed; `STRATA_PREFILL_TIMING` reports ~14,100 of ~20,700 slot waits skipped per 32K prompt. - Linux speed, same runs: prompt 4K 915 / 907 / 913, 32K 1,101 / 1,102 / 1,099 tok/s (main / off / on). - `ctest -j 1` on gfx1030 (Linux, the branch): 128 passed, 13 skipped (not applicable to gfx1030), 3 failed; the same 3 fail on `main` 7dd5cf18 with the same output (see Failed). - Windows 11, RX 6900 XT: `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. - CUDA 13.2.86 (GCC 15.2): `strata_prefill` compiles (`-DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=89`). Failed (also on `main` 7dd5cf18, 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 inside `libamdhip64.so.7` at the launch of `mmvq_multi_kernel<29,2,true,true>` (from `synthetic_q2`). - `isa_guard_check`: `iq512x_rows` holds AVX-512 instructions and is not listed; the same class as #3409. Not run: - Not executed on NVIDIA hardware (CUDA compile only). Not built for SYCL or Metal (no toolchain here; `sycl/CMakeLists.txt` compiles `prefill.cpp`). - No other Windows GPU; no gfx11/gfx12. - The ctest suite does not reach the streamed walk with the issuer thread for most tests; the switches' correctness check is the end-to-end comparison above. ## Limits - Measured on one card (RX 6900 XT, PCIe 3.0 x16, i9-10900K, 64 GB) under Windows 11 with HIP. NVIDIA under WDDM likely has a smaller per-call cost; not measured. - The gain shrinks with bigger chunks (fewer streamed passes): at `--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=16` matches `MMQ_GROUP`; other values were not swept. <details><summary>Every run (Windows 11, RX 6900 XT, in run order)</summary> | # | arm | --prefill | 4K prompt tok/s | 32K prompt tok/s | 4K decode | 32K decode | |---|---|---|---|---|---|---| | 1 | off | auto (6144) | 587.7 | 828.6 | 44.5 | 43.7 | | 2 | on | auto (6144) | 803.8 | 951.8 | 44.4 | 43.8 | | 3 | on | auto (6144) | 804.6 | 951.3 | 44.4 | 47.9 | | 4 | off | auto (6144) | 589.1 | 829.1 | 45.2 | 43.8 | | 5 | off | auto (6144) | 589.4 | 827.7 | 44.4 | 46.6 | | 6 | on | auto (6144) | 802.9 | 950.7 | 44.4 | 46.6 | | 7 | on | auto (6144) | 802.8 | 950.8 | 44.5 | 43.6 | | 8 | off | auto (6144) | 587.6 | 829.1 | 45.1 | 43.6 | | 9 | off | auto (6144) | 590.2 | 828.7 | 44.3 | 43.7 | | 10 | on | auto (6144) | 805.6 | 952.6 | 44.6 | 44.5 | | 11 | on | auto (6144) | 805.4 | 950.8 | 44.4 | 46.5 | | 12 | off | auto (6144) | 594.4 | 831.8 | 44.5 | 43.9 | | 13 | off | auto (6144) | 588.6 | 828.6 | 44.5 | 45.3 | | 14 | on | auto (6144) | 802.7 | 952.3 | 44.5 | 46.6 | | 15 | on | auto (6144) | 805.1 | 952.5 | 44.5 | 43.2 | | 16 | off | auto (6144) | 590.3 | 829.3 | 44.5 | 44.7 | | 17 | off | auto (6144) | 588.4 | 827.6 | 44.8 | 44.5 | | 18 | on | auto (6144) | 802.1 | 951.0 | 44.5 | 47.2 | | 19 | on | auto (6144) | 803.2 | 951.3 | 44.8 | 45.8 | | 20 | off | auto (6144) | 589.7 | 827.5 | 44.4 | 46.0 | | 21 | off | 8192 | 586.9 | 1071.7 | 44.3 | 42.4 | | 22 | on | 8192 | 804.9 | 1103.7 | 43.9 | 45.2 | | 23 | on | 8192 | 804.2 | 1103.4 | 44.5 | 42.7 | | 24 | off | 8192 | 592.2 | 1070.7 | 44.6 | 44.6 | | 25 | off | 8192 | 590.1 | 1070.0 | 44.4 | 43.4 | | 26 | on | 8192 | 811.0 | 1112.1 | 47.2 | 43.1 | Each cell is the median of the run's two requests of that size. No run failed or was dropped. </details> 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](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-07 16:31:01 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4873
No description provided.