Skip to content

opencl: cluster-parallel decode FA for Adreno GPUs#25473

Merged
lhez merged 1 commit into
ggml-org:masterfrom
qualcomm:hq/fa-decode-cluster
Jul 9, 2026
Merged

opencl: cluster-parallel decode FA for Adreno GPUs#25473
lhez merged 1 commit into
ggml-org:masterfrom
qualcomm:hq/fa-decode-cluster

Conversation

@wanghqc

@wanghqc wanghqc commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Overview

  • Motivation of this work: Decode flash attention on Adreno was latency-bound (20-42% of the bandwidth floor): one workgroup per Q-head leaves most of the GPU idle at ne1==1.
  • This work is to add cluster-parallel decode FA kernels (f16, q4_0, q8_0 KV) that split each head's KV range across a cluster of workgroups with a cross-workgroup reduction.
  • Cluster width is a register-spill gate, and the optimal value depends on GPU and KV types.
  • This can be override by using the env variable GGML_OPENCL_FA_CL_C= {8,16,32}.
  • It is turned on by default for X1 and X2 GPUs, and can be turned off by setting env var GGML_OPENCL_FA_C8 = 0;
  • For other GPUs set GGML_OPENCL_FA_C8 = 1 to turn on.

Additional information

  • Performance gain: Decode-at-depth (Adreno X2-90, Qwen3-30B-A3B): +47%/+62% tg at d8k/16k vs the earlier PR 25366, reaching 74% of the bandwidth floor; up to +74-93% at 16k across models.
  • May work with Intel GPUs.

Requirements

Tested with Windows on Snapdragon (WoS) Adreno GPUs, X1 and X2.

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

@wanghqc wanghqc requested a review from a team as a code owner July 9, 2026 04:42
@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 9, 2026

@max-krasnyansky max-krasnyansky left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fancy! :)

@lhez lhez merged commit 049326a into ggml-org:master Jul 9, 2026
42 of 47 checks passed
Geminihaha added a commit to Geminihaha/llama.cpp that referenced this pull request Jul 10, 2026
Keep this branch's OpenCL flash-attention subsystem; take upstream
everywhere else.

The only upstream OpenCL change in this merge is
049326a "opencl: cluster-parallel decode FA for Adreno (ggml-org#25473)" —
it adds new decode-kernel variants (q1_vec_mq_split, _c8 cluster-parallel,
_k_img, _g8, ...) that rely on sub_group_reduce_add/max. Those advanced
subgroup-arithmetic ops miscompile on Adreno 6xx (Adreno 660) —
clBuildProgram returns err=-6, then the empty kernel map aborts. That
optimization targets newer Adreno (7xx/8xx); this branch keeps its
Adreno-6xx-safe FA kernels (shuffle / local reductions, 0 sub_group_reduce).

All 8 ggml-opencl.cpp conflict hunks and the 3 flash_attn_f32_{f16,q4_0,q8_0}.cl
conflicts were purely these new-kernel additions (no non-FA changes), so the
4 OpenCL files are kept at this branch's version via checkout --ours; all
other upstream changes (CUDA, Hexagon, CPU, common, tests, ...) are merged.

Verified on gemma-4-E2B-it-qat: coherent output (-ngl 99 -fa on, f16 KV, no
crash/abort); test-backend-ops FLASH_ATTN_EXT 2551/2571 (0 crashes; gemma
GQA+quant-KV still routed to CPU; the 20 failures are the pre-existing
hsk=40 dim-3-broadcast cases).
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