M2XFP4 (MXFP4v2): quantiser, gfx1201 WMMA kernels, host rows, df2 wiring, .rad packer (Import::ParoM2), stability fixes (counters-in-scratch x3, aql publish fences), kbench rows, runbook (REMAINING.md)

This commit is contained in:
hugypufy committed 2026-10-23 12:25:59 +01:00
1 parent 9eaf10da6e
commit ea0908596b
60 files changed
+4619 -193

No files matched your search

+46 -6
View File
@@ -257,7 +257,10 @@ enum {
/* The same GEMM's 5-bit expert weight: per row, R4D_DT_MOEW4's nibble plane of the codes' low
* four bits (the magnitude), then the sign bits, one dword per 32 elements in the order the
* kernel merges them (r4d_layout.cpp, moew5_row). A row is 5K/8 bytes. */
R4D_DT_MOEW5 = RAD_DT_PLUGIN_BASE + 8
R4D_DT_MOEW5 = RAD_DT_PLUGIN_BASE + 8,
/* The M2XFP4 GEMMs' stored weight: R4D_DT_MXFP4_FRAG's fragment-order e2m1 codes, then the
* [K/32][N] meta plane the kernel reads beside the E8M0 exponents (r4d_layout.cpp, m2xfp4). */
R4D_DT_M2XFP4_FRAG = RAD_DT_PLUGIN_BASE + 9
};
/* The grouped MoE GEMM's code tables, as the four dwords w4_e4m3's byte permutes read
@@ -343,18 +346,55 @@ struct R4dMvCfg { int rb; };
/* The MXFP4 tiled GEMM's one axis: compiled arms of one template. 0 is the M crossover (TN=4 from
* M >= 2048), which needs M. */
static const int64_t kMxTn[] = { 0, 2, 4 };
static const RadTunable tGemmMxfp4Tiled[] = {
{ "tn", kMxTn, (int)(sizeof kMxTn / sizeof kMxTn[0]), 0,
"16-column fragments per wave: 2 = 256x64 block, 4 = 256x128. 0 = TN 4 from M >= 2048" },
};
/* The MXFP4 decode GEMM's axes. 0 on each is the kernel's own rule (r4d_gemm_mxfp4a8_decode.hip);
* `nt` 1 streams the weight past the caches, 2 loads it plainly. The M2XFP4 rows declare the same
* axes (r4d_rows.cpp) and resolve them through the same readers below, which sit in this header so
* a kernel unit links without the declaration side -- the r4d_emu build compiles the units alone. */
static const int64_t kMxDecKs[] = { 0, 1, 2, 4, 8, 16 };
static const int64_t kMxDecBk[] = { 0, 64, 128 };
static const int64_t kMxDecNt[] = { 0, 1, 2 };
static const RadTunable tGemmMxfp4Decode[] = {
{ "ks", kMxDecKs, (int)(sizeof kMxDecKs / sizeof kMxDecKs[0]), 0, "split-K workgroups a column block. 0 = the fill rule" },
{ "bk", kMxDecBk, (int)(sizeof kMxDecBk / sizeof kMxDecBk[0]), 0, "K slab in bytes. 0 = 128, or 64 for a wide unsplit DTM 4" },
{ "nt", kMxDecNt, (int)(sizeof kMxDecNt / sizeof kMxDecNt[0]), 0, "weight loads: 1 non-temporal, 2 plain. 0 = by weight size" },
};
/* The tuned configuration (r4d_rows.cpp's TUNE), inline so the kernel units carry it: the core
* appends the row's tuned point to RadArgs::p; a key absent falls to the axis default above. */
static inline int64_t r4d_tune_i(const RadArgs* a, const RadTunable* tab, int n, const char* key) {
long long v = 0;
if (rad_args_geti(a, key, &v)) return v;
for (int i = 0; i < n; ++i)
if (!std::strcmp(tab[i].key, key)) return tab[i].deflt;
return 0;
}
extern "C" {
/* -- the tuned configuration (r4d_rows.cpp) --
*
* The core picked a point in the space the row declared and appended it to RadArgs::p. These read
* it back, falling to the axis's default (defined once, in the RadTunable table) when a caller
* supplied none, so a checker with no tuned key runs what an untuned install runs. They cannot
* fail: the loader refuses a plugin whose default is not one of the axis's values. */
* it back, falling to the axis's default (defined once, above) when a caller supplied none, so a
* checker with no tuned key runs what an untuned install runs. They cannot fail: the loader
* refuses a plugin whose default is not one of the axis's values. */
void r4d_cfg_gemm (const RadArgs*, struct R4dGemmCfg*);
void r4d_cfg_tiled (const RadArgs*, struct R4dTileCfg*);
void r4d_cfg_prefill(const RadArgs*, struct R4dTileCfg*);
void r4d_cfg_mxfp4_tiled(const RadArgs*, struct R4dMxTileCfg*);
void r4d_cfg_mxfp4_decode(const RadArgs*, struct R4dMxDecCfg*);
inline void r4d_cfg_mxfp4_tiled(const RadArgs* a, struct R4dMxTileCfg* out) {
out->tn = (int)r4d_tune_i(a, tGemmMxfp4Tiled, (int)(sizeof tGemmMxfp4Tiled / sizeof tGemmMxfp4Tiled[0]), "tn");
}
inline void r4d_cfg_mxfp4_decode(const RadArgs* a, struct R4dMxDecCfg* out) {
out->ks = (int)r4d_tune_i(a, tGemmMxfp4Decode, (int)(sizeof tGemmMxfp4Decode / sizeof tGemmMxfp4Decode[0]), "ks");
out->bk = (int)r4d_tune_i(a, tGemmMxfp4Decode, (int)(sizeof tGemmMxfp4Decode / sizeof tGemmMxfp4Decode[0]), "bk");
out->nt = (int)r4d_tune_i(a, tGemmMxfp4Decode, (int)(sizeof tGemmMxfp4Decode / sizeof tGemmMxfp4Decode[0]), "nt");
}
void r4d_cfg_split (const RadArgs*, struct R4dSplitCfg*);
void r4d_cfg_ar (const RadArgs*, struct R4dArCfg*);
/* Whether the four-rank fused junction takes its tail form from 5 rows (the row's `tail` axis). */