whisper.cpp/ggml/src/ggml-sycl
Katostrofik 06cfc3653b SYCL: fix multi-GPU system RAM exhaustion by using Level Zero allocations (llama/21597)
* SYCL: fix multi-GPU system RAM exhaustion by using Level Zero allocations

Replace sycl::malloc_device with zeMemAllocDevice for GPU memory allocation
in the SYCL backend. sycl::malloc_device triggers the xe kernel driver's
DMA-buf/TTM path which mirrors every VRAM allocation 1:1 in system RAM.
zeMemAllocDevice uses the SVM/P2P path with no host staging.

On a dual Intel Arc Pro B70 system (64GB VRAM, 64GB RAM), a 15.6 GiB model
consumed 60 GiB of system RAM via sycl::malloc_device, causing OOM crashes.
With zeMemAllocDevice, the same workload uses ~6.7 GiB of system RAM with
no performance regression.

All Level Zero calls include automatic fallback to the original SYCL
allocation path if Level Zero interop is unavailable.

* SYCL: address review feedback - remove try/catch, check device types, deduplicate

- Remove try/catch from malloc/free/memcpy helpers, check backend and
  device type upfront instead (ggml_sycl_is_level_zero, ggml_sycl_is_dgpu)
- Move shared helpers (is_level_zero, is_dgpu, free_device) to common.cpp
  and declare in common.hpp to eliminate code duplication
- Use SYCL_CHECK(CHECK_TRY_ERROR()) for fallback sycl::free calls
- Guard dev2dev_memcpy L0 path to dGPU-to-dGPU only, preserving the
  host-staged path for iGPU-to-dGPU transfers
- Add Windows Level Zero SDK path detection (LEVEL_ZERO_V1_SDK_PATH)
  in CMakeLists.txt (co-authored with @arthw)

* SYCL: add build/runtime flags for Level Zero, address review feedback

Implements the architecture suggested by @arthw: compile-time and runtime
flags to cleanly separate Level Zero and SYCL memory API paths.

- Add GGML_SYCL_SUPPORT_LEVEL_ZERO cmake option (default ON). All Level
  Zero code is wrapped in #ifdef so the build works on systems without
  the Level Zero SDK installed (e.g. CPU-only CI servers). Both the
  loader library and headers are checked before enabling.

- Add GGML_SYCL_ENABLE_LEVEL_ZERO runtime env var (default 1). Controls
  whether Level Zero or SYCL memory APIs are used. Only one API style is
  used per session, no mixing. If Level Zero is enabled but the devices
  don't support the Level Zero backend, it auto-disables with a warning.

- Remove Level Zero code from dpct_malloc. It was unused (dpct::device_memory
  is not called anywhere in the backend) and used try/catch for flow control.

- Update SYCL.md with documentation for both new parameters.

Tested on Intel Arc Pro B70 (32GB), single-GPU and dual-GPU, with both
GGML_SYCL_SUPPORT_LEVEL_ZERO=ON and OFF builds. AI-assisted development
(Claude). Code reviewed and tested on my hardware.

* SYCL: unify Level Zero malloc/free call sites, address review feedback

Move ggml_sycl_malloc_device to common.cpp alongside ggml_sycl_free_device.
Both functions are now unconditionally available — Level Zero code is
#ifdef'd inside the functions, not at call sites. All call sites use
uniform SYCL_CHECK(CHECK_TRY_ERROR()) wrapping with no #ifdef blocks.

Addresses arthw's review: wrap all malloc/free in SYCL_CHECK for stack
traces on failure, eliminate duplicated #ifdef/else patterns at 6 call
sites (-29 lines net).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* SYCL: add Level Zero SDK to CI, fix device check and missed alloc paths

Add Level Zero SDK installation to Ubuntu and Windows SYCL CI jobs
so the Level Zero code path is compiled and tested in CI.

Fix two bugs found during extended dual-GPU testing (no
ONEAPI_DEVICE_SELECTOR set):

