libxe2: bf16 GEMV at 9-16 rows on DPAS, the weight read once

At 9 <= M <= 16 the bf16 skinny GEMM (gemm_nt, logits_gemm) fell to the SIMT kernel's one column a
sub-group, 6-8x the 8-row DPAS kernel's time on the same weight. The ESIMD kernel gains RC = 16: two
8-row DPAS on each transposed weight tile, rows past M clamped by the 2D load and not stored.

MiniCPM5-2B bf16 on the Arc Pro B65 (rad-kbench --bench, cold weights, M = 16): gate_up
712 -> 104 us, down 465 -> 61, qkv 148 -> 29, o 145 -> 25. Twelve concurrent 256-token streams:
198 -> 654 tok/s aggregate. rad-kbench gemm_nt + logits_gemm: MiniCPM5 360/360, fixture 686/686.
XE2_GEMV_SIMT=1 keeps the SIMT form.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-11-08 01:38:14 +01:00
1 parent 3582900903
commit 2f1fdd4d11
2 files changed
+32 -11

No files matched your search

+21 -10
View File
@@ -1,9 +1,9 @@
/* xe2_gemv_esimd.cpp -- the skinny bf16 GEMM (gemm_nt and logits_gemm at M <= 8) in ESIMD.
/* xe2_gemv_esimd.cpp -- the skinny bf16 GEMM (gemm_nt and logits_gemm at M <= 16) in ESIMD.
*
* A thread owns a (16-column tile, K split): per 16 columns of K it takes W^T straight from the
* weight rows by one transposed 2D load (16 rows by 8 dwords, which is the bf16 DPAS's VNNI B
* operand as it arrives) and the activation rows by a 2D load (rows past M read as zeros), and runs
* one DPAS of RC = 1, 2, 4 or 8 rows. A work-group is one tile's S splits; their partial sums meet in
* one DPAS of RC = 1, 2, 4 or 8 rows (RC = 16: two 8-row DPAS on each weight tile). A work-group is one tile's S splits; their partial sums meet in
* local memory and are added in split order, so the result is the same run to run. S is chosen for
* ~8192 threads: narrow outputs need many splits to fill the card (probe bfg.cpp, M = 1 unless said):
*
@@ -26,9 +26,13 @@ namespace xmx = sycl::ext::intel::esimd::xmx;
constexpr int kMaxS = 40;
/* RC rows a DPAS; RC = 16 is two 8-row DPAS on each weight tile, so 9-16 rows still read the weight
* once (the second band's rows past mm are clamped by the 2D load and never stored). */
template <int RC>
int launch(sycl::queue& q, const uint16_t* a, int64_t ars, int mm, const uint16_t* w, int64_t wrs, char* yb,
uint32_t ydt, int64_t yrs, int64_t N, int64_t K, int S) {
constexpr int RD = RC > 8 ? 8 : RC; /* rows a DPAS */
constexpr int NB = RC > 8 ? 2 : 1; /* DPAS bands */
const int64_t tiles = N / 16;
const int64_t kper = K / S;
return submit([&] {
@@ -39,16 +43,22 @@ int launch(sycl::queue& q, const uint16_t* a, int64_t ars, int mm, const uint16_
const int64_t n0 = (int64_t)it.get_group(0) * 16, k0 = sp * kper;
const unsigned wsw = (unsigned)(K * 2 - 1), wsh = (unsigned)(N - 1), wsp = (unsigned)(wrs * 2 - 1);
const unsigned asw = (unsigned)(K * 2 - 1), ash = (unsigned)(mm - 1), asp = (unsigned)(ars * 2 - 1);
simd<float, RC * 16> c = 0.0f;
simd<float, RD * 16> c[NB];
#pragma unroll
for (int b = 0; b < NB; ++b) c[b] = 0.0f;
for (int64_t k = k0; k < k0 + kper; k += 16) {
simd<uint32_t, 128> bt = load_2d<uint32_t, 8, 16, 1, true>((const uint32_t*)w, wsw, wsh, wsp, (int)(k / 2), (int)n0);
simd<uint16_t, RC * 16> av;
if constexpr (RC == 1) av = block_load<uint16_t, 16>(a + k);
else av = load_2d<uint16_t, 16, RC, 1, false>(a, asw, ash, asp, (int)k, 0);
c = xmx::dpas<8, RC, float, float, uint32_t, uint16_t, xmx::dpas_argument_type::bf16,
xmx::dpas_argument_type::bf16>(c, bt, av);
#pragma unroll
for (int b = 0; b < NB; ++b) {
simd<uint16_t, RD * 16> av;
if constexpr (RC == 1) av = block_load<uint16_t, 16>(a + k);
else av = load_2d<uint16_t, 16, RD, 1, false>(a, asw, ash, asp, (int)k, b * 8);
c[b] = xmx::dpas<8, RD, float, float, uint32_t, uint16_t, xmx::dpas_argument_type::bf16,
xmx::dpas_argument_type::bf16>(c[b], bt, av);
}
}
slm_block_store<float, RC * 16>((uint32_t)(sp * RC * 16 * 4), c);
#pragma unroll
for (int b = 0; b < NB; ++b) slm_block_store<float, RD * 16>((uint32_t)((sp * RC + b * 8) * 16 * 4), c[b]);
barrier();
for (int r = sp; r < RC && r < mm; r += S) { /* row r's 16 sums, the splits in order */
simd<float, 16> s = 0.0f;
@@ -88,7 +98,8 @@ int gemv_esimd(sycl::queue& q, int rc, const uint16_t* a, int64_t ars, int mm, c
case 1: return launch<1>(q, a, ars, mm, w, wrs, yb, ydt, yrs, N, K, S);
case 2: return launch<2>(q, a, ars, mm, w, wrs, yb, ydt, yrs, N, K, S);
case 4: return launch<4>(q, a, ars, mm, w, wrs, yb, ydt, yrs, N, K, S);
default: return launch<8>(q, a, ars, mm, w, wrs, yb, ydt, yrs, N, K, S);
case 8: return launch<8>(q, a, ars, mm, w, wrs, yb, ydt, yrs, N, K, S);
default: return launch<16>(q, a, ars, mm, w, wrs, yb, ydt, yrs, N, K, S);
}
}