Skip to content

[SYCL] fast ggml_sycl_comm_exchange() - +19% prompt eval -sm tensor t/s on Intel Arc Pro B70s - #30956

Merged
ggerganov merged 6 commits into
ggml-org:masterfrom
92es:sycl-fast-ggml_sycl_comm_exchange
Nov 2, 2026
Merged

ggerganov merged 6 commits into
ggml-org:masterfrom
92es:sycl-fast-ggml_sycl_comm_exchange

Conversation

@92es

@92es 92es commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Increases -sm tensor prompt eval t/s by +19% t/s ( making -sm tensor as fast as -sm layer ) with zero PPL change

Overview

  • increases -sm tensor` prompt-eval t/s: [+16.7% to +20.6%] (mean ≈ +19.0%) faster than stock, on every dense model tested
  • tensor split prompt eval is now as fast as layer split prompt eval with this optimization patch
  • PPL: no change in either split mode (tensor/tensor, layer/layer)

Additional information

Requirements

Collab: google.ai and Qwen3.8-27B-UD-Q8_K_4XL
Code gen: Qwen3.8-27B-UD-Q8_K_4XL

Test environment

GPUs: Dual B70s, one B70 in Gen5 x16 PCIe slot and one in Gen4 x4 PCIe slot.
OS: Debian Trixie Backports, Kernel 7.9.2
Toolkit: oneAPI 2026.1.1

Test command

llama-perplexity -m ${LLM_NAME}.gguf -dev SYCL0,SYCL1 -f ggml-sycl.cpp -sm [tensor|layer] -ts 1,1 -ngl 99 --load-mode dio --chunks 12 -n 64 -b 1024 -ub 1024 -c 512 -v
Retested with single shot llama-cli to validate MTP consistency using --spec-draft-n-max 4, 5 and 6

Out of tree unit test showed Gen5x16 to Gen4x4 pathway increased from 5.3 GB/s ( mainline code ) to 7.1 GB/s ( +34% patch code ), almost maxing out the theoretical limit of 7.5.GB/s.

Test matrix

  • stock layer vs stock tensor
  • patch layer vs patch tensor
  • stock layer vs patch layer
  • stock tenser vs patch tenser

Tensor mode — patch gain over mainline

Model stock → patched t/s Δ t/s (%)
Qwen3.8-27B-Q8_0 (A) 1065.18 → 1277.07 +211.89 (+19.9%)
Qwen3.8-27B-Q8_0 (B) 1075.98 → 1277.58 +201.60 (+18.7%)
Qwen3.8-27B-UD-Q8_K_XL 1077.49 → 1287.47 +209.98 (+19.5%)
Qwen3.8-27B-UD-Q8_K_4XL 1100.91 → 1325.57 +224.66 (+20.4%)
Qwen3-4B-Q8_0 3984.03 → 4650.81 +666.78 (+16.7%)
Qwen3.8-27B-BF16 1169.55 → 1410.09 +240.54 (+20.6%)
Mistral-Small-24B-Q8_0 1530.72 → 1792.46 +261.74 (+17.1%)

Consistent tensor-mode gain of +16.7% … +20.6% (mean ≈ +19.0%) across every model and
quantization tested.

llama-perplexity PPL ( no change layer vs layer and tensor vs tensor )

Layer mode: stock vs patched PPL (no change)

Model stock PPL patched PPL Δ patch−stock
Qwen3.8-27B-Q8_0 (A & B) 2.5204 ± 0.09071 2.5204 ± 0.09071 +0.0000
Qwen3.8-27B-UD-Q8_K_XL 2.5205 ± 0.09070 2.5205 ± 0.09070 +0.0000
Qwen3.8-27B-UD-Q8_K_4XL 2.5209 ± 0.09071 2.5209 ± 0.09071 +0.0000
Qwen3-4B-Q8_0 3.8538 ± 0.20216 3.8538 ± 0.20216 +0.0000
Qwen3.8-27B-BF16 2.5207 ± 0.09070 2.5207 ± 0.09070 +0.0000
Mistral-Small-24B-Q8_0 2.6652 ± 0.09276 2.6652 ± 0.09276 +0.0000

Tensor mode: stock vs patched PPL (no change)

Model stock PPL patched PPL Δ patch−stock
Qwen3.8-27B-Q8_0 (A) 2.5214 ± 0.09080 2.5214 ± 0.09080 +0.0000
Qwen3.8-27B-Q8_0 (B) 2.5210 ± 0.09077 2.5213 ± 0.09079 +0.0003
Qwen3.8-27B-UD-Q8_K_XL 2.5209 ± 0.09075 2.5213 ± 0.09077 +0.0004
Qwen3.8-27B-UD-Q8_K_4XL 2.5213 ± 0.09073 2.5214 ± 0.09075 +0.0001
Qwen3-4B-Q8_0 3.8531 ± 0.20205 3.8531 ± 0.20205 +0.0000
Qwen3.8-27B-BF16 2.5214 ± 0.09078 2.5220 ± 0.09081 +0.0006
Mistral-Small-24B-Q8_0 2.6649 ± 0.09276 2.6648 ± 0.09274 −0.0001

UPDATE:

Thanks to @Captain-Tripps eval, he discovered there was a MTP degradation with the original patch that used wait().

Switching the first pair of wait() to ext_oneapi_submit_barrier() restored MTP consistency between mainline and patch.

ext_oneapi_submit_barrier() retained the patch's speed improvements and PPL equivalencies as previously documented, confirmed by an entire rerun of the regression test suite tabled above.

Mainline vs Patch wait vs Patch barrier

CPU memcpy Buffers Mid-fn host block Cross-queue sync MTP impact
Baseline 2× serial 4 yes (D2H) none needed (CPU did the swap) stalls submission thread
Patch wait none 2 yes (D2H) ← problem host wait + resubmit degraded (heartbeat stall + dead gap)
Patch barrier none 2 no — final wait only, post-enqueue device-side barrier, in-order queues clean; pipeline stays full

Increases -sm tensor prompt eval t/s by +19% with zero PPL change.
@92es
92es requested a review from a team as a code owner October 22, 2026 01:55
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language labels Oct 22, 2026
Replace first pair of wait() calls with ext_oneapi_submit_barrier().  The wait() calls was discovered to cause MTP degradation.
@92es

92es commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

@Captain-Tripps

I did not find a comment section on your B70/MTP page so I am posting it here.

You had some good open questions to resolve.

I am making a hands-off scripted llama-cli script to regression test MTP. Here is the initial A/B run of a fixed 3,254 token prompt (C++ source code) that runs and exists without manual intervention to eliminate manual run-2-run variations.

My initial manual llama-cli MTP tests used much shorter prompts.

Preliminary results look promising:

Performance Comparison: Stock vs. Patched

A/B (hands off) scripted llama-cli Qwen3.6-27B-Q4_0-MTP.gguf on SYCL0, SYCL1

Both runs processed a 3,265 token prompt and 256 generation tokens.

Metric Stock Patch barrier Change / Delta
Prompt Processing Speed 679.50 t/s 746.32 t/s +9.83%
Prompt Processing Time 4805.02 ms 4374.81 ms -8.95% (Faster)
Generation Speed 29.57 t/s 31.25 t/s +5.68%
Generation Time 8622.43 ms 8159.23 ms -5.37% (Faster)
Draft Acceptance Rate 76.13% (118/155) 80.00% (132/165) +3.87%
Mean Draft Length 2.74 tokens 3.13 tokens +14.23%
MTP Draft Gen Duration 871.44 ms 856.30 ms -1.74% (shorter)
MTP Mean Acceptance 2.74 3.13 +14.2%

MTP

acc rate positions
Stock (0.882, 0.338, 0.235, 0.132, 0.074, 0.074)
Patch (0.952, 0.419, 0.306, 0.210, 0.129, 0.113)

Notes

~10% improvement in prompt evaluation speed (Time-to-First-Token)
~5.7% lift in continuous generation speed.

@92es

92es commented Oct 23, 2026

Copy link
Copy Markdown
Contributor Author

@Captain-Tripps

"... If you test the barrier approach where it does run, please check correctness with perplexity at ub 4 and ub 512 plus a long greedy decode against a stock build (a write-after-read race on reused staging buffers would show up there, not in a short MTP run), and post your OS, driver, and whether q0->get_context() == q1→get_context(). ..."

Requested Information:

The barrier patch runs with no crashes.

OS: Debian Trixie Backports, Kernel 7.2.9
oneAPI 2026.1.1 oneDNN

q0 and q1 get_context() are ALWAYS the same.

6145 tokens for all 4 runs with 60 second cool downs between runs.

Note: There are run-2-run +/- variance on both stock and patched binaries.

-dev SYCL0,SYCL1 -f ggml-sycl.cpp -sm tensor -ts 1,1 -ub 4
PPL 2.5196 +/- 0.09057 - Stock
PPL 2.5209 +/- 0.09065 - Patch barrier
Stock 74.91 t/s vs Patch 72.36 t/s

-dev SYCL0,SYCL1 -f ggml-sycl.cpp -sm tensor -ts 1,1 -ub 512
PLL 2.5217 +/- 0.09076 - Stock
PPL 2.5216 +/- 0.09075 - Patch barrier
Stock 1028.55 t/s vs Patch 1186.21 t/s

@92es

92es commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author

@Captain-Tripps ,

I added "-seed 1234" to try and stabilize the +/- PPL variance in both the STOCK and PATCH runs, but the run-2-run variance still remains in both.

This run, the PATCH barrier's PPL is better than the STOCK with both -ub 4 and 512 where last night was better with just 512.

I think we are chasing random run-2-run noise levels ( and random seed mixes ? ).

Multiple interleaved hands off -seed 1234 -ub 4 runs:

-dev SYCL0,SYCL1 -f ggml-sycl.cpp -sm tensor -ts 1,1 -seed 1234 -ub 4

PPL 2.5203 +/- 0.09064 - Stock
PPL 2.5209 +/- 0.09064 - Stock
PPL 2.5210 +/- 0.09069 - Stock
PPL 2.5203 +/- 0.09062 - Stock

PPL 2.5196 +/- 0.09056 - Patch barrier
PPL 2.5189 +/- 0.09052 - Patch barrier
PPL 2.5202 +/- 0.09062 - Patch barrier
PPL 2.5194 +/- 0.09054 - Patch barrier

Tokens per second Stock 75.16 t/s vs Patch 72.24 t/s
Tokenization Stock 76.185 ms vs Patch 75.963 ms

-dev SYCL0,SYCL1 -f ggml-sycl.cpp -sm tensor -ts 1,1 -seed 1234 -ub 512

PPL 2.5218 +/- 0.09077 - Stock
PPL 2.5214 +/- 0.09074 - Patch barrier
Tokens per second Stock 1029.96 t/s vs Patch 1184.14 t/s
Tokenization Stock 75.431 ms vs Patch 76.777 ms

As for your Windows crash, make sure code is q0:d2h_1 and q1:d2h_0.

    q0->ext_oneapi_submit_barrier({e_d2h_1}); // q0 waits for q1's device-to-host copy
    q1->ext_oneapi_submit_barrier({e_d2h_0}); // q1 waits for q0's device-to-host copy

@Captain-Tripps

Copy link
Copy Markdown
Contributor

Hi @92es -

Here is what we tested out:
q0->ext_oneapi_submit_barrier({e_d2h_1}) and q1->ext_oneapi_submit_barrier({e_d2h_0}), on 2x Arc Pro B70 running Windows 11 Pro, Level Zero driver 32.0.101.8976, with Qwen3.8-27B in Q8_0 and -sm tensor. This ran on my fork (r67c with #30956 ported by hand)

Here's what we found:
Unfortunately, the process aborts before producing any results, a fast-fail (0xc0000409) inside ze_intel_gpu64.dll. The stock exchange in the same build runs fine (pp512 971 t/s), so it’s the barrier that's the issue.

Why it fails here:
For windows, each device gets its' own SYCL context, so q0->get_context() != q1->get_context(), and a barrier on one queue can’t take an event from the other context. On Linux, the contexts are the same, which is why it works there.

What this likely means for this PR:
It would probably crash Windows multi-GPU users. A guard, using the barrier only when q0->get_context() == q1->get_context() and otherwise the current host-wait path, keeps the Linux speedup (+15% at ub 512, ub-4 perplexity identical) without breaking Windows.

What would fix it:
We believe that putting both cards in one SYCL context (like how Linux does it). That’s on our roadmap of next things to try, we haven't built it yet and aren't sure we'd see any additional speed up in PP or decode.

92es added 2 commits October 24, 2026 21:23
Adding comm_exchange function pointer to switch between 2 and 4 buffer ggml_sycl_comm_exchange versions @ initialization time (versus hot path) controlled by SYCL_ENABLE_DEFAULT_CONTEXTS=1 setting.
adding back 2nd half of 4-buffer free.
@92es

92es commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Patch Update:

Updated the patch to react to SYCL_ENABLE_DEFAULT_CONTEXTS settings to switch between the original 4-buffer-wait version (separate SYCL contexts) and the new 2-buffer-barrier version (same SYCL context) using a function pointer to remove the runtime check out of the hot path as per @Captain-Tripps lead.

kl-divergence

Also ran llama-perplexity's --kl-divergence-base --kl-divergence to verify PPL and KLD consistency. -ub 4 was identical and -ub 512 oscillated back and forth in noise levels between baseline code and patch barrier (again, as per @Captain-Tripps lead).

Removing extra whitespace.
@92es

92es commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

@arthw ,

I would like some guidance on this patch.

On Debian Trixie Backports Kernel 7.2.9, oneAPI 2026.1.1 and NEO 26.22.38646.4-0 both mainline and patch crashes with V2=1. It also crashed with 2025.x.x so I run with UR_LOADER_USE_LEVEL_ZERO_V2=0..

I also tried the latest 2.42.6 shared objects from Itel's github page and the mainline crashes as well with V2=1. The newest 2.42.6 shared objects V2=0 runs are about [1-2]% slower than Debian's stock 2.36.3 libraries.

@Captain-Tripps reported that the patch does not work on Windows because of crashes.

I updated the patch to check for same or different contexts and can #if !defined(Windows) until Windows gets fixed.

How should I handle the rest of this patch ?

Should I put a UR_LOADER_USE_LEVEL_ZERO_V2=1 runtime exclusion on it as well until the V2 mainline crashes are ironed out ?

Please let me know which direction I should take because it makes tensor splits on par with layer splits which is good for long context runs.

I also noticed that nsm is hard coded to ( prop.get_max_compute_units() / 16 ) which is not correct for Xe2 GPUs.

The specific architecture should probably be tested at runtime. I tested the divisor of 8 and it works fine on 1 and 2 B70s, but the B70's aren't the only Xe2 cards to be validated.

static int xve_engines_per_core(int device) {
    // 1st-gen Xe  Vector Engines per Xe-core, 16 @ SIMD8
    // 2nd-gen Xe2 Vector Engines per Xe-core,  8 @ SIMD16, 2X per clock
    // Note: BMG-G21 and Xe2-LPG should also be tested for 8
    return ( is_bmg_g31_arch(i) ? 8 : 16 );
}   

...

info.devices[i].nsm = prop.get_max_compute_units() / xve_engines_per_core(i);

I also removed the 60% allocation restriction on the B70 and it appears to work fine on my rig.

@arthw

arthw commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@92es
Sorry to review this issue late!

Answer your question:
UR_LOADER_USE_LEVEL_ZERO_V2=1 issue also happened in other user cases.
I think it's the running environment issue, instead of code.
Your baseline has the same issue.
It shouldn't impact your PR.
UR_LOADER_USE_LEVEL_ZERO_V2=1 is default setting in most user cases.

  1. I will test the PR with UR_LOADER_USE_LEVEL_ZERO_V2=1.
  2. UR_LOADER_USE_LEVEL_ZERO_V2=1/0 won't impact the functionality of this PR. But the performance will be impacted I guess.
  3. Suggest you fix UR_LOADER_USE_LEVEL_ZERO_V2=1 issue in your PC as soon, to avoid to impact the development in the future.
    a.
    Could you run the cmd and share the output?
lspci -nnk | grep -i vga -A3
dpkg -l | grep libze-intel-gpu

The correct result should use xe, instead of i915 driver.

b.
If you install the driver by more than one method before (like apt and dpkg), you'd better clean all driver packages manually and reinstall by one method.

Thank you!

@arthw arthw left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good job!
On 2xArc770

UR_LOADER_USE_LEVEL_ZERO_V2=1

GGUF Test fa Base t/s Primary t/s Increase Rate (Primary vs Base)
llama-2-7b.Q4_0.gguf pp512 1 971.36 1077.01 10.88%
llama-2-7b.Q4_0.gguf tg128 1 54.26 53.80 -0.85%

UR_LOADER_USE_LEVEL_ZERO_V2=0

GGUF Test fa Base t/s Primary t/s Increase Rate (Primary vs Base)
llama-2-7b.Q4_0.gguf pp512 1 956.68 1052.71 10.04%
llama-2-7b.Q4_0.gguf tg128 1 46.09 42.21 -8.42%

Thank you!

@92es

92es commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor Author

@92es Sorry to review this issue late!
Could you run the cmd and share the output?

lspci -nnk | grep -i vga -A3
dpkg -l | grep libze-intel-gpu

@arthw

Here are your requested results. I use sudo apt install, not dpkg to install packages.

I have the i5-14600K iGPU disabled in the BIOS. For some reason it is printed out G21 instead of G31.

lspci -nnk | grep -i vga -A3
dpkg -l | grep libze-intel-gpu
03:00.0 VGA compatible controller [0300]: Intel Corporation Battlemage G21 [Intel Graphics] [8086:e223]
	Subsystem: Intel Corporation Device [8086:1701]
	Kernel driver in use: xe
	Kernel modules: xe
--
0d:00.0 VGA compatible controller [0300]: Intel Corporation Battlemage G21 [Intel Graphics] [8086:e223]
	Subsystem: Intel Corporation Device [8086:1701]
	Kernel driver in use: xe
	Kernel modules: xe
ii  libze-intel-gpu1                               26.22.38646.4-0                      amd64        Intel(R) Graphics Compute Runtime for oneAPI Level Zero.

lspci | grep VGA
03:00.0 VGA compatible controller: Intel Corporation Battlemage G21 [Intel Graphics]
0d:00.0 VGA compatible controller: Intel Corporation Battlemage G21 [Intel Graphics]

llama-ls-sycl-device
Found 2 SYCL devices:
|  |                   |                                       |       |Max    |        |Max  |Global |                     |
|  |                   |                                       |       |compute|Max work|sub  |mem    |                     |
|ID|        Device Type|                                   Name|Version|units  |group   |group|size   |       Driver version|
|--|-------------------|---------------------------------------|-------|-------|--------|-----|-------|---------------------|
| 0| [level_zero:gpu:0]|             Intel Arc Pro B70 Graphics|   20.2|    256|    1024|   32| 34242M|         1.15.38646+4|
| 1| [level_zero:gpu:1]|             Intel Arc Pro B70 Graphics|   20.2|    256|    1024|   32| 34242M|         1.15.38646+4|
SYCL Optimization Feature:
|ID|        Device Type|Reorder|
|--|-------------------|-------|
| 0| [level_zero:gpu:0]|      Y|
| 1| [level_zero:gpu:1]|      Y|


Should I update the patch to exclude Windows ?


#if defined(_WIN32) || defined(_WIN64) // Not supported on Windows
    ctx->comm_exchange = ggml_sycl_comm_exchange;
#else
    // SYCL_ENABLE_DEFAULT_CONTEXTS=1 sets comm_exchange_fast on Linux - PR #30956
    ctx->comm_exchange = (sctx0->stream()->get_context() == sctx1->stream()->get_context())
                       ? ggml_sycl_comm_exchange_fast
                       : ggml_sycl_comm_exchange;
#endif

UPDATE: Added the Windows exclusion until someone can validate it works on Windows.

Excluding Windows until it is validated on Windows.
@92es

92es commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

@arthw , @Titaniumtown , can I get a final review on this patch.

I have a following patch that is additive to this patch.

Preview of following -sm tensor patch:

Configuration PP (t/s) PP Delta TG (t/s) TG Delta MTP Mean Acc MTP Delta
STOCK + NO FUSION (Baseline) 706.5 Base 31.8 Base 3.19 Base
STOCK + FUSION 720.0 +1.91% 35.6 +11.95% 3.23 +1.25%
PATCH + NO FUSION 738.8 +4.57% 41.3 +29.87% 3.27 +2.51%
PATCH + FUSION 753.7 +6.68% 39.3 +23.58% 3.15 -1.25%

@arthw arthw added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Oct 31, 2026
@ggerganov
ggerganov merged commit 2c93f0b into ggml-org:master Nov 2, 2026
23 of 25 checks passed
@AdamN1

AdamN1 commented Nov 2, 2026

Copy link
Copy Markdown

With 3xB70 and Qwen3.8-Flash-Next-GSQ-RCO-IQ3 by DasLab I don't have any performance increase

@moriz1

moriz1 commented Nov 2, 2026

Copy link
Copy Markdown

when running Qwen 3.8-27B-UD-Q8_K_XL with dual B70 and -sm tensor, I'm now getting

Abort was called at 3560 line in file: /usr/src/debug/intel-compute-runtime/compute-runtime-26.35.39758.10/level_zero/core/source/cmdlist/cmdlist_hw.inl

same for running other models with -sm tensor.

my system is running archlinux with kernel 7.2.14-arch1-1 and intel-deep-learning-essentials package installed.

@92es

92es commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

@AdamN1 ,

With 3xB70 and Qwen3.8-Flash-Next-GSQ-RCO-IQ3 by DasLab I don't have any performance increase

The original allreduce() was written for 2 GPUs. This patch did not increase that limitation. See original exclusion code in alllreduce():

    // Initial version: N=2 only. For N!=2, returning null makes the
    // meta-backend skip this backend-specific allreduce entirely.
    if (n_backends != 2) {
        return nullptr;
    }

Maybe a potential future upgrade to N > 1 dGPUs instead of N==2 dGPUs.

@92es

92es commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

@moriz1,

when running Qwen 3.8-27B-UD-Q8_K_XL with dual B70 and -sm tensor, I'm now getting

Abort was called at 3560 line in file: /usr/src/debug/intel-compute-runtime/compute-runtime-26.35.39758.10/level_zero/core/source/cmdlist/cmdlist_hw.inl

same for running other models with -sm tensor.

my system is running archlinux with kernel 7.2.14-arch1-1 and intel-deep-learning-essentials package installed.

Try setting env var export SYCL_ENABLE_DEFAULT_CONTEXTS=0 on Arch Linux to use the original 4-buffer implementation.

Also, on Arch Linux, are you running with UR_LOADER_USE_LEVEL_ZERO_V2= 0 or 1 ?

Also, on Arch Linux, does this happen at startup or during the middle of runtime ?

@moriz1

moriz1 commented Nov 2, 2026

Copy link
Copy Markdown

@92es

On startup. The model would fail to load and the server would crash after that point.

BTW SYCL_ENABLE_DEFAULT_CONTEXTS=0 worked, and what's better, is that I'm no longer seeing the "memory leak" that I reported in #27845

what is it about Arch that's causing this?

@92es

92es commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@moriz1,

@92es

On startup. The model would fail to load and the server would crash after that point.

BTW SYCL_ENABLE_DEFAULT_CONTEXTS=0 worked, and what's better, is that I'm no longer seeing the "memory leak" that I reported in #27845

what is it about Arch that's causing this?

You can't blame the memory leak "FIX" on me =). That environment variable forces the code to use the original unoptimized pathway that uses separate (not shared) contexts. Follow the link to read its official Intel docs.

My optimization patch relies on shared contexts. It sounds like another Intel library memory bug that needs to be isolated and reported.

I isolated an Intel memory leak bug yesterday. It allocates internal resources and does not free all of them which is probably a variant of what you were seeing on Arch.

Adding @arthw for the Intel memory leaks.

Below it only frees up @ half the resources allocated and it scales linearly.


               zeContextCreate = 1     \--->              zeContextDestroy = 1    
          zeCommandQueueCreate = 0     \--->         zeCommandQueueDestroy = 0    
                zeModuleCreate = 0     \--->               zeModuleDestroy = 0    
                zeKernelCreate = 0     \--->               zeKernelDestroy = 0    
             zeEventPoolCreate = 1564  \--->            zeEventPoolDestroy = 1564 
  zeCommandListCreateImmediate = 5     |
           zeCommandListCreate = 0     \--->          zeCommandListDestroy = 5    
                 zeEventCreate = 400007 \--->                zeEventDestroy = 200007 ---> LEAK = 200000
                 zeFenceCreate = 0     \--->                zeFenceDestroy = 0    
                 zeImageCreate = 0     |
          zeImageViewCreateExt = 0     \--->                zeImageDestroy = 0    
               zeSamplerCreate = 0     \--->              zeSamplerDestroy = 0    
              zeMemAllocDevice = 8     |
                zeMemAllocHost = 10    |
              zeMemAllocShared = 8     \--->                     zeMemFree = 26   
                                       \--->                  zeMemFreeExt = 0   
and

               zeContextCreate = 1     \--->              zeContextDestroy = 1    
          zeCommandQueueCreate = 4     \--->         zeCommandQueueDestroy = 0     ---> LEAK = 4
                zeModuleCreate = 0     \--->               zeModuleDestroy = 0    
                zeKernelCreate = 0     \--->               zeKernelDestroy = 0    
             zeEventPoolCreate = 159   \--->            zeEventPoolDestroy = 159  
  zeCommandListCreateImmediate = 1     |
           zeCommandListCreate = 6     \--->          zeCommandListDestroy = 7    
                 zeEventCreate = 40000 \--->                zeEventDestroy = 20001 ---> LEAK = 19999
                 zeFenceCreate = 6     \--->                zeFenceDestroy = 6    
                 zeImageCreate = 0     |
          zeImageViewCreateExt = 0     \--->                zeImageDestroy = 0    
               zeSamplerCreate = 0     \--->              zeSamplerDestroy = 0    
              zeMemAllocDevice = 8     |
                zeMemAllocHost = 10    |
              zeMemAllocShared = 8     \--->                     zeMemFree = 26   
                                       \--->                  zeMemFreeExt = 0 

@moriz1

moriz1 commented Nov 2, 2026

Copy link
Copy Markdown

@92es

Also, on Arch Linux, are you running with UR_LOADER_USE_LEVEL_ZERO_V2= 0 or 1 ?

I don't have this set, so the default value.

@AdamN1

AdamN1 commented Nov 2, 2026

Copy link
Copy Markdown

The original allreduce() was written for 2 GPUs. This patch did not increase that limitation. See original exclusion code in alllreduce():

@92es with 2xB70 work's great from 400+ tps to 1200tps, it would be great to have support for 3pc

@92es

92es commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor Author

@AdamN1,

The original allreduce() was written for 2 GPUs. This patch did not increase that limitation. See original exclusion code in alllreduce():

@92es with 2xB70 work's great from 400+ tps to 1200tps, it would be great to have support for 3pc

Whoa, what LLM/quants are you testing with ? Is this an MoE test ? I did not test MoE LLMs. 3X is more than I expected.

Thanks for testing with 2 B70's. I wish I had 3 or 4 to code/test with !!! =).

I have a following patch I am working on that is accumulative to this patch. I have to segment it due to the Intel driver memory leak I isolated yesterday so one of the future enhancements will have to be staged until Intel fixes that.

Preview of following -sm tensor patch:

Configuration PP (t/s) PP Delta TG (t/s) TG Delta MTP Mean Acc MTP Delta
STOCK + NO FUSION (Baseline) 706.5 Base 31.8 Base 3.19 Base
STOCK + FUSION 720.0 +1.91% 35.6 +11.95% 3.23 +1.25%
PATCH + NO FUSION 738.8 +4.57% 41.3 +29.87% 3.27 +2.51%
PATCH + FUSION 753.7 +6.68% 39.3 +23.58% 3.15 -1.25%

@AdamN1

AdamN1 commented Nov 3, 2026 •

Copy link
Copy Markdown

The original allreduce() was written for 2 GPUs. This patch did not increase that limitation. See original exclusion code in alllreduce():

@92es with 2xB70 work's great from 400+ tps to 1200tps, it would be great to have support for 3pc

Whoa, what LLM/quants are you testing with ? Is this an MoE test ? I did not test MoE LLMs. 3X is more than I expected.

Model from DasLab Qwen3.8-27B-GSQ-RCO-IQ3_S-mtp.gguf hash: d562806dbafae37109975e970aae91b43e73b440

Thanks for testing with 2 B70's. I wish I had 3 or 4 to code/test with !!! =).

I would be more that happy to test.

@moriz1

moriz1 commented Nov 3, 2026

Copy link
Copy Markdown

@92es

so i've thoroughly tested the two environment variables you gave me. here are the results:

SYCL_ENABLE_DEFAULT_CONTEXTS=0, `UR_LOADER_USE_LEVEL_ZERO_V2=1' (or unset)

