libxe2: m2xfp4 meta and exponents tiled too, each column's max exponent stored at load -- gate_up 222 -> 205 us

Where N % 16 == 0 and K % 512 == 0 the meta bytes (in the codes blob) and the E8M0 plane (b_scale,
tag "xe2.m2.e8m0.t16") are stored in chunks of a tile's 16 groups, [dword][lane], so the ESIMD
kernel reads four steps of them with one block load each instead of gathers across 16 rows. The
exponent plane's stored form appends each column's largest exponent (int32), computed once at
load, so the prepass no longer scans the plane on every call; unrelayout drops it and untiles the
exponents exactly. Every m2 reader reads the tiled forms.

rad-kbench against libref: 70 checked, 70 passed (worst rel_l2 1.2e-3). M = 8: gate_up 222 -> 205,
down 119 -> 113 us; prefill shapes flat to -5%. Greedy output identical; 512-token decode 33.3 ->
33.9 tok/s.

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 02:06:52 +01:00
1 parent 68d510b1f4
commit dad30c6b59
4 files changed
+124 -47

No files matched your search

+12 -5
View File
@@ -101,13 +101,20 @@ int gemm_m2_unrelayout(const RadParam* p, int n_p, int operand, const RadEncodin
const int* sel, const void* src, int64_t src_bytes, const RadTensor* planes,
int n);
/* The m2xfp4 codes tiled (xe2_gemm_m2.cpp's layout, tag "xe2.m2.tiled16"), where N % 16 == 0 and
* K % 128 == 0: a 16-column tile's 128-column step is 1 KiB, dword w (codes 8w .. 8w + 7) of its
* columns side by side -- the [word][lane] registers of the verify GEMM, one block load. m2t_off is
* byte b (codes 2b, 2b + 1) of column n's row; the meta rows follow the codes as before. */
inline bool m2_tiled(int64_t N, int64_t K) { return N % 16 == 0 && K % 128 == 0; }
/* The m2xfp4 planes tiled (xe2_gemm_m2.cpp's layout hooks), where N % 16 == 0 and K % 512 == 0.
* Codes ("xe2.m2.tiled16"): a 16-column tile's 128-column step is 1 KiB, dword w (codes 8w .. 8w + 7)
* of its columns side by side -- the [word][lane] registers of the verify GEMM, one block load;
* m2t_off is byte b (codes 2b, 2b + 1) of column n's row. The meta bytes after the codes and the
* E8M0 exponents ("xe2.m2.e8m0.t16") in chunks of a tile's 16 groups, 256 bytes [dword][lane], a
* dword four consecutive groups of a column; m2e_off is group g's byte of column n. The exponent
* plane's stored form then holds each column's largest exponent, int32, at m2_emax_off. */
inline bool m2_tiled(int64_t N, int64_t K) { return N % 16 == 0 && K % 512 == 0; }
inline int64_t m2t_off(int64_t n, int64_t b, int64_t K) {
return ((((n >> 4) * (K / 128) + (b >> 6)) * 16 + ((b >> 2) & 15)) * 64) + (n & 15) * 4 + (b & 3);
}
inline int64_t m2e_off(int64_t n, int64_t g, int64_t kg) {
return ((((n >> 4) * (kg / 16) + (g >> 4)) * 4 + ((g & 15) >> 2)) * 16 + (n & 15)) * 4 + (g & 3);
}
inline int64_t m2_emax_off(int64_t N, int64_t kg) { return (N * kg + 63) / 64 * 64; }
} // namespace xe2