[PR #365] HIP: use RDNA4 matrix kernels for EXL3 prefill by default #492

Open
opened 2026-10-29 21:26:01 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/365
Author: @LostVector
Created: 10/22/2026
Status: 🔄 Open

Base: main ← Head: upstream/rdna4-exl3


📝 Commits (4)

  • be736e1 HIP: add opt-in RDNA4 compressed EXL3 matrix prefill
  • 278dd3e docs: guide RDNA4 EXL3 matrix-prefill setup and verification
  • 85e4dfa HIP: default to RDNA4 EXL3 matrix prefill and explain rounding contract
  • 7016e3b Expose grouped WMMA selection for tests without changing CUDA-only prompt planning

📊 Changes

6 files changed (+324 additions, -22 deletions)

View changed files

➕ docs/EXL3_RDNA4.md (+139 -0)
📝 docs/SETTINGS.md (+19 -0)
📝 docs/SETUP.md (+8 -0)
📝 include/strata/kernels/exl3.hpp (+5 -2)
📝 src/kernels/cuda/exl3.cu (+118 -8)
📝 tests/exl3_test.cu (+35 -12)

📄 Description

Our pinned v1.1.29 integration test measured 7.7–9.2% faster whole-model warm 4K prefill with this RDNA4 matrix path: about 8.28–8.41 seconds fell to 7.69–7.71 seconds. The fresh disabled-path control reproduced the earlier logits exactly, with less than 0.5% timing drift. These are helper/transfer-pruning integration measurements, not a clean standalone or decode benchmark.

The numerical difference is how floating-point sums are accumulated. Both RDNA4 paths use the same compressed EXL3 weights, FP16 operands and FP32 accumulation. WMMA groups products and additions differently from the portable DOT2 path and its warp reduction, so rounding and low output bits can differ. Those differences can propagate through later layers and expert routing. Bit-identical logits are therefore not the contract for this kernel; the existing CPU-reference tolerances, finite checks and output guards remain unchanged. The recorded full-model logit differences do not by themselves demonstrate a loss of answer quality.

Default behavior: eligible HIP gfx12 devices use the 16-row matrix prefill path by default. EXL3_WMMA_GFX12=0 restores the portable path on gfx12; EXL3_WMMA=0 disables WMMA on both gfx11 and gfx12. Unsupported devices retain their existing paths. Kernel and dispatch comments document the rounding behavior, rather than leaving that explanation only in this PR body.

In plain terms: while Maya reads a prompt, this lets the GPU's matrix hardware do expert calculations for many tokens together. It unpacks each small weight tile just before use and shares it across 16 or 32 routed tokens, reducing repeated work. The weights stay compressed until needed.

What we measured earlier

  • Expert kernels: 34–56% less time across twelve synthetic model-shaped D5120/FF1152 K3/K4 groups on one R9700, with four interleaved trials per mode. This compares compressed WMMA16 against compressed FMA16; it is a kernel result, not a whole-model speedup. Recorded kernel measurements.
  • Full-model prefill: a further 1.56% lower latency from wide operand loads, compared with the already-padded matrix implementation. The ABBA comparison used four fresh loads and sixteen measured uncached 1,966-token requests; the two-pair 95% interval was 0.53–2.58%. This is the incremental wide-load benefit, not the total matrix-versus-FMA gain, and the two percentages should not be added. Recorded API measurements.

The existing operator accuracy thresholds are retained. Historical whole-model quality and decode observations remain below, including a 3.24% lower decode rate in one normal-cache/MTP comparison; no unchanged-quality or universal-throughput claim is made.

Focused implementation

This consolidates the compressed-weight RDNA4 matrix implementation from our fork experiments into upstream's existing grouped-expert launch path. It is one kernel proposal, not the entire experimental engine stack.

  • HIP gfx12 selects matrix prefill by default; EXL3_WMMA_GFX12=0 opts out on gfx12. EXL3_WMMA=0 overrides forced enable and disables WMMA.
  • Reuses EXL3_WMMA_ROWS=16 / 32 and the existing uniform/mixed expert wrappers for set_gate_up and set_down.
  • Uses the gfx12 eight-element FP16 operand and accumulator layout. Weight tiles decode directly from compressed register words into matrix operands, without a full reconstructed expert.
  • Retains eight-byte activation-row padding and two aligned 64-bit LDS loads per operand from the earlier wide-load experiment.
  • Adapts decoding to upstream's K2 representation, including supported half-integer bitrates.
  • Retains the existing gfx11 implementation, CUDA dispatch, and decode/verify arithmetic.

The separate sixteen-token scalar-FMA and predecoded-fragment-cache experiments are excluded. This PR adds neither peer transport nor host-packing, transfer-pruning, or model-cache policies. See docs/EXL3_RDNA4.md for guided setup, saved configuration, build/kernel verification, rollback and limitations. The existing setup and settings guides link to it; the setup example uses the exact EXL3_* kernel switches to pin the documented defaults.

Validation on upstream 451f9cb (v1.1.21)

  • Clean Release HIP/gfx1201 builds of maya-ds4 and exl3_test.
  • Full default-path exl3_test: zero failures and zero launch errors.
  • Focused grouped-expert tests in both 16-row and 32-row modes on two R9700s and one RX 9070 XT: all six runs passed with zero failures and zero launch errors.
  • Explicit EXL3_WMMA=0 override with the gfx12 opt-in set: focused tests passed.
  • Focused tests cover integer K=1..8 / all three codebooks, supported half-integer codes, different down bitrates, mixed expert layouts, empty experts, nonzero row offsets, tails around 16/32 rows, and output guards. The existing CPU-reference relative-RMS tolerance (3e-3), worst-element limit, and finite checks are unchanged.
  • gfx1100 HIP host/device syntax check passed; no gfx11 hardware runtime or NVIDIA build was performed.
  • git diff --check passed.

Earlier pinned integration check (v1.1.29 / 8b4b39f)

The three kernel/test/documentation files in this PR applied without changes to the current helper + packed-transfer + transfer-pruning stack; their SHA-256 hashes match this PR. The default-path control and matrix-enabled run used the same compiled integration binary. An earlier disabled-path run brackets the comparison.

Warm 4K prefill Earlier off Matrix on Fresh off Throughput gain vs controls
Standard combine 8.389 s 7.709 s 8.415 s 8.8–9.2%
Optional sparse combine 8.281 s 7.692 s 8.318 s 7.7–8.1%

Each table cell averages two warm requests. The harness used fixed residency and a 4,096-token coding-agent prefix; it loaded DSpark weights but did not execute drafting. Two short coding/async prompts were also checked. The combine modes were timed in ABBA order within each loaded model. Expert selections can change with the matrix arithmetic, so this measures the complete prompt pass, including resulting routing differences, rather than a fixed set of expert operations.

All seven current integration operator runs passed: a disabled-path control and matrix modes 16/32 on each of three R9700s, with the existing CPU-reference tolerances and guards. All nine disabled-path full-logit files reproduced the earlier reference byte-for-byte. Within the matrix path, all twelve sampled full-vocabulary checkpoints repeated bitwise across the three combine-mode trials. No process swapping, host swap-out or KFD queue evictions were observed in the measured warm windows; loading is excluded from that claim.

Numerical limitation: the eight short-prompt checkpoints match the disabled path exactly. For the four 4K-context checkpoints, only two top-token choices match; maximum absolute logit difference reaches 4.47 and reference-to-matrix KL ranges from 0.036 to 0.134 nats. Deterministic repeats and passing operator checks do not establish answer quality. A held-out quality comparison would quantify downstream answer-quality impact; these logit measurements alone do not measure quality loss.

Normal-cache/MTP follow-up

A subsequent two-arm test used the same current integration binary, normal adaptive cache/path selection and actual four-bit DSpark/MTP. Each arm emitted 6,144 timed tokens across coding, async-worker and 16K-context requests. Only EXL3_WMMA_GFX12 changed between arms; matrix rows stayed at 16.

  • Warm 16K prefill, with no long KV reuse: 18.52/18.60 s with matrix mode versus 21.15/21.20 s disabled, averaging 12.4% less time. The earlier disabled helper reference averaged 21.10 s, so warm-prefill control drift was 0.34%.
  • Aggregate decode: 39.48 versus 40.81 tokens/s (3.24% lower). The disabled arm was 1.13% faster than the earlier disabled reference. The matrix stack remains 14.1% above the older selected-serving control, but that is a whole-stack comparison, not a kernel attribution.
  • The predefined promotion gate failed: decode exceeded the allowed 3% regression, and three matrix-arm decode requests recorded brief KFD queue evictions (roughly 0.17/0.33/0.33 s per affected GPU queue). The disabled arm's measured decode windows were clean. No swapping or helper failures were observed. Queue times overlap across devices and are not a valid subtractive timing correction.
  • Natural continuations differed between matrix and disabled arms, and between the two disabled runs. These are end-to-end observations, not fixed-work decode or output-equivalence claims. Normal adaptive path/cache selection can change arithmetic; the short-prompt exactness reported above applies to the fixed-residency harness only.

The prefill improvement is useful evidence, but this run does not establish unchanged decode performance or broad quality. The selected serving configuration was restored and health/generation checked. That experiment restored its previous serving configuration afterward.

Further evaluation

  • Run current-base full-model numerical/quality comparisons, including routing and generated-answer differences. Operator accuracy does not establish model-level equivalence.
  • Repeat the normal-cache/MTP decode comparison to assess whether the earlier slowdown persists, distinguishing continuation/cache changes and driver stalls; do not claim unchanged decode performance.
  • Check representative model-sized expert distributions and decide whether 16/32-row dispatch needs tuning.
  • Broaden hardware/build coverage as available.

The historical kernel and wide-load measurements used the earlier experimental engine. The earlier pinned integration check adds warm 4K evidence but does not isolate a clean standalone branch or establish full-model quality. The experimental integration has not replaced the selected serving configuration.

Rebase validation on v1.1.36 (f031a23)

The rebase preserves upstream's newer Volta/Turing WMMA code, 32-byte alignment for its matrix operands, and compact Pascal mixed-kernel parameters. RDNA4 retains its separate padded operand layout. HIP builds for both gfx1100 and gfx1201 compile and link the operator test. On an R9700, portable default, 16-row matrix, 32-row matrix, and explicit opt-out all pass the focused CPU-reference cases with zero failures and launch errors. Existing tolerances and guards are unchanged. RDNA3 hardware and NVIDIA compilation/runtime were not available for these checks.

These are fresh compatibility and operator checks. The whole-model prefill and decode numbers above remain measurements from the earlier pinned integration, with its stated routing, quality and scheduling caveats. There is no fresh v1.1.36 model throughput or broad quality claim.

Default-selection validation

The gfx12 default is now matrix prefill with 16-row tiles. Comments beside rdna4_block_wmma and wmma_now explain the shared FP16-operand/FP32-accumulation formats and expected accumulation-grouping/rounding differences. The existing CUDA-only prompt_tc planner query stays unchanged; a read-only prompt_wmma query lets the test report the actual grouped-kernel selector.

The HIP Release engine and test binary compile and link for gfx1100 and gfx1201. On an R9700, three full operator-suite runs pass: no settings (matrix selected), EXL3_WMMA_GFX12=0 (portable selected), and EXL3_WMMA=0 (portable selected). Focused tests also pass with forced gfx12 enable plus global opt-out, and with 32-row matrix tiles. All five runs report zero failures and launch errors; dispatch diagnostics confirm each expected mode. Existing reference tolerances and exact/guard checks were not relaxed. These are operator/default-selection checks, not a new whole-model throughput or broad quality study. The running serving process was not changed.


🔄 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/mw00/project-maya/pull/365 **Author:** [@LostVector](https://github.com/LostVector) **Created:** 10/22/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `upstream/rdna4-exl3` --- ### 📝 Commits (4) - [`be736e1`](https://github.com/mw00/project-maya/commit/be736e15d4316701f98afa05c62219efdaf89703) HIP: add opt-in RDNA4 compressed EXL3 matrix prefill - [`278dd3e`](https://github.com/mw00/project-maya/commit/278dd3ef122f2e71a7e1f44cf18dbf21691677c8) docs: guide RDNA4 EXL3 matrix-prefill setup and verification - [`85e4dfa`](https://github.com/mw00/project-maya/commit/85e4dfa4d5abd5f417f153f1a9b30a3d4d60c61a) HIP: default to RDNA4 EXL3 matrix prefill and explain rounding contract - [`7016e3b`](https://github.com/mw00/project-maya/commit/7016e3bbefd4c35e27c78682200a95564ead1df6) Expose grouped WMMA selection for tests without changing CUDA-only prompt planning ### 📊 Changes **6 files changed** (+324 additions, -22 deletions) <details> <summary>View changed files</summary> ➕ `docs/EXL3_RDNA4.md` (+139 -0) 📝 `docs/SETTINGS.md` (+19 -0) 📝 `docs/SETUP.md` (+8 -0) 📝 `include/strata/kernels/exl3.hpp` (+5 -2) 📝 `src/kernels/cuda/exl3.cu` (+118 -8) 📝 `tests/exl3_test.cu` (+35 -12) </details> ### 📄 Description **Our pinned v1.1.29 integration test measured 7.7–9.2% faster whole-model warm 4K prefill with this RDNA4 matrix path: about 8.28–8.41 seconds fell to 7.69–7.71 seconds. The fresh disabled-path control reproduced the earlier logits exactly, with less than 0.5% timing drift. These are helper/transfer-pruning integration measurements, not a clean standalone or decode benchmark.** **The numerical difference is how floating-point sums are accumulated.** Both RDNA4 paths use the same compressed EXL3 weights, FP16 operands and FP32 accumulation. WMMA groups products and additions differently from the portable DOT2 path and its warp reduction, so rounding and low output bits can differ. Those differences can propagate through later layers and expert routing. Bit-identical logits are therefore not the contract for this kernel; the existing CPU-reference tolerances, finite checks and output guards remain unchanged. The recorded full-model logit differences do not by themselves demonstrate a loss of answer quality. **Default behavior:** eligible HIP gfx12 devices use the 16-row matrix prefill path by default. `EXL3_WMMA_GFX12=0` restores the portable path on gfx12; `EXL3_WMMA=0` disables WMMA on both gfx11 and gfx12. Unsupported devices retain their existing paths. Kernel and dispatch comments document the rounding behavior, rather than leaving that explanation only in this PR body. In plain terms: while Maya reads a prompt, this lets the GPU's matrix hardware do expert calculations for many tokens together. It unpacks each small weight tile just before use and shares it across 16 or 32 routed tokens, reducing repeated work. The weights stay compressed until needed. ### What we measured earlier - **Expert kernels: 34–56% less time** across twelve synthetic model-shaped D5120/FF1152 K3/K4 groups on one R9700, with four interleaved trials per mode. This compares compressed WMMA16 against compressed FMA16; it is a kernel result, not a whole-model speedup. [Recorded kernel measurements](https://github.com/LostVector/project-maya/blob/97a1aa60be1faa8cc4334e753806a746063bf009/docs/experiments/exl3-matrix-lds-pad-screen-analysis.json). - **Full-model prefill: a further 1.56% lower latency from wide operand loads**, compared with the already-padded matrix implementation. The ABBA comparison used four fresh loads and sixteen measured uncached 1,966-token requests; the two-pair 95% interval was 0.53–2.58%. This is the incremental wide-load benefit, not the total matrix-versus-FMA gain, and the two percentages should not be added. [Recorded API measurements](https://github.com/LostVector/project-maya/blob/97a1aa60be1faa8cc4334e753806a746063bf009/docs/experiments/exl3-wide-corrected-api-analysis.json). The existing operator accuracy thresholds are retained. Historical whole-model quality and decode observations remain below, including a 3.24% lower decode rate in one normal-cache/MTP comparison; no unchanged-quality or universal-throughput claim is made. ### Focused implementation This consolidates the compressed-weight RDNA4 matrix implementation from our fork experiments into upstream's existing grouped-expert launch path. It is one kernel proposal, not the entire experimental engine stack. - HIP gfx12 selects matrix prefill by default; `EXL3_WMMA_GFX12=0` opts out on gfx12. `EXL3_WMMA=0` overrides forced enable and disables WMMA. - Reuses `EXL3_WMMA_ROWS=16` / `32` and the existing uniform/mixed expert wrappers for `set_gate_up` and `set_down`. - Uses the gfx12 eight-element FP16 operand and accumulator layout. Weight tiles decode directly from compressed register words into matrix operands, without a full reconstructed expert. - Retains eight-byte activation-row padding and two aligned 64-bit LDS loads per operand from the earlier wide-load experiment. - Adapts decoding to upstream's K2 representation, including supported half-integer bitrates. - Retains the existing gfx11 implementation, CUDA dispatch, and decode/verify arithmetic. The separate sixteen-token scalar-FMA and predecoded-fragment-cache experiments are excluded. This PR adds neither peer transport nor host-packing, transfer-pruning, or model-cache policies. See `docs/EXL3_RDNA4.md` for guided setup, saved configuration, build/kernel verification, rollback and limitations. The existing setup and settings guides link to it; the setup example uses the exact `EXL3_*` kernel switches to pin the documented defaults. ### Validation on upstream `451f9cb` (v1.1.21) - Clean Release HIP/gfx1201 builds of `maya-ds4` and `exl3_test`. - Full default-path `exl3_test`: zero failures and zero launch errors. - Focused grouped-expert tests in both 16-row and 32-row modes on two R9700s and one RX 9070 XT: all six runs passed with zero failures and zero launch errors. - Explicit `EXL3_WMMA=0` override with the gfx12 opt-in set: focused tests passed. - Focused tests cover integer K=1..8 / all three codebooks, supported half-integer codes, different down bitrates, mixed expert layouts, empty experts, nonzero row offsets, tails around 16/32 rows, and output guards. The existing CPU-reference relative-RMS tolerance (`3e-3`), worst-element limit, and finite checks are unchanged. - gfx1100 HIP host/device syntax check passed; no gfx11 hardware runtime or NVIDIA build was performed. - `git diff --check` passed. ### Earlier pinned integration check (v1.1.29 / `8b4b39f`) The three kernel/test/documentation files in this PR applied without changes to the current helper + packed-transfer + transfer-pruning stack; their SHA-256 hashes match this PR. The default-path control and matrix-enabled run used the same compiled integration binary. An earlier disabled-path run brackets the comparison. | Warm 4K prefill | Earlier off | Matrix on | Fresh off | Throughput gain vs controls | | --- | ---: | ---: | ---: | ---: | | Standard combine | 8.389 s | 7.709 s | 8.415 s | 8.8–9.2% | | Optional sparse combine | 8.281 s | 7.692 s | 8.318 s | 7.7–8.1% | Each table cell averages two warm requests. The harness used fixed residency and a 4,096-token coding-agent prefix; it loaded DSpark weights but did not execute drafting. Two short coding/async prompts were also checked. The combine modes were timed in ABBA order within each loaded model. Expert selections can change with the matrix arithmetic, so this measures the complete prompt pass, including resulting routing differences, rather than a fixed set of expert operations. All seven current integration operator runs passed: a disabled-path control and matrix modes 16/32 on each of three R9700s, with the existing CPU-reference tolerances and guards. All nine disabled-path full-logit files reproduced the earlier reference byte-for-byte. Within the matrix path, all twelve sampled full-vocabulary checkpoints repeated bitwise across the three combine-mode trials. No process swapping, host swap-out or KFD queue evictions were observed in the measured warm windows; loading is excluded from that claim. **Numerical limitation:** the eight short-prompt checkpoints match the disabled path exactly. For the four 4K-context checkpoints, only two top-token choices match; maximum absolute logit difference reaches 4.47 and reference-to-matrix KL ranges from 0.036 to 0.134 nats. Deterministic repeats and passing operator checks do not establish answer quality. A held-out quality comparison would quantify downstream answer-quality impact; these logit measurements alone do not measure quality loss. ### Normal-cache/MTP follow-up A subsequent two-arm test used the same current integration binary, normal adaptive cache/path selection and actual four-bit DSpark/MTP. Each arm emitted 6,144 timed tokens across coding, async-worker and 16K-context requests. Only `EXL3_WMMA_GFX12` changed between arms; matrix rows stayed at 16. - Warm 16K prefill, with no long KV reuse: **18.52/18.60 s with matrix mode versus 21.15/21.20 s disabled**, averaging **12.4% less time**. The earlier disabled helper reference averaged 21.10 s, so warm-prefill control drift was 0.34%. - Aggregate decode: **39.48 versus 40.81 tokens/s (3.24% lower)**. The disabled arm was 1.13% faster than the earlier disabled reference. The matrix stack remains 14.1% above the older selected-serving control, but that is a whole-stack comparison, not a kernel attribution. - **The predefined promotion gate failed:** decode exceeded the allowed 3% regression, and three matrix-arm decode requests recorded brief KFD queue evictions (roughly 0.17/0.33/0.33 s per affected GPU queue). The disabled arm's measured decode windows were clean. No swapping or helper failures were observed. Queue times overlap across devices and are not a valid subtractive timing correction. - Natural continuations differed between matrix and disabled arms, and between the two disabled runs. These are end-to-end observations, not fixed-work decode or output-equivalence claims. Normal adaptive path/cache selection can change arithmetic; the short-prompt exactness reported above applies to the fixed-residency harness only. The prefill improvement is useful evidence, but **this run does not establish unchanged decode performance or broad quality**. The selected serving configuration was restored and health/generation checked. That experiment restored its previous serving configuration afterward. ### Further evaluation - Run current-base full-model numerical/quality comparisons, including routing and generated-answer differences. Operator accuracy does not establish model-level equivalence. - Repeat the normal-cache/MTP decode comparison to assess whether the earlier slowdown persists, distinguishing continuation/cache changes and driver stalls; do not claim unchanged decode performance. - Check representative model-sized expert distributions and decide whether 16/32-row dispatch needs tuning. - Broaden hardware/build coverage as available. The historical kernel and wide-load measurements used the earlier experimental engine. The earlier pinned integration check adds warm 4K evidence but does not isolate a clean standalone branch or establish full-model quality. The experimental integration has not replaced the selected serving configuration. ### Rebase validation on v1.1.36 (`f031a23`) The rebase preserves upstream's newer Volta/Turing WMMA code, 32-byte alignment for its matrix operands, and compact Pascal mixed-kernel parameters. RDNA4 retains its separate padded operand layout. HIP builds for both gfx1100 and gfx1201 compile and link the operator test. On an R9700, portable default, 16-row matrix, 32-row matrix, and explicit opt-out all pass the focused CPU-reference cases with zero failures and launch errors. Existing tolerances and guards are unchanged. RDNA3 hardware and NVIDIA compilation/runtime were not available for these checks. These are fresh compatibility and operator checks. The whole-model prefill and decode numbers above remain measurements from the earlier pinned integration, with its stated routing, quality and scheduling caveats. There is no fresh v1.1.36 model throughput or broad quality claim. ### Default-selection validation The gfx12 default is now matrix prefill with 16-row tiles. Comments beside `rdna4_block_wmma` and `wmma_now` explain the shared FP16-operand/FP32-accumulation formats and expected accumulation-grouping/rounding differences. The existing CUDA-only `prompt_tc` planner query stays unchanged; a read-only `prompt_wmma` query lets the test report the actual grouped-kernel selector. The HIP Release engine and test binary compile and link for gfx1100 and gfx1201. On an R9700, three full operator-suite runs pass: no settings (matrix selected), `EXL3_WMMA_GFX12=0` (portable selected), and `EXL3_WMMA=0` (portable selected). Focused tests also pass with forced gfx12 enable plus global opt-out, and with 32-row matrix tiles. All five runs report zero failures and launch errors; dispatch diagnostics confirm each expected mode. Existing reference tolerances and exact/guard checks were not relaxed. These are operator/default-selection checks, not a new whole-model throughput or broad quality study. The running serving process was not changed. --- <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 labels
pull-request
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
mw00/project-maya#492
No description provided.