libxe2: every op Qwen3.8-27B-PARO-M2XFP4 needs, correctness first -- the 27B serves on the B65

Kernels, each libref's arithmetic in libref's order:
- gemm_nt_q at m2xfp4 (xe2_gemm_m2.cpp) with libref's m2 layout hooks, and givens_dense_quant
  (xe2_givens.cpp, the rotation in double as libref's)
- the gated delta net (xe2_gdn.cpp): gdn_conv_prep, gdn_conv_update, gdn_kkt_solve, gdn_chunk_scan,
  gdn_recurrent_update (per-candidate and anchor state forms), gdn_gated_rmsnorm,
  gdn_conv_recurrent_update; each work-item one iteration of libref's parallel loop, the
  per-(sequence, head) workspaces in a shared device workspace (xe2_common: workspace())
- rope's multi-component modes (mrope, imrope, axial) and rope_table
- logits_gemm over an fp8 128x128 joined head, gemm_nt_bias with its epilogue
- mul, sigmoid, scatter_rows, layernorm, grid_embed, attn_dense (the vision tower)
- dflash_conv and logit_rerank (plain and joined head) for the DFlash2 drafter

libref's gemm_m2 gains the parts (pb1/pb2) every other ParoQuant grid and libr4d's mx_parts
already define -- weight rows [0, e1), [e1, e2), [e2, N) read activation copies 0, 1, 2 side by
side -- since this model's fused projections are rotated per piece and the oracle declined them;
its shape hook widens a and a_scale by the part count. Both m2 arms now take the stored
codes-then-meta blob as the engine describes it, u8 [N, K], beside the shape hook's rank-1 form
(libref refused the engine's launch; only libr4d had been run on it).

rad-kbench on the fixture: every new row at rel_l2 0 (90 gdn/givens cases, 108 rope, 80
elementwise, 20 attn_dense, the drafter's and the heads'). On the B65 the model starts with every
op on the card and answers "The capital of France is" -> " Paris.\nThe capital of Germany is
Berlin.\nThe capital of Italy is" (greedy), at 0.1 tok/s: the correctness-first kernels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
This commit is contained in:
pascallinxweilerandClaude Opus 5.5 committed 2026-10-24 00:30:40 +02:00
1 parent f98b4070cd
commit 4921641578
15 files changed
+2251 -78

No files matched your search

+109 -2
View File
@@ -11,7 +11,7 @@
namespace {
const RadConstraint cRopeModes[] = { RAD_CIN("mode", "neox gptj") };
const RadConstraint cRopeModes[] = { RAD_CIN("mode", "neox gptj mrope imrope axial") };
/* The GEMMs here read float weights only; a quantised dtype key is gemm_nt_q's. */
const RadConstraint cFloatDtype[] = { RAD_CIN("dtype", "bf16 f16 fp16 f32 fp32") };
/* The decode band of the skinny bf16 GEMV (xe2_gemv.cpp). */
@@ -24,6 +24,8 @@ const RadConstraint cFp8Dtype[] = { RAD_CIN("dtype", "fp8a8 fp8a8f32 fp8a16") };
const RadConstraint cFp8Gated[] = { RAD_CIN("dtype", "fp8a8 fp8a8f32 fp8a16"), RAD_CLE("N", 57344) };
/* The zero-point grids over quant_act_i8's activation (xe2_gemm_zp.cpp). */
const RadConstraint cZpI8Dtype[] = { RAD_CIN("dtype", "w2a8 w4a8_asym") };
/* The M2XFP4 grid over givens_dense_quant's fp8 activation (xe2_gemm_m2.cpp). */
const RadConstraint cM2Dtype[] = { RAD_CIN("dtype", "m2xfp4") };
/* Rows by field name (C++20 designated initialisers must follow declaration order, so the compiler
* checks it), unlike a positional table where a shifted field can still compile. */
@@ -34,6 +36,29 @@ const RadKernelInfo kKernels[] = {
.dtypes = "any float dtype in and out (bf16, f16, f32, fp8), f32 arithmetic, rounded as libref",
.domain = RAD_DOMAIN_DEVICE, .priority = 0,
.launch = xe2::add },
{ .name = "xe2_mul", .op = "mul", .family = "elem",
.computes = "elementwise product, b broadcast along rows when it is one row",
.shape = "any n and row count; rows may be padded, the last axis dense",
.dtypes = "any float dtype in and out, f32 arithmetic, rounded as libref",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::mul },
{ .name = "xe2_sigmoid", .op = "sigmoid", .family = "elem",
.computes = "1 / (1 + exp(-x)), the exp in double rounded once as libref's",
.shape = "any element count; any strides", .dtypes = "any float dtype in and out",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::sigmoid },
{ .name = "xe2_scatter_rows", .op = "scatter_rows", .family = "gather",
.computes = "row m of v to row idx[m] of x; a negative index skipped, one past x refused",
.shape = "any n and row counts; rows may be padded, the last axis dense",
.dtypes = "any float dtype; integer indices",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::scatter_rows },
{ .name = "xe2_layernorm", .op = "layernorm", .family = "norm",
.computes = "layer norm with a gain and an optional bias, libref's serial sums",
.shape = "any n and row count; rows may be padded, the last axis dense",
.dtypes = "any float dtype in and out",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::layernorm },
{ .name = "xe2_grid_embed", .op = "grid_embed", .family = "elem",
.computes = "x += a square position table bilinearly resampled at each row's grid cell",
.shape = "any n, rows and side", .dtypes = "any float dtype; integer coordinates",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::grid_embed },
{ .name = "xe2_rmsnorm", .op = "rmsnorm", .family = "norm",
.computes = "RMS norm, one work-group a row, f32 work-group reduction",
@@ -61,10 +86,14 @@ const RadKernelInfo kKernels[] = {
{ .name = "xe2_rope", .op = "rope", .family = "rope",
.computes = "rotary embedding in place over q and k heads; frequency ladder (YaRN, llama3) "
"on the host as libref builds it, cos/sin in double",
.shape = "neox or gptj, one position component a token, rotary_dim <= 256",
.shape = "neox, gptj, mrope, imrope, axial; [M] or [C, M] positions, rotary_dim <= 256",
.dtypes = "bf16 qkv (any float), integer or float positions",
.domain = RAD_DOMAIN_DEVICE, .constraints = cRopeModes, .n_constraints = 1,
.launch = xe2::rope },
{ .name = "xe2_rope_table", .op = "rope_table", .family = "rope",
.computes = "cos and sin rows per position on libref's ladder (YaRN), in double",
.shape = "rot <= 256", .dtypes = "integer positions, float table",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::rope_table },
{ .name = "xe2_embed_lookup", .op = "embed_lookup", .family = "vocab",
.computes = "embedding gather times mult; an id outside the table writes a zero row",
.shape = "any n_embd and n_vocab, vocab_offset",
@@ -234,6 +263,84 @@ 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_m2_ref", .op = "gemm_nt_q", .family = "gemm",
.computes = "Y = A B^T over the M2XFP4 grid against givens_dense_quant's fp8 activation, "
"libref's gemm_m2 per output; the correctness-first form",
.shape = "any M, N; K a multiple of 32, group 32",
.dtypes = "m2xfp4: e2m1 codes and u8 meta concatenated, e8m0 scale per (row, 32); E4M3 "
"activation with a scale per 128 columns",
.domain = RAD_DOMAIN_DEVICE, .constraints = cM2Dtype, .n_constraints = 1,
.launch = xe2::gemm_nt_q_m2, .layout = xe2::gemm_m2_layout,
.relayout = xe2::gemm_m2_relayout, .unrelayout = xe2::gemm_m2_unrelayout },
{ .name = "xe2_givens_dense_quant", .op = "givens_dense_quant", .family = "quant",
.computes = "ParoQuant's activation quantiser: x / D through a dense 128x128 rotation per "
"(part, group) in double, then the fp8 or i8 group quantiser; libref's form",
.shape = "any rows; n a multiple of 128, group 128, any parts",
.dtypes = "float x, f16 rotation, float channel scales; E4M3 or i8 codes, f32 scales",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::givens_dense_quant },
{ .name = "xe2_attn_dense", .op = "attn_dense", .family = "attn",
.computes = "unpaged dense attention over cu_seqlens segments (causal, window, blocks); "
"libref's two passes, exp in double",
.shape = "head_dim <= 256, any heads, gqa, segments", .dtypes = "any float q, k, v, o",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::attn_dense },
{ .name = "xe2_dflash_conv", .op = "dflash_conv", .family = "draft",
.computes = "DFlash2's per-block causal tap conv with per-row tap deltas; libref's order",
.shape = "any T, taps, groups, block size", .dtypes = "any float dtype",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::dflash_conv },
{ .name = "xe2_logit_rerank", .op = "logit_rerank", .family = "draft",
.computes = "R candidates a row rescored against a float head in double, row_topk's order",
.shape = "any rows and R", .dtypes = "float x and head; integer ids",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::logit_rerank },
{ .name = "xe2_logit_rerank_head", .op = "logit_rerank", .family = "draft",
.computes = "R candidates a row rescored against a head of codes and a scale plane, joined",
.shape = "any rows and R", .dtypes = "float x; E4M3 or i8 codes with a float scale",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::logit_rerank_head, .layout = xe2::head_layout,
.relayout = xe2::head_relayout, .unrelayout = xe2::head_unrelayout },
{ .name = "xe2_gemm_nt_bias_ref", .op = "gemm_nt_bias", .family = "gemm",
.computes = "Y = A B^T + bias, then gelu / gelu_tanh and a residual; libref's order",
.shape = "any M, N, K", .dtypes = "float A and B",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::gemm_nt_bias },
{ .name = "xe2_logits_gemm_head_ref", .op = "logits_gemm", .family = "vocab",
.computes = "the lm_head over a head of E4M3 / int8 codes with a scale plane, joined; each "
"weight decoded to code * scale, then libref's plain product",
.shape = "any M, n_vocab, n_embd", .dtypes = "float A; E4M3 or i8 codes, float block scale",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::logits_gemm_head, .layout = xe2::head_layout,
.relayout = xe2::head_relayout, .unrelayout = xe2::head_unrelayout },
{ .name = "xe2_gdn_conv_prep", .op = "gdn_conv_prep", .family = "gdn",
.computes = "the causal conv with silu and its state, the q/k l2 norm, the chunked gate cumsum and beta; libref's arithmetic",
.shape = "q, k, v as [T, heads, width]; conv width <= 17",
.dtypes = "any float dtype; integer cu, slots and counts",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::gdn_conv_prep },
{ .name = "xe2_gdn_conv_update", .op = "gdn_conv_update", .family = "gdn",
.computes = "the decode step's causal conv against the rolling window, shifted by one; libref's arithmetic",
.shape = "q, k, v as [T, heads, width]; conv width <= 17",
.dtypes = "any float dtype; integer cu, slots and counts",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::gdn_conv_update },
{ .name = "xe2_gdn_kkt_solve", .op = "gdn_kkt_solve", .family = "gdn",
.computes = "(I + strict_lower(beta K K^T e^{g_i-g_j}))^-1 per chunk and v head, forward substitution; libref's arithmetic",
.shape = "q, k, v as [T, heads, width]; conv width <= 17",
.dtypes = "any float dtype; integer cu, slots and counts",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::gdn_kkt_solve },
{ .name = "xe2_gdn_chunk_scan", .op = "gdn_chunk_scan", .family = "gdn",
.computes = "the chunked delta-rule scan over a prefill chunk, state in and out; libref's arithmetic",
.shape = "q, k, v as [T, heads, width]; conv width <= 17",
.dtypes = "any float dtype; integer cu, slots and counts",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::gdn_chunk_scan },
{ .name = "xe2_gdn_recurrent_update", .op = "gdn_recurrent_update", .family = "gdn",
.computes = "the decode delta-rule step against the paged state, gated RMS norm folded in; libref's arithmetic",
.shape = "q, k, v as [T, heads, width]; conv width <= 17",
.dtypes = "any float dtype; integer cu, slots and counts",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::gdn_recurrent_update },
{ .name = "xe2_gdn_gated_rmsnorm", .op = "gdn_gated_rmsnorm", .family = "gdn",
.computes = "x rsqrt(mean(x^2) + eps) w act(z) per (token, head); libref's arithmetic",
.shape = "q, k, v as [T, heads, width]; conv width <= 17",
.dtypes = "any float dtype; integer cu, slots and counts",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::gdn_gated_rmsnorm },
{ .name = "xe2_gdn_conv_recurrent_update", .op = "gdn_conv_recurrent_update", .family = "gdn",
.computes = "gdn_conv_update then gdn_recurrent_update, libref's definition of the pair; libref's arithmetic",
.shape = "q, k, v as [T, heads, width]; conv width <= 17",
.dtypes = "any float dtype; integer cu, slots and counts",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::gdn_conv_recurrent_update },
};
const RadPluginInfo kInfo = {