Archived
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:
1 parent
9eaf10da6e
commit
ea0908596b
60 files changed
+4619
-193
No files matched your search
+56
-30
@@ -4808,6 +4808,16 @@ static const RadConstraint cGemmMxfp4A8Decode[] = {
|
||||
static const RadConstraint cGemmMxfp4A8Tiled[] = {
|
||||
C_GE("M", 1), C_DIV("K", 64), C_DIV("N", 16), C_IN("dtype", "mxfp4a8"),
|
||||
};
|
||||
/* The M2XFP4 rows (r4d_gemm_m2xfp4a8_*.hip): the same bands at the m2xfp4 encoding, whose dtype
|
||||
* string alone separates them -- no skinny M2 row exists, so the decode row owns M <= 128 outright
|
||||
* and the tiled row everything above, with no priority question between them (MXDEC outranks TILED
|
||||
* wherever both match, as for mxfp4a8). */
|
||||
static const RadConstraint cGemmM2xfp4A8Decode[] = {
|
||||
C_LE("M", 128), C_LE("N", 36864), C_DIV("K", 64), C_DIV("N", 16), C_IN("dtype", "m2xfp4"),
|
||||
};
|
||||
static const RadConstraint cGemmM2xfp4A8Tiled[] = {
|
||||
C_GE("M", 1), C_DIV("K", 64), C_DIV("N", 16), C_IN("dtype", "m2xfp4"),
|
||||
};
|
||||
/* r4d_gemm_w8a8_tiled: the same kernel at radix 8. Its asym arm is not declared in r4d.h, so
|
||||
* `w8a8_asym` is absent from the dtype set. */
|
||||
static const RadConstraint cGemmW8A8Tiled[] = {
|
||||
@@ -4903,24 +4913,9 @@ static const RadTunable tGemmPrefill[] = {
|
||||
"compiled tile arm; 0 is BM 128 x BN 256, libr4d's own default" },
|
||||
};
|
||||
|
||||
/* 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, NELEM(kMxTn), 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. */
|
||||
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, NELEM(kMxDecKs), 0, "split-K workgroups a column block. 0 = the fill rule" },
|
||||
{ "bk", kMxDecBk, NELEM(kMxDecBk), 0, "K slab in bytes. 0 = 128, or 64 for a wide unsplit DTM 4" },
|
||||
{ "nt", kMxDecNt, NELEM(kMxDecNt), 0, "weight loads: 1 non-temporal, 2 plain. 0 = by weight size" },
|
||||
};
|
||||
/* The MXFP4 tiled GEMM's one axis and the MXFP4 decode GEMM's axes (with the M2XFP4 rows
|
||||
* declaring the decode set) live in r4d_args.h now, beside the cfg readers that resolve them, so
|
||||
* a kernel unit links without this declaration side. */
|
||||
|
||||
/* ------------------------------------------------------------------------ split-KV attention
|
||||
* 0 is libr4d's split law (table in r4d_attn_paged_h256_gqa6.hip), which reads num_seqs and
|
||||
@@ -7530,6 +7525,42 @@ R4D_WIN_PAIR(512, 1) R4D_WIN_PAIR(512, 2) R4D_WIN_PAIR(512, 4) R4D_WIN_PAIR(512,
|
||||
nullptr, nullptr, r4d_rad_gemm_mxfp4a8_tiled, r4d_rad_gemm_mxfp4a8_tiled_scratch,
|
||||
r4d_rad_layout_mxfp4, r4d_rad_relayout_mxfp4 },
|
||||
|
||||
/* M2XFP4: the mxfp4a8 rows at the paper's weight-side Sg-EM (arXiv 2601.19213 §4.4.2) -- per 32 K
|
||||
* one more byte of weight, four two-bit subgroup multipliers, folded into the same e4m3 staging
|
||||
* bytes through r4d_m2xfp4.h's table. The bands, tunables (ks/bk/nt and tn resolve through the
|
||||
* same cfg readers) and relayout contract are the OCP rows', with the meta plane in the stored
|
||||
* weight's tail (r4d_layout.cpp, m2xfp4) and no skinny row: at these row counts the decode kernel
|
||||
* covers the whole M <= 128 band, the tiled one prefill. */
|
||||
{ "gemm_m2xfp4a8_decode", "gemm_nt_q", "gemm",
|
||||
"the M2XFP4 GEMM for the DECODE band: the mxfp4a8 decode kernel's split-K across workgroups with "
|
||||
"a fused last-arriver reduction, the weight unpacked through LDS with its per-subgroup meta "
|
||||
"multiplier, streaming weight loads",
|
||||
"M <= 128; N a multiple of 16; K a multiple of 64; the skinny kernel's fragment-order weight, "
|
||||
"[K/32][N] E8M0 exponents and per-row reference exponent, and the [K/32][N] meta plane in the "
|
||||
"stored weight's tail; the split partial in the op's scratch",
|
||||
"e4m3 A with an f32 scale per row or per (row, 128), e2m1 W with an E8M0 scale per 32 K (bias "
|
||||
"folded) and a two-bit multiplier per 8 K folded into the element against a per-row reference, "
|
||||
"bf16 C, fp32 accumulate",
|
||||
RAD_DOMAIN_DEVICE, R4D_PRIO_GEMM_MXDEC,
|
||||
ROW(cGemmM2xfp4A8Decode), ROW(tGemmMxfp4Decode), nullptr,
|
||||
nullptr, nullptr, r4d_rad_gemm_m2xfp4a8_decode, r4d_rad_gemm_m2xfp4a8_decode_scratch,
|
||||
r4d_rad_layout_m2xfp4, r4d_rad_relayout_m2xfp4 },
|
||||
|
||||
{ "gemm_m2xfp4a8_tiled", "gemm_nt_q", "gemm",
|
||||
"the M2XFP4 GEMM tiled for PREFILL row counts: the mxfp4a8 tiled kernel's 256-row block, the "
|
||||
"activation re-tiled into the op's scratch, the weight with its meta multipliers unpacked once "
|
||||
"per K slab into LDS",
|
||||
"any M; N a multiple of 16; K a multiple of 64; the skinny kernel's fragment-order weight, "
|
||||
"[K/32][N] E8M0 exponents and per-row reference exponent, and the [K/32][N] meta plane in the "
|
||||
"stored weight's tail; the re-tiled activation in the op's scratch",
|
||||
"e4m3 A with an f32 scale per row or per (row, 128), e2m1 W with an E8M0 scale per 32 K (bias "
|
||||
"folded) and a two-bit multiplier per 8 K folded into the element against a per-row reference, "
|
||||
"bf16 C, fp32 accumulate",
|
||||
RAD_DOMAIN_DEVICE, R4D_PRIO_GEMM_TILED,
|
||||
ROW(cGemmM2xfp4A8Tiled), ROW(tGemmMxfp4Tiled), nullptr,
|
||||
nullptr, nullptr, r4d_rad_gemm_m2xfp4a8_tiled, r4d_rad_gemm_m2xfp4a8_tiled_scratch,
|
||||
r4d_rad_layout_m2xfp4, r4d_rad_relayout_m2xfp4 },
|
||||
|
||||
/* Band read off the entry point's own rejection tests. */
|
||||
{ "gemm_w4a8_prefill", "gemm_nt_q", "gemm",
|
||||
"the 4-bit GEMM for PREFILL row counts, where the matrix pipe rather than the weight stream is "
|
||||
@@ -9389,10 +9420,11 @@ extern "C" const RadKernelInfo* rad_kernel_at(int i) {
|
||||
* every collective the peer flags and exchange buffers the all-reduces own
|
||||
*
|
||||
* gemm_fp8a8_nt_m16's finisher counters are keyed on the stream and the output;
|
||||
* gemm_mxfp4a8_decode's split partial is the op's scratch and its arrival counters are keyed on the
|
||||
* output alone; router_gemm_topk_scatter_bf16's arrival counter belongs to its op instance (taken
|
||||
* at init, one per declared op and band). Concurrent launches never share these, so those three
|
||||
* rows are concurrent. A new row with stream-ordered state belongs in the list above.
|
||||
* gemm_mxfp4a8_decode's and gemm_m2xfp4a8_decode's split partial is the op's scratch and their
|
||||
* arrival counters are keyed on the output alone (the M2 row keeps its own counter blocks,
|
||||
* m2d_out_ctr); router_gemm_topk_scatter_bf16's arrival counter belongs to its op instance (taken
|
||||
* at init, one per declared op and band). Concurrent launches never share these, so those rows are
|
||||
* concurrent. A new row with stream-ordered state belongs in the list above.
|
||||
*
|
||||
* lora_* ordered on purpose: the core appends them behind the GEMM whose `y` they
|
||||
* update and refills the pools they read between steps with its own copies,
|
||||
@@ -9545,14 +9577,8 @@ extern "C" void r4d_cfg_tiled(const RadArgs* a, R4dTileCfg* out) {
|
||||
extern "C" void r4d_cfg_prefill(const RadArgs* a, R4dTileCfg* out) {
|
||||
tile_bmbn(TUNE(a, tGemmPrefill, "tile"), 1, out);
|
||||
}
|
||||
extern "C" void r4d_cfg_mxfp4_decode(const RadArgs* a, R4dMxDecCfg* out) {
|
||||
out->ks = TUNE(a, tGemmMxfp4Decode, "ks");
|
||||
out->bk = TUNE(a, tGemmMxfp4Decode, "bk");
|
||||
out->nt = TUNE(a, tGemmMxfp4Decode, "nt");
|
||||
}
|
||||
extern "C" void r4d_cfg_mxfp4_tiled(const RadArgs* a, R4dMxTileCfg* out) {
|
||||
out->tn = TUNE(a, tGemmMxfp4Tiled, "tn");
|
||||
}
|
||||
/* r4d_cfg_mxfp4_decode and r4d_cfg_mxfp4_tiled are inline in r4d_args.h, beside their tables and
|
||||
* the tune reader, so the kernel units carry them without this declaration side. */
|
||||
extern "C" void r4d_cfg_split(const RadArgs* a, R4dSplitCfg* out) {
|
||||
out->splits = TUNE(a, tAttnSplit, "splits");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user