mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #5033] [Engine] gfx906 decode: faster GEMV, expert and hyper-connection kernels (+24 % on 2x MI50, same output) #5294
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#5294
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/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_bpermute870ac80[Engine] Sampler and verify: eight logit loads in flight per threadb26b900[Engine] BF16 GEMV: STRATA_MMVF_ROWS=1 also takes one token, two rows a blocke58cee2[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 waves3a8815b[Engine] gfx906 hyper-connection read: down prefetch kernel, up occupancy, GR_SPLIT fixes78ed8f5[Engine] Benches: T-invariance in fused_gr_bench, pre-quantization hash in native_expert_bench7a4d4f4[Engine] HIP pipeline: reserve the MTP prefill, do not unpin under a window in flight06d119b[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:
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:
Related discussion
-DSTRATA_HIP_GFX906=ONbecause ofdflash2.cpp. This branch carries the sameone-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.
Approach
The details, the measurements behind each change and the dead ends are in
docs/AMD_MI50.md. The changes: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.
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:
same order (new opt-in
STRATA_MMVQ_*andSTRATA_IQ_MMVQ_*switches).Grouped experts. Three changes run on the default path, all bitwise:
global_loadinstead offlat_load;v_permreplaces a quarter-ratev_mul_lo_u32;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_*).Hyper-connection read.
__shfl_xor_syncon HIP is a DPP ords_swizzlestep instead ofds_bpermute(same values);STRATA_GR_DOWN_PF=1adds a down kernel with the same bits and more CUs streaming.STRATA_GR_SPLIT=1: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.
Host,
--pipeline-windows 2on HIP.pl_applyno longer callshipHostUnregisterwhile a stage still has a verify in flight. Before, this couldhang the pipeline.
Benches.
fused_gr_benchalso checks T-invariance.native_expert_benchhashes before the q8_1 quantization,where a 1-ulp difference would otherwise hide.
Compatibility:
reserve_prefillcall, and the rows-kernel block shape (onlyunder
STRATA_MMVF_ROWS=1).global_loadcast,v_permand__mul24.STRATA_HIP_GFX906.Validation
Passed:
gfx906 build, this branch at
06d119bce(0.2.9c62d5e3a1+ 9 commits):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:
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, prose294fcadd, 9,927-token prompt84a03701. 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 8reports "bitwise equal", no T-variance, for T 1–8. The output hashes areidentical on stock 0.2.9 and on this branch, also with
STRATA_GR_DOWN_PF=1and withSTRATA_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
strataandstrata_kq.Failed:
Not run:
sycl/, which has its own.global_loadcast,v_permand__mul24. All of them are value-preserving by construction, but no RDNA build was compiled or run.native_expert_benchon 0.2.9. It was run on the 0.2.8 base with the same kernel code. On 0.2.9 theend-to-end texts cover it.
Limits
waves, 60 CUs). They are not expected to carry over to other GPUs.
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.