From b52a1801417e7b8d1906731aa16637ffbf2fc8c0 Mon Sep 17 00:00:00 2001 From: aneinander Date: Wed, 18 Nov 2026 21:20:16 +0100 Subject: [PATCH] libxe2: split the ESIMD GEMV along K for wide outputs too gemv_esimd_splits only aimed at ~8192 threads, so an output wide enough to fill the card at one split (the lm head, N = 248320) ran S = 1: each thread walked all of K alone and was latency-bound at ~350-530 GB/s. The split now also keeps K a thread at ~1024 or less. rad-kbench, B65, cold weights (us): logits_gemm n_vocab 248320 n_embd 5120 M=1 4710 -> 4255 M=4 4674 -> 4289 logits_gemm n_vocab 248320 n_embd 4096 M=1 3652 -> 3418 gemm_nt N 34816 K 5120 M=1 621 -> 605 other gemm_nt shapes unchanged. kbench 1989/1989 replay, model checks pass; Qwen3.8-27B greedy output unchanged. Co-Authored-By: Claude Opus 5.5 --- libxe2/xe2_gemv_esimd.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libxe2/xe2_gemv_esimd.cpp b/libxe2/xe2_gemv_esimd.cpp index 88151bb0..690f2b2d 100644 --- a/libxe2/xe2_gemv_esimd.cpp +++ b/libxe2/xe2_gemv_esimd.cpp @@ -17,6 +17,8 @@ #include +#include + namespace xe2 { namespace { @@ -78,11 +80,14 @@ int launch(sycl::queue& q, const uint16_t* a, int64_t ars, int mm, const uint16_ } // namespace -/* The split count for N columns and K: the smallest divisor of K / 16 that gives ~8192 threads, at - * most kMaxS; 0 when K / 16 has none worth taking (the caller then keeps its SIMT form). */ +/* The split count for N columns and K: the smallest divisor of K / 16 that gives ~8192 threads and + * at most ~1024 of K a thread, at most kMaxS; 0 when K / 16 has none worth taking (the caller then + * keeps its SIMT form). The K bound is for wide outputs that fill the card at one split: a thread + * walking all of a long K alone is latency-bound (probe bfgl.cpp, M = 1, cold weights: logits + * N 248320 K 5120 S 1 7.27 ms, 350 GB/s -> S 5 4.21 ms, 604 GB/s; K 4096 S 1 5.78 -> S 4 3.39 ms). */ int gemv_esimd_splits(int64_t N, int64_t K) { const int64_t tiles = N / 16, steps = K / 16; - const int64_t want = (8192 + tiles - 1) / tiles; + const int64_t want = std::max((8192 + tiles - 1) / tiles, (K + 1023) / 1024); int best = 0; for (int s = 1; s <= kMaxS && s <= steps; ++s) { if (steps % s) continue;