mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3484] [CLOSED] [Engine] prefill: a padded activation is gfx11 only, and Gemm::native copies it unpadded instead of exiting #4652
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#4652
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/3484
Author: @John-Pi
Created: 10/20/2026
Status: ❌ Closed
Base:
main← Head:fix/prefill-padded-gfx11📝 Commits (1)
3416250prefill: a padded activation is gfx11 only, and Gemm::native copies it unpadded instead of ending the engine📊 Changes
6 files changed (+74 additions, -3 deletions)
View changed files
📝
docs/AMD_HIP.md(+11 -0)📝
include/strata/prefill/gemm.hpp(+6 -0)📝
src/prefill/gemm.cu(+34 -2)📝
src/prefill/prefill.cpp(+10 -1)📝
src/prefill/wmma_gemm.cu(+5 -0)📝
src/prefill/wmma_gemm.h(+8 -0)📄 Description
Problem and result
STRATA_PF_PAD=1 STRATA_PF_GEMM=1pads the two K 6144 producers' activation row stride to 6,208 for the prompt GEMM. The only product that reads a padded stride isstrata_pf_gemm_f16_ld, which is compiled intowmma_gemm.cu's gfx11 matrix-core block and returnsfalseon every other arch. On an RDNA4 cardGemm::nativetherefore fell through to its "a padded X … needs STRATA_PF_PAD's path" branch and calledstd::exit(1)— underserve/, one engine restart per request.Before: the engine exits on the first prompt GEMM.
After: the producer does not pad where no kernel reads the stride (one line at the first prompt), and if a padded X does arrive from anywhere (
Gemm::nativeis public), its rows are copied unpadded and the ordinary paths run — same products, same bits.Related discussion
None: no issue tracks this (the
#0placeholder in my earlier note was never a real number).STRATA_PF_GEMMitself is discussed in #1386 and #1478, both closed and about other arches; neither covers the padded-activation exit. Say the word if you would rather have this as an issue first.Approach
strata_pf_padded_gemm_available()(wmma_gemm.h/.cu) answers whether the padded product exists on the current device: the same gfx11 list the kernels are compiled for, and a hardfalsein a build with no gfx11 target (inline falseoutside HIP). It sits next tostrata_wmma_gfx11_device()so the two answers cannot drift.prefill.cpp'spf_pad()asks it before padding, and prints one line when the env asks for a product this card has not — the alternative was padding for a kernel that will never be there.Gemm::unpad_x()(gemm.cu/.hpp): a padded X no kernel took is copied to a contiguous FP16 buffer of stride K — onecudaMemcpy2DAsync, one grow-only buffer perGemm— andnative()recurses on it.exit(1)remains only for a failed allocation, and its message now says that.native()recursion passesbeta = 0as the original call did, so the products and their accumulate are unchanged.docs/AMD_HIP.md: one bullet in the RDNA4 section with the reproduction, the numbers below, and what was not tested.Compatibility: nothing changes when
STRATA_PF_PADis unset (the default), on gfx11 (where the padded product exists andpf_pad()behaves as before), or for any CUDA or SYCL build (strata_pf_padded_gemm_available()isfalse,pf_pad()is already off on those arches).Validation
Passed:
cmake --build build-hip -j$(nproc)— 338 of 338, Release,CMAKE_HIP_ARCHITECTURES=gfx1201, RX 9070 (gfx1201, 16 GB), system ROCm 7.2.4, kernel 7.2.11, engine 0.1.46.1 at9ae93f7b+ this change.ctest --test-dir build-hip -j4— 77 of 79 (see Failed for the two).STRATA_PF_PAD=1 STRATA_PF_GEMM=1, and its 8 greedy tokens are identical to the run without the switch (1,199-token prompt,--spec 4 --prefill 2048 --kv k8v4, Coder IQ1_M):Gemm::nativetakes the padded branch), the run still prints no exit, no "needs STRATA_PF_PAD's path", and the same 8 tokens. The temporary patch is not part of the diff.Failed:
engine/strata.bak-0.1.45-pre-gemmfix, same pack, same prompt) exits 1 witha padded X (ldx 6208, K 6144) needs STRATA_PF_PAD's path— the reproduction. No output tokens.ctest:ple_parity(wants../../Q2_0/Qwen3.8-Flash-Next-GSQ-RCO-Q2_0-00002-of-00002.gguf, not on this machine) andhip_prefill_mmq_parity(its APR block callsggml_type_name(145)while the TQ overlay leavesGGML_TYPE_COUNTat 43 → out-of-boundstype_traits[]read →basic_string: construction from null is not valid). Both fail identically onorigin/mainhere; neither file is touched.Not run:
src/prefill/gemm.cu,gemm.hppandprefill.cppare shared with the CUDA build (SYCL takes the sources fromsrc/too) and this machine has nonvcc, so I could not build them. The changed code is host-side and arch-gated, andstrata_pf_padded_gemm_available()isfalsethere, but it is unbuilt on those backends.pf_pad()must keep padding) is unmeasured — thefalse/trueanswers come from the same arch check the kernels are compiled against, and that is all I can claim.Limits
STRATA_PF_GEMM=1stays inert on RDNA4 rather than becoming useful: it needs a gfx11 matrix-core product, and writing one for gfx12 is a separate piece of work. With the gate in place the switch alone measured 1,247 against 1,243 tok/s at 4K and 1,330 against 1,321 at 8K (medians of 3 starts) — noise.unpad_x()fallback costs one D2D copy of the activation (T x KFP16, ~14 MiB at a 1,199-token chunk) when it fires. It only fires for a padded X that no kernel took, which after this change means a caller that pads without asking — i.e. it is a safety net, not a path I recommend.docs/AMD_HIP.md: I put the bullet in the RX 9070 (RDNA4) list; if you would rather keep that list for shipped defaults only, move it to the closer/deep-context notes and I will follow.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.