Skip to content

opencl: general flash attention decode performance optimizations#25366

Merged
lhez merged 12 commits into
ggml-org:masterfrom
qualcomm:hq/fa-decode-opt
Jul 7, 2026
Merged

opencl: general flash attention decode performance optimizations#25366
lhez merged 12 commits into
ggml-org:masterfrom
qualcomm:hq/fa-decode-opt

Conversation

@wanghqc

@wanghqc wanghqc commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Overview

  • This PR has a comprehensive performance optimization on token generation (decode) for Adreno GPUs, i.e., when n_q == 1. In particular, we target token generation performance with the long context window of 8k, 16k and beyond for agentic use cases.

  • Non-Adreno devices keep the original path.

Additional information

Details of the features in this PR:

  1. Vec decode kernels for f16/q8_0/q4_0 KV (DV-split, subgroup-reduced dots), with a flash-decoding KV split for deep contexts
  2. KV-head-coalesced multi-query decode kernels for GQA models (MQ_GQA 4 and 8);
  3. Fix an OOO issue with Adreno compiler by compiling the MQ_GQA=8 kernels in a separate minimal program
  4. Multi-output and GQA-coalesced mul_mat kernels for the KQ/KQV matmuls when flash attention is off, with option of using image1d_buffer_t
  5. DK=DV=512 (gemma-4 global-attention layers): prefill runs on the GPU via split programs; decode is offloading to CPU for now due to CPU's performance edge for this case (effective GPU BW < CPU BW)
  6. f16-KV decode split granularity: 512 KV/split (from 2048); For quantized KV keeps 2048
  7. A few correctness fixes along these paths: finite running-max init, pooled buffers for the quantized-K dequant path, build retry on transient compiler OOM, trans-weight restore for broadcast quantized mul_mat, etc.

Requirements

Fully tested with Adreno X1 and X2 Windows on Snapdragon (WoS) devices.

  • I have read and agree with the contributing guidelines Yes.
  • AI usage disclosure: Yes, for testing and quick prototyping.

wanghqc and others added 12 commits July 1, 2026 22:04
The DK=512 decode-only program does not create the f32_f16 prefill
kernel, so the compiled check in ensure_fa_variant never hit and
supports_op gave inconsistent answers for the same op. block_n is also
unset for DK=512 decode; guard it to avoid an out-of-range read at
dispatch.
DK=512 decode is bandwidth-bound and faster on the CPU than the GPU,
increasingly so with depth. Decline it in supports_op; prefill stays on the GPU.
The full program compiled with -D MQ_GQA=8 runs the Adreno compiler out
of memory at DK>=256. Only the vec_mq kernels are used from this
program, so compile it with FA_MQ_ONLY, which excludes everything else.
Also include the program name in the compile error log.
A stray "." broke the f32_f16 program build.
The 2048 default under-fills the GPU on single-query f16-KV decode;
use 512 for f16 KV to get more splits. Quantized KV keeps 2048.
@wanghqc wanghqc requested a review from a team as a code owner July 6, 2026 17:38
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning OpenCL Issues specific to the OpenCL backend labels Jul 6, 2026
@lhez lhez merged commit 6f8895f into ggml-org:master Jul 7, 2026
36 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning OpenCL Issues specific to the OpenCL backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants