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

+25 -2
View File
@@ -84,7 +84,20 @@ struct Scales {
uint32_t dt;
int64_t rs, cs, group, rblk;
bool e8m0;
/* M2XFP4 (libquant's `m2xfp4`, lq_m2xfp.cpp): `group` is 8, so `g` names a subgroup of
* eight columns. The E8M0 byte is one per four subgroups and the meta plane's two-bit field
* refines it, the scale of subgroup g being e8m0(scale[g >> 2]) . (1 + k/4) with k the
* field's value -- the quantiser's own decode, stated where this folds it into the product. */
const uint8_t* m2_meta = nullptr; /* [rows][K/32] meta bytes, canonical rows */
int64_t m2_mrs = 0; /* bytes between meta rows */
bool m2 = false;
inline float grp(int64_t row, int64_t g) const {
if (m2) {
const int64_t gi = g >> 2;
const int64_t i = (rblk > 1 ? row / rblk : row) * rs + gi * cs;
const int k = (m2_meta[row * m2_mrs + gi] >> (2 * (g & 3))) & 3;
return rad_e8m0_to_f32(((const uint8_t*)p)[i]) * (1.0f + 0.25f * (float)k);
}
const int64_t i = (rblk > 1 ? row / rblk : row) * rs + g * cs;
if (e8m0) {
const uint8_t e = ((const uint8_t*)p)[i];
@@ -95,6 +108,17 @@ struct Scales {
/* Groups [g0, g0 + n) of `row` into dst, the same values grp() returns, with the dtype
* resolved once rather than per scale. */
inline void row_groups(int64_t row, int64_t g0, int64_t n, float* dst) const {
if (m2) {
const int64_t rr = rblk > 1 ? row / rblk : row;
const uint8_t* b = (const uint8_t*)p;
for (int64_t g = 0; g < n; ++g) {
const int64_t gi = g0 + g;
const int k = (m2_meta[row * m2_mrs + (gi >> 2)] >> (2 * (gi & 3))) & 3;
dst[g] = rad_e8m0_to_f32(b[rr * rs + (gi >> 2) * cs]) *
(1.0f + 0.25f * (float)k);
}
return;
}
const int64_t base = (rblk > 1 ? row / rblk : row) * rs + g0 * cs;
const uint8_t* b = (const uint8_t*)p;
if (cs == 1) {
@@ -112,8 +136,7 @@ struct Scales {
for (int64_t g = 0; g < n; ++g)
dst[g] = rad_bf16_to_f32(((const uint16_t*)p)[base + g * cs]);
} else if (dt == RAD_F16) {
for (int64_t g = 0; g < n; ++g)
dst[g] = rad_f16_to_f32(((const uint16_t*)p)[base + g * cs]);
for (int64_t g = 0; g < n; ++g) dst[g] = rad_f16_to_f32(((const uint16_t*)p)[base + g * cs]);
} else if (dt == RAD_F32) {
for (int64_t g = 0; g < n; ++g) dst[g] = ((const float*)p)[base + g * cs];
} else {