SYCL_ENABLE_DEFAULT_CONTEXTS=0, `UR_LOADER_USE_LEVEL_ZERO_V2=0'

  • fixes crash
  • same performance as before
  • no more memory leak

SYCL_ENABLE_DEFAULT_CONTEXTS=1, `UR_LOADER_USE_LEVEL_ZERO_V2=0'

  • fixes crash (because the changes of this PR is disabled, i assume?)
  • same performance as before
  • memory leak (llama-server's memory usage increases by about 10mb/s during decode)

SYCL_ENABLE_DEFAULT_CONTEXTS=1, `UR_LOADER_USE_LEVEL_ZERO_V2=1'

  • crash (as i reported previously)

@92es

92es commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

@moriz1,

What OS, version, kernel version and libze1 loader are you using ?

uname -a
icpx --version
ldd llama-cli | grep -Ei 'sycl|ur_|ze_loader|ze_intel'
dpkg -l | grep -E "intel-opencl|intel-media|libze|intel-igc"
echo "NEO version:"; apt-cache policy intel-opencl-icd

The V2=1 crash appears to be tied to the libze1 loader level. I am running 1.20.6-1 and V2=1 crashes no matter what I do.

ii libze1:amd64 1.20.6-1 amd64 oneAPI Level Zero -- share libraries

It appears I will have to try building, from source Debian Forky's ( testing ) version with Debian Trixie's compiler to get 1.32 or above.

I moved to oneAPI 2026-2 yesterday and the V2=1 crash still happens.

# • libze1 in Trixie (1.20.6-1): Compiled against libstdc++6 (>= 11).
# • libze1 in Forky (1.32.0-1): Compiled against libstdc++6 (>= 14) and libc6 (>= 2.38).

If you want to try one more test, in ggml-sycl.cpp, change the 2 barrier calls in ggml_sycl_comm_exchange_fast() to wait calls and run with SYCL_ENABLE_DEFAULT_CONTEXTS=1.

    // Step 2: Asynchronous Barrier Interlocking (NO HOST BLOCKING), wait() causes MTP conflicts
#if 1
    e_d2h_0.wait();
    e_d2h_1.wait();
#else
    q0->ext_oneapi_submit_barrier({e_d2h_1}); // q0 waits for q1's device-to-host copy
    q1->ext_oneapi_submit_barrier({e_d2h_0}); // q1 waits for q0's device-to-host copy
#endif

TIA for the testing.

@moriz1

moriz1 commented Nov 3, 2026

Copy link
Copy Markdown

@92es

archlinux

uname -a:

Linux blackbox 7.2.14-arch1-1 #1 SMP PREEMPT_DYNAMIC Fri, 30 Oct 2026 14:32:40 +0000 x86_64 GNU/Linux

icpx --version:

-bash: icpx: command not found

dd llama-cli | grep -Ei 'sycl|ur_|ze_loader|ze_intel'

libggml-sycl.so.0 => /home/moriz/runner/bin/libggml-sycl.so.0 (0x00007f84ad800000) libze_loader.so.1 => /usr/lib/libze_loader.so.1 (0x00007f84ad680000) libsycl.so.9 => /opt/intel/oneapi/compiler/latest/lib/libsycl.so.9 (0x00007f84a1e00000) libmkl_sycl_blas.so.6 => /opt/intel/oneapi/mkl/latest/lib/libmkl_sycl_blas.so.6 (0x00007f849d800000)

unfortunately the rest of those commands don't work, or don't reveal anything useful.

@moriz1

moriz1 commented Nov 3, 2026

Copy link
Copy Markdown

@92es

Found the arch equivalents:

pacman -Qi intel-compute-runtime
Name            : intel-compute-runtime
Version         : 26.35.39758.10-1
Description     : Intel(R) Graphics Compute Runtime for oneAPI Level Zero and OpenCL(TM) Driver
Architecture    : x86_64
URL             : https://github.com/intel/compute-runtime/
Licenses        : MIT
Groups          : None
Provides        : level-zero-driver  opencl-driver
Depends On      : glibc  intel-gmmlib  intel-graphics-compiler  libgcc  libstdc++
Optional Deps   : igsc<1.0.0: for discrete GPU firmware enumeration through Level Zero
                  libdrm: for cl_intel_va_api_media_sharing OpenCL extension [installed]
                  libnl>=3.0.0: for using Fabric related APIs in Level Zero [installed]
                  libnl<4.0.0: for using Fabric related APIs in Level Zero [installed]
                  libva: for cl_intel_va_api_media_sharing OpenCL extension [installed]
                  systemd-libs: for using Sysman events API in Level Zero [installed]
Required By     : intel-xpu-smi-bin
Optional For    : ocl-icd
Conflicts With  : None
Replaces        : None
Installed Size  : 119.37 MiB
Packager        : Daniel Bermond <dbermond@archlinux.org>
Build Date      : Sat 19 Sep 2026 12:12:50 PM EDT
Install Date    : Mon 02 Nov 2026 10:22:43 AM EST
Install Reason  : Explicitly installed
Install Script  : No
Validated By    : Signature


/opt/intel/oneapi/compiler/latest/bin/icpx --version
Intel(R) oneAPI DPC++/C++ Compiler 2026.2.0 (2026.2.0.20261001)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/intel/oneapi/compiler/2026.2/bin/compiler
Configuration file: /opt/intel/oneapi/compiler/2026.2/bin/compiler/../icpx.cfg

hope these help.

@92es

92es commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

@moriz1 ,

leak_repro_sycl.cpp

If you could, please compile and run this out of tree memory leak test on your Arch Linux box with the 26.35 loader. The top of the cpp file has the compile, environment variables and run command in the [#if 0 #endif] section.

Test with SYCL_ENABLE_DEFAULT_CONTEXTS=1.

Adding @PoizenJam.

It uses

export UR_L0_LEAKS_DEBUG=1 # Turn on memory leak logging

to log the resource allocations and releases.

If it happens on the newer 26.35 loader, it will help with the bug report to Intel.

Thank you very much.

The tail of the output should look something like this if your oneAPI has the leak.

SYCL_ENABLE_DEFAULT_CONTEXTS=1
ONEAPI_DEVICE_SELECTOR=level_zero:0,1
SYCL_UR_USE_LEVEL_ZERO_V2=0
UR_L0_LEAKS_DEBUG=1
UR_LOADER_USE_LEVEL_ZERO_V2=0

Running leak_repro_sycl ...

done: 100 iters in 0.1s (751 it/s)
exiting ./leak_repro_sycl(162) after N 100 loop iterations
Check balance of create/destroy calls
----------------------------------------------------------
               zeContextCreate = 1     \--->              zeContextDestroy = 1    
          zeCommandQueueCreate = 0     \--->         zeCommandQueueDestroy = 0    
                zeModuleCreate = 0     \--->               zeModuleDestroy = 0    
                zeKernelCreate = 0     \--->               zeKernelDestroy = 0    
             zeEventPoolCreate = 3     \--->            zeEventPoolDestroy = 3    
  zeCommandListCreateImmediate = 5     |
           zeCommandListCreate = 0     \--->          zeCommandListDestroy = 5    
                 zeEventCreate = 407   \--->                zeEventDestroy = 207   ---> LEAK = 200
                 zeFenceCreate = 0     \--->                zeFenceDestroy = 0    
                 zeImageCreate = 0     |
          zeImageViewCreateExt = 0     \--->                zeImageDestroy = 0    
               zeSamplerCreate = 0     \--->              zeSamplerDestroy = 0    
              zeMemAllocDevice = 8     |
                zeMemAllocHost = 10    |
              zeMemAllocShared = 8     \--->                     zeMemFree = 26   
                                       \--->                  zeMemFreeExt = 0    

Adding @arthw

@arthw

arthw commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

when running Qwen 3.8-27B-UD-Q8_K_XL with dual B70 and -sm tensor, I'm now getting

Abort was called at 3560 line in file: /usr/src/debug/intel-compute-runtime/compute-runtime-26.35.39758.10/level_zero/core/source/cmdlist/cmdlist_hw.inl

same for running other models with -sm tensor.

my system is running archlinux with kernel 7.2.14-arch1-1 and intel-deep-learning-essentials package installed.

Only install intel-deep-learning-essentials is not enough.
It doesn't include oneDNN dll/so file.
Please install oneDNN: https://www.intel.com/content/www/us/en/developer/tools/oneapi/onednn-download.html

Install oneAPI toolkit package can cover above all.

@arthw

arthw commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

@92es

so i've thoroughly tested the two environment variables you gave me. here are the results:

SYCL_ENABLE_DEFAULT_CONTEXTS=0, `UR_LOADER_USE_LEVEL_ZERO_V2=1' (or unset)

* fixes the crash i mention

* slight decode performance increase (~3 t/s with speculative decoding off)

* no more memory leak ([Eval bug: potential memory leak with using `-sm tensor` during token generation with dual Intel B70 SYCL backend #27845](https://github.com/ggml-org/llama.cpp/issues/27845))

SYCL_ENABLE_DEFAULT_CONTEXTS=0, `UR_LOADER_USE_LEVEL_ZERO_V2=0'

* fixes crash

* same performance as before

* no more memory leak

SYCL_ENABLE_DEFAULT_CONTEXTS=1, `UR_LOADER_USE_LEVEL_ZERO_V2=0'

* fixes crash (because the changes of this PR is disabled, i assume?)

* same performance as before

* memory leak (llama-server's memory usage increases by about 10mb/s during decode)

SYCL_ENABLE_DEFAULT_CONTEXTS=1, `UR_LOADER_USE_LEVEL_ZERO_V2=1'

* crash (as i reported previously)

SYCL_ENABLE_DEFAULT_CONTEXTS=1 is not verified with SYCL backend.
SYCL backend has created the context for every queue and device in initial stage.
No need it I guess.

@arthw

arthw commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

For event leak, I know some PRs use event in the code. But I didn't see the release event code in them.
If a code which create event is called multiple times and without release the event, it leak the event.
Maybe AI agent can help scan it.

Thank you!

@92es

92es commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@arthw

when running Qwen 3.8-27B-UD-Q8_K_XL with dual B70 and -sm tensor, I'm now getting
Abort was called at 3560 line in file: /usr/src/debug/intel-compute-runtime/compute-runtime-26.35.39758.10/level_zero/core/source/cmdlist/cmdlist_hw.inl
same for running other models with -sm tensor.
my system is running archlinux with kernel 7.2.14-arch1-1 and intel-deep-learning-essentials package installed.

Only install intel-deep-learning-essentials is not enough. It doesn't include oneDNN dll/so file. Please install oneDNN: https://www.intel.com/content/www/us/en/developer/tools/oneapi/onednn-download.html

Install oneAPI toolkit package can cover above all.

I installed 2026.2 oneAPI toolkit yesterday (was running 2026.1.1), no changes with 2026.2.

Please run the following out of tree code. It appears there is an Intel oneAPI library VRAM leak that needs to be reported to Intel.

Instructions are at the top in the [#if 1 #endif] section.

leak_repro_sycl.cpp

iki007 added a commit to iki007/llama.cpp that referenced this pull request Nov 4, 2026
…a61c46)

The -X theirs replay of 190 commits onto master 162e2bb dropped upstream's side where both changed a hunk.
This commit sets the 9 files that differ to the one-time merge resolution (73fa61c46), so the tip's tree equals it:
ggml-sycl/fattn-mkl.cpp and fattn-onednn.cpp (ours: upstream's ggml-org#30761 fixes the same strides and per-sequence
offsets as 8e35c17 / a4cc5c9; the replay applied both offsets, ib * nb3 on top of K_batch), ggml-sycl/dmmv.cpp
(upstream's templated launchers, ggml-org#31325, without the three reorder launchers they replace), ggml-sycl/ggml-sycl.cpp
(upstream's comm_exchange pointer, ggml-org#30956, kept next to our host exchange, which returns first for one context),
ggml-sycl/CMakeLists.txt (upstream's pkg-config lookup, ggml-org#31076, our include line in its fallback),
common/speculative.cpp (upstream's DFlash device features, ggml-org#31506, next to our pos_inject; the MTP nextn setters
after is_mem_shared, ggml-org#31356), src/llama-context.cpp (ggml-org#31506's wait before our ubatch loop), src/models/dflash.cpp,
tests/test-backend-ops.cpp.

Assisted-by: Claude Opus 5.5
@arthw

arthw commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

I try to test the code on BMG580x2.
I install oneAPI 2026.2, upgrade the driver to latest: libze-intel-gpu1 26.40.40196.8-0.
I can reproduce the same issues.
Including the crash with UR_LOADER_USE_LEVEL_ZERO_V2=1 and event leak with UR_LOADER_USE_LEVEL_ZERO_V2=0.

I will report to repo: https://github.com/intel/compute-runtime.

Thank you!

@moriz1

moriz1 commented Nov 4, 2026 •

Copy link
Copy Markdown

when running Qwen 3.8-27B-UD-Q8_K_XL with dual B70 and -sm tensor, I'm now getting
Abort was called at 3560 line in file: /usr/src/debug/intel-compute-runtime/compute-runtime-26.35.39758.10/level_zero/core/source/cmdlist/cmdlist_hw.inl
same for running other models with -sm tensor.
my system is running archlinux with kernel 7.2.14-arch1-1 and intel-deep-learning-essentials package installed.

Only install intel-deep-learning-essentials is not enough. It doesn't include oneDNN dll/so file. Please install oneDNN: https://www.intel.com/content/www/us/en/developer/tools/oneapi/onednn-download.html

Install oneAPI toolkit package can cover above all.

@arthw

oneDNN is provided by intel-deep-learning-essentials. any attempt to install both it and the oneDNN package via pacman would throw a conflicting package error.

@PoizenJam

Copy link
Copy Markdown

@92es (thanks for tagging me in)
@arthw

Just popping in to reiterate the results from my testing in another issue report.

Windows 11 data point, 2x Arc Pro B70, llama.cpp SYCL build, -sm tensor: same-build A/B on a 25-minute growing-conversation test, Qwen3.8-27B Q4, -np 1.

Default contexts: private memory grew 142 MB/turn after turn 15 (28.1 to 43.3 GB over 72 turns). SYCL_ENABLE_DEFAULT_CONTEXTS=0: flat after a ~5 GB warm-up (0 MB/turn through turn 76), no speed loss (18.2 vs 19.3 s/turn).

Q8 at 262K context with -np 4 --kv-unified: also flat with the variable. So the leak and the workaround both apply on Windows too, and at least here default contexts are in use (the variable changes behaviour). Happy to run the repro if a Windows build would help.

@moriz1

moriz1 commented Nov 4, 2026

Copy link
Copy Markdown

@92es

i compiled your provided file with icpx -fsycl leak_repro_sycl.cpp -o leak_repro_sycl and tried to run it:

./leak_repro_sycl 
Abort was called at 3560 line in file:
/usr/src/debug/intel-compute-runtime/compute-runtime-26.35.39758.10/level_zero/core/source/cmdlist/cmdlist_hw.inl

using export SYCL_ENABLE_DEFAULT_CONTEXTS=0 seems to have no effect. same happens when i set the env to 1.

might be something i'm doing wrong on my end.

@arthw

arthw commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

@92es
I report this issue to level-zero: oneapi-src/level-zero#556.

Thank you!

@92es

92es commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@arthw

@92es I report this issue to level-zero: oneapi-src/level-zero#556.

Thank you!

Thank you for testing the out-of-tree test sample code and reporting it to Intel/level-zero.

edwardyoon pushed a commit to edwardyoon/focus-llama that referenced this pull request Nov 6, 2026
…#30956)

* Update ggml-sycl.cpp

Increases -sm tensor prompt eval t/s by +19% with zero PPL change.

* Update ggml-sycl.cpp

Replace first pair of wait() calls with ext_oneapi_submit_barrier().  The wait() calls was discovered to cause MTP degradation.

* Update ggml-sycl.cpp

Adding comm_exchange function pointer to switch between 2 and 4 buffer ggml_sycl_comm_exchange versions @ initialization time (versus hot path) controlled by SYCL_ENABLE_DEFAULT_CONTEXTS=1 setting.

* Update ggml-sycl.cpp

adding back 2nd half of 4-buffer free.

* Update ggml-sycl.cpp

Removing extra whitespace.

* Update ggml-sycl.cpp

Excluding Windows until it is validated on Windows.

(cherry picked from commit 2c93f0b)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ggml changes relating to the ggml tensor library for machine learning merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. SYCL https://en.wikipedia.org/wiki/SYCL - GPU programming language

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants