libxe2: gemm_nt and logits_gemm, correctness first

One work-item an output, f32 over ascending k from zero with no fused multiply-add: libref's
gemm_plain order, so MiniCPM5-2B's projections and its 130560-row head agree with the reference
exactly. Slow on purpose; the XMX kernels of Phase 4 are checked against this and libref. The rows
take float weights only (a dtype constraint); a quantised weight is gemm_nt_q's.

rad-kbench against libref: fixture 276/276, MiniCPM5-2B 164/164 (rel_l2 0).

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-23 16:09:17 +02:00
1 parent fca4cbe3b5
commit c52f76c33e
3 files changed
+97

No files matched your search

+16
View File
@@ -12,6 +12,8 @@
namespace {
const RadConstraint cRopeModes[] = { RAD_CIN("mode", "neox gptj") };
/* 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") };
/* 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. */
@@ -68,6 +70,20 @@ const RadKernelInfo kKernels[] = {
.shape = "contiguous operands",
.dtypes = "any float or integer pair",
.domain = RAD_DOMAIN_DEVICE, .launch = xe2::cast },
{ .name = "xe2_gemm_nt_ref", .op = "gemm_nt", .family = "gemm",
.computes = "Y = A B^T, one work-item an output, f32 over ascending k (libref's order); the "
"correctness-first form, not the fast one",
.shape = "any M, N, K; strided A",
.dtypes = "float A and W (bf16 in the recipes), float Y",
.domain = RAD_DOMAIN_DEVICE, .constraints = cFloatDtype, .n_constraints = 1,
.launch = xe2::gemm_nt },
{ .name = "xe2_logits_gemm_ref", .op = "logits_gemm", .family = "gemm",
.computes = "logits = x lm_head^T, as xe2_gemm_nt_ref",
.shape = "any M, n_vocab, n_embd",
.dtypes = "float x and head, f32 logits",
.domain = RAD_DOMAIN_DEVICE, .constraints = cFloatDtype, .n_constraints = 1,
.launch = xe2::logits_gemm },
};
const RadPluginInfo kInfo = {