Skip to content

ggml-sycl: kernels and graph replay for audio models - #1242

Merged
0xShug0 merged 11 commits into
0xShug0:mainfrom
newjordan:pr/ggml-sycl-audio-kernels
Nov 9, 2026
Merged

0xShug0 merged 11 commits into
0xShug0:mainfrom
newjordan:pr/ggml-sycl-audio-kernels

Conversation

@newjordan

@newjordan newjordan commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Second of three PRs that together take YuE2 to 2.98x realtime on an Arc Pro B70, up from 1.75x with enablement alone: #1241 (backend), #1242 (this PR, ggml-sycl kernels), #1243 (YuE2). Full numbers are in #1243.

Changes to external/ggml/src/ggml-sycl and its op tests only, one commit per change. Nothing here affects other backends.

  • Missing ops: EXPM1, ROUND_BF16, and F16/BF16 CONCAT.
  • CONV_TRANSPOSE_1D reads only the inputs that contribute to each output, in the same order, so results are unchanged. Same change as sycl: bound CONV_TRANSPOSE_1D input iteration ggml-org/llama.cpp#31109.
  • RMS_NORM x weight MUL fusion, with RMS_NORM_MUL_VECTOR backend tests, including outputs that must not be fused away.
  • Vector flash attention for single-token GQA decode, which previously took the tile kernel.
  • Hardware dp4a for reordered Q8_0 MMVQ, selected per device. Architectures without it keep the software path.
  • oneDNN fused SDPA for long F16 flash attention, backported from llama.cpp. New here: the mask is optional, because llama.cpp's gate excludes unmasked attention. GGML_SYCL_FA_ONEDNN=0 disables it.
  • Graph replay: repeated graphs are recorded and replayed as SYCL command graphs, backported from llama.cpp. Graphs that use oneDNN stay eager unless oneDNN is 3.12.3 or newer.
  • F16 weight expansions can be kept between GEMMs instead of being re-converted on every graph run. Off by default; GGML_SYCL_WEIGHT_F16_CACHE=1 enables them. They live with the buffer, are dropped when it is written, and are never captured by a recorded graph.

One behavior worth a reviewer's attention: graph replay is on by default here (GGML_SYCL_DISABLE_GRAPH=1 opts out), while llama.cpp defaults it off. It measured +2.3% on YuE2, and check_graph_compatibility still excludes the operators that wait on the host.

The weight cache costs memory, about 2x the size of the weights it expands. When enabled, it is limited to devices with at least 20 GiB and to a third of device memory.

Measurements

Arc Pro B70, oneAPI 2026.1, YuE2 city_lights (seed 831001, 8 NAR steps, cot=full, one warmup and 3 measured runs). These use the SYCL backend from #1241 and #1243, with yue2.perf_mode=cuda_perf on both sides, so the difference is these kernels. Both sides are built with GGML_SYCL_F16=ON.

Before After
Realtime factor (median) 1.75x 2.61x
ABC decode 93.4 tok/s 117.4 tok/s
Semantic decode 101.4 tok/s 140.4 tok/s
NAR stage 8.2 s 3.0 s

Individual controls, with the preset in #1243:

Control On Off
Graph replay (default on) 3.02x 2.95x
Weight cache (default off), realtime 3.02x 2.98x
Weight cache (default off), peak VRAM 16.5 GiB 8.6 GiB
source /opt/intel/oneapi/setvars.sh
cmake -S external/ggml -B build/ggml-sycl -G Ninja -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL=ON -DGGML_SYCL_F16=ON \
  -DGGML_SYCL_TARGET=INTEL -DGGML_BUILD_TESTS=ON -DGGML_BUILD_EXAMPLES=OFF
cmake --build build/ggml-sycl --target test-backend-ops -j 16
build/ggml-sycl/bin/test-backend-ops test -b SYCL0 \
  -o RMS_NORM,RMS_NORM_MUL_VECTOR,FLASH_ATTN_EXT,CONV_TRANSPOSE_1D,CONCAT,EXPM1

Validation

  • test-backend-ops as above on the B70: 2826/2826.
  • Each commit builds on its own.
  • CUDA is not compiled against any of this. YuE2 PCM on an RTX 4080 stays byte-identical to main; details are in Add SYCL backend support #1241.

Limitations

Tested on one Intel GPU, the Arc Pro B70. The fallback for GPUs without dp4a and the path for devices under 20 GiB have not been run on such hardware.

These ops are used by YuE2 and other audio models but were missing from
the SYCL backend, so their graphs failed on --backend sycl.

- EXPM1: unary op through the existing elementwise helpers.
- ROUND_BF16: f32/f16/bf16 input with contiguous rows to contiguous f32,
  rounding as ggml_compute_fp32_to_bf16 does (round to nearest even,
  quiet NaN).
- CONCAT: F16 and BF16 (BF16 when GGML_SYCL_HAS_BF16).
Each output sample only reads inputs with i*s0 <= idx < i*s0 + K. Visit
that window instead of every input frame, in the same ascending order, so
the result is unchanged. Assert s0 > 0, since the bound divides by it.

