[PR #1006] [CLOSED] HIP RDNA2 (gfx103x): run the prompt path's 16-bit GEMMs as FP32 SGEMMs (RX 6800: prompts 312 -> 452 tok/s) #2959

Closed
opened 2026-11-04 02:04:30 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/1006
Author: @vallicgrr
Created: 10/6/2026
Status: ❌ Closed

Base: main ← Head: rdna2-sgemm


📝 Commits (10+)

  • 5a30024 calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447)
  • 9f60d13 serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448)
  • eb8da1d /metrics: each request's speculative draft counts, and their sums in the totals (#457)
  • 6a09387 setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444)
  • d6a91e2 docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438)
  • d8d4ad3 Merge branch 'f-135-eng' into rel-0.1.35
  • 7b600d5 Merge branch 'f-135-small' into rel-0.1.35
  • d9ab843 Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it
  • 57bd713 sycl: pipeline the expert cache's profile fill (model load 3-4x faster)
  • e3bdd74 A prompt cancelled mid-read is logged and recorded with the tokens it read (#471)

📊 Changes

1 file changed (+5 additions, -0 deletions)

View changed files

📝 tests/hip/prefill_gemm.cpp (+5 -0)

📄 Description

On gfx1030 the rocBLAS that setup installs (ROCm 10.2.0a20260930) has tuned kernels for FP16 -> FP16, int8 and FP32 -> FP32 only. The prompt path's dense GEMMs take FP16 or BF16 inputs and write FP32 (rocBLAS's HS / BS types), so every one of them runs a fallback kernel at about 5 TFLOPS. This PR widens both inputs to FP32 on gfx103x and runs SGEMM instead.

  • Gemm::rdna2_sgemm (src/prefill/gemm.cu): the weight is widened once per call, the activations in slices of up to 128 MiB of FP32. Widening FP16 / BF16 to FP32 is exact, and SGEMM accumulates in FP32 like the native call.
  • Gemm::bf16 and Gemm::f16 try it after hipBLASLt and before the native hipblasGemmEx. Gemm::native goes through f16, so dequantized weights take the route too.
  • It is on by default for gfx103x only. Every other AMD architecture and CUDA are unchanged. N < 64 (routers, gates) keeps the native call, because there the widening costs more than the GEMM gains. If the FP32 buffers cannot be allocated, the native call runs.
  • STRATA_RDNA2_SGEMM=0 / =1 turns it off / on for any AMD card. These are the A/B arms below.
  • docs/AMD_HIP.md, RDNA2 section: the measurement, and a Windows gfx1030 report.

Measured on an RX 6800 16 GB over OCuLink (PCIe 4.0 x4, 7.1 GB/s), Ryzen 7 8845HS, 28.8 GB RAM, Windows 11. Coder IQ1_M with setup's arguments (64K context, MTP), fresh 12K-token prompts with no reuse, 4 per arm, the same binary with STRATA_RDNA2_SGEMM=0 against the default:

