Skip to content

sycl: pick the src1 fp16 conversion from the runtime oneDNN switch - #288

Merged
bri-prism merged 1 commit into
prismfrom
fix/sycl-dnn0-src1-conversion
Sep 28, 2026
Merged

bri-prism merged 1 commit into
prismfrom
fix/sycl-dnn0-src1-conversion

Conversation

@bri-prism

Copy link
Copy Markdown
Collaborator

What

Fixes wrong MUL_MAT results on SYCL when oneDNN is compiled in but turned off at runtime with GGML_SYCL_ENABLE_DNN=0.

Cause

ggml_sycl_mul_mat_batched_sycl makes two choices at different times:

  • The src1 → fp16 conversion is picked at compile time (#if GGML_SYCL_DNNL).
  • The GEMM is picked at runtime (g_ggml_sycl_enable_dnn).

In a oneDNN build run with GGML_SYCL_ENABLE_DNN=0:

  1. src1 is converted into the strided layout oneDNN expects.
  2. s11/s12/s13 are then reset to contiguous strides.
  3. The MKL gemm_batch fallback reads that strided buffer as if it were contiguous.

The result is wrong whenever src1 isn't contiguous.

Fix

The oneDNN conversion now runs only when the runtime switch is on. Otherwise the existing _nc conversion runs. The change is 5 lines in one function. The default oneDNN path takes exactly the same code as before.

Testing

test-backend-ops test -o MUL_MAT -b SYCL0 on an Intel Arc B390 (Panther Lake). Setup: Windows 11, oneAPI 2025.3 with oneDNN 2025.1, GGML_SYCL_F16=OFF, base adfffbe41.

before after
GGML_SYCL_ENABLE_DNN=0 1297/1329 1329/1329
default (oneDNN) 1329/1329 1329/1329

All 32 cases that failed were type_a=f16,type_b=f32,n=1 with non-contiguous views (k_v=2112/2113), with ERR around 1.1–2.0. They failed identically with and without #278.

The same code is in ggml-org/llama.cpp master, so the fix should also go upstream.

ggml_sycl_mul_mat_batched_sycl chose how to convert src1 to fp16 at
compile time (#if GGML_SYCL_DNNL), but chose the GEMM at runtime
(g_ggml_sycl_enable_dnn). In a oneDNN-enabled build run with
GGML_SYCL_ENABLE_DNN=0, src1 was converted into the strided oneDNN
layout, and s11/s12/s13 were then reset to contiguous strides for the
MKL gemm_batch path. The fallback read a strided buffer as contiguous
and gave wrong results whenever src1 was not contiguous.

Gate the oneDNN conversion on the runtime switch and use the
contiguous _nc conversion otherwise.

test-backend-ops -o MUL_MAT -b SYCL0 on Arc B390 with
GGML_SYCL_ENABLE_DNN=0: 1297/1329 -> 1329/1329. The 32 cases that
failed were f16 x f32 with non-contiguous views (k_v != 0). The
default oneDNN path is unchanged at 1329/1329.
@bri-prism
bri-prism merged commit 8444536 into prism Sep 28, 2026
8 checks passed
@bri-prism
bri-prism deleted the fix/sycl-dnn0-src1-conversion branch September 28, 2026 00:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant