libxe2: the w4a8i8 prefill GEMM tiled through local memory -- 27 -> 62-78 int8 TOPS, prefill 291 -> 378 tok/s

The first form gave each thread 32 rows by 32 columns in 256 registers and its own 2D loads of the
activation: 23-29 TOPS at M = 2048 (probe w4p.cpp), and the probe's breakdown put the time in the
activation loads, then the group epilogue (DPAS alone ran 120 TOPS). Now a work-group of 8 threads
shares 16 rows: each group's activation is staged in local memory once, double-buffered, a step
a 2D load; a thread owns 16 rows by 32 columns in 128 registers (8 threads an EU) and runs the
group's epilogue on whole [8 rows][16] blocks against factors broadcast once; for outputs wider than
8192 the work-groups go rows fastest, so one 256-column slice of the weight stays in L2 while every
row block uses it. TOPS at M = 2048: gate_up 27 -> 78, N 16384 K 5120 27 -> 75, down 24 -> 62,
N 5120 K 6144 29 -> 78. The chain is unchanged: still libref's result bit for bit (XE2_W4_CHECK on
the 27B: 0 of 349568, 327680 and 445696 outputs differ).

quant_act_i8g for bf16 rows in groups of 128 reads a lane's 8 values in one 16-byte load and stores
its 8 codes in one 8-byte store, typed (677 us a call at 2048 x 5120 through the generic accessors);
the same floats and rounding: rad-kbench fixture 153/153 and the 27B 96/96, rel_l2 0.

Prefill, 2234 tokens: 7.68 -> 5.90 s (378 tok/s).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-10-28 00:52:58 +01:00
1 parent e85124c0f0
commit 2365a2ae51
2 files changed
+107 -36

No files matched your search

+37
View File
@@ -203,6 +203,43 @@ int quant_act_groups(const RadArgs* a, RadStream st, float top, const char* what
/* a sub-group a (row, group): the groups are independent, and a row's work-group walking its
* groups in turn ran ~5 us a group (48 us at n = 17408) */
const int64_t wpr = (ngrp + kSubs - 1) / kSubs; /* work-groups a row */
/* bf16 in, int8 out, groups of 128 (the int4 release's prefill quantiser): a lane's 8 values one
* 16-byte load and its 8 codes one 8-byte store, typed -- the generic accessors per element
* ran 677 us a call at 2048 rows of 5120. The same floats, amax, scale and rounding (round to
* nearest even and saturate, NaN to 0, rad_store_f32's rule). */
if (top == 127.0f && x.dtype == RAD_BF16 && qv.dtype == RAD_I8 && g == 128 && n % 128 == 0 &&
x.pitch % 8 == 0 && qv.pitch % 8 == 0 && rad_ptr_aligned(x.base, 16) && rad_ptr_aligned(qv.base, 8)) {
return submit([&] {
syclex::nd_launch(*q, sycl::nd_range<1>{(size_t)(rows * wpr) * kWg, kWg},
[=](sycl::nd_item<1> it) [[sycl::reqd_sub_group_size(kSub)]] {
const int64_t r = (int64_t)it.get_group(0) / wpr;
const sycl::sub_group sg = it.get_sub_group();
const int64_t gi = ((int64_t)it.get_group(0) % wpr) * kSubs + (int64_t)sg.get_group_linear_id();
if (gi >= ngrp) return; /* uniform over the sub-group */
const int lane = (int)sg.get_local_linear_id();
const int64_t k0 = gi * 128 + lane * 8;
const sycl::vec<uint16_t, 8> w = *(const sycl::vec<uint16_t, 8>*)((const uint16_t*)x.base + r * x.pitch + k0);
float c[8];
float amax = 0.0f;
for (int j = 0; j < 8; ++j) {
c[j] = rad_bf16_to_f32(w[j]);
amax = sycl::fmax(amax, sycl::fabs(c[j]));
}
amax = sycl::reduce_over_group(sg, amax, sycl::maximum<float>());
const float sc = amax > 0.0f ? amax * (1.0f / 127.0f) : 1.0f;
const float inv = 1.0f / sc;
sycl::vec<int8_t, 8> o;
for (int j = 0; j < 8; ++j) {
float v = c[j] * inv;
if (v > 127.0f) v = 127.0f;
if (v < -127.0f) v = -127.0f;
o[j] = v != v ? (int8_t)0 : (int8_t)sycl::rint(v);
}
*(sycl::vec<int8_t, 8>*)((int8_t*)qv.base + r * qv.pitch + k0) = o;
if (lane == 0) rad_store_f32(sv.base, sv.dtype, r * sv.pitch + gi, sc);
});
});
}
return submit([&] {
syclex::nd_launch(*q, sycl::nd_range<1>{(size_t)(rows * wpr) * kWg, kWg},
[=](sycl::nd_item<1> it) [[sycl::reqd_sub_group_size(kSub)]] {