mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3230] [Engine] perf(hip): enable exact wave32 QSA decode kernels and B6 MMVQ fragment reuse on gfx12 #4510
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#4510
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/3230
Author: @bsorensen110
Created: 10/19/2026
Status: 🔄 Open
Base:
main← Head:perf/rdna4-d5-qsa-decode-mmvq📝 Commits (1)
67c4a31perf(hip): enable exact wave32 QSA decode kernels and B6 MMVQ fragment reuse on gfx12📊 Changes
5 files changed (+236 additions, -82 deletions)
View changed files
📝
CMakeLists.txt(+23 -27)📝
include/strata/kernels/native_mmvq.hpp(+4 -4)📝
src/kernels/b6_mmvq_bench.cpp(+5 -3)📝
src/kernels/cuda/native_mmvq.cu(+164 -35)📝
src/kernels/cuda/qsa_decode_attn.cu(+40 -13)📄 Description
Problem and result
Supersedes #3102 (closed during the
0.2.0-betatracker reset), rebased onto0.2.0-beta(e88ee39d).On RDNA4 (
gfx1200/gfx1201), QSA decode attention (src/kernels/cuda/qsa_decode_attn.cu) and multi-column native MMVQ (src/kernels/cuda/native_mmvq.cu) left several 100% bitwise-identical wave32 optimizations disabled:qsa_decode_attnfell back toattn_chunk_kernel(12 warp-wide shuffle reductions per KV cell, 1 cell per warp step, scalar V loads) andattn_merge_kernelinstead of the exact wave32attn_chunk_kernel_pre75<M, 8, true>(NC=8cells per warp step, DPP16reduce12, 4-cell unrolled V loads,float4broadcast weight folds) andattn_merge_v2_kernel<kMergeU>, and used full-workgroup__syncthreads()(s_wait_loadcnt_dscnt 0x0; s_barrier; global_inv scope:SCOPE_SE) for LDS-only barriers.src/kernels/cuda/native_mmvq.cu, multi-columnnative_mmvq_multi_kernelreloaded each column'sQ8_1activation fragment for every output row in the block and recomputedQ4_K/Q5_Kdot2andQ6_K/Q4_K/Q5_Kweight nibble shifts per column instead of reusing pre-decoded activation/weight fragments in registers acrossROWS = 2or4rows (b6_mmvq_rows_kernel), whileiq4_table_lookupgated the 6-instructionv_perm_b32lookup behindSTRATA_HIP_GFX906instead of__HIPCC__.This PR enables
attn_chunk_kernel_pre75<M, 8, true>andattn_merge_v2_kernel<kMergeU>by default per device ongfx12, adds LDS-onlyqda_sync_lds()andmmvq_sync_lds(), enablesv_perm_b32iq4_table_lookupon all HIP targets, and enables a per-format/shapeb6_default_rows_gfx12table (STRATA_B6_MMVQ_ROWS=-1auto) ongfx12while preserving first-useSTRATA_B6_MMVQ_ROWSevaluation forapply_nv_defaultson CUDA. All outputs are 100% bitwise identical (0differing bits across1,172QSA decode cases,148,480MMVQ multi-column outputs, and all102b6_mmvq_benchshape/column pairs).Related discussion
Supersedes #3102. Rebased cleanly onto
0.2.0-beta(e88ee39d) preserving upstreamkPdlPrefetch/launch_pdl,Il58Arch(ncols 5..8),kMergeU, and first-useb6_rows_mode()evaluation.Approach
pre75_attn()(attn_chunk_kernel_pre75<M, 8, true>) andattn_merge_v2()(attn_merge_v2_kernel<kMergeU>) by default ongfx12(cached per device incc[64]/g12[64]) and replace LDS barriers withqda_sync_lds()insrc/kernels/cuda/qsa_decode_attn.cu.mmvq_sync_lds(), enablev_perm_b32iq4_table_lookupunder#if defined(__HIPCC__), pre-decodeB6X<Q6KTraits>/B6XK<Q4KTraits, 4>/B6XK<Q5KTraits, 5>fragments (vi,v0/v1,dot2), addB6X<SmallTraits<IQ4NLBlock, 4>>andB6X<SmallTraits<Q80Block, 8>>, and enableb6_default_rows_gfx12<F, NCOLS>(n_out)whenb6_rows_mode() < 0 && dev_class() == 1insrc/kernels/cuda/native_mmvq.cu.qsa_merge_daily_parityandb6_mmvq_benchon HIP inCMakeLists.txt.Validation
Passed:
cmake --build build-copilot-hip --target strata qsa_merge_daily_parity mmvq_multi_parity b6_mmvq_bench arch_defaults_test -j16: revision67c4a310on0.2.0-beta(e88ee39d), AMD Radeon AI PRO R9700 (gfx1201, 32 GB, Linux7.2.9-2-cachyos-server, ROCm10.2.0a20260914), clean build & link../build-copilot-hip/arch_defaults_test: revision67c4a310(0.2.0-beta),arch_defaults_test: OK../build-copilot-hip/qsa_merge_daily_parity: revision67c4a310(0.2.0-beta),gfx1201,1172 cases, 0 differ, 21336168 nonzero output values in all -> PASS(fp16295,int8291,q4_0294,k8v4292)../build-copilot-hip/mmvq_multi_parity: revision67c4a310(0.2.0-beta),gfx1201,multi_exact on: 148480 outputs compared, 0 differ bitwise, 0 non-finite,mmvq_multi_parity: ok../build-copilot-hip/b6_mmvq_bench 80 0 -1: revision67c4a310(0.2.0-beta),gfx1201, all 102 shape/column pairs bitwise equal (B=A,A=1col,B=1colallok; e.g.,head Q6_KT=4:1.4507 -> 1.0208 ms(-29.6%),MTP head Q6_KT=5:0.6422 -> 0.5186 ms(-19.2%),gdn qkv Q4_KT=4:0.0586 -> 0.0537 ms(-8.4%)).Failed:
Not run:
gfx103x/gfx11and CUDA hardware (nogfx103x/gfx11or NVIDIA GPU in this host).qsa_decode_attn.cuandnative_mmvq.cuare CUDA/HIP only).Limits
b6_default_rows_gfx12is active only whendev_class() == 1(gfx12) andSTRATA_B6_MMVQ_ROWSis unset or-1; CUDA and non-gfx12HIP devices keep their existing defaults unlessSTRATA_B6_MMVQ_ROWSis explicitly set.Problem and result
This PR combines two bitwise-exact RDNA4 (gfx12, wave32) decode/speculative-verification optimizations and enables their parity/benchmark harnesses under
STRATA_ENABLE_HIP:__syncthreads()withqda_sync_lds()to avoid stalling on global KV VMEM loads, enables wave32attn_chunk_kernel_pre75<M,8,true>by default on gfx12, enables boundedattn_merge_v2_kernel<16>by default on gfx12.mmvq_sync_lds()on gfx12/gfx103x, enablesv_perm_b32IQ4 lookup path across HIP targets, extendsb6_mmvq_rows_kernelto SmallTraits (Q8_0, IQ4_NL) with preload of activation fragments, addsb6_default_rows_gfx12for auto row count on gfx12.Related discussion
none
Approach
On gfx12, the prior implementation suffered from shared-memory barriers draining in-flight global KV VMEM loads due to
__syncthreads()emitting full system scope barriers. The workgroup-scopedqda_sync_lds()andmmvq_sync_lds()avoid L0 vector cache invalidation and global-load drain while preserving synchronization. For MMVQ, activation fragments and reusable weight-code transforms are preloaded once across output rows, reducing redundant global loads. The auto row count table (b6_default_rows_gfx12) selects measured optimal rows per shape on gfx12, falling back to off elsewhere.Validation
Passed:
qsa_scores_parity: revisione88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS (zero bitwise differences)qsa_topk_active_parity: revisione88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS (selected IDs bitwise identical)mmvq_multi_parity: revisione88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS (0 bit-different with multi_exact on)b6_mmvq_bench 80 0 -1: revisione88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS (0 failed comparisons)qsa_merge_daily_parity: revisione88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASS (0 bitwise differences)arch_defaults_test: revisione88ee39d, GPU AMD Radeon AI PRO R9700 (gfx1201), observed PASSFailed:
Not run:
Limits
ncols == 1) is unchanged:b6_launchis only invoked fromlaunch_multi_nwhenncols > 1andmulti_exact()is true. EvaluatedSTRATA_Q6_PACKED=1for one-columnQ6_Kheads on gfx1201, but at the default 640-block grid it regressed the 106,299-row MTP head (339.9 → 408.8 us) and 248,320-row output head (794.1 → 960.4 us) while requiring ~213–497 MiB of additional persistent VRAM; bothSTRATA_Q8_PACKEDandSTRATA_Q6_PACKEDremain off by default.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.