libr4d: decode tile arms for the int4/int5 x int8 GEMM

gemm_w4a8i8_tiled / gemm_w5a8i8_tiled ran one 256 x 64 tile, built for
2048-row prefill chunks. At decode row counts its time is the weight's
trip through the block and is flat in M (N=5120 K=17408: 272 us at
M=32, 284 at M=256): a 128-row step computes half padding, and N/64
blocks (80 at N=5120) leave most of an R9700 idle.

The kernel is now templated on its tile (TM x TN fragments a wave,
WM x WN waves a block), with the body unchanged, and the rows gain one
tunable axis, `arm`: 0 is the prefill tile (the old constants, so an
untuned install runs the same kernel), 1-8 are 128-, 64- and 32-row
tiles. tools/opshapes.cpp describes the int8-activation operands so
rad-tune can walk the axis, and r4d_selftest checks every arm against
the host reference for int4 and int5, with ragged M and a partitioned
weight; --perfwpa takes R4D_PERF_ARM.

Tuned on an R9700 at the trunk shapes of Qwen3.8-27B ParoQuant int5
(rad-tune, us, arm 0 -> the tuned arm):

  shape             M=32         M=64         M=128
  N=16384 K=5120    258 -> 72    229 -> 97    233 -> 151
  N=5120  K=6144    101 -> 38    101 -> 42    101 -> 62
  N=34816 K=5120    497 -> 217   494 -> 234   504 -> 309
  N=5120  K=17408   273 -> 89    275 -> 103   277 -> 168
  N=12288 K=5120    167 -> 52    167 -> 72    168 -> 112
  N=1024  K=5120     36 -> 21     36 -> 22     37 -> 24

The prefill band (M=2048) keeps arm 0. Which rows reach this kernel is
unchanged: the qwen35 plugin still hands the rotated int4/int5 linears
to it above 64 rows, so the M=32/64 columns only bound what a lower
handover could gain.

The int4 rows share the kernel and gain alike (int4 x int8 at M=128,
arm 0 -> best: N=5120 K=17408 267 -> 150 us, N=34816 K=5120 444 -> 248,
N=16384 K=5120 211 -> 118, N=12288 K=5120 160 -> 91).

End to end, Qwen3.8-27B ParoQuant int5 + DFlash2 on one R9700 (k6_v4
cache, f16 state, depth 3, 32 sequences of ~3k shared + ~2.5k unique
prompt, 3000 tokens out, so 128-row verify steps), against origin/main
on the same boot and tune cache: mean decode step 111.0 -> 93.8 ms,
decode 467 -> 614 tok/s, wall 345 -> 418, no preemptions. Decode at up
to 64 rows (one to eight sequences at depth 7) and prefill (arm 0) run
the same kernels as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019BxxGmKGSAyx2h88G3sEGp
This commit is contained in:
KeziandClaude Opus 5.5 authored and StillDeadcode committed 2026-11-11 22:41:02 +01:00
1 parent 7da9ccf38b
commit 60bcc30e5e
5 files changed
+96 -22

No files matched your search

+15 -2
View File
@@ -5766,6 +5766,15 @@ static const RadTunable tGemmPrefill[] = {
"compiled tile arm; 0 is BM 128 x BN 256, libr4d's own default" },
};
/* The int4 / int5 x int8 tiled GEMM's one axis (r4d_gemm_wpa8i8_tiled.hip): its tile arm. Arm 0 is
* the 256x64 prefill tile as it always ran. */
static const int64_t kWpaArm[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
static const RadTunable tGemmWpa8i8[] = {
{ "arm", kWpaArm, NELEM(kWpaArm), 0,
"tile arm (r4d_gemm_wpa8i8_tiled.hip WPT_ARMS): 0 = 256x64 prefill, 1 = 128x128, 2 = 128x64, "
"3 = 128x32, 4 = 64x128, 5 = 64x64, 6 = 64x32, 7 = 32x128, 8 = 32x32" },
};
/* 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 };
@@ -8661,7 +8670,7 @@ R4D_WIN_TREE_PAIR(512, 4) R4D_WIN_TREE_PAIR(512, 8)
"I8 A (parts side by side) with an f32 scale per (row, part, 128), 4-bit W with an f16 scale and "
"integer zero per 128 K, bf16 C, int32 accumulate per 128 of K",
RAD_DOMAIN_DEVICE, R4D_PRIO_GEMM_SKINNY,
ROW(cGemmNtW4A8I8), NOTUNE,
ROW(cGemmNtW4A8I8), ROW(tGemmWpa8i8), nullptr,
nullptr, nullptr, r4d_rad_gemm_w4a8i8_tiled, r4d_rad_gemm_mxfp4a8_tiled_scratch,
r4d_rad_layout_w4, r4d_rad_relayout_w4, nullptr, r4d_rad_unrelayout_w4 },
@@ -8673,7 +8682,7 @@ R4D_WIN_TREE_PAIR(512, 4) R4D_WIN_TREE_PAIR(512, 8)
"I8 A (parts side by side) with an f32 scale per (row, part, 128), 5-bit W with an f16 scale and "
"integer zero per 128 K, bf16 C, int32 accumulate per 128 of K",
RAD_DOMAIN_DEVICE, R4D_PRIO_GEMM_SKINNY,
ROW(cGemmNtW5A8I8), NOTUNE,
ROW(cGemmNtW5A8I8), ROW(tGemmWpa8i8), nullptr,
nullptr, nullptr, r4d_rad_gemm_w5a8i8_tiled, r4d_rad_gemm_mxfp4a8_tiled_scratch,
r4d_rad_layout_w5, r4d_rad_relayout_w5, nullptr, r4d_rad_unrelayout_w5 },
@@ -11333,6 +11342,10 @@ static int64_t tune_i(const RadArgs* a, const RadTunable* tab, int n, const char
}
#define TUNE(a, tab, key) ((int)tune_i((a), (tab), NELEM(tab), (key)))
extern "C" void r4d_cfg_wpa8i8(const RadArgs* a, R4dWpaCfg* out) {
out->arm = TUNE(a, tGemmWpa8i8, "arm");
}
extern "C" void r4d_cfg_gemm(const RadArgs* a, R4dGemmCfg* out) {
out->wv = TUNE(a, tGemmSkinny, "wv");
out->sk = TUNE(a, tGemmSkinny, "sk");