- The Level Zero backend check was iterating all SYCL devices
  including CPU. The OpenCL CPU device caused Level Zero to be
  disabled for the GPUs, defeating the fix on multi-GPU systems.
  Added is_gpu() filter so only GPU devices are checked.

- sycl_ext_malloc_device/sycl_ext_free (tensor reorder temp buffers)
  were still calling sycl::malloc/sycl::free directly, bypassing the
  Level Zero path. Routed through ggml_sycl_malloc_device/free_device
  for consistency with the other device memory call sites.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* SYCL: address arthw review feedback on Level Zero memory API structure

- Move ggml_sycl_malloc_device to static function in ggml-sycl.cpp;
  only ggml_sycl_free_device (used by common.cpp) stays in common.cpp
- Switch both helpers to use g_ggml_sycl_enable_level_zero global
  instead of per-call queue backend checks
- Remove #ifdef wrapper from global definition; always declare at 0,
  add #else branch in init block so it stays 0 when L0 not compiled in
- Update init loop comment to explain GPU-only device check
- CMakeLists: message(STATUS) before the if block; align option wording

AI-assisted implementation. Reviewed and tested on dual Intel Arc Pro
B70 (32 GB each): test-backend-ops OK on both GPUs, single/dual-GPU
Q4_K_M and Q8_0 bench correct, zeMemAllocDevice GTT delta confirmed
<5 MiB per 4 GiB allocation (vs ~4 GiB shadow with sycl::malloc_device).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* SYCL: remove unused cstdio/cstdlib includes from common.cpp

Leftover from the deleted ggml_sycl_queue_supports_level_zero helper.

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>

* Apply suggestions from code review

Co-authored-by: Neo Zhang <zhang.jianyu@outlook.com>

* SYCL: preserve Level Zero allocation path during early malloc

* ci: fix Level Zero package conflict in Intel Docker build

* ci: find Level Zero loader in oneAPI package step