Same change as ggml-org/llama.cpp#31109. Adds perf cases with audio codec
decoder upsampling shapes to test-backend-ops.
@0xShug0

0xShug0 commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@newjordan Thanks for the improvements! I found three potential correctness issues:

  • Async uploads leave cached FP16 weights stale. ggml_backend_sycl_set_tensor_async() uploads new contents without calling clear_f16_weights(). The next eligible matmul calls ggml_sycl_cached_f16_weight(), finds the existing entry and returns the old expansion.
  • Graph replay can retain freed weight pointers. ggml_backend_sycl_buffer_set_tensor() calls clear_f16_weights(), freeing expansions previously captured by a command graph. However, ggml_sycl_graph_update_required() checks the original tensor metadata—or returns early for an unchanged graph UID. Neither detects the freed expansion, so ggml_backend_sycl_graph_compute() can replay the old pointer.
  • oneDNN accepts an incompatible mask layout. ggml_sycl_flash_attn_ext_onednn_supported() checks the mask’s type and higher dimensions, but not its row width against the active KV length. build_sdpa() describes it as dense {1, 1, 1, q, seq}, and ggml_sycl_flash_attn_ext_onednn() binds mask->data directly. A 128-wide mask with 64 active KV entries therefore passes the gate but is read with the wrong row stride.

I reproduced these host-side contracts without Intel hardware by compiling the PR’s functions unchanged, replacing device allocation/copies and command submission with host doubles. For replay: warm up, capture the expansion’s pointer, upload new weights, then verify that replay submits the freed pointer. Both metadata-comparison and graph-UID cases fail; no-upload controls pass.

Another issue from code review only: The oneDNN partition cache is shared without synchronization. A function-static unordered_map is read and modified by independent backend instances. Concurrent sessions can race during lookup/insertion. Suggestion: Keep the oneDNN partition cache owned by each SYCL backend context, rather than function-static so separate sessions won’t modify the same map.

Also please keeping weight caching default off and opt-in. 8.6 → 16.5 GiB peak VRAM for roughly 1.3% speedup is a substantial trade-off. It leaves less VRAM headroom for multi-model pipelines such as voice chat. A model may run successfully alone, while the combined ASR, TTS and LLM pipeline fails with OOM because cached FP16 expansions retain extra memory.

@0xShug0 0xShug0 added the ggml label Nov 9, 2026
…ed graphs

Peak VRAM for YuE2 goes from 16.5 to 8.6 GiB for about 1.3% speed, so the
cache is now off unless GGML_SYCL_WEIGHT_F16_CACHE=1. Asynchronous uploads
drop stale expansions the same way synchronous ones do. Expansions are
never handed to a queue that is recording a graph, because an upload frees
them while the graph stays replayable. The per-device total is atomic.
The SDPA graph binds the mask as one dense plane. A mask wider than the
active KV length, or a strided one, would be read with the wrong row stride
and now takes the other kernels.
The function-static map was read and modified by independent backend
instances, which races between concurrent sessions.
@newjordan

Copy link
Copy Markdown
Contributor Author

Thanks for going through this so carefully. All four were real, and they're fixed in the three commits I just pushed:

  • Async uploads: ggml_backend_sycl_set_tensor_async() now drops the buffer's expansions before uploading, as the synchronous paths do. cpy_tensor_async does the same.
  • Replay: a queue that is recording never gets a cached expansion, so a recorded graph can't capture a pointer an upload later frees. Graphs convert into pool memory instead.
  • Mask layout: the oneDNN gate now requires the mask's rows to match the active KV length and the query count, and the mask to be contiguous. Anything else takes the existing kernels.
  • Partition cache: it's now owned by each backend context. I also made the per-device expansion byte count atomic, since it had the same concurrency problem.

The weight cache is now off by default and needs GGML_SYCL_WEIGHT_F16_CACHE=1. Agreed on the trade-off: peak VRAM for YuE2 goes back to 8.6 GiB, and it costs about 1.3% (3.02x to 2.98x, on the B70).

test-backend-ops -b SYCL0 for RMS_NORM, RMS_NORM_MUL_VECTOR, FLASH_ATTN_EXT, CONV_TRANSPOSE_1D, CONCAT and EXPM1 passes 2826/2826 on this branch, and each new commit builds on its own. I don't have a host-double harness like yours, so the replay and async fixes are checked by review and by those tests rather than by a reproduction of your failing case.

The SYCL validation report you asked for on #1241 is coming as a follow-up.

newjordan added a commit to newjordan/audio.cpp that referenced this pull request Nov 9, 2026
@0xShug0
0xShug0 merged commit 7d20b41 into 0xShug0:main Nov 9, 2026
7 checks passed
@0xShug0

0xShug0 commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@newjordan Thanks! Host tests passed. PR merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants