libxe2: the w2a8 draft head on int8 DPAS with u2 B operands, codes tiled at load -- 2.56 -> 1.66 ms

This card's DPAS takes 2-bit B operands against s8 A, 16 codes a dword from the low end (probe
dpas_u2.cpp), so the drafter's 2-bit vocabulary head needs no decode: gemm_zp_layout stores the u2
codes tiled ("xe2.zp.u2.t16": a 16-column tile's 32-column step is 128 bytes, [dword][lane],
each dword the column's codes at the activation's stored positions -- quant_act_i8's step order is
folded into the layout), and an ESIMD kernel (xe2_gemm_zp_esimd.cpp) feeds them to DPAS as they
lie, against the activation staged in local memory as the A operand. Each group's sum is exact
in int32 and the terms are added in group order, as zp_dpas and libref do. The exact kernel and
the SIMT GEMV read the tiled form too.

Checked: 20 calls on the engine's real inputs, the ESIMD kernel against the SIMT GEMV on the same
bytes, 0 of 1738240 outputs differ each; greedy output identical (rad-kbench has no w2a8 recipe
on this container).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-10-26 03:18:30 +01:00
1 parent 5d09eb98b5
commit 34ae231e97
3 files changed
+205 -4

No files matched your search

+18
View File
@@ -117,4 +117,22 @@ inline int64_t m2e_off(int64_t n, int64_t g, int64_t kg) {
}
inline int64_t m2_emax_off(int64_t N, int64_t kg) { return (N * kg + 63) / 64 * 64; }
/* The zero-point GEMM's u2 codes tiled (xe2_gemm_zp.cpp, tag "xe2.zp.u2.t16") where N % 16 == 0,
* K % 32 == 0 and the group a multiple of 32: a 16-column tile's 32-column step is 128 bytes,
* dword [r][lane] holding the column's codes for the activation's stored positions 16 r .. 16 r +
* 15, two bits each from the low end -- the u2 B operand of an int8 DPAS as it lies. The
* activation is quant_act_i8's step order (position p holds column p with bits 2 and 3 swapped),
* so dword r's code u is logical column 32 s + swap23(16 r + u). zpt_code reads logical column k. */
inline bool zp_tiled(int cbits, int64_t N, int64_t K, int64_t group) {
return cbits == 2 && N > 0 && N % 16 == 0 && K > 0 && K % 32 == 0 && group > 0 && group % 32 == 0 && K % group == 0;
}
inline int64_t zpt_dword(int64_t n, int64_t s, int r, int64_t K) {
return (((n >> 4) * (K / 32) + s) * 2 + r) * 16 + (n & 15);
}
inline uint32_t zpt_code(const uint32_t* t, int64_t n, int64_t k, int64_t K) {
const int x = (int)(k & 31);
const int p = (x & ~12) | ((x & 4) << 1) | ((x & 8) >> 1);
return (t[zpt_dword(n, k >> 5, p >> 4, K)] >> (2 * (p & 15))) & 3u;
}
} // namespace xe2