* ci: allow Windows SYCL package without Level Zero DLL

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Neo Zhang <zhang.jianyu@outlook.com>
2026-05-25 12:26:07 +03:00
..
dpct supprt Flash Attention for fp32/fp16/Q4/Q5/Q8 (llama/20190) 2026-03-16 13:10:15 +02:00
template-instances sycl : add flash-attn support for head size 512 (llama/21654) 2026-04-30 11:29:04 +03:00
CMakeLists.txt SYCL: fix multi-GPU system RAM exhaustion by using Level Zero allocations (llama/21597) 2026-05-25 12:26:07 +03:00
add-id.cpp sycl : fix wrong variable check by assert (llama/20903) 2026-03-29 15:04:36 +03:00
add-id.hpp Support gpt-oss by OPs add-id, mul_mat for mxfp4, swiglu_oai (llama/17826) 2025-12-18 08:20:56 +02:00
backend.hpp ehance UPSCALE to support all UT cases (llama/20637) 2026-03-29 15:04:36 +03:00
binbcast.cpp support permuted, remove check s0/s10 (llama/19889) 2026-02-27 20:57:58 +02:00
binbcast.hpp fix UT fault cases: count-equal, argsort, pad OPs (llama/16521) 2025-10-15 09:29:17 +03:00
common.cpp SYCL: fix multi-GPU system RAM exhaustion by using Level Zero allocations (llama/21597) 2026-05-25 12:26:07 +03:00
common.hpp SYCL: fix multi-GPU system RAM exhaustion by using Level Zero allocations (llama/21597) 2026-05-25 12:26:07 +03:00
concat.cpp sycl: add CONCAT operator support (llama/16047) 2025-11-09 23:38:03 +02:00
concat.hpp SYCL: Refactor ggml_sycl_compute_forward (llama/11121) 2025-01-14 10:38:01 +02:00
conv.cpp Revert "sycl: add usage of enqueue_functions extension (llama/14244)" (llama/15910) 2025-09-20 13:45:28 +03:00
conv.hpp SYCL: Refactor ggml_sycl_compute_forward (llama/11121) 2025-01-14 10:38:01 +02:00
convert.cpp sycl: Q5_K reorder MMVQ/dequant + Q8_0 reorder MMVQ path (llama/22152) 2026-05-14 21:26:48 +03:00
convert.hpp sycl: Improve mul_mat_id memory efficiency and add BF16 fast path (llama/22119) 2026-04-30 11:29:16 +03:00
count-equal.cpp supprt Flash Attention for fp32/fp16/Q4/Q5/Q8 (llama/20190) 2026-03-16 13:10:15 +02:00
count-equal.hpp fix UT fault cases: count-equal, argsort, pad OPs (llama/16521) 2025-10-15 09:29:17 +03:00
cpy.cpp sycl : support to malloc memory on device more than 4GB, update the doc and script (llama/17566) 2025-12-12 17:53:13 +02:00
cpy.hpp SYCL: Add set_rows support for quantized types (llama/14883) 2025-08-18 20:30:45 +03:00
cumsum.cpp sycl: add FILL, CUMSUM, DIAG, SOLVE_TRI, SSM_SCAN, GATED_DELTA_NET (llama/22149) 2026-05-14 21:26:48 +03:00
cumsum.hpp sycl: add FILL, CUMSUM, DIAG, SOLVE_TRI, SSM_SCAN, GATED_DELTA_NET (llama/22149) 2026-05-14 21:26:48 +03:00
dequantize.hpp sycl: Q5_K reorder MMVQ/dequant + Q8_0 reorder MMVQ path (llama/22152) 2026-05-14 21:26:48 +03:00
diag.cpp sycl: add FILL, CUMSUM, DIAG, SOLVE_TRI, SSM_SCAN, GATED_DELTA_NET (llama/22149) 2026-05-14 21:26:48 +03:00
diag.hpp sycl: add FILL, CUMSUM, DIAG, SOLVE_TRI, SSM_SCAN, GATED_DELTA_NET (llama/22149) 2026-05-14 21:26:48 +03:00
dmmv.cpp Fix Q8_0 reorder: garbage on 2nd prompt + crash on full VRAM (llama/21638) 2026-04-30 11:29:10 +03:00
dmmv.hpp whisper : reorganize source code + improve CMake (#2256) 2024-06-26 19:34:09 +03:00
element_wise.cpp sycl: disable Q1_0 in backend and cleanup unused variables (llama/21807) 2026-04-30 11:29:07 +03:00
element_wise.hpp ehance UPSCALE to support all UT cases (llama/20637) 2026-03-29 15:04:36 +03:00
fattn-buffers.cpp SYCL: reduce allocation overhead during flash attention (llama/22732) 2026-05-14 21:26:48 +03:00
fattn-buffers.hpp SYCL: reduce allocation overhead during flash attention (llama/22732) 2026-05-14 21:26:48 +03:00
fattn-common.hpp SYCL: reduce allocation overhead during flash attention (llama/22732) 2026-05-14 21:26:48 +03:00
fattn-tile.cpp sycl : add flash-attn support for head size 512 (llama/21654) 2026-04-30 11:29:04 +03:00
fattn-tile.hpp sycl : add flash-attn support for head size 512 (llama/21654) 2026-04-30 11:29:04 +03:00
fattn-vec.hpp sycl : add flash-attn support for head size 512 (llama/21654) 2026-04-30 11:29:04 +03:00
fattn.cpp sycl : add flash-attn support for head size 512 (llama/21654) 2026-04-30 11:29:04 +03:00
fattn.hpp supprt Flash Attention for fp32/fp16/Q4/Q5/Q8 (llama/20190) 2026-03-16 13:10:15 +02:00
fill.cpp sycl: add FILL, CUMSUM, DIAG, SOLVE_TRI, SSM_SCAN, GATED_DELTA_NET (llama/22149) 2026-05-14 21:26:48 +03:00
fill.hpp sycl: add FILL, CUMSUM, DIAG, SOLVE_TRI, SSM_SCAN, GATED_DELTA_NET (llama/22149) 2026-05-14 21:26:48 +03:00
gated_delta_net.cpp sycl: disable Q1_0 in backend and cleanup unused variables (llama/21807) 2026-04-30 11:29:07 +03:00
gated_delta_net.hpp sycl: add FILL, CUMSUM, DIAG, SOLVE_TRI, SSM_SCAN, GATED_DELTA_NET (llama/22149) 2026-05-14 21:26:48 +03:00
gemm.hpp sycl: Improve mul_mat_id memory efficiency and add BF16 fast path (llama/22119) 2026-04-30 11:29:16 +03:00
getrows.cpp Add BF16 support to GET_ROWS operation (llama/21391) 2026-05-14 21:26:48 +03:00
getrows.hpp SYCL: Remove misleading ggml_sycl_op_flatten function (llama/12387) 2025-03-31 14:56:53 +03:00
ggml-sycl.cpp SYCL: fix multi-GPU system RAM exhaustion by using Level Zero allocations (llama/21597) 2026-05-25 12:26:07 +03:00
gla.cpp Revert "sycl: add usage of enqueue_functions extension (llama/14244)" (llama/15910) 2025-09-20 13:45:28 +03:00
gla.hpp SYCL: Add gated linear attention kernel (llama/11175) 2025-02-03 22:00:57 +02:00
im2col.cpp Add OP im2col_3d (llama/22903) 2026-05-14 21:26:48 +03:00
im2col.hpp Add OP im2col_3d (llama/22903) 2026-05-14 21:26:48 +03:00
mmq.cpp Revert "sycl: add usage of enqueue_functions extension (llama/14244)" (llama/15910) 2025-09-20 13:45:28 +03:00
mmq.hpp whisper : reorganize source code + improve CMake (#2256) 2024-06-26 19:34:09 +03:00
mmvq.cpp sycl: Q5_K reorder MMVQ/dequant + Q8_0 reorder MMVQ path (llama/22152) 2026-05-14 21:26:48 +03:00
mmvq.hpp sycl : fused MoE mul_mat_vec_q for TG (llama/21920) 2026-04-30 11:29:17 +03:00
norm.cpp fix for failed UT case: ACC, L2_NORM, UPSCALE, fused_glu, unary (llama/20283) 2026-03-16 13:10:15 +02:00
norm.hpp sycl: add RMS_NORM_BACK operation support (llama/16808) 2025-11-09 23:38:03 +02:00
outprod.cpp Remove support for Nvidia & AMD GPU, because the oneAPI plugin for Nvidia & AMD GPU is unavailable: download/installation channels are out of work. (llama/19246) 2026-02-08 09:29:10 +02:00
outprod.hpp SYCL: Refactor ggml_sycl_compute_forward (llama/11121) 2025-01-14 10:38:01 +02:00
pad.cpp sycl: support non-contiguous input in PAD op (llama/22148) 2026-05-14 21:26:48 +03:00
pad.hpp fix UT fault cases: count-equal, argsort, pad OPs (llama/16521) 2025-10-15 09:29:17 +03:00
pad_reflect_1d.cpp refactor pad_reflect_1d to make the UT case pass (llama/17204) 2025-12-12 17:53:10 +02:00
pad_reflect_1d.hpp refactor pad_reflect_1d to make the UT case pass (llama/17204) 2025-12-12 17:53:10 +02:00
presets.hpp supprt Flash Attention for fp32/fp16/Q4/Q5/Q8 (llama/20190) 2026-03-16 13:10:15 +02:00
quantize.hpp sycl: refactor quantization to q8_1 (llama/14815) 2025-08-18 20:30:45 +03:00
quants.hpp sycl: Q5_K reorder MMVQ/dequant + Q8_0 reorder MMVQ path (llama/22152) 2026-05-14 21:26:48 +03:00
repeat_back.cpp SYCL: optimized repeat_back kernel (3× fewer asm instructions, 2× faster)Feature/sycl repeat back opt (#16869) 2025-11-09 23:38:03 +02:00
repeat_back.hpp sycl: add REPEAT_BACK operation support (llama/16734) 2025-11-09 23:38:03 +02:00
roll.cpp sycl: add ROLL operation support (llama/16665) 2025-11-09 23:38:03 +02:00
roll.hpp sycl: add ROLL operation support (llama/16665) 2025-11-09 23:38:03 +02:00
rope.cpp fix op rope, add rope_back (llama/20293) 2026-03-16 13:10:15 +02:00
rope.hpp fix op rope, add rope_back (llama/20293) 2026-03-16 13:10:15 +02:00
set.cpp SYCL SET operator optimized for F32 tensors (llama/16350) 2025-10-22 12:58:11 +03:00
set.hpp SYCL SET operator optimized for F32 tensors (llama/16350) 2025-10-22 12:58:11 +03:00
set_rows.cpp sycl: Improve mul_mat_id memory efficiency and add BF16 fast path (llama/22119) 2026-04-30 11:29:16 +03:00
set_rows.hpp SYCL: Initial set_rows kernel implementation (llama/14562) 2025-07-12 19:23:56 +03:00
softmax.cpp supprt Flash Attention for fp32/fp16/Q4/Q5/Q8 (llama/20190) 2026-03-16 13:10:15 +02:00
softmax.hpp refactor soft_max, add soft_max_back (llama/16472) 2025-10-12 11:16:23 +03:00
solve_tri.cpp sycl: add FILL, CUMSUM, DIAG, SOLVE_TRI, SSM_SCAN, GATED_DELTA_NET (llama/22149) 2026-05-14 21:26:48 +03:00
solve_tri.hpp sycl: add FILL, CUMSUM, DIAG, SOLVE_TRI, SSM_SCAN, GATED_DELTA_NET (llama/22149) 2026-05-14 21:26:48 +03:00
ssm_conv.cpp sycl: add FILL, CUMSUM, DIAG, SOLVE_TRI, SSM_SCAN, GATED_DELTA_NET (llama/22149) 2026-05-14 21:26:48 +03:00
ssm_conv.hpp sycl: add SSM_CONV operation support (llama/16800) 2025-11-09 23:38:03 +02:00
ssm_scan.cpp sycl: add FILL, CUMSUM, DIAG, SOLVE_TRI, SSM_SCAN, GATED_DELTA_NET (llama/22149) 2026-05-14 21:26:48 +03:00
ssm_scan.hpp sycl: add FILL, CUMSUM, DIAG, SOLVE_TRI, SSM_SCAN, GATED_DELTA_NET (llama/22149) 2026-05-14 21:26:48 +03:00
sycl_hw.cpp Optimize Q4_0 mul_mat for Arc770, add scripts (llama/22291) 2026-04-30 11:29:19 +03:00
sycl_hw.hpp Optimize Q4_0 mul_mat for Arc770, add scripts (llama/22291) 2026-04-30 11:29:19 +03:00
tsembd.cpp ggml : fix padding in timestep embedding kernels (llama/15932) 2025-09-20 13:45:30 +03:00
tsembd.hpp SYCL: Refactor ggml_sycl_compute_forward (llama/11121) 2025-01-14 10:38:01 +02:00
type.hpp sycl : support nvfp4 type in mul_mat (llama/21227) 2026-04-30 11:28:59 +03:00
upscale.cpp sycl: disable Q1_0 in backend and cleanup unused variables (llama/21807) 2026-04-30 11:29:07 +03:00
upscale.hpp ehance UPSCALE to support all UT cases (llama/20637) 2026-03-29 15:04:36 +03:00
vecdotq.hpp sycl: Q5_K reorder MMVQ/dequant + Q8_0 reorder MMVQ path (llama/22152) 2026-05-14 21:26:48 +03:00
wkv.cpp Remove support for Nvidia & AMD GPU, because the oneAPI plugin for Nvidia & AMD GPU is unavailable: download/installation channels are out of work. (llama/19246) 2026-02-08 09:29:10 +02:00
wkv.hpp llama: Add support for RWKV v7 architecture (llama/12412) 2025-03-27 11:06:03 +02:00