Repository navigation
[WebGPU]: Add Intel subgroup prefill flash-attention kernel - #32702
Open
Jianhui Dai (daijh) wants to merge 7 commits into
Open
Jianhui Dai (daijh) wants to merge 7 commits into
Jianhui Dai (daijh) wants to merge 7 commits into
Conversation
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
Author
|
Prerequisite: #32605 |
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The kernel has out-of-bounds subgroup accesses, incorrect long-context fp16 accumulation, and no automated Intel execution coverage.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (3)
What changed in this PR
Adds an Intel-optimized WebGPU flash-attention prefill path using subgroup shuffles and deferred V loading.
Changes:
- Adds the simplified WGSL prefill kernel.
- Adds host-side configuration and Intel-specific dispatch.
- Retains the existing kernel as fallback.
| File | Description |
|---|---|
flash_attention.h |
Declares the new program and helpers. |
flash_attention.cc |
Configures and selects the Intel kernel. |
flash_attention_prefill_simple.wgsl.template |
Implements tiled attention and online softmax. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Jianhui Dai (daijh)
marked this pull request as draft
September 22, 2026 05:15
Jianhui Dai (daijh)
force-pushed
the
pr/flash-attn-prefill
branch
2 times, most recently
from
October 19, 2026 05:41
5e758ee to
1402c7b
Compare
Introduce FlashAttentionPrefillSimpleProgram and its template (flash_attention_prefill_simple.wgsl.template). This is a simplified version of the FlashAttentionProgram kernel. (TODO: Merge back into the original FlashAttentionProgram) Key implementation details: - Latency Hiding: Only K is loaded before the QK^T + online-softmax stage. V is fetched just before the PV matmul, allowing global-memory latency to overlap with softmax compute. - Avoids Bank Conflicts: K and V tiles are stored in transposed layout ([head_size_vec][kv_step]), ensuring the subgroup column is the inner/ fastest dimension. Adjacent lanes hit adjacent shared-memory addresses. - Static Shuffle Codepath: Unconditionally uses a subgroup-shuffle path based on the host-configured minimum subgroup size. This avoids dynamic runtime SubgroupSize detection inside the WGSL kernel. - Configurations: The host determines kv_step (8 or 16) based on the adapter's guaranteed minimum subgroup size (needs minimum of 8). Workgroup size is 128 for causal and 256 for non-causal prefill. - Unsupported Features: Does not support quantized KV cache (int8/ TurboQuant) or the shared-memory fallback path (to be supported). Integration & Selection: - Adds CanApplyFlashAttentionPrefillSimple and ApplyFlashAttentionPrefillSimple, mirroring the MatMulNBits pattern. - ApplyFlashAttention selects this kernel only if 'is_intel' is true, subgroup_min_size >= 8, and the KV cache is unquantized. Otherwise, it falls back to the existing FlashAttentionProgram. **Test on Phi-4-mini, EdgeLLMOnDeviceModel\2026.5.8.1, Panther Lake:** | Metric | Baseline Prefill TPS | Optimized Prefill TPS | Improve | |---|---|---|---| | Prefill-128 | 1289.89 | 1264.72 | -1.95% | | Prefill-256 | 1647.14 | 1631.21 | -0.97% | | Prefill-512 | 1915.64 | 2012.29 | 5.05% | | Prefill-1024 | 1834.62 | 1935.33 | 5.49% | | Prefill-2048 | 1745.07 | 1947.23 | 11.58% | | Prefill-4096 | 1508.13 | 1812.86 | 20.21% |
Jianhui Dai (daijh)
force-pushed
the
pr/flash-attn-prefill
branch
from
October 21, 2026 05:06
e42eba8 to
80b8310
Compare
Jianhui Dai (daijh)
marked this pull request as ready for review
October 27, 2026 03:52
Contributor
Author
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Description
Add
FlashAttentionPrefillProgram, a simplified variant ofFlashAttentionProgramused for dense prefill on Intel GPUs.Kernel design (and key differences from
FlashAttentionProgram):stage. V is staged just before the PV matmul, in slices of up to 16
vec4 values, so global-memory latency overlaps with softmax compute
and V needs less workgroup memory. The default kernel stages both K
and V at full head size.
[head_size_vec][kv_step]),so adjacent lanes hit adjacent shared-memory addresses and avoid bank
conflicts. The default kernel uses
[kv_step][head_size_vec].adapter's guaranteed minimum subgroup size (
shuffle_chunk = min(kv_step, subgroup_min_size)). Below 8, the kernel reads K/Vdirectly from shared memory, which also covers adapters without
subgroups.
paths.
Configuration (host-selected per adapter):
256 threads / 32 KV rows.
maxComputeWorkgroupStorageSize, fall back to the default
configuration.
Integration:
ApplyDensePrefill selects this kernel when the adapter is Intel and
the KV cache is not quantized. Otherwise it uses the existing
FlashAttentionProgram.
kernel yet.
Tests:
head_size 80 and 96 cases, whose head_size / 4 is not a multiple of
the V slice width.
Performance (Phi-4-mini, Intel Panther Lake):
TODO (follow-up PRs):
FlashAttentionProgram.Motivation and Context
See above.