libr4d: gemm_mxfp4a8_gemv_wide, the gemv row's WMMA form at 9 to 64 rows

The WMMA form takes up to four 16-row tiles a wave: each weight word of a chunk is loaded and folded
once and multiplied with every tile's activation fragment, so the weight streams once from DRAM to
registers whatever the row count, with no LDS staging. A row's sum is its tile's WMMA chain alone, so
its bits are the same at every tile count: the first row is bit-identical from M = 1 to 64 (selftest),
across the gemv row (M <= 8) and the new gemv_wide row (9 <= M <= 64, K % 128 == 0, same entry and
priority). Several streams with speculation land there (4 x (1 + 7) = 32, 16 x (1 + 3) = 64).

--perfmx against the decode row that served 9..64 before (us, Qwen3.8-27B / TranslateGemma per-rank
decode shapes): down 51-80 vs 56-105, ssm_out 27-42 vs 30-55, attn_qg 40-63 vs 44-74, TranslateGemma
down 61-97 vs 66-123, o 22-35 vs 25-51, gate_up at 24-48 rows 110-141 vs 145-170; gate_up at 48-64
rows about even (Qwen) or behind (TranslateGemma at 64, 171 vs 153).

Selftest: gemv_wide at RT 2..4, both activation grids, a partly live tile, parts; the M-invariance check
runs the wide row under the gemv row's selection (mxfp4a8_numeric's any_row).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
mici81andClaude Opus 5.5 authored and StillDeadcode committed 2026-10-24 11:09:03 +02:00
1 parent 75b4d0baa7
commit b66752adcc
3 files changed
+98 -50

No files matched your search

+23 -6
View File
@@ -4263,8 +4263,9 @@ static float mxfp4_act(int64_t i, int64_t k, uint32_t seed) {
* as the zero a fresh allocation holds. `row0`, when given, receives the first row's bits. */
static void mxfp4a8_numeric(const Plugin& pl, const char* row, int64_t M, int64_t N, int64_t K,
int tn, bool ablk = false, std::vector<RadParam> extra = {},
int64_t pb1 = 0, int64_t pb2 = 0, std::vector<uint16_t>* row0 = nullptr) {
if (!sel(row)) return;
int64_t pb1 = 0, int64_t pb2 = 0, std::vector<uint16_t>* row0 = nullptr,
bool any_row = false) {
if (!any_row && !sel(row)) return;
/* Parts (ParoQuant): weight rows [0, pb1), [pb1, pb2), [pb2, N) each meet their own copy of
* the activation, side by side in a row. `K` is one copy's width. */
const PartCut cut(N, pb1, pb2);
@@ -4399,13 +4400,20 @@ static void mxfp4a8_numeric(const Plugin& pl, const char* row, int64_t M, int64_
static void mxfp4a8_m_invariant(const Plugin& pl, const char* row, int64_t N, int64_t K, bool ablk) {
if (!sel(row)) return;
char nm[160];
std::snprintf(nm, sizeof nm, "%s first row bit-identical at M = 1..8, N=%lld K=%lld%s", row,
std::snprintf(nm, sizeof nm, "%s first row bit-identical at M = 1..%s, N=%lld K=%lld%s", row,
!std::strcmp(row, "gemm_mxfp4a8_gemv") && K % 128 == 0 ? "64 (gemv_wide past 8)" : "8",
(long long)N, (long long)K, ablk ? " ascale=row x 128" : "");
std::vector<uint16_t> ref, got;
mxfp4a8_numeric(pl, row, 1, N, K, 0, ablk, {}, 0, 0, &ref);
for (int64_t M = 2; M <= 8; ++M) {
mxfp4a8_numeric(pl, row, 1, N, K, 0, ablk, {}, 0, 0, &ref, true);
/* With K % 128 == 0 the gemv row's WMMA form continues in gemv_wide to 64 rows: the first row
* must keep its bits there too (every tile count). Run under this check's own selection, so the
* wide row runs here whichever row the process was started for. */
const bool wide = !std::strcmp(row, "gemm_mxfp4a8_gemv") && K % 128 == 0;
for (const int64_t M : { 2, 3, 4, 5, 6, 7, 8, 9, 16, 17, 32, 33, 48, 64 }) {
if (M > 8 && !wide) break;
got.clear();
mxfp4a8_numeric(pl, row, M, N, K, 0, ablk, {}, 0, 0, &got);
mxfp4a8_numeric(pl, M > 8 ? "gemm_mxfp4a8_gemv_wide" : row, M, N, K, 0, ablk, {}, 0, 0, &got,
true);
if (ref.size() != (size_t)N || got != ref) {
ok(nm, false, "M=" + std::to_string(M) + " differs from M=1");
return;
@@ -26904,6 +26912,15 @@ static void device_phase(const Plugin& pl) {
mxfp4a8_numeric(pl, "gemm_mxfp4a8_gemv", m, n, 576, 0, true);
mxfp4a8_numeric(pl, "gemm_mxfp4a8_gemv", m, n, 576, 0, false);
}
/* gemv_wide: the WMMA form over two to four 16-row tiles, both grids, a tile partly
* live, and parts. */
mxfp4a8_numeric(pl, "gemm_mxfp4a8_gemv_wide", 9, 5120, 5120, 0, true);
mxfp4a8_numeric(pl, "gemm_mxfp4a8_gemv_wide", 17, 1072, 2560, 0, false);
mxfp4a8_numeric(pl, "gemm_mxfp4a8_gemv_wide", 32, 17408, 5120, 0, true);
mxfp4a8_numeric(pl, "gemm_mxfp4a8_gemv_wide", 40, 5376, 10752, 0, true);
mxfp4a8_numeric(pl, "gemm_mxfp4a8_gemv_wide", 64, 10288, 640, 0, false);
mxfp4a8_numeric(pl, "gemm_mxfp4a8_gemv_wide", 33, 16, 128, 0, true);
mxfp4a8_numeric(pl, "gemm_mxfp4a8_gemv_wide", 24, 34816, 5120, 0, true, {}, 17408);
mxfp4a8_m_invariant(pl, "gemm_mxfp4a8_gemv", 5120, 5120, true);
mxfp4a8_m_invariant(pl, "gemm_mxfp4a8_gemv", 1088, 576, true);
mxfp4a8_m_invariant(pl, "gemm_mxfp4a8_gemv", 1056, 576, false);