libxe2: the int4 W4A16 release's GEMMs -- w4a16_asym on fp16 DPAS, w4a8i8_asym on int8 DPAS, quant_act_i8g

For qwen3.8-27b-w4a16-rtn (u4 codes, f16 scale and u4 zero per 128 of K): the engine casts a
linear's input to f16 for gemm_nt_q at w4a16_asym up to 64 rows a step, and quantises it with
quant_act_i8g for w4a8i8_asym above. None had a device kernel.

- The planes are stored tiled at load (xe2_ops.h, w4_tiled): a 16-column tile's codes side by
  side, the even codes of each dword in its low half so (w >> 4s) & 0x000F000F is a VNNI pair, and
  the scale with f16(1024 + zero) one dword a (column, group). unrelayout inverts both exactly.
- gemm_nt_q_w4: libref's gemm_zp loop per output, the exact form (XE2_EXACT=1, XE2_W4_EXACT=1).
- w4a16_asym, M <= 64: ESIMD, a thread a tile; (code | 0x6400) less f16(1024 + zero) is
  code - zero exactly; eight fp16 DPAS of RC = 1, 2, 4 or 8 rows a group, scaled in f32 a group.
  Narrow outputs split K. Probe w4d.cpp, incompressible codes: gate_up (N 34816, K 5120) 173 us at
  M = 1 (546 GB/s), 190 us at M = 4.
