[PR #370] [MERGED] ds4: prompt sparse attention on RDNA4 matrix cores (gfx12 WMMA) #496

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/370
Author: @Gazelle221B
Created: 10/22/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @mw00

Base: main ← Head: ds4-attn-wmma-gfx12


📝 Commits (1)

  • 6f1bf67 Enable DS4 prompt sparse attention WMMA on gfx12

📊 Changes

3 files changed (+133 additions, -17 deletions)

View changed files

📝 src/ds4/ds4_kernels.cu (+37 -12)
📝 src/ds4/ds4_kernels.cuh (+1 -1)
📝 tests/ds4_gguf_test.cu (+95 -4)

📄 Description

On RDNA4, DeepSeek's prompt sparse attention ran the scalar FP32 kernel, because DS4_ATTN_WMMA / attn_wmma_now() only accepted gfx11. In profiles on gfx1201, sparse attention was the largest single part of a long prompt. This change runs the existing WMMA kernel on gfx12 as well, using gfx12's native wave32 layouts:

  • A/B operands: __builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12 takes 8 values per lane. Lanes 0-15 hold k 0-7 and lanes 16-31 hold k 8-15, instead of gfx11's duplicated 16. attn_wmma() passes each half.
  • Accumulator: element i is row 8 * (lane / 16) + i on gfx12, and 2 * i + lane / 16 on gfx11. attn_wmma_row() maps it.
  • Unchanged: the tiling, the high/residual BF16 products, the softmax, and the DS4_ATTN_WMMA=0 opt-out. gfx11 device code is byte-identical (gfx1100 assembly compared), and nothing changes on NVIDIA.

Independent of #343 and #369.

Prefill, 2x 32 GB AMD GPUs (HIP, gfx1201)

Maya-S six-shard, automatic split, DSpark on, zero prompt reuse, 3 alternating rounds, scalar vs WMMA on the same binary. DS4_LT=0 was set because of #366.

New tokens Scalar tok/s WMMA tok/s Speedup TTFT scalar → WMMA
2,048 184 214 1.16x 11.1 → 9.6 s
8,192 348 488 1.40x 23.6 → 16.8 s
32,768 485 643 1.33x 67.5 → 51.0 s
122,880 557 711 1.28x 221 → 173 s

Decode (400 tokens) is 26.2 → 28.7 tok/s, i.e. unchanged within noise. With #343's prompt skip also on, WMMA adds 1.33-1.37x at 8K-120K (prefill 823 tok/s at 32K, 856 at 120K). Decode in that combination was too noisy to read (12-29 tok/s in both arms).

Numerics

  • Kernel tests: the three existing gfx11 fixtures keep their tolerances, and 29 new bounded cases (partial/empty tiles, real model shapes) pass on both cards, with the scalar opt-out checked too.
  • Extreme-value stress (not in the default run): a supplementary test fails 5 comparisons on both cards. It uses KV group scales from 2^-30 to 2^10 with spikes up to 1e6 and is reproducible with DS4_ATTN_TEST_EXTREME=1. I haven't been able to run it on gfx11 to see whether the high/residual BF16 scheme shows the same thing there, so I'm leaving it out of the default tests and flagging it here.
  • End to end, fixed dispatch (--no-expert-cache, greedy, spec=0, DS4_STREAM=1 DS4_STREAM_FORCE=012345678 DS4_LANE_CAL=none, identical starting profiles): two scalar processes give bit-identical logits on 23/23 requests, which is the floor. WMMA vs scalar: prompt last-row KL ≤ 4e-5 nats, 21/23 identical greedy answers, with the 32K and 64K answers diverging at generated token 19. On 20 known-answer prompts (including a ~60K needle) WMMA and scalar both score 19/20, with the same outputs.

CI-equivalent checks pass: HIP mapping check, server tests, tools tests. I have no CUDA machine to compile on, but the change is under STRATA_USE_HIP only.

🤖 Generated with Claude Code


🔄 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/370 **Author:** [@Gazelle221B](https://github.com/Gazelle221B) **Created:** 10/22/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `ds4-attn-wmma-gfx12` --- ### 📝 Commits (1) - [`6f1bf67`](https://github.com/mw00/project-maya/commit/6f1bf67ce337cc8d579dbbd9b8fc212b57c4c701) Enable DS4 prompt sparse attention WMMA on gfx12 ### 📊 Changes **3 files changed** (+133 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `src/ds4/ds4_kernels.cu` (+37 -12) 📝 `src/ds4/ds4_kernels.cuh` (+1 -1) 📝 `tests/ds4_gguf_test.cu` (+95 -4) </details> ### 📄 Description On RDNA4, DeepSeek's prompt sparse attention ran the scalar FP32 kernel, because `DS4_ATTN_WMMA` / `attn_wmma_now()` only accepted gfx11. In profiles on gfx1201, sparse attention was the largest single part of a long prompt. This change runs the existing WMMA kernel on gfx12 as well, using gfx12's native wave32 layouts: - **A/B operands:** `__builtin_amdgcn_wmma_f32_16x16x16_bf16_w32_gfx12` takes 8 values per lane. Lanes 0-15 hold k 0-7 and lanes 16-31 hold k 8-15, instead of gfx11's duplicated 16. `attn_wmma()` passes each half. - **Accumulator:** element i is row `8 * (lane / 16) + i` on gfx12, and `2 * i + lane / 16` on gfx11. `attn_wmma_row()` maps it. - **Unchanged:** the tiling, the high/residual BF16 products, the softmax, and the `DS4_ATTN_WMMA=0` opt-out. gfx11 device code is byte-identical (gfx1100 assembly compared), and nothing changes on NVIDIA. Independent of #343 and #369. ## Prefill, 2x 32 GB AMD GPUs (HIP, gfx1201) Maya-S six-shard, automatic split, DSpark on, zero prompt reuse, 3 alternating rounds, scalar vs WMMA on the same binary. `DS4_LT=0` was set because of #366. | New tokens | Scalar tok/s | WMMA tok/s | Speedup | TTFT scalar → WMMA | |---:|---:|---:|---:|---:| | 2,048 | 184 | 214 | 1.16x | 11.1 → 9.6 s | | 8,192 | 348 | 488 | 1.40x | 23.6 → 16.8 s | | 32,768 | 485 | 643 | 1.33x | 67.5 → 51.0 s | | 122,880 | 557 | 711 | 1.28x | 221 → 173 s | Decode (400 tokens) is 26.2 → 28.7 tok/s, i.e. unchanged within noise. With #343's prompt skip also on, WMMA adds 1.33-1.37x at 8K-120K (prefill 823 tok/s at 32K, 856 at 120K). Decode in that combination was too noisy to read (12-29 tok/s in both arms). ## Numerics - **Kernel tests:** the three existing gfx11 fixtures keep their tolerances, and 29 new bounded cases (partial/empty tiles, real model shapes) pass on both cards, with the scalar opt-out checked too. - **Extreme-value stress (not in the default run):** a supplementary test fails 5 comparisons on both cards. It uses KV group scales from 2^-30 to 2^10 with spikes up to 1e6 and is reproducible with `DS4_ATTN_TEST_EXTREME=1`. I haven't been able to run it on gfx11 to see whether the high/residual BF16 scheme shows the same thing there, so I'm leaving it out of the default tests and flagging it here. - **End to end, fixed dispatch** (`--no-expert-cache`, greedy, `spec=0`, `DS4_STREAM=1 DS4_STREAM_FORCE=012345678 DS4_LANE_CAL=none`, identical starting profiles): two scalar processes give bit-identical logits on 23/23 requests, which is the floor. WMMA vs scalar: prompt last-row KL ≤ 4e-5 nats, 21/23 identical greedy answers, with the 32K and 64K answers diverging at generated token 19. On 20 known-answer prompts (including a ~60K needle) WMMA and scalar both score 19/20, with the same outputs. CI-equivalent checks pass: HIP mapping check, server tests, tools tests. I have no CUDA machine to compile on, but the change is under `STRATA_USE_HIP` only. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:26:04 +07:00
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#496
No description provided.