native GEMMs SGEMM route
prompt 312 tok/s 452 tok/s
prompt GPU timeline (STRATA_PREFILL_TIMING) 37.2 s 25.5 s
gdn / qsa proj / hc read 9.4 / 3.6 / 3.85 s 2.8 / 1.4 / 2.84 s
decode 29-34 tok/s 29-35 tok/s
  • Per call (the engine's exact hipblasGemmEx: opA = T, opB = N, FP32 out, fp32 compute):
    • N 10240 x T 8192 x K 2560: 86.7 -> 27.7 ms, including the widening.
    • N 2560 x T 8192 x K 6144: 53.2 -> 17.9 ms.
    • N 320 x T 8192 x K 10240 (BF16): 10.9 -> 7.5 ms.
    • Summed over one prompt's FP16 calls: 14.1 -> 4.7 s.
  • Accuracy: I checked the native call and the SGEMM route against a float64 reference, using random inputs in [-1, 1] and 5 shapes in each of FP16 and BF16 at T = 2048.
    • The two routes differ by at most 4.3e-6 of the largest output.
    • The SGEMM route is as close to the reference as the native call, or closer, on all 10 shapes.
  • End to end: a 9-task code-repair benchmark, where the model patches seeded bugs in a browser game until 38 browser checks pass. Both arms solved 9/9 on the first try; model time went from 458 s to 374 s.
  • Builds: tools/hip/build_windows.bat with STRATA_HIP_ARCHS=gfx1030, using the gfx103X-all 10.2.0a20260930 wheels. The engine starts through serve/server.py and serves both APIs.
  • Test: tests/hip/prefill_gemm.cpp gains two cases that cross the route's activation slice boundary (T 3300, K 10240): FP16 with beta = 1 and a padded ldy, and BF16. All six cases pass against the float64 reference on the RX 6800, with rel_l2 at most 1.8e-6.
  • ctest (build_windows.bat tests, the RX 6800 with the 780M hidden by HIP_VISIBLE_DEVICES=1): 59 passed, 2 skipped (gfx12 only), 6 failed out of 67. A build of main (6f32ec0) fails the same six tests with the same messages, and so does this branch with STRATA_RDNA2_SGEMM=0:
    • ple_parity, expert_parity and pool_test need model fixtures (Q2_0/...gguf, pack/full/experts.bin) that are not on this machine.
    • expert_cache_segmented_test: --vram-elastic is CUDA-only.
    • hip_handoff: "separate copy/ring timeout".
    • hip_prefill_mmq_parity: "synthetic-Q2_0-GU-pass0: non-finite or unwritten MMQ output".
    • The last two look like gfx1030 (or Windows) issues of their own. I have not looked into them.
  • Not tested: Linux, and other gfx103x cards.

Also noticed, not changed here: after this change, the prompt path's biggest phase on this PC is waiting for streamed experts (wait copy, ~6 s of 25.5 s), and then the QSA attention fallback (3.7 s).


🔄 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/1006 **Author:** [@vallicgrr](https://github.com/vallicgrr) **Created:** 10/6/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `rdna2-sgemm` --- ### 📝 Commits (10+) - [`5a30024`](https://github.com/Niko1221/Strata/commit/5a3002446dbb9dfcabb7d0bd9f113da90cc2f3c0) calibrate: the engine's arguments come from the server's engine_args; a failed tuning says why (#447) - [`9f60d13`](https://github.com/Niko1221/Strata/commit/9f60d13246e46b02b1dd0841980b4d18b0faaea7) serve, setup: name the small split card that caps the prompt chunk; setup recommends the big card alone (#448) - [`eb8da1d`](https://github.com/Niko1221/Strata/commit/eb8da1d8c26ec41e6ffb084fdf579dba7cad10bd) /metrics: each request's speculative draft counts, and their sums in the totals (#457) - [`6a09387`](https://github.com/Niko1221/Strata/commit/6a093874fe037020f49bd5cf053879ff6a133c21) setup (--gguf-dir): GGUFs Strata cannot run are named as such, with the --family/--model to use (#444) - [`d6a91e2`](https://github.com/Niko1221/Strata/commit/d6a91e2d1770d0f469d6ec15890acc7ee93e764c) docs: the Coder is weaker outside code, Chinese/CJK text included; the unpruned sizes for that (#438) - [`d8d4ad3`](https://github.com/Niko1221/Strata/commit/d8d4ad337d3c98ba21d3bd0af1a16e9177e112b6) Merge branch 'f-135-eng' into rel-0.1.35 - [`7b600d5`](https://github.com/Niko1221/Strata/commit/7b600d55ff801caaaa11542af1523050992e049b) Merge branch 'f-135-small' into rel-0.1.35 - [`d9ab843`](https://github.com/Niko1221/Strata/commit/d9ab8435f654c368c586340d490915f6addf56a3) Engine 0.1.35: Windows AMD uses its bundled HIP runtime (#468 #461), the low-RAM resident mode on Windows 32 GB PCs (#467), fixes #460 #459 #446 #447 #457 #448 #444; setup requires it - [`57bd713`](https://github.com/Niko1221/Strata/commit/57bd713454ddb4b965f994e95d95cacd68c93fb1) sycl: pipeline the expert cache's profile fill (model load 3-4x faster) - [`e3bdd74`](https://github.com/Niko1221/Strata/commit/e3bdd7449223c4305ef53e331538346765855a2c) A prompt cancelled mid-read is logged and recorded with the tokens it read (#471) ### 📊 Changes **1 file changed** (+5 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `tests/hip/prefill_gemm.cpp` (+5 -0) </details> ### 📄 Description On gfx1030 the rocBLAS that setup installs (ROCm 10.2.0a20260930) has tuned kernels for FP16 -> FP16, int8 and FP32 -> FP32 only. The prompt path's dense GEMMs take FP16 or BF16 inputs and write FP32 (rocBLAS's HS / BS types), so every one of them runs a fallback kernel at about 5 TFLOPS. This PR widens both inputs to FP32 on gfx103x and runs SGEMM instead. - `Gemm::rdna2_sgemm` (`src/prefill/gemm.cu`): the weight is widened once per call, the activations in slices of up to 128 MiB of FP32. Widening FP16 / BF16 to FP32 is exact, and SGEMM accumulates in FP32 like the native call. - `Gemm::bf16` and `Gemm::f16` try it after hipBLASLt and before the native `hipblasGemmEx`. `Gemm::native` goes through `f16`, so dequantized weights take the route too. - It is on by default for gfx103x only. Every other AMD architecture and CUDA are unchanged. N < 64 (routers, gates) keeps the native call, because there the widening costs more than the GEMM gains. If the FP32 buffers cannot be allocated, the native call runs. - `STRATA_RDNA2_SGEMM=0` / `=1` turns it off / on for any AMD card. These are the A/B arms below. - `docs/AMD_HIP.md`, RDNA2 section: the measurement, and a Windows gfx1030 report. **Measured** on an RX 6800 16 GB over OCuLink (PCIe 4.0 x4, 7.1 GB/s), Ryzen 7 8845HS, 28.8 GB RAM, Windows 11. Coder IQ1_M with setup's arguments (64K context, MTP), fresh 12K-token prompts with no reuse, 4 per arm, the same binary with `STRATA_RDNA2_SGEMM=0` against the default: | | native GEMMs | SGEMM route | |---|---|---| | prompt | 312 tok/s | 452 tok/s | | prompt GPU timeline (`STRATA_PREFILL_TIMING`) | 37.2 s | 25.5 s | | gdn / qsa proj / hc read | 9.4 / 3.6 / 3.85 s | 2.8 / 1.4 / 2.84 s | | decode | 29-34 tok/s | 29-35 tok/s | - **Per call** (the engine's exact `hipblasGemmEx`: opA = T, opB = N, FP32 out, fp32 compute): - N 10240 x T 8192 x K 2560: 86.7 -> 27.7 ms, including the widening. - N 2560 x T 8192 x K 6144: 53.2 -> 17.9 ms. - N 320 x T 8192 x K 10240 (BF16): 10.9 -> 7.5 ms. - Summed over one prompt's FP16 calls: 14.1 -> 4.7 s. - **Accuracy:** I checked the native call and the SGEMM route against a float64 reference, using random inputs in [-1, 1] and 5 shapes in each of FP16 and BF16 at T = 2048. - The two routes differ by at most 4.3e-6 of the largest output. - The SGEMM route is as close to the reference as the native call, or closer, on all 10 shapes. - **End to end:** a 9-task code-repair benchmark, where the model patches seeded bugs in a browser game until 38 browser checks pass. Both arms solved 9/9 on the first try; model time went from 458 s to 374 s. - **Builds:** `tools/hip/build_windows.bat` with `STRATA_HIP_ARCHS=gfx1030`, using the `gfx103X-all` 10.2.0a20260930 wheels. The engine starts through `serve/server.py` and serves both APIs. - **Test:** `tests/hip/prefill_gemm.cpp` gains two cases that cross the route's activation slice boundary (T 3300, K 10240): FP16 with `beta = 1` and a padded `ldy`, and BF16. All six cases pass against the float64 reference on the RX 6800, with rel_l2 at most 1.8e-6. - **ctest** (`build_windows.bat tests`, the RX 6800 with the 780M hidden by `HIP_VISIBLE_DEVICES=1`): 59 passed, 2 skipped (gfx12 only), 6 failed out of 67. A build of `main` (6f32ec0) fails the same six tests with the same messages, and so does this branch with `STRATA_RDNA2_SGEMM=0`: - `ple_parity`, `expert_parity` and `pool_test` need model fixtures (`Q2_0/...gguf`, `pack/full/experts.bin`) that are not on this machine. - `expert_cache_segmented_test`: `--vram-elastic` is CUDA-only. - `hip_handoff`: "separate copy/ring timeout". - `hip_prefill_mmq_parity`: "synthetic-Q2_0-GU-pass0: non-finite or unwritten MMQ output". - The last two look like gfx1030 (or Windows) issues of their own. I have not looked into them. - **Not tested:** Linux, and other gfx103x cards. **Also noticed, not changed here:** after this change, the prompt path's biggest phase on this PC is waiting for streamed experts (`wait copy`, ~6 s of 25.5 s), and then the QSA attention fallback (3.7 s). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:04:30 +07:00
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#2959
No description provided.