mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #1215] [CLOSED] prefill MoE (SYCL): batch the per-expert GEMMs via oneMKL strided gemm_batch (+43% prefill on Arc Pro B70) #3313
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3313
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/1215
Author: @verycaptain
Created: 10/6/2026
Status: ❌ Closed
Base:
main← Head:pr-upstream-moe-batch📝 Commits (1)
97c611aprefill MoE (SYCL): batch the per-expert GEMMs via oneMKL strided gemm_batch📊 Changes
10 files changed (+149 additions, -96 deletions)
View changed files
📝
include/strata/prefill/gemm.hpp(+5 -0)📝
src/kernels/cpu/expert.cpp(+6 -0)📝
src/kernels/cpu/expert_layout.cpp(+6 -78)📝
sycl/include/dpct/util.hpp(+1 -1)➕
sycl/mkl-links/libmkl_core.so(+1 -0)➕
sycl/mkl-links/libmkl_gnu_thread.so(+1 -0)➕
sycl/mkl-links/libmkl_intel_lp64.so(+1 -0)➕
sycl/mkl-links/libmkl_rt.so(+1 -0)➕
sycl/mkl-links/libmkl_sycl_blas.so(+1 -0)📝
sycl/src/prefill/prefill.cpp(+126 -17)📄 Description
Batch the per-expert MoE GEMMs on the SYCL prefill walk (+43% prefill on Arc Pro B70)
What
STRATA_MOE_BATCH=1(default off, SYCL builds only): in the prefill MoE fallback walk, group 16 experts per layer, sort them by row count descending, pad each expert's rows to the group's max, and run gate/up and down as one stridedgemm_batchcall per group instead of 16 sequentialGemm::f16calls. NewGemm::f16_batch(oneMKL strided batch, falls back to sequential calls on any MKL exception).Supporting changes:
ordervector, so it is safe); the stream-all walk takes windowed cnt-desc sorts with W <= ring/2 so the slot-release walk keeps its id-order invariantWhy
oneMKL's fp16 batch efficiency scales with the per-matrix size: on Arc Pro B70, 39.9 TF/s at M=96 vs 123 TF/s at M=1024 (single-GEMM M-sweep). The engine's per-expert GEMMs at live chunk sizes sit far below that. Batching 16 experts with sorted order (padding ~1.03x; unsorted is 1.63x and a net loss) recovers most of the gap.
Measured (1x Intel Arc Pro B70, qwen3.8-flash-next IQ3_S/q4km, 124k cold prompt, alternating flag A/B on the same binary; the box has a second B70 running a separate production instance, not used for these numbers)
End-to-end numbers below were measured on our fork tree (0.1.39-merged, same engine code paths and the same port); the parity gates were then re-run against current upstream/main + this commit with the flag on.
Things I measured that shaped the design (worth knowing before reviewing)
gemm_batch(pointer arrays, per-expert n) is mediocre on this driver: 1.21x gate/up, 0.67x down. The strided form with uniform n per call is what MKL's batch kernel exploits.gemm_batchmust outlive the call: stack vectors destroyed after the call returns make MKL read freed memory and fake a driver DEVICE_LOST at large group counts. The port keeps them persistent; benches insycl/src/kernels/moe_bench/(available if you want them in-tree) reproduce both the crash and the fix.Not included
XMX alternatives were measured and regress on bmg-g31 (quantized GEMM 0.20-0.25x) — not used here.
Build note (pre-existing, not from this PR)
The SYCL tree does not build as-is against a current oneAPI nightly (icpx 7.1 / clang 22):
-fp-model=preciseis not a valid icpx argument,-qmklwas dropped from the compiler,cpuid.h's static__cpuidexcollides with the new builtin,__spirv_GroupNonUniformShuffle*calls are ambiguous for non-longT, and several shared headers have drifted past the SYCL copies (Gemm::bf16/nativegainedldx,load_experts_ggufgainedready,fused_gr_read_multi's return type differs). I patched all of these locally to build and gate this change; they are kept out of this PR to keep it scoped to the MoE batching. The parity gates (qsa_parity, iq_parity, qsa_prompt_attn_parity) build and pass with the flag on.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.