mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #2152] [CLOSED] hip(RDNA4): fused-GR register-half down kernel for gfx1200/gfx1201 decode #3886
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#3886
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/2152
Author: @bsorensen110
Created: 10/12/2026
Status: ❌ Closed
Base:
main← Head:pr/rdna4-fused-gr-p4📝 Commits (9)
d9c408bperf(hip): add parity-gated RDNA4 fused-GR P4 path1cac253docs(hip): document fused-GR P4 gate and measurements08b4717fix(hip): preserve RDNA4 P4 self-test fallback safety2cbc8f4fix(hip): harden P4 parity self-test gatese8e1e1fdocs(hip): refresh P4 decode comparison8abf010docs(hip): disclose overlay context for P4 timings859b8b8docs(hip): focus P4 data on staged referencebdc1b63perf(hip): default optimized fused-GR P4 on gfx12120c89edocs(hip): record P4 default validation📊 Changes
6 files changed (+288 additions, -38 deletions)
View changed files
📝
CMakeLists.txt(+5 -0)📝
docs/AMD_HIP.md(+5 -0)📝
include/strata/kernels/fused_gr.hpp(+7 -10)➕
include/strata/kernels/fused_gr_policy.hpp(+23 -0)📝
src/kernels/cuda/fused_gr.cu(+208 -28)➕
tests/kernels/fused_gr_selector_test.cpp(+40 -0)📄 Description
Summary
Adds one extra selection for the hyper-connection fused-GR read on AMD RDNA4: the down-projection kernel
gr_down_register_half_kernel("P4"), which carries the next activation tile in a compile-time register tuplebefore scattering it into the existing shared-memory buffer. It is gated to runtime
gfx1200/gfx1201only, andit is selected only when asked for —
STRATA_HC_SPLIT=7— and only after a per-device self-test proves it isbitwise identical to the existing staged kernel. If any gate fails, the established staged / split / plain
path is selected unchanged.
This is not a replacement of the gfx12 kernel set and not a new arithmetic path. The accumulation order, tile
order, grid, block size and dynamic shared-memory layout are the staged kernel's; only the way the
h+2tilereaches shared memory differs.
Opt-in surface:
STRATA_HC_SPLIT(new selector value7, existing0/1/2). Unset stays on the stagedupstream path on every architecture: it never runs the P4 self-test and never selects P4.
=2requests staged,=1split,=0plain. Only=7requests P4, and only ongfx1200/gfx1201, still subject to both paritygates. Every other architecture keeps upstream's staged selection.
Files:
src/kernels/cuda/fused_gr.cu,include/strata/kernels/fused_gr.hpp,include/strata/kernels/fused_gr_policy.hpp(new),tests/kernels/fused_gr_p4_policy_test.cpp(new),CMakeLists.txt,docs/AMD_HIP.md.Motivation
The fused-GR read is part of the per-token decode path and stages activation tiles for each hidden-state tile.
P4 tests whether an explicit per-thread register prefetch can hide some of that data-movement cost without
changing the dot products. The existing staged implementation fills a shared-memory double buffer through
stage_htile; P4 preserves that shared layout and the staged arithmetic order.P4 splits the next tile into two compile-time halves: half A is already in registers before the tile is needed,
and half B is fetched in the middle of the dot-product loop. The compile-time
HcChainavoids a runtime-indexedper-thread array that the source comment says could lower to private scratch on gfx1201. Fetching half B at
q==2is intended to expose load/compute overlap with the remaining dot products; that overlap has not been confirmed
by an ISA dump or profiler. The arithmetic and q/k order are unchanged, so bitwise parity with staged is required.
Related prior work, distinct from this change: #2070 (CUDA sm_75 hyper-connection up kernel and token-pair
staged down kernel), #1370 (CUDA sm_80+ opt-in
STRATA_HC_UPMIX), and closed #329 (gfx12 WMMA for QSA promptattention). None of them touch the RDNA4 fused-GR decode down path.
Implementation
src/kernels/cuda/fused_gr.cu:HcChain<I>— a recursive struct offloat4slots indexed only at compile time. The source comment statesthis is to keep the per-slot activations from lowering to private scratch on gfx1201; no ISA dump or profile
is included with this PR.
gr_down_register_half_kernel<MAX_T, EXACT_T>followsgr_down_staged_kernelexactly for tiles 0 and 1(
stage_htile+cp_async_commit), then handles tileh+2in two halves per thread:NS = ceil(MAX_T * (H_TILE/4) / THREADS)slots per thread, split atH0 = (NS+1)/2. For the genericinstantiation (
MAX_T = 8,H_TILE = 1280,THREADS = 256) that is 10 slots, 5 per half, i.e. 40 floatsper thread in registers.
t0) of tileh+2is loaded one iteration ahead — at the end of iterationhthe kernel issueshc_load_allfor tileh+3, which is iterationh+1's half A (tile 2's half A is loaded before the loop);t1) of tileh+2is fetched inside the dot loop atq == 2, so that its global loads are issuedwhile the remaining dot products of tile
hare still executing. This is the intended schedule, not ameasured overlap — no codegen or profiling evidence is attached.
hc_scatter_alluses the same index swizzle asstage_htile(k*(H_TILE/4) + (s4&1)*(H_TILE/8) + (s4>>1)), so the dot products read the same sharedlayout, and the same bits.
single fetch of half B, because they still take part in the shared-buffer scatter.
DOWN_BLOCKS + 1, 256 threads) and dynamic shared-memory size, and the kernelinstantiations get the same
cudaFuncSetAttributetreatment as the staged ones (max dynamic shared memory,100% shared-memory carveout).
fused_gr_read_multidispatcheskHcRegisterHalf(=7) to this kernel; plain/split/staged dispatch isunchanged.
fused_gr_check()andfused_gr_variant()ask the policy header what the environment asks for, so theselector rules live in one place and are unit-tested.
fused_gr_variant()reports the requested path capped atstaged until the check has run, so an untested
=7request never reaches the candidate kernel.include/strata/kernels/fused_gr_policy.hpp(new, header-only, no GPU) holds the selection and error rules asconstexprfunctions so they are unit-testable:fused_gr.custatic_asserts every code the classifier uses against its own backend's header name(
cudaError*indriver_types.h,hipError*inhip_runtime_api.h) in the backend being compiled, so a headerthat renames or renumbers one breaks the build instead of the classification. The CUDA-only codes (226, 714–718,
721, 810, 911, 912) are asserted in the CUDA branch and the HIP-only HSA runtime codes (1052, 1053) in the HIP
branch; HIP's different meanings for 911 (
hipErrorInvalidChannelDescriptor) and 912 (hipErrorInvalidTexture)are asserted where they differ, together with the classification those numbers get in that backend.
Correctness and fallback
Architecture gate.
p4_gfx12_device()readscudaDeviceProp::gcnArchNameat runtime and accepts onlygfx1200orgfx1201(gfx_arch_is_gfx12). Under a non-HIP compile it returns false. An explicitSTRATA_HC_SPLIT=7on any other part logs that P4 is restricted to gfx1200/gfx1201 and keeps staged.Opt-in gate. The P4 self-test runs only for an explicit
=7on gfx1200/gfx1201. Unset,=2,=1and=0neverrun it, and the selector never promotes P4 on their behalf: unset with every gate passing stays staged. On
gfx1200/gfx1201 with anything but
=7the check logs that P4 is opt-in through=7.Promotion gate. P4 is selected only when
gfx12 && staged_ok && p4_ok— that is, the staged kernel must itselfmatch the plain reference bitwise, and P4 must match staged bitwise. A P4 candidate that passes while the
staged reference is failing cannot be promoted.
Self-test coverage (
fused_gr_selftest, run once per card and latched infused_gr_check): T = 1..8, applyoff/on, injection weights present/null, and with and without the q8_1 path (the q8 arm also exercises the
QFUSE_HCq32 up kernel). Compared bitwise:lo,rs,inject,mixed,R_outfloats and theq8_1output bytes.
Failure isolation, split by what the error leaves usable. The candidate runs on its own non-blocking stream,
which isolates recoverable candidate-only errors: a refused P4 launch, a bad configuration/handle, P4 stream
creation, final synchronization, or stream-destruction failure disables P4 without invalidating staged/split checks.
Shared scratch-allocation, reference-stream setup/sync/destruction, or shared cleanup failures fail the self-test, so
P4 cannot be selected. A separate stream does not isolate an asynchronous device fault — an illegal address or
device exception from the candidate poisons the shared context for the whole process, so fallback kernels would only
return the same error. Context-fatal errors returned by device/property/attribute queries, H2D copies or memsets,
shared-memory setup, launch/sync, read-back, allocation, stream creation/destruction, final sync or cleanup are
classified before clearing an error or making another GPU call; they log the code, flush output and call
std::_Exit(1)immediately. This matches #224's handling insrc/program/generate.cppand avoids unwinding/destructors on a poisoned context. The fatal set includes illegal address (700), timeout (702), destroyed context
(709), device assert (710), launch failure (719), and uncorrectable ECC (214) in both backends, plus CUDA's 226,
714–718, 721, 810 and 911. HIP's 911/912 are known recoverable API errors; HIP's 1052/1053 are documented HSA-call
failures. Unknown (
cudaErrorUnknown/hipErrorUnknown) and all other unclassified runtime values fail closed; onlyexplicitly listed ordinary API/resource errors (invalid value/configuration, allocation/launch-resource refusal,
invalid device function/image, bad handle, not-ready, unsupported limit/capture, etc.) are allowed to fall back.
Selector semantics (
STRATA_HC_SPLIT): unset = staged, the upstream path — no P4 self-test, no P4 selection;=2requests staged;=1selects split;=0selects plain;=7is the only value that requests the P4self-test, on gfx1200/gfx1201 only, and selects P4 only if both gates pass, falling back staged → split → plain
otherwise.
Diagnostic marker. The
P4 + QFUSE_HC q32 outputs passed bitwise parityline is emitted only when the wholeself-test succeeded,
QFUSE_HCis enabled, and both parity flags passed — it cannot print after an unrelatedself-test failure.
Measurements
These are previous same-host results, not a new run on the rebased branch. The host was a Radeon AI PRO R9700
(native gfx1201), ROCm 10.2.0 nightly / HIP 7.17.26391 / hipBLASLt 100500, running Swift / Qwen3.8-Flash-Next
IQ3_XXS. Each arm used a 439-token warmup and three fresh 80-line / 1,111-token outputs at
temperature=0andcache_n=0. The staged and P4 arms used the same v0.1.43 serve module and same integration binary, serially,differing only by selector. That binary also carried independent local MMQ/hipBLASLt overlays, held constant across
both arms; these numbers are an integration-build A/B, not a clean-upstream benchmark.
STRATA_HC_SPLIT=2)P4's observed median is +1.89% vs the staged upstream path. The ranges overlap (153.3–154.3), so this is not a
statistically established gain: three trials on one host/workload. The 156.1 tok/s P4 timing comes from the
earlier integration build, where an unset selector promoted P4 once both gates passed. The explicit
=7selector that this update makes the only P4 request was exercised for correctness in those runs, not for timing,
and no P4 or clean-upstream decode run was performed on the rebased v0.1.43.1 tree because the live service was
kept online.
Correctness observed in the existing runs: P4 and staged replies were byte-identical in all three paired trials.
The four tested selector configurations —
=2staged,=1split,=7P4 opt-in, and that build's unset P4default — all returned the same arithmetic answer
391; the P4 arms logged bitwise P4/staged parity and QFUSE_HCq32 parity.
Test plan
fused_gr_p4_policy_test(new, registered inCMakeLists.txtunderSTRATA_BUILD_TESTS): 122 CPU-only cases,no GPU and no model — 5 promotion-gate cases, 5 marker-condition cases, 9 exact selector-value cases (including
=70,=7suffix, and=07), 9 opt-in cases, 12 selection cases, 78 backend-aware error-classification cases,and 4 cleanup-policy cases. The error cases cover shared context-fatal statuses including uncorrectable ECC (214),
backend-specific CUDA faults, explicitly recoverable API/refusal codes, and fail-closed behavior for
Unknownand unclassified values. Cleanup cases verify that P4-only final-sync/destruction errors preserve reference
results while shared cleanup errors invalidate the self-test.
g++ -std=c++17 -I includeand passed all 122 cases.stratatargets compiled and linked successfully for CUDA (sm_80) and HIP (gfx1200,gfx1201). Thesewere build-only checks; neither executable was run and no GPU work was performed.
remained online, so no GPU self-test, CTest, benchmark, or service restart was run. The existing P4 correctness
logs are from the earlier integration build, not this rebased branch.
git diff --checkpassed. What is not claimed: no generated-ISA evidence, no profiler-measured load/computeoverlap, no multi-host or multi-model sweep, no statistically significant decode gain, no timing of the
=7selector, and no GPU run of any kind on the rebased branch.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.