Skip to content

vulkan: two-subgroup coopmat1 FA tile so HSK 512/576 fit 32 KiB shared memory - #270

Open
danielhanchen wants to merge 1 commit into
masterfrom
vulkan-fa-cm1-32k-shmem
Open

danielhanchen wants to merge 1 commit into
masterfrom
vulkan-fa-cm1-32k-shmem

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 13, 2026 •

Copy link
Copy Markdown
Member

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 maxComputeSharedMemorySize 32768, so get_fa_tuning_params falls back to FA_SCALAR. RADV on the same chip reports 65536 and is not affected.

On the Windows runner, the GGML_VK_PERF_LOGGER profile 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_coopmat1 takes a subgroup count. When the 4-subgroup tile does not fit, get_fa_tuning_params tries 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 with row_split, so halving it halves both.

shape bytes needed
HSK 512, 2 subgroups 29,032
HSK 576, 2 subgroups 31,080

Bc is kept at 64 deliberately. A first version halved Bc to 32 instead. With wave64, cols_per_thread = Bc * row_split / WorkGroupSize came 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_support now reads row_split from 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_slabs is 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:

arm result
base 5321/5321 passed
this PR 5321/5321 passed

llama-bench, unsloth/gemma-4-26B-A4B-it-qat-GGUF UD-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:

test Vulkan base Vulkan this PR ROCm (b11541-mix)
pp512 1888 1967 1270
pp4096 930 1604 1140
pp512 @ d16384 215 843 739
pp4096 @ d16384 196 788 715
tg128 67.1 67.0 60.5
tg128 @ d16384 53.4 54.1 47.2

NVIDIA B200, regression check on the four-subgroup path, with coopmat2 disabled so coopmat1 runs: test-backend-ops -o FLASH_ATTN_EXT -b Vulkan0 passes 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

  • The 2-subgroup tile was only measured on gfx1151 with the proprietary driver.
  • On an NVIDIA B200 with the 2-subgroup tile forced through a local test hook, the driver spent over 15 minutes in pipeline creation for the first case. NVIDIA reports 48 KiB, so it never selects this tile.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for security reviews. Please try again later.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T10:19:59.285358Z 7968eda PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen
danielhanchen changed the base branch from master to base/upstream-4413a1924 October 13, 2026 10:16

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +1353 to +1354
// 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant