libxe2: the int8 lm_head in ESIMD -- 96 ms -> ~2.5 ms a call at N = 248320, K = 5120

An int4 release's head is int8 codes with a bf16 scale per (row, 128 of K), joined. head_dpas
reads E4M3 only, and its fallback walked a column a lane in f32: 96 ms a call, 35 of a decode
token's 61 ms (profile_decode.sh). The ESIMD form reads 16 columns' rows 16 bytes a lane (d32x4
gathers), turns a byte into fp16 exactly as (b ^ 0x80) | 0x6400 less 1152, paired (0, 2) and (1, 3)
as the fp8 path pairs its bytes so the prepass's activation serves both, and sums a 128-block on
fp16 DPAS scaled once. head_dpas leaves exactly this form to it (head_i8_fast); both read the
planes on the card.

rad-kbench on qwen3.8-27b-w4a16-rtn: logits_gemm 28/28 (worst rel_l2 1.7e-3, tolerance 8e-3).
Decode, story prompt with the MTP drafter: 15.0 -> 43.2 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:06:22 +01:00
1 parent efdfc4a570
commit e85124c0f0
2 files changed
+168 -1

No files matched your search

+12 -1
View File
@@ -286,6 +286,7 @@ int head_dpas(sycl::queue& q, const sycl::half* a16, const float* rr, const char
if (n0 >= N) return; /* uniform */
const HPlane cp = hplane(bb, "codes"), sp = hplane(bb, "scale");
if (!cp.p || !sp.p) return;
if (head_i8_fast(cp.dt, cp.row_bytes, sp.br, sp.bc, sp.dt, K)) return; /* xe2_head_esimd.cpp's */
const int64_t n = sycl::min(n0 + lane, N - 1);
const uint8_t* crow = (const uint8_t*)cp.p + n * cp.row_bytes;
if (cp.dt != RAD_F8E4M3 || !(sp.bc == 0 || sp.bc % 64 == 0) || cp.row_bytes % 16 ||
@@ -352,6 +353,10 @@ int head_dpas(sycl::queue& q, const sycl::half* a16, const float* rr, const char
});
}
/* xe2_head_esimd.cpp */
int head_i8_esimd(sycl::queue& q, int rc, const sycl::half* a16, const float* rr, const char* bb, char* yb,
uint32_t ydt, int64_t N, int64_t K, int64_t yrs, int64_t ycs, int mm);
int logits_gemm_head_gemv(const RadArgs* a, RadStream st) {
if (exact_only()) return logits_gemm_head(a, st);
if (!a || a->n_t < 3 || !a->t[0].data || !a->t[1].data || !a->t[2].data) return RAD_E_INVAL;
@@ -402,7 +407,13 @@ int logits_gemm_head_gemv(const RadArgs* a, RadStream st) {
const char* bb = (const char*)B->data;
char* yb = (char*)Y->data;
const int mm = (int)M;
if (dpas) return head_dpas(*q, a16, rr, bb, yb, Y->dtype, N, K, yrs, ycs, mm);
if (dpas) {
/* head_dpas serves the E4M3 head and every form but the int8 one, which it leaves to the
* ESIMD kernel (each reads the planes on the card; a form not its own returns at once) */
if (int r = head_dpas(*q, a16, rr, bb, yb, Y->dtype, N, K, yrs, ycs, mm); r != RAD_OK) return r;
return head_i8_esimd(*q, mm == 1 ? 1 : (mm <= 2 ? 2 : (mm <= 4 ? 4 : 8)), a16, rr, bb, yb, Y->dtype, N, K, yrs,
ycs, mm);
}
if (mm == 1) return head_gemv<1>(*q, a16, rr, bb, yb, Y->dtype, N, K, yrs, ycs, mm);
if (mm <= 8) return head_gemv<8>(*q, a16, rr, bb, yb, Y->dtype, N, K, yrs, ycs, mm);
return head_gemv<16>(*q, a16, rr, bb, yb, Y->dtype, N, K, yrs, ycs, mm);