SYCL: add oneMKL GEMM flash attention for XMX-accelerated prompt proc…#25025
SYCL: add oneMKL GEMM flash attention for XMX-accelerated prompt proc…#25025johnkarlhill wants to merge 1 commit into
Conversation
|
Hi @johnkarlhill, thanks for your contribution! Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:
Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below. |
|
Adding before and after... both compiled with arch flags to show side-by-side. Compiling without arch flags will degrade performance from these numbers but should still be better than stock. I'll add more models if needed. |
|
@johnkarlhill For user, how to trigger the new code in usage? Thank you! |
Adds a flash attention path that routes Q·K^T and S·V matrix multiplies
through oneMKL GEMM, enabling XMX hardware acceleration on Intel GPUs.
Motivation
The existing SYCL flash attention kernels (VEC, TILE) run entirely in
SYCL subgroup operations. On Intel Arc GPUs with XMX matrix engines
(Battlemage and later), oneMKL GEMM can process the large matmuls in
attention significantly faster — particularly at high context lengths
where the KV cache is quantized.
When it activates
These thresholds route prompt processing through MKL while leaving
single-token decode to the existing TG-optimized kernels. The path is
never activated for f16/bf16 KV cache — those already perform well
with the TILE kernel and graph capture.
Implementation
All logic is in one new file,
fattn-mkl.cpp(567 lines). The pipeline:GQA groups sharing a KV head are batched into single GEMM calls —
6 query heads × 1020 tokens = 6120 rows in one MKL call, amortizing
launch overhead.
Performance (Arc Pro B70 / BMG-G21, 32 GB)
For comparison, stock bf16 KV cache + FA off on the same GPU achieves
~822 t/s PP at 8K — the MKL path with q8_0 is within 1% while using
quantized memory.
Testing
quant types, head sizes 64–512, causal/non-causal masks, sinks,
max_bias, GQA ratios, multi-batch)
no coherence errors
BEST_FATTN_KERNEL_MKLenum; other backends and non-quantizedpaths are completely unaffected
Known limitations
incompatible with SYCL command graph replay. The existing
GGML_SYCL_DISABLE_GRAPHdefault (1) handles this.max_bias == 0.0fasserted; models needing ALiBiwill fall through to the TILE kernel.
dst->src[4]is not yet supported.Debug output
Timing instrumentation is gated behind
MKL_FA_DEBUG=1. In normaloperation the MKL path produces no output.
AI disclosure
Claude Code was used for SYCL boilerplate (ND-range kernel launches,
ggml_sycl_pool_alloc patterns) and initial drafting of the chunked KV
loop. All algorithmic decisions — oneMKL GEMM integration, online
softmax with GQA batching, activation thresholds, chunk sizing — were
human-directed. Comprehensive testing (3605 test-backend-ops,
multi-quant and multi-batch coherence validation, performance
benchmarking at contexts up to 110K) was performed manually.
🤖 Generated with Claude Code using DeepSeek-V4-Pro