Repository navigation
[SYCL] fast ggml_sycl_comm_exchange() - +19% prompt eval -sm tensor t/s on Intel Arc Pro B70s - #30956
Conversation
Increases -sm tensor prompt eval t/s by +19% with zero PPL change.
Replace first pair of wait() calls with ext_oneapi_submit_barrier(). The wait() calls was discovered to cause MTP degradation.
|
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. PatchedA/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.
MTP
Notes~10% improvement in prompt evaluation speed (Time-to-First-Token) |
|
"... 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 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 -dev SYCL0,SYCL1 -f ggml-sycl.cpp -sm tensor -ts 1,1 -ub 512 |
|
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.5196 +/- 0.09056 - Patch barrier Tokens per second Stock 75.16 t/s vs Patch 72.24 t/s -dev SYCL0,SYCL1 -f ggml-sycl.cpp -sm tensor -ts 1,1 -seed 1234 -ub 512 PPL 2.5218 +/- 0.09077 - Stock As for your Windows crash, make sure code is q0:d2h_1 and q1:d2h_0. |
|
Hi @92es - Here is what we tested out: Here's what we found: Why it fails here: What this likely means for this PR: What would fix it: |
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.
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-divergenceAlso 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.
|
@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. I also removed the 60% allocation restriction on the B70 and it appears to work fine on my rig. |
|
@92es Answer your question:
The correct result should use b. Thank you! |
arthw
left a comment
There was a problem hiding this comment.
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!
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. Should I update the patch to exclude Windows ? UPDATE: Added the Windows exclusion until someone can validate it works on Windows. |
Excluding Windows until it is validated on Windows.
|
@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:
|
|
With 3xB70 and Qwen3.8-Flash-Next-GSQ-RCO-IQ3 by DasLab I don't have any performance increase |
|
when running Qwen 3.8-27B-UD-Q8_K_XL with dual B70 and
same for running other models with my system is running archlinux with |
|
@AdamN1 ,
The original allreduce() was written for 2 GPUs. This patch did not increase that limitation. See original exclusion code in alllreduce(): Maybe a potential future upgrade to N > 1 dGPUs instead of N==2 dGPUs. |
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 ? |
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. |
I don't have this set, so the default value. |
@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:
|
Model from DasLab Qwen3.8-27B-GSQ-RCO-IQ3_S-mtp.gguf hash: d562806dbafae37109975e970aae91b43e73b440
I would be more that happy to test. |
|
so i've thoroughly tested the two environment variables you gave me. here are the results:
|
|
What OS, version, kernel version and libze1 loader are you using ? 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.
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. 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. TIA for the testing. |
|
archlinux
|
|
Found the arch equivalents: hope these help. |
|
@moriz1 , 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
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. Adding @arthw |
Only install intel-deep-learning-essentials is not enough. Install oneAPI toolkit package can cover above all. |
|
|
For event leak, I know some PRs use event in the code. But I didn't see the release event code in them. Thank you! |
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. |
…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
|
I try to test the code on BMG580x2. I will report to repo: https://github.com/intel/compute-runtime. Thank you! |
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. |
|
@92es (thanks for tagging me in) 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. |
|
i compiled your provided file with using might be something i'm doing wrong on my end. |
|
@92es Thank you! |
Thank you for testing the out-of-tree test sample code and reporting it to Intel/level-zero. |
…#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)
Increases -sm tensor prompt eval t/s by +19% t/s ( making -sm tensor as fast as -sm layer ) with zero PPL change
Overview
Additional information
NOTE: PPL is inherently higher in tensor split mode than layer split in the base code, thus PPL has to be A/B compared with tensor/tensor or layer/layer, NOT tensor/layer. The same delta appears in both the mainline build and the patch build.
NOTE: This a complementary patch with sycl: add set_tensor_2d for faster tensor-split loading #30358 authored by @Captain-Tripps . This patch picks up tensor split mode optimizations where his hands off (load => runtime). They do NOT depend on each other, but complement each other.
NOTE: Related PR SYCL: reduce tensor allreduce sync with pinned host buffers #29604
UPDATE: First pair of waits replaced with barriers to restore MTP and remove host.
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
Tensor mode — patch gain over mainline
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)
Tensor mode: stock vs patched PPL (no change)
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