[PR #348] [MERGED] HIP: reduce packed DS4 attention LDS bank conflicts without changing arithmetic #479

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

📋 Pull Request Information

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

Base: main ← Head: upstream/hip-attention-lds


📝 Commits (1)

  • 53a0661 HIP: add opt-in exact LDS layout for packed DS4 attention

📊 Changes

3 files changed (+94 additions, -4 deletions)

View changed files

📝 CMakeLists.txt (+3 -0)
📝 src/ds4/ds4_kernels.cu (+40 -4)
➕ tests/ds4_attention_layout_bench.cu (+51 -0)

📄 Description

This helps AMD GPUs process prompts faster by rearranging attention's temporary data so GPU workers spend less time waiting for the same memory lanes. It keeps the data values and calculations unchanged.

Think of several checkout lanes: if too many workers line up at the same lane, they wait while other lanes sit idle. This change spreads their memory accesses across the lanes more evenly.

Measured impact on our experimental branch: about 16% faster prefill for 32K-token prompts and 18% faster for 8K-token prompts. Prefill is the time spent reading a prompt before generating the answer. Those speedups have not yet been established on the current upstream version. On the upstream base, the attention kernel passed 192 bit-exact comparisons across our three AMD GPUs. The change is opt-in and leaves the existing kernel as the default.

HIP packed sparse attention repeatedly stages BF16 vectors in LDS with a linear row layout. On our RDNA4 cards, permuting those vectors improves the attention kernel without changing the stored values, reduction order, or 16 KiB LDS footprint.

This adds an opt-in DS4_HIP_ATTN_SWIZZLE=1 specialization. The existing kernel remains the default and the CUDA dispatch is unchanged. Staging, dot-product reads and value reads use the same bijective mapping. A standalone HIP test/benchmark covers generated and explicit selections, window-only attention, ragged sizes, single-token and single-head cases, grouping overrides, finite outputs and output guards.

This changes the packed-attention kernel only. Upstream also has a separate WMMA attention path, which bypasses this layout when selected. The standalone test uses explicit packed-kernel group sizes to ensure that the on/off comparisons exercise this change; end-to-end applicability depends on the selected attention path.

Rebased and validated against upstream 451f9cb (v1.1.21):

  • Clean HIP gfx1201 CMake builds of maya-ds4 and ds4_attention_layout_bench; 192 bit-exact comparisons across two Radeon AI PRO R9700 cards and one RX 9070 XT, including fallback repetitions.
  • Build target: cmake --build build-hip --target ds4_attention_layout_bench; run ./build-hip/ds4_attention_layout_bench 0 (device index argument).

Earlier full-model evidence, on our experimental branch rather than this upstream base: four fresh-load ABBA arms, 24 measured requests, 32K prefill 884.53 → 1024.89 tok/s (+15.87% throughput), 8K 611.53 → 724.13 (+18.41%). Both paired 32K blocks improved, but there were only two blocks and the interval is wide. Candidate/repeat/reference logits were exact for 195 saved states each. These figures are supporting evidence, not a measured v1.1.20 end-to-end gain. Existing fork checkpoints: https://github.com/LostVector/project-maya/pull/41 and https://github.com/LostVector/project-maya/pull/42.

I also compared the current #344 head: its packed-attention tile accesses remain linear, so this change can be reviewed independently of its multi-GPU transport and pruning work.


🔄 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/348 **Author:** [@LostVector](https://github.com/LostVector) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `upstream/hip-attention-lds` --- ### 📝 Commits (1) - [`53a0661`](https://github.com/mw00/project-maya/commit/53a066190bd1b995eb2fa6455ce908f68aff0af1) HIP: add opt-in exact LDS layout for packed DS4 attention ### 📊 Changes **3 files changed** (+94 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+3 -0) 📝 `src/ds4/ds4_kernels.cu` (+40 -4) ➕ `tests/ds4_attention_layout_bench.cu` (+51 -0) </details> ### 📄 Description **This helps AMD GPUs process prompts faster by rearranging attention's temporary data so GPU workers spend less time waiting for the same memory lanes. It keeps the data values and calculations unchanged.** Think of several checkout lanes: if too many workers line up at the same lane, they wait while other lanes sit idle. This change spreads their memory accesses across the lanes more evenly. **Measured impact on our experimental branch:** about **16% faster prefill for 32K-token prompts** and **18% faster for 8K-token prompts**. Prefill is the time spent reading a prompt before generating the answer. Those speedups have **not yet been established on the current upstream version**. On the upstream base, the attention kernel passed 192 bit-exact comparisons across our three AMD GPUs. The change is opt-in and leaves the existing kernel as the default. HIP packed sparse attention repeatedly stages BF16 vectors in LDS with a linear row layout. On our RDNA4 cards, permuting those vectors improves the attention kernel without changing the stored values, reduction order, or 16 KiB LDS footprint. This adds an opt-in `DS4_HIP_ATTN_SWIZZLE=1` specialization. The existing kernel remains the default and the CUDA dispatch is unchanged. Staging, dot-product reads and value reads use the same bijective mapping. A standalone HIP test/benchmark covers generated and explicit selections, window-only attention, ragged sizes, single-token and single-head cases, grouping overrides, finite outputs and output guards. This changes the packed-attention kernel only. Upstream also has a separate WMMA attention path, which bypasses this layout when selected. The standalone test uses explicit packed-kernel group sizes to ensure that the on/off comparisons exercise this change; end-to-end applicability depends on the selected attention path. Rebased and validated against upstream `451f9cb` (v1.1.21): - Clean HIP gfx1201 CMake builds of `maya-ds4` and `ds4_attention_layout_bench`; 192 bit-exact comparisons across two Radeon AI PRO R9700 cards and one RX 9070 XT, including fallback repetitions. - Build target: `cmake --build build-hip --target ds4_attention_layout_bench`; run `./build-hip/ds4_attention_layout_bench 0` (device index argument). Earlier full-model evidence, **on our experimental branch rather than this upstream base**: four fresh-load ABBA arms, 24 measured requests, 32K prefill 884.53 → 1024.89 tok/s (+15.87% throughput), 8K 611.53 → 724.13 (+18.41%). Both paired 32K blocks improved, but there were only two blocks and the interval is wide. Candidate/repeat/reference logits were exact for 195 saved states each. These figures are supporting evidence, not a measured v1.1.20 end-to-end gain. Existing fork checkpoints: https://github.com/LostVector/project-maya/pull/41 and https://github.com/LostVector/project-maya/pull/42. I also compared the current #344 head: its packed-attention tile accesses remain linear, so this change can be reviewed independently of its multi-GPU transport and pruning work. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:25:53 +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#479
No description provided.