SYCL: add TurboQuant KV cache support for Intel GPUs - #211
Conversation
Add complete TurboQuant KV cache support to the SYCL backend: - SET_ROWS kernels for turbo2/3/4 (cooperative 128-work-item groups) - Walsh-Hadamard rotation (group_size 64 and 128) - VEC flash attention for all turbo K/V combos (D=64-512) - 21 FA template instantiations (turbo*turbo, turbo*f16/q8_0, etc.) - GGML_SYCL_TURBO_QUANT cmake gate (ON by default) - GGML_SYCL_SCALAR_MMQ and GGML_SYCL_SG32 cmake options - supports_op guards: F32 type check for SET_ROWS, contiguity for WHT - Lloyd-Max optimal centroids matching CUDA reference exactly - Fixed set_rows index mapping for batched inference - Updated README with SYCL backend info and build instructions Tested on Intel Arc Pro B70 (Battlemage, 32GB VRAM, oneAPI 2025.3). turbo3/turbo3: 46.37 t/s decode, PPL 318.29 (Gemma 4 12B QAT Q4_0). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds TurboQuant KV-cache support to the SYCL backend (Intel GPUs), including SYCL-side TurboQuant constants/dequant helpers, TurboQuant SET_ROWS quantization kernels, a SYCL Walsh-Hadamard transform op, and extensive FlashAttention VEC template instantiations/dispatch for turbo K/V type combinations.
Changes:
- Implement SYCL Walsh-Hadamard transform (
GGML_OP_TURBO_WHT) and wire it into SYCL op dispatch / supports-op checks. - Add TurboQuant centroids/WHT sign tables and turbo2/3/4 dequant helpers, and use them in SYCL SET_ROWS + FlashAttention VEC paths.
- Add SYCL build/config switches (
GGML_SYCL_TURBO_QUANT,GGML_SYCL_SCALAR_MMQ, optional SG32 warp size) and document SYCL support in the README.
Reviewed changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Documents SYCL TurboQuant coverage and a oneAPI build example |
| ggml/src/ggml-sycl/turbo-wht.hpp | Declares SYCL Turbo WHT entry point |
| ggml/src/ggml-sycl/turbo-wht.cpp | Implements SYCL Turbo WHT kernels + dispatch |
| ggml/src/ggml-sycl/turbo-quant.hpp | Adds TurboQuant constants/sign tables + inline centroid/dequant helpers |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo4_0-turbo4_0.cpp | Explicit VEC FA instantiations for turbo4/turbo4 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo4_0-turbo3_0.cpp | Explicit VEC FA instantiations for turbo4/turbo3 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo4_0-turbo2_0.cpp | Explicit VEC FA instantiations for turbo4/turbo2 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo4_0-q8_0.cpp | Explicit VEC FA instantiations for turbo4/q8_0 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo4_0-f16.cpp | Explicit VEC FA instantiations for turbo4/f16 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo3_0-turbo4_0.cpp | Explicit VEC FA instantiations for turbo3/turbo4 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo3_0-turbo3_0.cpp | Explicit VEC FA instantiations for turbo3/turbo3 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo3_0-turbo2_0.cpp | Explicit VEC FA instantiations for turbo3/turbo2 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo3_0-q8_0.cpp | Explicit VEC FA instantiations for turbo3/q8_0 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo3_0-f16.cpp | Explicit VEC FA instantiations for turbo3/f16 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo2_0-turbo4_0.cpp | Explicit VEC FA instantiations for turbo2/turbo4 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo2_0-turbo3_0.cpp | Explicit VEC FA instantiations for turbo2/turbo3 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo2_0-turbo2_0.cpp | Explicit VEC FA instantiations for turbo2/turbo2 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo2_0-q8_0.cpp | Explicit VEC FA instantiations for turbo2/q8_0 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-turbo2_0-f16.cpp | Explicit VEC FA instantiations for turbo2/f16 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-turbo4_0.cpp | Explicit VEC FA instantiations for q8_0/turbo4 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-turbo3_0.cpp | Explicit VEC FA instantiations for q8_0/turbo3 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-q8_0-turbo2_0.cpp | Explicit VEC FA instantiations for q8_0/turbo2 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-turbo4_0.cpp | Explicit VEC FA instantiations for f16/turbo4 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-turbo3_0.cpp | Explicit VEC FA instantiations for f16/turbo3 |
| ggml/src/ggml-sycl/template-instances/fattn-vec-instance-f16-turbo2_0.cpp | Explicit VEC FA instantiations for f16/turbo2 |
| ggml/src/ggml-sycl/set_rows.cpp | Adds TurboQuant SET_ROWS cooperative quantization kernels and dispatch cases |
| ggml/src/ggml-sycl/mmvq.cpp | Adjusts workgroup/subgroup sizing for varying WARP_SIZE (Battlemage) |
| ggml/src/ggml-sycl/ggml-sycl.cpp | Registers Turbo WHT op and extends supports-op validation for turbo paths |
| ggml/src/ggml-sycl/fattn.cpp | Adds turbo K/V dispatch cases and selection guards for VEC FA |
| ggml/src/ggml-sycl/fattn-vec.hpp | Adds turbo-aware VEC FA logic (turbo LUT path + type handling) |
| ggml/src/ggml-sycl/fattn-common.hpp | Adds turbo KQ dot + turbo V dequant specializations for VEC FA |
| ggml/src/ggml-sycl/convert.cpp | Adds turbo2/3/4 dequant-to-fp16/fp32 conversion kernels |
| ggml/src/ggml-sycl/common.hpp | Disables XMX path when scalar MMQ is requested |
| ggml/src/ggml-sycl/CMakeLists.txt | Adds SYCL TurboQuant/scalar MMQ/SG32 options and WARP_SIZE selection |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- turbo-wht.cpp: assert direction is 0 or 1 (fail fast on bad op_params) - turbo-wht.cpp: validate scale tensor type (F32) and contiguity before cast - ggml-sycl.cpp: add dst contiguity and scale tensor checks to supports_op - README.md: replace Unicode en dash with ASCII hyphen Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@cclecle maybe you want to test this SYCL port. |
- turbo-quant.hpp: #error when TURBO4_USE_4BIT=0 (SYCL assumes 4-bit layout) - set_rows.cpp: replace intel::reqd_sub_group_size with sycl::reqd_sub_group_size to match the rest of the SYCL backend and improve portability Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 34 out of 34 changed files in this pull request and generated 7 comments.
Comments suppressed due to low confidence (1)
ggml/src/ggml-sycl/mmvq.cpp:1595
- This reorder kernel asserts
block_num_y % num_subgroups == 0, which effectively requiresnrowsto be a multiple of the workgroup-row granularity (sinceGGML_SYCL_MMV_Y==1). The underlyingmul_mat_vec_q_reorderkernel already checksif (row >= nrows) return;, so it's safe (and more robust for split tails) to roundblock_num_yup instead of aborting.
constexpr size_t num_subgroups = 256 / WARP_SIZE;
GGML_ASSERT(block_num_y % num_subgroups == 0);
const sycl::range<3> global_size(1, GGML_SYCL_MMV_Y, block_num_y * WARP_SIZE);
const sycl::range<3> workgroup_size(1, GGML_SYCL_MMV_Y, num_subgroups * WARP_SIZE);
- mmvq.cpp: replace block_num_y divisibility asserts with round-up in all ncols reorder paths (kernel already skips out-of-range rows) - turbo-wht.cpp: add explicit #include <cstring> for memcpy Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 34 out of 34 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
ggml/src/ggml-sycl/fattn-common.hpp:13
fattn-common.hppusesstd::is_same_vin the newly added turbo dequant helpers, but the header does not include<type_traits>. This is undefined to rely on transitive includes from SYCL/DPCT headers and can break builds with different toolchains or header versions.
#include "turbo-quant.hpp"
#include "ggml.h"
#include <cstdint>
Copilot review flagged std::is_same_v usage without explicit include. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
To be honest I gave up on my A380 because it is too limited and bought 2x R9700 :). |
|
Thanks @gagarinlg! Merged to Isolation check before merge:
Appreciate the Arc Pro B70 benches, Lloyd-Max centroid alignment with CUDA, and the follow-up validation commits. |
|
Thanks again @gagarinlg. Really solid SYCL TurboQuant work. Happy to have it in. |
|
Don't hesitate to ping me, in case an issue in that code comes up. |
…ing, and -fa off (ggml-org#24503) * Add interface is_model_splitted() to check the c-graph is splited or not * Infer and propagate dynamic-dimension indices for all tensors in the GGML graph in api compute_model_outputs() * Only do this for fallback sub graph * Move dynamic dims compute in graph missmatch * ggml-openvino: fix tensor data handling for PERMUTE/VIEW ops in split models * ggml-openvino:add comments * ggml-openvino: override VIEW op_case to 0 for split model inputs * openvino backend: Handle unsupported VIEW shape-mismatch in OpenVINO backend * Enable additional mul_mat tests and add tensor data saving function (TheTom#81) * ggml-openvino: fix CONT/TRANSPOSE mapping and improve dynamic-dimension handling * OpenVINO: add NORM/TANH support and rework SOFT_MAX translation * ggml-openvino: extend VIEW handling * Enable -fa off (TheTom#118) * Enable --context-shift * Fix llm param compute error for normal softmax not the softmax in attention * OpenVINO backend: fix error for attention size compute in llm param * use tensor->extra in infer_request i/o * OpenVINO backend: refacter the compute_llm_params() func add get_attention_pattern_case to easy extand * OpenVINO backend: clean unused code * 1to1 match op update (TheTom#146) * added translate_1to1_match_1_input function and updated gelu and tanh translations * Remove unused translation function calls --------- Co-authored-by: Mustafa Cavus <mustafacavus@intel.com> * initial gemma4 support * removed hardcoded names for kv cache slicing * OpenVINO backend: Add new attention pattern for llm parameters compute * flash attn Q shape static conversion * Remove slice in permute translation when n_seq is 1 * return optional in extract_layer_from_name * OpenVINO backend: refactor VIEW related operation (TheTom#148) * OpenVINO backend: refactor VIEW related operation * Enable VIEW handling in following ops * OpenVINO backend does not support GGML_OP_NORM & GGML_OP_L2_NORM with VIEW input accuracy issue from OpenVINO * OpenVINO backend: Add ops l2_norm & pad * OpenVINO backend does not support CPY with non-contiguous data or mismatched types * add op SSM_CONV GATED_DELTA_NET * OpenVINO backend: fix error for bf16 in OV gpu plugin * reverted static Q input shape for attention layer * OpenVINO backend: remove hardcode name inp_tokens, which ignore some leaf case * Disable remote tensor due to bug in ov gpu * Disable n_token > 1 GATED_DELTA_NET on gpu * OpenVINO backend: fix the view op dynamic handling issue in gemma4 & enable view + get_row * OpenVINO backend: clean code * OpenVINO backend: enable view + norm/rms_norm * OpenVINO backend: concat op * OpenVINO backend: argsort op * OpenVINO backend: enable unary + view & GGML_UNARY_OP_SOFTPLUS * Fix issue for test-backend-ops in TOPK_MOE, which compare VIEW ops result, VIEW node in OpenVINO no need compare, the whole graph result is correct * OpenVINO backend: enable sum_rows * OpenVINO backend: enable clamp * OpenVINO backend: enable DIV * OpenVINO backend: enable GGML_OP_MUL_MAT_ID * OpenVINO backend: disable MUL_MAT_ID_FUSION case with large mem needed * OpenVINO backend: Disable GGML_OP_ARGSORT, cause test_backend-ops failed * OpenVINO backend: fix issue in mul_mat_id * OpenVINO backend: Disable DIV with broadcast on GPU * OpenVINO backend: update DIV * use ov internal op GatedDeltaNet * OpenVINO backend: enable llama erch test qwen3next * OpenVINO backend: enable RMS_NORM + VIEW & remove op_case 2 for rope * OpenVINO backend: fix error * suggested changes, need review * suggested changes, need review * OpenVINO backend: clean unused code & fix build warning * OpenVINO backend: enable minicpm3 for arch test * Disable GDN op (TheTom#177) * disable gated_delta_net * update stateful_kv_size correctly in mismatch case * OpenVINO backend: enable arch test for qwen3vl * OpenVINO backend: enable cohere2 for arch test * OpenVINO backend: enable t5 for arch test * OpenVINO backend: enable jamba for arch test * OpenVINO backend: remove warning for tmp * OpenVINO backend: enable kimi-linear for arch test * Remove unused * Fix gpt-oss accuracy issue * OpenVINO backend: enable arctic for arch test * OpenVINO backend: enable grok for arch test * Gemma4 initial npu support (TheTom#179) * Initiall gemma4 npu support * temp. fix for gemma4 accuracy bug on npu * Remove hardcoded names for npu-fold handling * revert static n tokens for cont translation as it is not needed * removed unused variable * ggml-openvino: add GGML_OPENVINO_ENABLE_CACHE env var to control decoder cache. Add environment variable GGML_OPENVINO_ENABLE_CACHE (default: YES). When set to NO, the decoder_cache is bypassed and models are rebuilt from the cgraph on every inference call in both dynamic and static compute paths. This is useful for debugging and verifying correctness without caching interference. * Revert "Gemma4 initial npu support (TheTom#179)" This reverts commit 0d29a9c. * OpenVINO backend: disable debug log print * Update TBB discovery. Delegated to OpenVINOs own config. * OpenVINO backend: GGML_OPENVINO_ENABLE_CACHE YES -> 1 * OpenVINO backend: fallback FLASH_ATTN_EXT in gemma3n to CPU backend * Add raw ov infer profiling metric * Add OV raw infer time metric to static compute path Co-authored-by: virajwad <84867530+virajwad@users.noreply.github.com> * Modify precision of static profiling * update to OV 2026.2, add OV windows CI * fix editorconfig-checks * Initiall gemma4 npu support * temp. fix for gemma4 accuracy bug on npu * Remove hardcoded names for npu-fold handling * revert static n tokens for cont translation as it is not needed * removed unused variable * test-llama-archs fix * Fix gemma4 flash_attn fallback * support im2col * fix code style * disable add_rope_sin_cos optimization * stateless boradcast and rope optimizations * Enable manual gqa attn by default for stateless gpu * manual gqa: fixed static batch * gemma4 llama-bench ctx update fix * Update OV win CI * stateful rope fusion temp. fix * OpenVINO backend: Conslolidate supported ops * Exclude unsupported GGML_OP_SUB cases * Exclude unsupported TOPK_MOE cases * OpenVINO Backend: MUL_MAT enhancements * Update OV CI * support f16 mask input for npu * Make GGML_OPENVINO_* env vars usage uniform Standardize all GGML_OPENVINO_* env flags: positive integers >0 to enable. Unset, empty, =0, or non-numeric values to disable. This fixes cases where text values or empty strings enabled features. * OpenVINO backend: Enhance envvar handling * more cleanup * move ggml_openvino_env_flag to appropriate place * OpenVINO backend: add REPEAT translator, Q5_1 weights, and GLU view-input fix * ggml-openvino: fix -Werror=cast-qual in extract_q5_1_data * Update openvino.Dockerfile Use BuildKit cache mounts for faster Docker rebuilds. Use apt instead of dpkg, remove unused .ddeb downloads, add DLLAMA_BUILD_TESTS=OFF. * ggml-openvino: centralize env var access via *getenv_str/getenv_int helpers Replace getenv and legacy flags with _str and _int helpers.Minor cleanup, doc updates. * OpenVINO backend: Enable GGML_OP_ADD_ID * Uptade openvino backend clamg-format * clang-format * Update OPENVINO.md (TheTom#211) * OpenVINO backend: fix accuracy issue for op CONCAT with i64 precision * Remove strict concurrency for gpu-openvino-low-perf * Update openvino CI keynames; add ccache-clear * Apply suggestions from code review Co-authored-by: Sigbjørn Skjæret <1629204+CISC@users.noreply.github.com> * Fix formatting --------- Co-authored-by: Xuejun Zhai <Xuejun.Zhai@intel.com> Co-authored-by: Mustafa Cavus <mustafa.cavus@intel.com> Co-authored-by: Mustafa Cavus <mustafacavus@intel.com> Co-authored-by: Xuejun <XuejunZhai@intel.com> Co-authored-by: Wang Yang <yang4.wang@intel.com> Co-authored-by: Ravi Panchumarthy <ravi.panchumarthy@intel.com> Co-authored-by: virajwad <84867530+virajwad@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Mostafa Faheem <mostafaaafaheem@gmail.com> Co-authored-by: Sigbjørn Skjæret <1629204+CISC@users.noreply.github.com>
Overview
Add complete TurboQuant KV cache support to the SYCL backend for Intel GPUs: quantized SET_ROWS kernels (turbo2/3/4), Walsh-Hadamard rotation, VEC flash attention with turbo K/V dequant, and all cross-type FA template instantiations (21 files). Includes
GGML_SYCL_TURBO_QUANTcmake gate,GGML_SYCL_SCALAR_MMQfor Battlemage tile sizes, andsupports_opguards for safe scheduler fallback.Tested on Intel Arc Pro B70 (Battlemage G31, 32GB VRAM, oneAPI 2025.3). Lloyd-Max optimal centroids match CUDA reference.
Benchmarks (Gemma 4 12B QAT Q4_0, tg100, ngl 99, Intel Arc Pro B70):
Perplexity (wikitext-2-raw, 50 chunks, n_ctx=512): turbo3/turbo3 PPL 318.29 vs q8_0 baseline 280.78 (+13.4%, consistent with turbo3 compression ratio on 12B model).
Coherence:
-ctk turbo3 -ctv turbo3produces correct reasoning output.Additional information
The CUDA upstream refactored FA type validation to check both K and V types (
a395d83) — this SYCL implementation uses the same pattern. Vulkan turbo4 centroids were also updated upstream to matching Lloyd-Max values (175a652).A proper code review is required.
Build config:
Requirements