[PR #3264] [Engine] perf(hip): optimize MTP draft, shared expert, and verify/sampler head kernels on RDNA4 #4534

Open
opened 2026-11-07 15:37:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3264
Author: @bsorensen110
Created: 10/19/2026
Status: 🔄 Open

Base: main ← Head: new/pr3069


📝 Commits (2)

  • d79fe8e perf(hip): optimize MTP draft, shared expert, and verify/sampler head kernels on RDNA4
  • 78e0bf5 fix(kernels): remove duplicate SM60 shared_expert q8_1 quantize and scope counter-free gr_parity test

📊 Changes

13 files changed (+711 additions, -266 deletions)

View changed files

📝 CMakeLists.txt (+2 -2)
📝 src/core/mtp.cpp (+66 -31)
📝 src/core/verify.cpp (+26 -10)
📝 src/kernels/cuda/elementwise.cu (+25 -18)
📝 src/kernels/cuda/fused_gr.cu (+10 -4)
📝 src/kernels/cuda/quantize_act.cu (+13 -12)
📝 src/kernels/cuda/s2_expert_grouped.cu (+233 -153)
📝 src/kernels/cuda/shared_expert.cu (+13 -7)
📝 src/kernels/cuda/verify_kernels.cu (+40 -12)
📝 src/kernels/gr_parity.cpp (+69 -0)
📝 src/kernels/s2_expert_grouped_parity.cpp (+7 -5)
📝 src/kernels/shared_expert_parity.cpp (+40 -0)
📝 src/kernels/verify_parity.cpp (+167 -12)

📄 Description

Problem and result

Supersedes #3069 (closed during the 0.2.0-beta tracker reset), rebased onto 0.2.0-beta (e88ee39d).

During speculative decode and verification on RDNA4 (gfx1200/gfx1201), six bottlenecks in the MTP drafter, shared expert, S2 routed experts, and verify/sampler head operations accounted for significant per-window overhead while having 100% bitwise-identical replacements:

  1. multi_block_head_ops() and argmax_rows_wanted() in src/kernels/cuda/verify_kernels.cu unconditionally returned false under #if defined(__HIPCC__), forcing argmax_rows (T x 248,320 logits) and row_top_prob_split onto single-WGP (<<<n_rows, 1024>>>) launches instead of 128-block (argmax_rows_kernel) and 32-block (row_top_prob_split_kernel) wave32 kernels (402.0 -> 35.1 us at T=5, 11.45× speedup).
  2. quantize_q8_0_scaled in src/kernels/cuda/quantize_act.cu used a 1-thread-per-block serial 32-element loop under #if defined(__HIPCC__) instead of the warp-per-block shuffle-reduction kernel (quantize_q8_0_scaled_kernel).
  3. moe_hit_grouped_s2, moe_hit_grouped_s2_dev, and moe_hit_grouped_s2_multi in src/kernels/cuda/s2_expert_grouped.cu launched swiglu_kernel and quantize_q8_0_scaled separately instead of the fused swiglu_quantize_q8_0_scaled_kernel already used by moe_grouped_s2, and gu_grouped_t_kernel/down_grouped_t_kernel allocated 25 KB / 6.25 KB LDS (GMAX=8) even for cap_entries <= 16 (T=1 MTP draft), capping occupancy at 2 blocks/WGP.
  4. MtpDrafter::forward_body (src/core/mtp.cpp) and Verifier::forward_range (src/core/verify.cpp) quantized mixed to Q8_1 twice per layer (once in fused_gr_read_multi / native_quantize_q8_1 for routed experts, and a second time inside shared_expert), and fused_gr_read_multi declined q8_mixed when q8_cnt == nullptr (STRATA_QFUSE_HC_LOCAL=1).
  5. Verifier::forward_range issued up to 8 separate cudaMemcpyAsync(..., cudaMemcpyHostToDevice) calls per layer to copy pinned expert blobs for misses instead of a single batched copy_from_mapped_multi device kernel reading mapped host pointers.

Every optimization in this PR is 100% bitwise identical (0 differing bits across all outputs).

Supersedes #3069 (includes the copy_from_mapped_multi_fallback alignment-safe scalar fallback for bytes % 4 != 0 or 4 mod 8 pointers and the verify_parity unaligned fallback tests from review on #3069).

Approach

  • Enable wave32 argmax_rows_kernel (128 blocks/row) and row_top_prob_split_kernel (kTopBlocks = 32 single-warp blocks/row) on RDNA HIP (p.warpSize == 32, cached per device in arch[64]) in src/kernels/cuda/verify_kernels.cu.
  • Enable warp-per-block quantize_q8_0_scaled_kernel on HIP in src/kernels/cuda/quantize_act.cu (STRATA_OLD_Q80_SCALED=1 fallback).
  • Route moe_hit_grouped_s2{,_dev,_multi} through launch_hit_swiglu_q8, specialize gu_grouped_t_kernel<1> / down_grouped_t_kernel<1> for cap_entries <= 16 (reducing LDS from 25 KB to 3.125 KB), and use s2_sync_lds() in src/kernels/cuda/s2_expert_grouped.cu.
  • Reuse pre-quantized x_q8_1 across routed and shared experts in src/kernels/cuda/shared_expert.cu, src/core/mtp.cpp, and src/core/verify.cpp, and allow counter-free q8_mixed in fused_gr_read_multi (src/kernels/cuda/fused_gr.cu) when q8_cnt == nullptr.
  • Add copy_from_mapped_multi in src/kernels/cuda/elementwise.cu (with alignment-safe fallback for non-8B-aligned pointers/sizes) to batch mapped-host miss expert copies in src/core/verify.cpp.

Validation

Passed:

  • cmake --build build-copilot-hip --target strata verify_parity gr_parity shared_expert_parity s2_expert_grouped_parity arch_defaults_test -j16: revision d79fe8e8 on 0.2.0-beta (e88ee39d), AMD Radeon AI PRO R9700 (gfx1201, 32 GB, Linux 7.2.9-2-cachyos-server, ROCm 10.2.0a20260914), clean build & link.
  • ./build-copilot-hip/arch_defaults_test: revision d79fe8e8 (0.2.0-beta), arch_defaults_test: OK.
  • ./build-copilot-hip/verify_parity: revision d79fe8e8 (0.2.0-beta), gfx1201, argmax_rows, row_top_prob_split: bitwise equal, copy_from_mapped_multi: bitwise equal (multi=1 and fallback=0, aligned + 1025w + 4B-aligned), quantize_q8_0_scaled: bitwise equal, verify_parity: PASS.
  • ./build-copilot-hip/gr_parity --selftest: revision d79fe8e8 (0.2.0-beta), gfx1201, fused GR counter-free q8_1 (q8_cnt == nullptr), T 1..8, direct/graph + LOCAL=0 guard: pass, gr_read/gr_write: 0 failures, gr_parity OK.
  • ./build-copilot-hip/shared_expert_parity: revision d79fe8e8 (0.2.0-beta), gfx1201, native shared x_q8_1 reuse: byte-identical, shared_expert: 0 failures.
  • ./build-copilot-hip/s2_expert_grouped_parity (default, STRATA_S2_SWIGLU_Q8=0, and STRATA_OLD_Q80_SCALED=1): revision d79fe8e8 (0.2.0-beta), gfx1201, all 14 cases bitwise identical (s2_expert_grouped_parity: 0 failures, PASS).

Failed:

  • none observed

Not run:

  • Target-device runtime execution on gfx11 / gfx906 and CUDA hardware (no gfx11/gfx906 or NVIDIA GPU in this host).
  • SYCL and Metal builds (changes are in CUDA/HIP kernels and engine verify/MTP paths).

Limits

  • Wave64 gfx906 keeps the single-block row_top_prob and sampler_greedy_kernel paths (#if !defined(STRATA_HIP_GFX906) and p.warpSize == 32 check).

Summary

This PR enables and optimizes several bitwise-identical paths across the MTP draft layer, the verify/draft head greedy sampler & top-probability kernels, the S2 grouped expert kernels, and the shared expert on RDNA HIP (gfx1201):

  1. Wave32 multi-block argmax_rows and row_top_prob_split on RDNA HIP (src/kernels/cuda/verify_kernels.cu, CMakeLists.txt):

    • argmax_rows_kernel and row_top_prob_split_kernel were previously compiled out under #if !defined(__HIPCC__), forcing wave32 RDNA GPUs (warpSize == 32) onto the single-block sampler_greedy_kernel<<<n_rows, 1024>>> and row_top_prob_kernel<<<n_rows, 1024>>> (1..5 blocks total across 48 WGPs to scan 425 KB..4.97 MB of logits).
    • Guards the wave32 multi-block kernels with #if !defined(STRATA_HIP_GFX906) (keeping wave64 gfx906 on the one-block kernels) and enables multi_block_head_ops() / argmax_rows_wanted() per device on HIP when p.warpSize == 32 (STRATA_MULTI_BLOCK_ARGMAX=0 and STRATA_ARGMAX_ROWS=0 force them off).
    • Sets kTopBlocks = 32 (32 threads = 1 warp/block across 32 WGPs, avoiding intra-block __syncthreads() barriers when blockDim.x == 32) and adds #pragma unroll 8 to the stride-1024 reduction loop in row_top_prob_kernel and row_top_prob_split_kernel (preserving exact per-thread summation order while overlapping 8 global loads in flight).
    • Enables the verify_parity target on HIP (STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP) and extends verify_parity with copy_from_mapped_multi, quantize_q8_0_scaled, and --bench checks.
  2. Fused HC q8_mixed, STRATA_HEAD_MIX_MULTI, and shared-expert x_q8_1 reuse in MTP and Verify (src/core/mtp.cpp, src/core/verify.cpp, src/kernels/cuda/fused_gr.cu, src/kernels/cuda/shared_expert.cu):

    • Allows fused_gr_read_multi (src/kernels/cuda/fused_gr.cu) to write q8_mixed without a q8_cnt buffer when qfuse_hc_local() && a[0].s_down == nullptr (gr_up_q32_kernel and gr_up_q8_q32_kernel assign one warp per 32-column q8_1 block and never touch q8_cnt).
    • Enables STRATA_HEAD_MIX_MULTI by default on gfx12 in verify.cpp and mtp.cpp (STRATA_HEAD_MIX_MULTI=0 disables), replacing the 4-launch gr_read fallback on the MTP final mixer with fused_gr_read_multi.
    • Passes q8_mixed = xq_ + t * (N / 32) * 36 to all 3 fused_gr_read_multi calls in MtpDrafter (attn_hyper_connection, mlp_hyper_connection, and hyper_connection_mixer) and to the final output_hc_* fused_gr_read_multi in Verifier, skipping redundant standalone native_quantize_q8_1 launches when fused_gr_read_multi writes xq_.
    • Updates shared_expert() (src/kernels/cuda/shared_expert.cu) to honor native->x_q8_1 (set by MtpDrafter when q8_mlp && T == 1), matching shared_expert_multi.
  3. S2 grouped expert <1> specialization, LDS-only barriers, and fused SwiGLU+Q8_0 on hit paths (src/kernels/cuda/s2_expert_grouped.cu, src/kernels/s2_expert_grouped_parity.cpp):

    • Adds s2_sync_lds() (s_wait_dscnt 0x0; s_barrier_signal -1; s_barrier_wait -1 on gfx12; s_waitcnt lgkmcnt(0); s_barrier on gfx1030/gfx11xx) for LDS-only staging barriers.
    • Adds MAX_E = 1 template specializations gu_grouped_t_kernel<1> (LDS = 3,200 B, VGPR = 85 vs <8>'s LDS = 25,600 B, VGPR = 89) and down_grouped_t_kernel<1> (LDS = 800 B, VGPR = 47 vs <8>'s LDS = 6,400 B, VGPR = 40) dispatched when cap_entries <= 16 (covering single-token MTP T = 1, K = 10).
    • Uses swiglu_quantize_q8_0_scaled_kernel in moe_hit_grouped_s2, moe_hit_grouped_s2_dev, and moe_hit_grouped_s2_multi when fast && x_scales != nullptr && swiglu_q8_on() (STRATA_S2_SWIGLU_Q8=0 disables), matching moe_grouped_s2.
  4. Warp-per-block quantize_q8_0_scaled and copy_from_mapped_multi on HIP (src/kernels/cuda/quantize_act.cu, src/kernels/cuda/elementwise.cu, src/core/mtp.cpp):

    • Enables the warp-per-block quantize_q8_0_scaled_kernel on HIP (STRATA_OLD_Q80_SCALED=1 restores the thread-per-block kernel).
    • Enables copy_from_mapped_multi_kernel on HIP (STRATA_MTP_MULTI_COPY=0 restores individual copies) and uses copy_from_mapped_multi in MtpDrafter::capture_round and MtpDrafter::capture_step.

Verification & Parity Evidence (AMD Radeon AI PRO R9700 gfx1201)

All 7 parity and self-test suites pass with 0 failures and 100% bitwise equality:

$ ./build-copilot-hip/arch_defaults_test
arch_defaults_test: OK

$ ./build-copilot-hip/verify_parity --selftest --bench
argmax_rows, row_top_prob_split: bitwise equal to the one-block kernels (ties, NaN, -inf, 1-8 rows on one scratch)
copy_from_mapped_multi: bitwise equal to individual mapped copies (multi=1 and fallback=0, aligned + 1025w + 4B-aligned)
quantize_q8_0_scaled: bitwise equal to CPU act_quant_q8_1 reference (zero, .5 ties, normal)
  V=106299 rows=1: greedy 1-blk  24.39 us -> argmax_rows   7.87 us (x3.10) | top_prob 1-blk  22.43 us -> split  11.24 us (x2.00)
  V=248320 rows=1: greedy 1-blk  46.94 us -> argmax_rows   7.17 us (x6.55) | top_prob 1-blk  44.95 us -> split  13.57 us (x3.31)
  V=248320 rows=4: greedy 1-blk  47.01 us -> argmax_rows   7.62 us (x6.17) | top_prob 1-blk  44.78 us -> split  13.69 us (x3.27)
  V=248320 rows=5: greedy 1-blk  47.12 us -> argmax_rows  11.06 us (x4.26) | top_prob 1-blk  44.78 us -> split  13.68 us (x3.27)
verify_parity: PASS

$ ./build-copilot-hip/s2_expert_grouped_parity --bench
  moe_hit_grouped_s2 (fp32 scales)             bitwise identical
  moe_hit_grouped_s2 (fp16 d)                  bitwise identical
  moe_hit_grouped_s2_dev (count 7 of 10)       bitwise identical
  moe_hit_grouped_s2_multi (4 tokens, 29 hits) bitwise identical
  moe_grouped_s2 (20 groups, fp32 scales)      bitwise identical
  moe_grouped_s2 (20 groups, fp16 d)           bitwise identical
  moe_group_resident + moe_grouped_s2 T=1 (fp32) bitwise identical
  moe_group_resident + moe_grouped_s2 T=1 (fp16) bitwise identical
  moe_group_resident + moe_grouped_s2 T=5 (fp32) bitwise identical
  moe_group_resident + moe_grouped_s2 T=5 (fp16) bitwise identical
bench: AMD Radeon AI PRO R9700, L2 8 MB, 48 blobs (66 MB) cycled
  moe_hit_grouped_s2, 9 hits               previous     61.4 us (   203 GB/s)   new     25.6 us (   486 GB/s)   x2.40
  moe_hit_grouped_s2, 5 hits               previous     45.2 us (   153 GB/s)   new     18.5 us (   375 GB/s)   x2.45
  moe_hit_grouped_s2, 3 hits               previous     39.2 us (   106 GB/s)   new     14.9 us (   278 GB/s)   x2.63
  moe_hit_grouped_s2, 2 hits               previous     35.9 us (    77 GB/s)   new     13.6 us (   203 GB/s)   x2.64
  moe_hit_grouped_s2, 1 hits               previous     32.8 us (    42 GB/s)   new     11.9 us (   116 GB/s)   x2.75
  moe_grouped_s2, 1 token, MTP shape (10 groups) previous     55.0 us (   251 GB/s)   new     21.1 us (   655 GB/s)   x2.60
  moe_grouped_s2, 4 tokens, no sharing (40 groups) previous    122.0 us (   453 GB/s)   new     55.0 us (  1006 GB/s)   x2.22
  moe_grouped_s2, 4 tokens, 30% shared (31 groups) previous    105.6 us (   402 GB/s)   new     48.0 us (   885 GB/s)   x2.20
  moe_grouped_s2, 8 tokens, 30% shared (59 groups) previous    173.0 us (   472 GB/s)   new     83.3 us (   981 GB/s)   x2.08
  moe_grouped_s2, 8 tokens, all shared (ne 8) (10 groups) previous    131.4 us (   105 GB/s)   new     65.7 us (   210 GB/s)   x2.00
s2_expert_grouped_parity: 0 failures
PASS

$ ./build-copilot-hip/shared_expert_parity --selftest
shared_expert: 0 failures
shared_expert_parity OK

$ ./build-copilot-hip/sampler_parity
sampler: 0 failures

$ ./build-copilot-hip/gr_parity
gr_read/gr_write: 0 failures

$ ./build-copilot-hip/quantize_act_parity
quantize_act: 0 failures over 5 Q8_0 + 4 Q8_K distributions

Multi-architecture compilation verified cleanly on:

  • HIP (hipcc): gfx1100, gfx1101, gfx1102, gfx1103, gfx1151, gfx1200, gfx1201
  • CUDA (nvcc): sm_75, sm_89, sm_100, sm_120

End-to-End 397B Speculative Decode A/B (Radeon AI PRO R9700 gfx1201)

Workload: Qwen3.5-397B-A17B (swift-iq3_s pack + native GGUF + MTP drafter --spec 4 --spec-min-p 0.5 --pcie-frac 0.30 --kv int8), 512 prompt tokens, 256 generated tokens per trial, 1 warmup + 5 timed trials per arm (111 verify windows/trial, 147 / 224 drafts accepted, identical token sequence SHA-256 ced7b38252fd809d across all trials and arms).

Arm Binary & Selectors Per-trial Decode (ms) Median Decode (ms) Median (tok/s) Range (tok/s) Window (ms/win) MTP Step Graph GPU (ms/step)
Primary: d4_on (default) strata.d4 (default switches) 2747.3, 2765.6, 2769.8, 2778.3, 2778.5 2,769.8 92.43 92.14..93.18 24.95 0.947
Primary: d4_all_off (same binary) strata.d4 (STRATA_MULTI_BLOCK_ARGMAX=0 STRATA_HEAD_MIX_MULTI=0 STRATA_MTP_MULTI_COPY=0 STRATA_OLD_Q80_SCALED=1 STRATA_QFUSE_HC=0 STRATA_LFUSE=0 STRATA_S2_SWIGLU_Q8=0) 2826.2, 2817.2, 2818.8, 2832.3, 2826.9 2,826.2 90.58 90.39..90.87 25.46 1.016
Baseline: origin/main strata.main (477ac13c) 2794.6, 2796.1, 2801.2, 2805.7, 2808.0 2,801.2 91.39 91.17..91.61 25.24 1.007
  • Same-binary selector delta (d4_on vs d4_all_off): -56.4 ms (+1.85 tok/s, +2.04%) end-to-end decode (24.95 vs 25.46 ms/window), -69 us/step (-6.8%) on the MTP step graph (0.947 vs 1.016 ms/step).
  • Delta vs origin/main (d4_on vs main_base): -31.4 ms (+1.04 tok/s, +1.14%) end-to-end decode (24.95 vs 25.24 ms/window, non-overlapping 5-trial distributions [2747.3, 2778.5] ms vs [2794.6, 2808.0] ms), -60 us/step (-6.0%) on the MTP step graph (0.947 vs 1.007 ms/step).

Per-Stage MTP Step Graph Breakdown (STRATA_MTP_PROFILE=1, 492 step graphs)

  • k/v+append (skips native_quantize_q8_1 via q8_attn): 0.046 ms -> 0.043 ms (-3 us)
  • experts (quantize_q8_0_scaled warp-per-block + gu/down_grouped_t_kernel<1> + s2_sync_lds()): 0.046 ms -> 0.044 ms (-2 us)
  • shared (skips native_quantize_q8_1 via nsw.x_q8_1 reuse): 0.036 ms -> 0.034 ms (-2 us)
  • hc-read mixer (STRATA_HEAD_MIX_MULTI=1 + q8_head fused into fused_gr_read_multi): 0.049 ms -> 0.035 ms (-14 us)
  • head gemv (skips native_quantize_q8_1(sample_, xq_)): 0.344 ms -> 0.341 ms (-3 us)
  • argmax+prob (wave32 argmax_rows + row_top_prob_split): 0.054 ms -> 0.025 ms (-29 us, 2.16x)
  • Total per MTP step graph: 1.031 ms -> 0.980 ms (-51 us/step in mtp profile; 1.007 ms -> 0.947 ms = -60 us/step without profile stamps).

What This Does NOT Fix / Scope Notes

  • Wave64 CDNA/Vega (STRATA_HIP_GFX906 / warpSize == 64) remains on the single-block sampler_greedy_kernel and row_top_prob_kernel.
  • Target-device hardware execution was validated on gfx1201 (AMD Radeon AI PRO R9700); gfx1100..gfx1151 and CUDA sm_75..sm_120 were verified by compilation.
  • Escape hatches are preserved for every path: STRATA_MULTI_BLOCK_ARGMAX=0, STRATA_ARGMAX_ROWS=0, STRATA_HEAD_MIX_MULTI=0, STRATA_QFUSE_HC=0, STRATA_MTP_MULTI_COPY=0, STRATA_OLD_Q80_SCALED=1, STRATA_LFUSE=0, STRATA_S2_SWIGLU_Q8=0.

Reproduction Commands

cmake -B build-hip -DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1201
cmake --build build-hip --target strata verify_parity s2_expert_grouped_parity shared_expert_parity sampler_parity gr_parity quantize_act_parity arch_defaults_test -j16
./build-hip/arch_defaults_test
./build-hip/verify_parity --selftest --bench
./build-hip/s2_expert_grouped_parity --bench
./build-hip/shared_expert_parity --selftest
./build-hip/sampler_parity
./build-hip/gr_parity
./build-hip/quantize_act_parity

Full-Stack Combined Integration Benchmark (All 8 Open RDNA4 PRs Merged)

For reference when testing the full RDNA4 series together (separate from PR #3069's isolated single-PR numbers in the description above), here are the combined parity and end-to-end 397B prefill + speculative decode results when merging all 8 open RDNA4 PRs onto origin/main (477ac13c):

Merged Stack (32 files changed, +2,037 / -675 lines)

  • Prefill series: #2988 (HC_Q8 dequant + gfx12 Q8_0 gr_upmix), #3001 (moe_fused_iq.cu native_w11_kernel LDS barrier), #3010 (wmma_gemm.cu + gdn_chunked RDNA4 WMMA), #3013 (qsa_prompt_attn.cu RDNA4 WMMA, STRATA_HIP_WMMA=1 opt-in)
  • Decode / Verify / MTP series: #2997 (fused_gr.cu gfx12 tsum + gr_up_q32_kernel + gr_sync_lds), #3024 (iq_kernels.cu EXPDEC + STRATA_IQ_STAGE_GRID), #3064 (verify_kernels.cu GDN verify vk_sync_lds + GS_COLS=32 + batched 36-layer commit under STRATA_GDN_SPLIT=1), #3069 (this PR: wave32 argmax_rows/row_top_prob_split, MTP q8_mixed + STRATA_HEAD_MIX_MULTI, shared-expert x_q8_1 reuse, S2 <1> specialization + s2_sync_lds + hit swiglu_q8, warp-per-block quantize_q8_0_scaled, copy_from_mapped_multi)

1. Combined Parity Verification (AMD Radeon AI PRO R9700 gfx1201)

All 14 parity harnesses pass with 0 failures on the combined build:

  • arch_defaults_test, gr_parity, gr_upmix_parity, hip_prefill_wmma_gemm_parity (3,529 cases, max_abs = 0), hip_gdn_chunked, iq_multi_parity, gdn_parity (STRATA_GDN_SPLIT=0 and 1), verify_batch_parity --selftest, spec_verify_parity, verify_parity --selftest, s2_expert_grouped_parity, shared_expert_parity --selftest, sampler_parity, quantize_act_parity.

2. End-to-End 397B Prefill + Speculative Decode A/B (origin/main vs Combined 8-PR Stack)

Workload: Qwen3.5-397B-A17B (swift-iq3_s pack + native GGUF + MTP --spec 4 --spec-min-p 0.5 --pcie-frac 0.30 --kv int8 --prefill 4096), STRATA_HIPBLASLT_TUNING=tools/hip/gfx1201-hipblaslt-100500.txt STRATA_DENSE_MMQ=1 STRATA_PF_FUSED=1 STRATA_HC_Q8=1, 1 warmup + 5 timed trials per arm.

A. prompt = 512, gen = 256 (111 verify windows, 147 / 224 drafts accepted, bitwise-identical token hash ced7b38252fd809d across all trials)

Arm Per-Trial Decode (ms) Median Decode (ms) Median (tok/s) Range (tok/s) Window (ms/win) Verify GPU-Reach Wait (ms/win) MTP Draft (ms/win) MTP Step Graph GPU (ms/step)
origin/main (477ac13c, STRATA_HIP_WMMA=1) 2820.8, 2841.3, 2831.5, 2834.4, 2849.7 2,834.4 90.32 89.83..90.75 25.53 19.16 3.15 1.008
Combined 8-PR Stack (STRATA_HIP_WMMA=1) 2699.6, 2716.4, 2716.8, 2718.7, 2720.6 2,716.8 94.23 94.10..94.83 24.48 18.35 2.98 0.948
Combined Delta — -117.6 ms (-4.15%) +3.91 tok/s (+4.33%) non-overlapping -1.05 ms/win -0.81 ms/win -0.17 ms/win -60 us/step (-5.95%)

B. prompt = 4096, gen = 256 (92 verify windows, 166 / 224 drafts accepted, token hash b52b193b1859dbf7)

Arm Per-Trial 4K Prefill (ms) Median Prefill (ms / tok/s) Per-Trial Decode (ms) Median Decode (ms / tok/s) Window (ms/win) Verify GPU-Reach Wait (ms/win) MTP Step Graph GPU (ms/step)
origin/main (STRATA_HIP_WMMA=0 default) 1995.0, 2001.2, 2004.6, 2011.3, 2017.4 2,004.6 ms (2,043.3 tok/s) 2581.1, 2603.8, 2591.3, 2672.5, 2660.5 2,603.8 ms (98.32 tok/s) 27.12 19.15 1.030
origin/main (STRATA_HIP_WMMA=1) 1420.3, 1426.7, 1425.7, 1428.2, 1449.0 1,426.7 ms (2,871.0 tok/s) 2486.0, 2509.3, 2491.9, 2495.2, 2513.8 2,495.2 ms (102.60 tok/s) 27.12 19.49 1.034
Combined 8-PR Stack (STRATA_HIP_WMMA=1) 1401.7, 1417.5, 1408.6, 1410.9, 1413.1 1,410.9 ms (2,903.1 tok/s) 2411.2, 2409.6, 2412.9, 2430.0, 2418.6 2,412.9 ms (106.10 tok/s) 26.23 18.71 0.975
Delta vs main (WMMA=1) — -15.8 ms (+1.12%) — -82.3 ms (+3.41%, +3.50 tok/s) -0.89 ms/win -0.78 ms/win -59 us/step (-5.71%)
Delta vs main (WMMA=0) — -593.7 ms (+42.08%) — -190.9 ms (+7.91%, +7.78 tok/s) -0.89 ms/win -0.44 ms/win -55 us/step (-5.34%)

🔄 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/3264 **Author:** [@bsorensen110](https://github.com/bsorensen110) **Created:** 10/19/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `new/pr3069` --- ### 📝 Commits (2) - [`d79fe8e`](https://github.com/Niko1221/Strata/commit/d79fe8e8881f805c34b00e56387abd4d303fe2ac) perf(hip): optimize MTP draft, shared expert, and verify/sampler head kernels on RDNA4 - [`78e0bf5`](https://github.com/Niko1221/Strata/commit/78e0bf5ca7cf772cdf95f078dab9fcdaafe53e6e) fix(kernels): remove duplicate SM60 shared_expert q8_1 quantize and scope counter-free gr_parity test ### 📊 Changes **13 files changed** (+711 additions, -266 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+2 -2) 📝 `src/core/mtp.cpp` (+66 -31) 📝 `src/core/verify.cpp` (+26 -10) 📝 `src/kernels/cuda/elementwise.cu` (+25 -18) 📝 `src/kernels/cuda/fused_gr.cu` (+10 -4) 📝 `src/kernels/cuda/quantize_act.cu` (+13 -12) 📝 `src/kernels/cuda/s2_expert_grouped.cu` (+233 -153) 📝 `src/kernels/cuda/shared_expert.cu` (+13 -7) 📝 `src/kernels/cuda/verify_kernels.cu` (+40 -12) 📝 `src/kernels/gr_parity.cpp` (+69 -0) 📝 `src/kernels/s2_expert_grouped_parity.cpp` (+7 -5) 📝 `src/kernels/shared_expert_parity.cpp` (+40 -0) 📝 `src/kernels/verify_parity.cpp` (+167 -12) </details> ### 📄 Description ## Problem and result Supersedes #3069 (closed during the `0.2.0-beta` tracker reset), rebased onto `0.2.0-beta` (`e88ee39d`). During speculative decode and verification on RDNA4 (`gfx1200`/`gfx1201`), six bottlenecks in the MTP drafter, shared expert, S2 routed experts, and verify/sampler head operations accounted for significant per-window overhead while having **100% bitwise-identical** replacements: 1. `multi_block_head_ops()` and `argmax_rows_wanted()` in `src/kernels/cuda/verify_kernels.cu` unconditionally returned `false` under `#if defined(__HIPCC__)`, forcing `argmax_rows` (`T x 248,320` logits) and `row_top_prob_split` onto single-WGP (`<<<n_rows, 1024>>>`) launches instead of 128-block (`argmax_rows_kernel`) and 32-block (`row_top_prob_split_kernel`) wave32 kernels (`402.0 -> 35.1 us` at `T=5`, **11.45× speedup**). 2. `quantize_q8_0_scaled` in `src/kernels/cuda/quantize_act.cu` used a 1-thread-per-block serial 32-element loop under `#if defined(__HIPCC__)` instead of the warp-per-block shuffle-reduction kernel (`quantize_q8_0_scaled_kernel`). 3. `moe_hit_grouped_s2`, `moe_hit_grouped_s2_dev`, and `moe_hit_grouped_s2_multi` in `src/kernels/cuda/s2_expert_grouped.cu` launched `swiglu_kernel` and `quantize_q8_0_scaled` separately instead of the fused `swiglu_quantize_q8_0_scaled_kernel` already used by `moe_grouped_s2`, and `gu_grouped_t_kernel`/`down_grouped_t_kernel` allocated 25 KB / 6.25 KB LDS (`GMAX=8`) even for `cap_entries <= 16` (`T=1` MTP draft), capping occupancy at 2 blocks/WGP. 4. `MtpDrafter::forward_body` (`src/core/mtp.cpp`) and `Verifier::forward_range` (`src/core/verify.cpp`) quantized `mixed` to `Q8_1` twice per layer (once in `fused_gr_read_multi` / `native_quantize_q8_1` for routed experts, and a second time inside `shared_expert`), and `fused_gr_read_multi` declined `q8_mixed` when `q8_cnt == nullptr` (`STRATA_QFUSE_HC_LOCAL=1`). 5. `Verifier::forward_range` issued up to 8 separate `cudaMemcpyAsync(..., cudaMemcpyHostToDevice)` calls per layer to copy pinned expert blobs for misses instead of a single batched `copy_from_mapped_multi` device kernel reading mapped host pointers. Every optimization in this PR is **100% bitwise identical** (`0` differing bits across all outputs). ## Related discussion Supersedes #3069 (includes the `copy_from_mapped_multi_fallback` alignment-safe scalar fallback for `bytes % 4 != 0` or `4 mod 8` pointers and the `verify_parity` unaligned fallback tests from review on #3069). ## Approach - Enable wave32 `argmax_rows_kernel` (`128` blocks/row) and `row_top_prob_split_kernel` (`kTopBlocks = 32` single-warp blocks/row) on RDNA HIP (`p.warpSize == 32`, cached per device in `arch[64]`) in `src/kernels/cuda/verify_kernels.cu`. - Enable warp-per-block `quantize_q8_0_scaled_kernel` on HIP in `src/kernels/cuda/quantize_act.cu` (`STRATA_OLD_Q80_SCALED=1` fallback). - Route `moe_hit_grouped_s2{,_dev,_multi}` through `launch_hit_swiglu_q8`, specialize `gu_grouped_t_kernel<1>` / `down_grouped_t_kernel<1>` for `cap_entries <= 16` (reducing LDS from 25 KB to 3.125 KB), and use `s2_sync_lds()` in `src/kernels/cuda/s2_expert_grouped.cu`. - Reuse pre-quantized `x_q8_1` across routed and shared experts in `src/kernels/cuda/shared_expert.cu`, `src/core/mtp.cpp`, and `src/core/verify.cpp`, and allow counter-free `q8_mixed` in `fused_gr_read_multi` (`src/kernels/cuda/fused_gr.cu`) when `q8_cnt == nullptr`. - Add `copy_from_mapped_multi` in `src/kernels/cuda/elementwise.cu` (with alignment-safe fallback for non-8B-aligned pointers/sizes) to batch mapped-host miss expert copies in `src/core/verify.cpp`. ## Validation **Passed:** - `cmake --build build-copilot-hip --target strata verify_parity gr_parity shared_expert_parity s2_expert_grouped_parity arch_defaults_test -j16`: revision `d79fe8e8` on `0.2.0-beta` (`e88ee39d`), AMD Radeon AI PRO R9700 (`gfx1201`, 32 GB, Linux `7.2.9-2-cachyos-server`, ROCm `10.2.0a20260914`), clean build & link. - `./build-copilot-hip/arch_defaults_test`: revision `d79fe8e8` (`0.2.0-beta`), `arch_defaults_test: OK`. - `./build-copilot-hip/verify_parity`: revision `d79fe8e8` (`0.2.0-beta`), `gfx1201`, `argmax_rows, row_top_prob_split: bitwise equal`, `copy_from_mapped_multi: bitwise equal (multi=1 and fallback=0, aligned + 1025w + 4B-aligned)`, `quantize_q8_0_scaled: bitwise equal`, `verify_parity: PASS`. - `./build-copilot-hip/gr_parity --selftest`: revision `d79fe8e8` (`0.2.0-beta`), `gfx1201`, `fused GR counter-free q8_1 (q8_cnt == nullptr), T 1..8, direct/graph + LOCAL=0 guard: pass`, `gr_read/gr_write: 0 failures`, `gr_parity OK`. - `./build-copilot-hip/shared_expert_parity`: revision `d79fe8e8` (`0.2.0-beta`), `gfx1201`, `native shared x_q8_1 reuse: byte-identical`, `shared_expert: 0 failures`. - `./build-copilot-hip/s2_expert_grouped_parity` (default, `STRATA_S2_SWIGLU_Q8=0`, and `STRATA_OLD_Q80_SCALED=1`): revision `d79fe8e8` (`0.2.0-beta`), `gfx1201`, all 14 cases bitwise identical (`s2_expert_grouped_parity: 0 failures`, `PASS`). **Failed:** - none observed **Not run:** - Target-device runtime execution on `gfx11` / `gfx906` and CUDA hardware (no `gfx11`/`gfx906` or NVIDIA GPU in this host). - SYCL and Metal builds (changes are in CUDA/HIP kernels and engine verify/MTP paths). ## Limits - Wave64 `gfx906` keeps the single-block `row_top_prob` and `sampler_greedy_kernel` paths (`#if !defined(STRATA_HIP_GFX906)` and `p.warpSize == 32` check). --- ## Summary This PR enables and optimizes several bitwise-identical paths across the MTP draft layer, the verify/draft head greedy sampler & top-probability kernels, the S2 grouped expert kernels, and the shared expert on RDNA HIP (`gfx1201`): 1. **Wave32 multi-block `argmax_rows` and `row_top_prob_split` on RDNA HIP (`src/kernels/cuda/verify_kernels.cu`, `CMakeLists.txt`):** - `argmax_rows_kernel` and `row_top_prob_split_kernel` were previously compiled out under `#if !defined(__HIPCC__)`, forcing wave32 RDNA GPUs (`warpSize == 32`) onto the single-block `sampler_greedy_kernel<<<n_rows, 1024>>>` and `row_top_prob_kernel<<<n_rows, 1024>>>` (1..5 blocks total across 48 WGPs to scan 425 KB..4.97 MB of logits). - Guards the wave32 multi-block kernels with `#if !defined(STRATA_HIP_GFX906)` (keeping wave64 `gfx906` on the one-block kernels) and enables `multi_block_head_ops()` / `argmax_rows_wanted()` per device on HIP when `p.warpSize == 32` (`STRATA_MULTI_BLOCK_ARGMAX=0` and `STRATA_ARGMAX_ROWS=0` force them off). - Sets `kTopBlocks = 32` (`32` threads = 1 warp/block across 32 WGPs, avoiding intra-block `__syncthreads()` barriers when `blockDim.x == 32`) and adds `#pragma unroll 8` to the stride-1024 reduction loop in `row_top_prob_kernel` and `row_top_prob_split_kernel` (preserving exact per-thread summation order while overlapping 8 global loads in flight). - Enables the `verify_parity` target on HIP (`STRATA_ENABLE_CUDA OR STRATA_ENABLE_HIP`) and extends `verify_parity` with `copy_from_mapped_multi`, `quantize_q8_0_scaled`, and `--bench` checks. 2. **Fused HC `q8_mixed`, `STRATA_HEAD_MIX_MULTI`, and shared-expert `x_q8_1` reuse in MTP and Verify (`src/core/mtp.cpp`, `src/core/verify.cpp`, `src/kernels/cuda/fused_gr.cu`, `src/kernels/cuda/shared_expert.cu`):** - Allows `fused_gr_read_multi` (`src/kernels/cuda/fused_gr.cu`) to write `q8_mixed` without a `q8_cnt` buffer when `qfuse_hc_local() && a[0].s_down == nullptr` (`gr_up_q32_kernel` and `gr_up_q8_q32_kernel` assign one warp per 32-column `q8_1` block and never touch `q8_cnt`). - Enables `STRATA_HEAD_MIX_MULTI` by default on `gfx12` in `verify.cpp` and `mtp.cpp` (`STRATA_HEAD_MIX_MULTI=0` disables), replacing the 4-launch `gr_read` fallback on the MTP final mixer with `fused_gr_read_multi`. - Passes `q8_mixed = xq_ + t * (N / 32) * 36` to all 3 `fused_gr_read_multi` calls in `MtpDrafter` (`attn_hyper_connection`, `mlp_hyper_connection`, and `hyper_connection_mixer`) and to the final `output_hc_*` `fused_gr_read_multi` in `Verifier`, skipping redundant standalone `native_quantize_q8_1` launches when `fused_gr_read_multi` writes `xq_`. - Updates `shared_expert()` (`src/kernels/cuda/shared_expert.cu`) to honor `native->x_q8_1` (set by `MtpDrafter` when `q8_mlp && T == 1`), matching `shared_expert_multi`. 3. **S2 grouped expert `<1>` specialization, LDS-only barriers, and fused SwiGLU+Q8_0 on hit paths (`src/kernels/cuda/s2_expert_grouped.cu`, `src/kernels/s2_expert_grouped_parity.cpp`):** - Adds `s2_sync_lds()` (`s_wait_dscnt 0x0; s_barrier_signal -1; s_barrier_wait -1` on `gfx12`; `s_waitcnt lgkmcnt(0); s_barrier` on `gfx1030`/`gfx11xx`) for LDS-only staging barriers. - Adds `MAX_E = 1` template specializations `gu_grouped_t_kernel<1>` (`LDS = 3,200 B`, `VGPR = 85` vs `<8>`'s `LDS = 25,600 B`, `VGPR = 89`) and `down_grouped_t_kernel<1>` (`LDS = 800 B`, `VGPR = 47` vs `<8>`'s `LDS = 6,400 B`, `VGPR = 40`) dispatched when `cap_entries <= 16` (covering single-token MTP `T = 1, K = 10`). - Uses `swiglu_quantize_q8_0_scaled_kernel` in `moe_hit_grouped_s2`, `moe_hit_grouped_s2_dev`, and `moe_hit_grouped_s2_multi` when `fast && x_scales != nullptr && swiglu_q8_on()` (`STRATA_S2_SWIGLU_Q8=0` disables), matching `moe_grouped_s2`. 4. **Warp-per-block `quantize_q8_0_scaled` and `copy_from_mapped_multi` on HIP (`src/kernels/cuda/quantize_act.cu`, `src/kernels/cuda/elementwise.cu`, `src/core/mtp.cpp`):** - Enables the warp-per-block `quantize_q8_0_scaled_kernel` on HIP (`STRATA_OLD_Q80_SCALED=1` restores the thread-per-block kernel). - Enables `copy_from_mapped_multi_kernel` on HIP (`STRATA_MTP_MULTI_COPY=0` restores individual copies) and uses `copy_from_mapped_multi` in `MtpDrafter::capture_round` and `MtpDrafter::capture_step`. --- ## Verification & Parity Evidence (AMD Radeon AI PRO R9700 `gfx1201`) All 7 parity and self-test suites pass with **0 failures** and 100% bitwise equality: ```text $ ./build-copilot-hip/arch_defaults_test arch_defaults_test: OK $ ./build-copilot-hip/verify_parity --selftest --bench argmax_rows, row_top_prob_split: bitwise equal to the one-block kernels (ties, NaN, -inf, 1-8 rows on one scratch) copy_from_mapped_multi: bitwise equal to individual mapped copies (multi=1 and fallback=0, aligned + 1025w + 4B-aligned) quantize_q8_0_scaled: bitwise equal to CPU act_quant_q8_1 reference (zero, .5 ties, normal) V=106299 rows=1: greedy 1-blk 24.39 us -> argmax_rows 7.87 us (x3.10) | top_prob 1-blk 22.43 us -> split 11.24 us (x2.00) V=248320 rows=1: greedy 1-blk 46.94 us -> argmax_rows 7.17 us (x6.55) | top_prob 1-blk 44.95 us -> split 13.57 us (x3.31) V=248320 rows=4: greedy 1-blk 47.01 us -> argmax_rows 7.62 us (x6.17) | top_prob 1-blk 44.78 us -> split 13.69 us (x3.27) V=248320 rows=5: greedy 1-blk 47.12 us -> argmax_rows 11.06 us (x4.26) | top_prob 1-blk 44.78 us -> split 13.68 us (x3.27) verify_parity: PASS $ ./build-copilot-hip/s2_expert_grouped_parity --bench moe_hit_grouped_s2 (fp32 scales) bitwise identical moe_hit_grouped_s2 (fp16 d) bitwise identical moe_hit_grouped_s2_dev (count 7 of 10) bitwise identical moe_hit_grouped_s2_multi (4 tokens, 29 hits) bitwise identical moe_grouped_s2 (20 groups, fp32 scales) bitwise identical moe_grouped_s2 (20 groups, fp16 d) bitwise identical moe_group_resident + moe_grouped_s2 T=1 (fp32) bitwise identical moe_group_resident + moe_grouped_s2 T=1 (fp16) bitwise identical moe_group_resident + moe_grouped_s2 T=5 (fp32) bitwise identical moe_group_resident + moe_grouped_s2 T=5 (fp16) bitwise identical bench: AMD Radeon AI PRO R9700, L2 8 MB, 48 blobs (66 MB) cycled moe_hit_grouped_s2, 9 hits previous 61.4 us ( 203 GB/s) new 25.6 us ( 486 GB/s) x2.40 moe_hit_grouped_s2, 5 hits previous 45.2 us ( 153 GB/s) new 18.5 us ( 375 GB/s) x2.45 moe_hit_grouped_s2, 3 hits previous 39.2 us ( 106 GB/s) new 14.9 us ( 278 GB/s) x2.63 moe_hit_grouped_s2, 2 hits previous 35.9 us ( 77 GB/s) new 13.6 us ( 203 GB/s) x2.64 moe_hit_grouped_s2, 1 hits previous 32.8 us ( 42 GB/s) new 11.9 us ( 116 GB/s) x2.75 moe_grouped_s2, 1 token, MTP shape (10 groups) previous 55.0 us ( 251 GB/s) new 21.1 us ( 655 GB/s) x2.60 moe_grouped_s2, 4 tokens, no sharing (40 groups) previous 122.0 us ( 453 GB/s) new 55.0 us ( 1006 GB/s) x2.22 moe_grouped_s2, 4 tokens, 30% shared (31 groups) previous 105.6 us ( 402 GB/s) new 48.0 us ( 885 GB/s) x2.20 moe_grouped_s2, 8 tokens, 30% shared (59 groups) previous 173.0 us ( 472 GB/s) new 83.3 us ( 981 GB/s) x2.08 moe_grouped_s2, 8 tokens, all shared (ne 8) (10 groups) previous 131.4 us ( 105 GB/s) new 65.7 us ( 210 GB/s) x2.00 s2_expert_grouped_parity: 0 failures PASS $ ./build-copilot-hip/shared_expert_parity --selftest shared_expert: 0 failures shared_expert_parity OK $ ./build-copilot-hip/sampler_parity sampler: 0 failures $ ./build-copilot-hip/gr_parity gr_read/gr_write: 0 failures $ ./build-copilot-hip/quantize_act_parity quantize_act: 0 failures over 5 Q8_0 + 4 Q8_K distributions ``` Multi-architecture compilation verified cleanly on: - **HIP (`hipcc`):** `gfx1100`, `gfx1101`, `gfx1102`, `gfx1103`, `gfx1151`, `gfx1200`, `gfx1201` - **CUDA (`nvcc`):** `sm_75`, `sm_89`, `sm_100`, `sm_120` --- ## End-to-End 397B Speculative Decode A/B (Radeon AI PRO R9700 `gfx1201`) Workload: Qwen3.5-397B-A17B (`swift-iq3_s` pack + native GGUF + MTP drafter `--spec 4 --spec-min-p 0.5 --pcie-frac 0.30 --kv int8`), `512` prompt tokens, `256` generated tokens per trial, `1` warmup + `5` timed trials per arm (`111` verify windows/trial, `147 / 224` drafts accepted, identical token sequence SHA-256 `ced7b38252fd809d` across all trials and arms). | Arm | Binary & Selectors | Per-trial Decode (ms) | Median Decode (ms) | Median (tok/s) | Range (tok/s) | Window (ms/win) | MTP Step Graph GPU (ms/step) | |---|---|---|---:|---:|---|---:|---:| | **Primary: `d4_on` (default)** | `strata.d4` (default switches) | `2747.3, 2765.6, 2769.8, 2778.3, 2778.5` | **2,769.8** | **92.43** | `92.14..93.18` | **24.95** | **0.947** | | **Primary: `d4_all_off` (same binary)** | `strata.d4` (`STRATA_MULTI_BLOCK_ARGMAX=0 STRATA_HEAD_MIX_MULTI=0 STRATA_MTP_MULTI_COPY=0 STRATA_OLD_Q80_SCALED=1 STRATA_QFUSE_HC=0 STRATA_LFUSE=0 STRATA_S2_SWIGLU_Q8=0`) | `2826.2, 2817.2, 2818.8, 2832.3, 2826.9` | **2,826.2** | **90.58** | `90.39..90.87` | **25.46** | **1.016** | | **Baseline: `origin/main`** | `strata.main` (`477ac13c`) | `2794.6, 2796.1, 2801.2, 2805.7, 2808.0` | **2,801.2** | **91.39** | `91.17..91.61` | **25.24** | **1.007** | - **Same-binary selector delta (`d4_on` vs `d4_all_off`):** **`-56.4 ms` (`+1.85 tok/s`, `+2.04%`)** end-to-end decode (`24.95` vs `25.46 ms/window`), **`-69 us/step` (`-6.8%`)** on the MTP step graph (`0.947` vs `1.016 ms/step`). - **Delta vs `origin/main` (`d4_on` vs `main_base`):** **`-31.4 ms` (`+1.04 tok/s`, `+1.14%`)** end-to-end decode (`24.95` vs `25.24 ms/window`, non-overlapping 5-trial distributions `[2747.3, 2778.5] ms` vs `[2794.6, 2808.0] ms`), **`-60 us/step` (`-6.0%`)** on the MTP step graph (`0.947` vs `1.007 ms/step`). ### Per-Stage MTP Step Graph Breakdown (`STRATA_MTP_PROFILE=1`, 492 step graphs) - `k/v+append` (skips `native_quantize_q8_1` via `q8_attn`): `0.046 ms` -> **`0.043 ms`** (`-3 us`) - `experts` (`quantize_q8_0_scaled` warp-per-block + `gu/down_grouped_t_kernel<1>` + `s2_sync_lds()`): `0.046 ms` -> **`0.044 ms`** (`-2 us`) - `shared` (skips `native_quantize_q8_1` via `nsw.x_q8_1` reuse): `0.036 ms` -> **`0.034 ms`** (`-2 us`) - `hc-read mixer` (`STRATA_HEAD_MIX_MULTI=1` + `q8_head` fused into `fused_gr_read_multi`): `0.049 ms` -> **`0.035 ms`** (`-14 us`) - `head gemv` (skips `native_quantize_q8_1(sample_, xq_)`): `0.344 ms` -> **`0.341 ms`** (`-3 us`) - `argmax+prob` (wave32 `argmax_rows` + `row_top_prob_split`): `0.054 ms` -> **`0.025 ms`** (`-29 us`, **`2.16x`**) - **Total per MTP step graph:** `1.031 ms` -> **`0.980 ms`** (`-51 us/step` in `mtp profile`; `1.007 ms` -> **`0.947 ms`** = `-60 us/step` without profile stamps). --- ## What This Does NOT Fix / Scope Notes - Wave64 CDNA/Vega (`STRATA_HIP_GFX906` / `warpSize == 64`) remains on the single-block `sampler_greedy_kernel` and `row_top_prob_kernel`. - Target-device hardware execution was validated on `gfx1201` (AMD Radeon AI PRO R9700); `gfx1100..gfx1151` and CUDA `sm_75..sm_120` were verified by compilation. - Escape hatches are preserved for every path: `STRATA_MULTI_BLOCK_ARGMAX=0`, `STRATA_ARGMAX_ROWS=0`, `STRATA_HEAD_MIX_MULTI=0`, `STRATA_QFUSE_HC=0`, `STRATA_MTP_MULTI_COPY=0`, `STRATA_OLD_Q80_SCALED=1`, `STRATA_LFUSE=0`, `STRATA_S2_SWIGLU_Q8=0`. ## Reproduction Commands ```bash cmake -B build-hip -DSTRATA_ENABLE_HIP=ON -DCMAKE_HIP_ARCHITECTURES=gfx1201 cmake --build build-hip --target strata verify_parity s2_expert_grouped_parity shared_expert_parity sampler_parity gr_parity quantize_act_parity arch_defaults_test -j16 ./build-hip/arch_defaults_test ./build-hip/verify_parity --selftest --bench ./build-hip/s2_expert_grouped_parity --bench ./build-hip/shared_expert_parity --selftest ./build-hip/sampler_parity ./build-hip/gr_parity ./build-hip/quantize_act_parity ``` --- ## Full-Stack Combined Integration Benchmark (All 8 Open RDNA4 PRs Merged) For reference when testing the full RDNA4 series together (separate from PR #3069's isolated single-PR numbers in the description above), here are the combined parity and end-to-end 397B prefill + speculative decode results when merging all 8 open RDNA4 PRs onto `origin/main` (`477ac13c`): ### Merged Stack (`32 files changed, +2,037 / -675 lines`) - **Prefill series:** #2988 (`HC_Q8` dequant + `gfx12` Q8_0 `gr_upmix`), #3001 (`moe_fused_iq.cu` `native_w11_kernel` LDS barrier), #3010 (`wmma_gemm.cu` + `gdn_chunked` RDNA4 WMMA), #3013 (`qsa_prompt_attn.cu` RDNA4 WMMA, `STRATA_HIP_WMMA=1` opt-in) - **Decode / Verify / MTP series:** #2997 (`fused_gr.cu` `gfx12` `tsum` + `gr_up_q32_kernel` + `gr_sync_lds`), #3024 (`iq_kernels.cu` `EXPDEC` + `STRATA_IQ_STAGE_GRID`), #3064 (`verify_kernels.cu` GDN verify `vk_sync_lds` + `GS_COLS=32` + batched 36-layer commit under `STRATA_GDN_SPLIT=1`), #3069 (this PR: wave32 `argmax_rows`/`row_top_prob_split`, MTP `q8_mixed` + `STRATA_HEAD_MIX_MULTI`, shared-expert `x_q8_1` reuse, S2 `<1>` specialization + `s2_sync_lds` + hit `swiglu_q8`, warp-per-block `quantize_q8_0_scaled`, `copy_from_mapped_multi`) ### 1. Combined Parity Verification (AMD Radeon AI PRO R9700 `gfx1201`) All **14 parity harnesses** pass with **0 failures** on the combined build: - `arch_defaults_test`, `gr_parity`, `gr_upmix_parity`, `hip_prefill_wmma_gemm_parity` (`3,529` cases, `max_abs = 0`), `hip_gdn_chunked`, `iq_multi_parity`, `gdn_parity` (`STRATA_GDN_SPLIT=0` and `1`), `verify_batch_parity --selftest`, `spec_verify_parity`, `verify_parity --selftest`, `s2_expert_grouped_parity`, `shared_expert_parity --selftest`, `sampler_parity`, `quantize_act_parity`. ### 2. End-to-End 397B Prefill + Speculative Decode A/B (`origin/main` vs Combined 8-PR Stack) Workload: Qwen3.5-397B-A17B (`swift-iq3_s` pack + native GGUF + MTP `--spec 4 --spec-min-p 0.5 --pcie-frac 0.30 --kv int8 --prefill 4096`), `STRATA_HIPBLASLT_TUNING=tools/hip/gfx1201-hipblaslt-100500.txt STRATA_DENSE_MMQ=1 STRATA_PF_FUSED=1 STRATA_HC_Q8=1`, `1` warmup + `5` timed trials per arm. #### A. `prompt = 512`, `gen = 256` (`111` verify windows, `147 / 224` drafts accepted, bitwise-identical token hash `ced7b38252fd809d` across all trials) | Arm | Per-Trial Decode (ms) | Median Decode (ms) | Median (tok/s) | Range (tok/s) | Window (ms/win) | Verify GPU-Reach Wait (ms/win) | MTP Draft (ms/win) | MTP Step Graph GPU (ms/step) | |---|---|---:|---:|---|---:|---:|---:|---:| | **`origin/main` (`477ac13c`, `STRATA_HIP_WMMA=1`)** | `2820.8, 2841.3, 2831.5, 2834.4, 2849.7` | **2,834.4** | **90.32** | `89.83..90.75` | **25.53** | **19.16** | **3.15** | **1.008** | | **Combined 8-PR Stack (`STRATA_HIP_WMMA=1`)** | `2699.6, 2716.4, 2716.8, 2718.7, 2720.6` | **2,716.8** | **94.23** | `94.10..94.83` | **24.48** | **18.35** | **2.98** | **0.948** | | **Combined Delta** | — | **-117.6 ms (-4.15%)** | **+3.91 tok/s (+4.33%)** | non-overlapping | **-1.05 ms/win** | **-0.81 ms/win** | **-0.17 ms/win** | **-60 us/step (-5.95%)** | #### B. `prompt = 4096`, `gen = 256` (`92` verify windows, `166 / 224` drafts accepted, token hash `b52b193b1859dbf7`) | Arm | Per-Trial 4K Prefill (ms) | Median Prefill (ms / tok/s) | Per-Trial Decode (ms) | Median Decode (ms / tok/s) | Window (ms/win) | Verify GPU-Reach Wait (ms/win) | MTP Step Graph GPU (ms/step) | |---|---|---:|---|---:|---:|---:|---:| | **`origin/main` (`STRATA_HIP_WMMA=0` default)** | `1995.0, 2001.2, 2004.6, 2011.3, 2017.4` | **2,004.6 ms** (`2,043.3 tok/s`) | `2581.1, 2603.8, 2591.3, 2672.5, 2660.5` | **2,603.8 ms** (`98.32 tok/s`) | **27.12** | **19.15** | **1.030** | | **`origin/main` (`STRATA_HIP_WMMA=1`)** | `1420.3, 1426.7, 1425.7, 1428.2, 1449.0` | **1,426.7 ms** (`2,871.0 tok/s`) | `2486.0, 2509.3, 2491.9, 2495.2, 2513.8` | **2,495.2 ms** (`102.60 tok/s`) | **27.12** | **19.49** | **1.034** | | **Combined 8-PR Stack (`STRATA_HIP_WMMA=1`)** | `1401.7, 1417.5, 1408.6, 1410.9, 1413.1` | **1,410.9 ms** (`2,903.1 tok/s`) | `2411.2, 2409.6, 2412.9, 2430.0, 2418.6` | **2,412.9 ms** (`106.10 tok/s`) | **26.23** | **18.71** | **0.975** | | **Delta vs `main` (`WMMA=1`)** | — | **-15.8 ms (+1.12%)** | — | **-82.3 ms (+3.41%, +3.50 tok/s)** | **-0.89 ms/win** | **-0.78 ms/win** | **-59 us/step (-5.71%)** | | **Delta vs `main` (`WMMA=0`)** | — | **-593.7 ms (+42.08%)** | — | **-190.9 ms (+7.91%, +7.78 tok/s)** | **-0.89 ms/win** | **-0.44 ms/win** | **-55 us/step (-5.34%)** | --- <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#4534
No description provided.