Repository navigation
vulkan: two-subgroup coopmat1 FA tile so HSK 512/576 fit 32 KiB shared memory - #270
danielhanchen wants to merge 1 commit into
Conversation
|
You have reached your Codex usage limits for security reviews. Please try again later. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 7968eda613
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Two subgroups halve the V and O staging, which lets HSK 512/576 fit 32 KiB of shared | ||
| // memory (AMD proprietary driver) instead of falling back to the much slower scalar path. |
There was a problem hiding this comment.
Join the hard-wrapped comment sentence
Keep this comment as one line; splitting the sentence after shared violates the repository's explicit rule against wrapping a sentence across multiple lines and unnecessarily slows review of the change.
AGENTS.md reference: AGENTS.md:L84-L84
Useful? React with 👍 / 👎.
Pin #270: two-subgroup coopmat1 FA tile for 32 KiB shared memory
Vulkan flash attention for head size 512 and 576 drops to the scalar shader whenever a device has only 32 KiB of shared memory. This change adds a two-subgroup coopmat1 tile that fits in 32 KiB, so those devices keep using matrix cores. It mainly affects Gemma 4, whose global-attention layers use head size 512, on the AMD proprietary Windows driver.
Related: unslothai/unsloth#10656
Why
The coopmat1 path needs 34,160 bytes of shared memory at HSK 512 with f32 accumulation (4 subgroups, Bc 64). The AMD proprietary driver on Strix Halo (Radeon 8060S, gfx1151) reports
maxComputeSharedMemorySize32768, soget_fa_tuning_paramsfalls back toFA_SCALAR. RADV on the same chip reports 65536 and is not affected.On the Windows runner, the
GGML_VK_PERF_LOGGERprofile of a 512-token prompt at 16k context showed where the time goes. Flash attention in the five HSK-512 layers took 1,984 ms of the 2,262 ms pass, at 714 GFLOP/s.What changes
get_fa_tuning_params_coopmat1takes a subgroup count. When the 4-subgroup tile does not fit,get_fa_tuning_paramstries 2 subgroups before falling back to scalar.Bc stays 64, so each subgroup now computes
k_slabs = Bc / (16 * row_split)16-row slabs of S. The V preload and O staging scale withrow_split, so halving it halves both.Bc is kept at 64 deliberately. A first version halved Bc to 32 instead. With wave64,
cols_per_thread = Bc * row_split / WorkGroupSizecame out 0, and every HSK 512/576 case returned -FLT_MAX: 315 test-backend-ops failures on the real device.ggml_vk_flash_attn_coopmat_shmem_supportnow readsrow_splitfrom the tuning params instead of deriving it from Bc.Devices where the 4-subgroup tile already fits pick it first, so their path is unchanged. With 4 subgroups
k_slabsis 1 and the shader does the same work as before.Results
Windows 11 Pro, Radeon 8060S (gfx1151), AMD driver 32.0.31041.3013. Both arms were built from b11580 on windows-latest with the Vulkan SDK 1.4.357.0.
test-backend-ops -o FLASH_ATTN_EXT -b Vulkan0, compared against CPU on the 32 KiB device:
llama-bench,
unsloth/gemma-4-26B-A4B-it-qat-GGUFUD-Q4_K_XL with-ngl 99 -fa 1 -r 2, t/s. Arms ran interleaved (base, PR, ROCm, base, PR, ROCm); each figure is the mean of the two rounds:NVIDIA B200, regression check on the four-subgroup path, with coopmat2 disabled so coopmat1 runs:
test-backend-ops -o FLASH_ATTN_EXT -b Vulkan0passes 5321/5321 with this change.At 16k depth prefill is about 4x faster and now ahead of ROCm on the same machine. Decode is unchanged.
Not covered