[PR #5033] [Engine] gfx906 decode: faster GEMV, expert and hyper-connection kernels (+24 % on 2x MI50, same output) #5294

Open
opened 2026-11-07 16:34:08 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5033
Author: @freapsy
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: mi50-v029


📝 Commits (9)

  • 6345798 [Engine] HIP: a constant-mask __shfl_xor_sync is a DPP or ds_swizzle step, not ds_bpermute
  • 870ac80 [Engine] Sampler and verify: eight logit loads in flight per thread
  • b26b900 [Engine] BF16 GEMV: STRATA_MMVF_ROWS=1 also takes one token, two rows a block
  • e58cee2 [Engine] gfx906 MMVQ (Q4_K, Q6_K): activations in LDS and four lanes in one (opt-in)
  • 63a105f [Engine] gfx906 IQ GEMV and grouped experts: fewer address-unit cycles, fuller waves
  • 3a8815b [Engine] gfx906 hyper-connection read: down prefetch kernel, up occupancy, GR_SPLIT fixes
  • 78ed8f5 [Engine] Benches: T-invariance in fused_gr_bench, pre-quantization hash in native_expert_bench
  • 7a4d4f4 [Engine] HIP pipeline: reserve the MTP prefill, do not unpin under a window in flight
  • 06d119b [Docs] 2x MI50 32 GB: decode tuning page and step-by-step results

📊 Changes

15 files changed (+1168 additions, -126 deletions)

View changed files

➕ bench/results/2026-10-30-mi50-32gb-decode/README.md (+79 -0)
📝 docs/AMD_HIP.md (+4 -0)
➕ docs/AMD_MI50.md (+220 -0)
📝 include/strata/platform/hip_compat/strata_hip.h (+20 -1)
📝 src/core/dflash2.cpp (+1 -1)
📝 src/kernels/cuda/fused_gr.cu (+316 -41)
📝 src/kernels/cuda/iq_kernels.cu (+292 -61)
📝 src/kernels/cuda/native_bf16.cu (+9 -4)
📝 src/kernels/cuda/native_mmvq.cu (+161 -9)
📝 src/kernels/cuda/router_top10.cu (+3 -3)
📝 src/kernels/cuda/sampler.cu (+17 -1)
📝 src/kernels/cuda/verify_kernels.cu (+11 -1)
📝 src/kernels/fused_gr_bench.cpp (+14 -2)
📝 src/kernels/native_expert_bench.cpp (+14 -1)
📝 src/program/generate.cpp (+7 -1)

📄 Description

Problem and result

On Instinct MI50 (gfx906), decode was limited by how the kernels issue work, not by HBM bandwidth. The causes were:

  • a launch-shape stall on the router GEMV;
  • too many vector-memory instructions per byte in the quantized GEMVs and expert kernels;
  • register counts that left the hyper-connection and expert kernels at 2 waves per SIMD;
  • one dependent load per round in the sampler.

This branch fixes these without changing any output.

Measured on 2x MI50 32 GB with Qwen3.8 Flash Next IQ3_M. Each cell is tokens/s for 192 greedy tokens. The config, the
requests and the day are the same for every row:

Build and switches Code Prose 9,927-token prompt
stock 0.2.9, no switches 84.4 54.4 59.7
this branch, no switches 90.1 58.1 64.3
stock 0.2.9, the gfx906 switches it already has 92.3 60.2 67.0
this branch, those switches plus the new ones 115.1 74.7 82.8
  • Every row gives the same answer text: the SHA-256 of each answer matches, and draft acceptance matches.
  • The default path (row 2) is 6.8–7.7 % faster with identical output.
  • With the switches, decode is 23.6–24.7 % faster than stock 0.2.9 with its own switches.
  • Niko1221/Strata#2883 tracks gfx906 community validation.
  • Stock 0.2.9 does not build with -DSTRATA_HIP_GFX906=ON because of dflash2.cpp. This branch carries the same
    one-line guard as the open Niko1221/Strata#3986, so it builds on its own. If Niko1221/Strata#3986 is merged first, that hunk falls out on rebase.
  • The new switches are off by default. No default changes beyond the bit-identical ones listed below.

Approach

The details, the measurements behind each change and the dead ends are in docs/AMD_MI50.md. The changes:

  1. Router GEMV dispatch stall. On gfx906, a launch of 509–512 blocks of 256 threads takes at least ~46 µs once it
    does more than ~0.5 µs of work, although its blocks finish in ~1.5 µs. The BF16 router (512 rows, one block per row)
    hit this on every layer. STRATA_MMVF_ROWS=1 (existing switch) now also sends one-token GEMVs to the rows kernel,
    2 rows per block: ~11 µs instead of ~46 µs. The output bits are the same.

  2. Quantized GEMVs (Q4_K, Q6_K, IQ). Every vector-memory instruction costs the address unit at least 16 cycles on
    gfx906, regardless of width. Two changes cut the instruction count:

    • the activation rows are staged in LDS;
    • one lane does the work of four lanes, then replays the original xor butterfly, so the additions happen in the
      same order (new opt-in STRATA_MMVQ_* and STRATA_IQ_MMVQ_* switches).
  3. Grouped experts. Three changes run on the default path, all bitwise:

    • the expert blob pointer is cast to the global address space, giving global_load instead of flat_load;
    • a v_perm replaces a quarter-rate v_mul_lo_u32;
    • the gate/up kernel does at most two entries per pass, with amdgpu_waves_per_eu(3) on gfx906 only.

    Opt-in: half-warp row pairs for the 80-call IQ3_S rows, and the Q5_0 down through the LDS kernel
    (STRATA_EXP_*).

  4. Hyper-connection read.

    • Default path:
      • a constant-mask __shfl_xor_sync on HIP is a DPP or ds_swizzle step instead of ds_bpermute (same values);
      • the up kernel keeps all 160 blocks resident on 60 CUs.
    • Opt-in STRATA_GR_DOWN_PF=1 adds a down kernel with the same bits and more CUs streaming.
    • Two fixes in the existing opt-in STRATA_GR_SPLIT=1:
      • its slice sums were shared by all streams, so the drafter's read raced the verifier's;
      • its output was quantized twice.
  5. Sampler and verify. Each thread now loads eight logits before it uses any of them. The visiting order and the
    comparisons are unchanged, so the result is bitwise the same. This runs on every backend.

  6. Host, --pipeline-windows 2 on HIP.

    • The drafter's prefill is reserved for the real window size.
    • pl_apply no longer calls hipHostUnregister while a stage still has a verify in flight. Before, this could
      hang the pipeline.
  7. Benches. fused_gr_bench also checks T-invariance. native_expert_bench hashes before the q8_1 quantization,
    where a 1-ulp difference would otherwise hide.

Compatibility:

  • Code shared with CUDA: the sampler/verify loads, the reserve_prefill call, and the rows-kernel block shape (only
    under STRATA_MMVF_ROWS=1).
  • Every HIP target gets the DPP shuffles, the global_load cast, v_perm and __mul24.
  • The occupancy attributes are limited to STRATA_HIP_GFX906.

Validation

Passed:

  • gfx906 build, this branch at 06d119bce (0.2.9 c62d5e3a1 + 9 commits):

    cmake -G Ninja -DSTRATA_HIP_GFX906=ON -DSTRATA_ORCA_Q4KS_MMQ=ON -DCMAKE_HIP_ARCHITECTURES=gfx906
    

    ROCm 7.14 (gfx906 community build), Linux 7.0.

  • End to end on 2x MI50 32 GB (Core i5-11600K, 64 GB RAM). Model: Qwen3.8 Flash Next IQ3_M, pack orca-iq3_m,
    MTP drafter. Flags:

    --layer-split 24 --spec 3 --spec-min-p 0.5 --kv int8 --pipeline-windows 2 --trim-stage-weights --resident-experts
    

    The five runs in bench/results/2026-10-30-mi50-32gb-decode (section "Re-run on 0.2.9") all return the same texts:
    code d0f87379, prose 294fcadd, 9,927-token prompt 84a03701. These match the 0.2.8 runs of 2026-10-30.

  • Default path unchanged: stock 0.2.9 and this branch, both without switches, return identical texts in all four
    requests.

  • Kernel bench: fused_gr_bench 200 1 8 reports "bitwise equal", no T-variance, for T 1–8. The output hashes are
    identical on stock 0.2.9 and on this branch, also with STRATA_GR_DOWN_PF=1 and with STRATA_GR_DOWN_TG=a.

  • CUDA 13.0 compile: nvidia/cuda:13.0.0-devel-ubuntu24.04, with the Dockerfile's CMake options, for sm_75,
    sm_86 and sm_120. Targets strata and strata_kq.

Failed:

  • None observed.

Not run:

  • CUDA on an NVIDIA card. It compiles; I have no card to run it on.
  • SYCL and Metal. Their sources are not touched. The sampler change does not reach sycl/, which has its own.
  • HIP on RDNA (gfx11/gfx12, wave32) and gfx1151. These builds get the DPP shuffles, the global_load cast,
    v_perm and __mul24. All of them are value-preserving by construction, but no RDNA build was compiled or run.
  • native_expert_bench on 0.2.9. It was run on the 0.2.8 base with the same kernel code. On 0.2.9 the
    end-to-end texts cover it.
  • One card, other models, more prompts.

Limits

  • One machine and one model. The gains come from gfx906-specific limits (address-unit cost per instruction, 64-wide
    waves, 60 CUs). They are not expected to carry over to other GPUs.
  • The new switches stay opt-in. Making any of them a gfx906 default would need more machines.
  • In stock Strata, the long-prompt text depends on pipeline timing. About 1 in 9 runs of the same binary takes a
    different window structure; see "Known issues" in the doc. Code and prose are not affected. This branch neither
    causes nor fixes that.

🔄 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/5033 **Author:** [@freapsy](https://github.com/freapsy) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `mi50-v029` --- ### 📝 Commits (9) - [`6345798`](https://github.com/Niko1221/Strata/commit/6345798e50279f3446169426fa89c891fbcbb311) [Engine] HIP: a constant-mask __shfl_xor_sync is a DPP or ds_swizzle step, not ds_bpermute - [`870ac80`](https://github.com/Niko1221/Strata/commit/870ac8052879ada1db47b92f6e1d909d65097c80) [Engine] Sampler and verify: eight logit loads in flight per thread - [`b26b900`](https://github.com/Niko1221/Strata/commit/b26b90090cc283e194ed011070d49010f052d003) [Engine] BF16 GEMV: STRATA_MMVF_ROWS=1 also takes one token, two rows a block - [`e58cee2`](https://github.com/Niko1221/Strata/commit/e58cee2cd96c145515922cb652bc1829c38003bc) [Engine] gfx906 MMVQ (Q4_K, Q6_K): activations in LDS and four lanes in one (opt-in) - [`63a105f`](https://github.com/Niko1221/Strata/commit/63a105f7172fd15e946e7393b8181499e8a73803) [Engine] gfx906 IQ GEMV and grouped experts: fewer address-unit cycles, fuller waves - [`3a8815b`](https://github.com/Niko1221/Strata/commit/3a8815b479231dab774ee145f1db4cf91fd5e528) [Engine] gfx906 hyper-connection read: down prefetch kernel, up occupancy, GR_SPLIT fixes - [`78ed8f5`](https://github.com/Niko1221/Strata/commit/78ed8f5367bfc97e2556d167da404bade9bd7af8) [Engine] Benches: T-invariance in fused_gr_bench, pre-quantization hash in native_expert_bench - [`7a4d4f4`](https://github.com/Niko1221/Strata/commit/7a4d4f4589f3ee312458761cf206a0ff328bad8a) [Engine] HIP pipeline: reserve the MTP prefill, do not unpin under a window in flight - [`06d119b`](https://github.com/Niko1221/Strata/commit/06d119bce57539b70b717b187f0e03049e95dbac) [Docs] 2x MI50 32 GB: decode tuning page and step-by-step results ### 📊 Changes **15 files changed** (+1168 additions, -126 deletions) <details> <summary>View changed files</summary> ➕ `bench/results/2026-10-30-mi50-32gb-decode/README.md` (+79 -0) 📝 `docs/AMD_HIP.md` (+4 -0) ➕ `docs/AMD_MI50.md` (+220 -0) 📝 `include/strata/platform/hip_compat/strata_hip.h` (+20 -1) 📝 `src/core/dflash2.cpp` (+1 -1) 📝 `src/kernels/cuda/fused_gr.cu` (+316 -41) 📝 `src/kernels/cuda/iq_kernels.cu` (+292 -61) 📝 `src/kernels/cuda/native_bf16.cu` (+9 -4) 📝 `src/kernels/cuda/native_mmvq.cu` (+161 -9) 📝 `src/kernels/cuda/router_top10.cu` (+3 -3) 📝 `src/kernels/cuda/sampler.cu` (+17 -1) 📝 `src/kernels/cuda/verify_kernels.cu` (+11 -1) 📝 `src/kernels/fused_gr_bench.cpp` (+14 -2) 📝 `src/kernels/native_expert_bench.cpp` (+14 -1) 📝 `src/program/generate.cpp` (+7 -1) </details> ### 📄 Description ## Problem and result On Instinct MI50 (gfx906), decode was limited by how the kernels issue work, not by HBM bandwidth. The causes were: - a launch-shape stall on the router GEMV; - too many vector-memory instructions per byte in the quantized GEMVs and expert kernels; - register counts that left the hyper-connection and expert kernels at 2 waves per SIMD; - one dependent load per round in the sampler. This branch fixes these without changing any output. Measured on 2x MI50 32 GB with Qwen3.8 Flash Next IQ3_M. Each cell is tokens/s for 192 greedy tokens. The config, the requests and the day are the same for every row: | Build and switches | Code | Prose | 9,927-token prompt | | --- | ---: | ---: | ---: | | stock 0.2.9, no switches | 84.4 | 54.4 | 59.7 | | this branch, no switches | 90.1 | 58.1 | 64.3 | | stock 0.2.9, the gfx906 switches it already has | 92.3 | 60.2 | 67.0 | | this branch, those switches plus the new ones | **115.1** | **74.7** | **82.8** | - Every row gives the same answer text: the SHA-256 of each answer matches, and draft acceptance matches. - The default path (row 2) is 6.8–7.7 % faster with identical output. - With the switches, decode is 23.6–24.7 % faster than stock 0.2.9 with its own switches. ## Related discussion - Niko1221/Strata#2883 tracks gfx906 community validation. - Stock 0.2.9 does not build with `-DSTRATA_HIP_GFX906=ON` because of `dflash2.cpp`. This branch carries the same one-line guard as the open Niko1221/Strata#3986, so it builds on its own. If Niko1221/Strata#3986 is merged first, that hunk falls out on rebase. - The new switches are off by default. No default changes beyond the bit-identical ones listed below. ## Approach The details, the measurements behind each change and the dead ends are in `docs/AMD_MI50.md`. The changes: 1. **Router GEMV dispatch stall.** On gfx906, a launch of 509–512 blocks of 256 threads takes at least ~46 µs once it does more than ~0.5 µs of work, although its blocks finish in ~1.5 µs. The BF16 router (512 rows, one block per row) hit this on every layer. `STRATA_MMVF_ROWS=1` (existing switch) now also sends one-token GEMVs to the rows kernel, 2 rows per block: ~11 µs instead of ~46 µs. The output bits are the same. 2. **Quantized GEMVs (Q4_K, Q6_K, IQ).** Every vector-memory instruction costs the address unit at least 16 cycles on gfx906, regardless of width. Two changes cut the instruction count: - the activation rows are staged in LDS; - one lane does the work of four lanes, then replays the original xor butterfly, so the additions happen in the same order (new opt-in `STRATA_MMVQ_*` and `STRATA_IQ_MMVQ_*` switches). 3. **Grouped experts.** Three changes run on the default path, all bitwise: - the expert blob pointer is cast to the global address space, giving `global_load` instead of `flat_load`; - a `v_perm` replaces a quarter-rate `v_mul_lo_u32`; - the gate/up kernel does at most two entries per pass, with `amdgpu_waves_per_eu(3)` on gfx906 only. Opt-in: half-warp row pairs for the 80-call IQ3_S rows, and the Q5_0 down through the LDS kernel (`STRATA_EXP_*`). 4. **Hyper-connection read.** - Default path: - a constant-mask `__shfl_xor_sync` on HIP is a DPP or `ds_swizzle` step instead of `ds_bpermute` (same values); - the up kernel keeps all 160 blocks resident on 60 CUs. - Opt-in `STRATA_GR_DOWN_PF=1` adds a down kernel with the same bits and more CUs streaming. - Two fixes in the existing opt-in `STRATA_GR_SPLIT=1`: - its slice sums were shared by all streams, so the drafter's read raced the verifier's; - its output was quantized twice. 5. **Sampler and verify.** Each thread now loads eight logits before it uses any of them. The visiting order and the comparisons are unchanged, so the result is bitwise the same. This runs on every backend. 6. **Host, `--pipeline-windows 2` on HIP.** - The drafter's prefill is reserved for the real window size. - `pl_apply` no longer calls `hipHostUnregister` while a stage still has a verify in flight. Before, this could hang the pipeline. 7. **Benches.** `fused_gr_bench` also checks T-invariance. `native_expert_bench` hashes before the q8_1 quantization, where a 1-ulp difference would otherwise hide. Compatibility: - Code shared with CUDA: the sampler/verify loads, the `reserve_prefill` call, and the rows-kernel block shape (only under `STRATA_MMVF_ROWS=1`). - Every HIP target gets the DPP shuffles, the `global_load` cast, `v_perm` and `__mul24`. - The occupancy attributes are limited to `STRATA_HIP_GFX906`. ## Validation **Passed:** - **gfx906 build**, this branch at `06d119bce` (0.2.9 `c62d5e3a1` + 9 commits): ``` cmake -G Ninja -DSTRATA_HIP_GFX906=ON -DSTRATA_ORCA_Q4KS_MMQ=ON -DCMAKE_HIP_ARCHITECTURES=gfx906 ``` ROCm 7.14 (gfx906 community build), Linux 7.0. - **End to end on 2x MI50 32 GB** (Core i5-11600K, 64 GB RAM). Model: Qwen3.8 Flash Next IQ3_M, pack `orca-iq3_m`, MTP drafter. Flags: ``` --layer-split 24 --spec 3 --spec-min-p 0.5 --kv int8 --pipeline-windows 2 --trim-stage-weights --resident-experts ``` The five runs in `bench/results/2026-10-30-mi50-32gb-decode` (section "Re-run on 0.2.9") all return the same texts: code `d0f87379`, prose `294fcadd`, 9,927-token prompt `84a03701`. These match the 0.2.8 runs of 2026-10-30. - **Default path unchanged:** stock 0.2.9 and this branch, both without switches, return identical texts in all four requests. - **Kernel bench:** `fused_gr_bench 200 1 8` reports "bitwise equal", no T-variance, for T 1–8. The output hashes are identical on stock 0.2.9 and on this branch, also with `STRATA_GR_DOWN_PF=1` and with `STRATA_GR_DOWN_TG=a`. - **CUDA 13.0 compile:** `nvidia/cuda:13.0.0-devel-ubuntu24.04`, with the Dockerfile's CMake options, for sm_75, sm_86 and sm_120. Targets `strata` and `strata_kq`. **Failed:** - None observed. **Not run:** - **CUDA on an NVIDIA card.** It compiles; I have no card to run it on. - **SYCL and Metal.** Their sources are not touched. The sampler change does not reach `sycl/`, which has its own. - **HIP on RDNA (gfx11/gfx12, wave32) and gfx1151.** These builds get the DPP shuffles, the `global_load` cast, `v_perm` and `__mul24`. All of them are value-preserving by construction, but no RDNA build was compiled or run. - **`native_expert_bench` on 0.2.9.** It was run on the 0.2.8 base with the same kernel code. On 0.2.9 the end-to-end texts cover it. - **One card, other models, more prompts.** ## Limits - One machine and one model. The gains come from gfx906-specific limits (address-unit cost per instruction, 64-wide waves, 60 CUs). They are not expected to carry over to other GPUs. - The new switches stay opt-in. Making any of them a gfx906 default would need more machines. - In stock Strata, the long-prompt text depends on pipeline timing. About 1 in 9 runs of the same binary takes a different window structure; see "Known issues" in the doc. Code and prose are not affected. This branch neither causes nor fixes that. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#5294
No description provided.