- w4a8i8_asym: int8 DPAS takes the tiled codes as its u4 B operand (nibble i meets A's byte i), so
  a prepass reorders the activation's bytes of each 8 evens first and forms each group's sum of
  codes; the group's integer sum is exact and its term ((sum - zero * asum) * a_scale) * scale is
  added in group order.
- quant_act_i8g: quant_act_fp8's form at libref's int8 rule (top 127).

rad-kbench and the op oracle cannot draw the zero-point grids, so XE2_W4_CHECK=n checks the first
n calls of each form against libref's loop on the host, on the engine's operands. On the 27B: the
exact form 0 of 81920 and 0 of 25600 outputs differ; w4a8i8 (M = 2048) 0 of 349568 and 0 of 327680;
w4a16 (M = 4) 0 of 65536 and 2 of 20480 (bf16 ties, rel_l2 5e-9). quant_act_i8g: rad-kbench
fixture 153/153 (quant_act*), the 27B 96/96, rel_l2 0. ctest -L sycl 3/3; the host tier's five
failures are the baseline's (FFmpeg, CPU budgets).

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 ab0175564b
commit efdfc4a570
7 files changed
+892 -48

No files matched your search

+36
View File
@@ -25,6 +25,11 @@ const RadConstraint cFp8Gated[] = { RAD_CIN("dtype", "fp8a8 fp8a8f32 fp8a16"), R
/* The zero-point grids over quant_act_i8's activation (xe2_gemm_zp.cpp). */
const RadConstraint cZpI8Dtype[] = { RAD_CIN("dtype", "w2a8 w4a8_asym") };
const RadConstraint cZpGemv[] = { RAD_CIN("dtype", "w2a8 w4a8_asym"), RAD_CLE("M", 16) };
/* The 4-bit zero-point grids of an int4 W4A16 release (xe2_gemm_w4.cpp): one stored form, so every
* row of either dtype shares gemm_w4_layout. */
const RadConstraint cW4Dtype[] = { RAD_CIN("dtype", "w4a16_asym w4a8i8_asym") };
const RadConstraint cW4a16[] = { RAD_CIN("dtype", "w4a16_asym"), RAD_CLE("M", 64) };
const RadConstraint cW4a8i8[] = { RAD_CIN("dtype", "w4a8i8_asym") };
/* The M2XFP4 grid over givens_dense_quant's fp8 activation (xe2_gemm_m2.cpp). */
const RadConstraint cM2Dtype[] = { RAD_CIN("dtype", "m2xfp4") };
/* The fp8 head's decode band. */
@@ -83,6 +88,11 @@ const RadKernelInfo kKernels[] = {
.shape = "any n and group",
.dtypes = "float in, E4M3 codes, f32 scales",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::quant_act_fp8 },
{ .name = "xe2_quant_act_i8g", .op = "quant_act_i8g", .family = "quant",
.computes = "row-major int8 codes and an f32 scale amax/127 per group, libref's q8_group",
.shape = "any n and group",
.dtypes = "float in, i8 codes, f32 scales",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::quant_act_i8g },
{ .name = "xe2_gated_quant_fp8", .op = "gated_quant_fp8", .family = "quant",
.computes = "silu(gate)*up or sigmoid(gate)*up over packed gate_up, bf16 narrowing, E4M3 "
"codes and an f32 scale per group",
@@ -279,6 +289,32 @@ const RadKernelInfo kKernels[] = {
.domain = RAD_DOMAIN_DEVICE, .constraints = cZpI8Dtype, .n_constraints = 1,
.launch = xe2::gemm_nt_q_zp, .layout = xe2::gemm_zp_layout,
.relayout = xe2::gemm_zp_relayout, .unrelayout = xe2::gemm_zp_unrelayout },
{ .name = "xe2_gemm_nt_q_w4a16", .op = "gemm_nt_q", .family = "gemm",
.computes = "Y = A B^T over u4 codes with an f16 scale and zero per (row, 128): codes decoded to "
"code - zero in fp16 registers, fp16 DPAS a group into f32, scaled once a group",
.shape = "M <= 64 (blocks of 8 rows); N a multiple of 16, K of 128, group 128 (else the exact form)",
.dtypes = "w4a16_asym: u4 codes, f16 scale and u4/u8 zero per (row, 128 of K), f16 activation",
.domain = RAD_DOMAIN_DEVICE, .priority = 10, .constraints = cW4a16, .n_constraints = 2,
.launch = xe2::gemm_nt_q_w4a16, .layout = xe2::gemm_w4_layout,
.relayout = xe2::gemm_w4_relayout, .unrelayout = xe2::gemm_w4_unrelayout },
{ .name = "xe2_gemm_nt_q_w4a8i8", .op = "gemm_nt_q", .family = "gemm",
.computes = "Y = A B^T over u4 codes against an int8 activation: int8 DPAS with the codes as its "
"u4 B operand, exact group sums, libref's group terms in order -- libref's result",
.shape = "any M; N a multiple of 32, K of 128, group 128 (else the exact form)",
.dtypes = "w4a8i8_asym: u4 codes, f16 scale and u4/u8 zero per (row, 128 of K), row-major int8 "
"activation with an f32 scale per (row, 128)",
.domain = RAD_DOMAIN_DEVICE, .priority = 10, .constraints = cW4a8i8, .n_constraints = 1,
.launch = xe2::gemm_nt_q_w4a8i8, .layout = xe2::gemm_w4_layout,
.relayout = xe2::gemm_w4_relayout, .unrelayout = xe2::gemm_w4_unrelayout },
{ .name = "xe2_gemm_nt_q_w4_ref", .op = "gemm_nt_q", .family = "gemm",
.computes = "Y = A B^T over the 4-bit zero-point grids, libref's gemm_zp per output; the "
"correctness-first form",
.shape = "any M, N; K a multiple of group",
.dtypes = "w4a16_asym (f16 activation), w4a8i8_asym (int8 activation, f32 scale per (row, "
"group)): u4 codes, f16 scale and u4/u8 zero per (row, group)",
.domain = RAD_DOMAIN_DEVICE, .constraints = cW4Dtype, .n_constraints = 1,
.launch = xe2::gemm_nt_q_w4, .layout = xe2::gemm_w4_layout,
.relayout = xe2::gemm_w4_relayout, .unrelayout = xe2::gemm_w4_unrelayout },
{ .name = "xe2_gemm_nt_q_m2_gemv", .op = "gemm_nt_q", .family = "gemm",
.computes = "Y = A B^T over the M2XFP4 grid for M <= 16: e2m1 to fp16 by bits, fp16 activation "
"and subgroup sums, f32 group sums; libref's products regrouped",