Archived
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:
1 parent
7da9ccf38b
commit
60bcc30e5e
5 files changed
+96
-22
No files matched your search
+16
-4
@@ -6077,14 +6077,14 @@ static void w5a16_perf(const Plugin& pl, int bits, int64_t M, int64_t N, int64_t
|
||||
* scale and a u8 zero per 128 of K, an int8 activation with an f32 scale per (row, 128), parts
|
||||
* side by side. */
|
||||
static void wpa8i8_numeric(const Plugin& pl, int bits, int64_t M, int64_t N, int64_t K, int64_t pb1 = 0,
|
||||
int64_t pb2 = 0, uint32_t zdt = RAD_U8) {
|
||||
int64_t pb2 = 0, uint32_t zdt = RAD_U8, int64_t arm = 0) {
|
||||
const char* row = bits == 4 ? "gemm_w4a8i8_tiled" : "gemm_w5a8i8_tiled";
|
||||
if (!sel(row)) return;
|
||||
const PartCut cut(N, pb1, pb2);
|
||||
const int parts = cut.parts;
|
||||
char nm[160];
|
||||
std::snprintf(nm, sizeof nm, "%s numeric M=%lld N=%lld K=%lld parts=%d zero %s", row,
|
||||
(long long)M, (long long)N, (long long)K, parts, rad_dtype_name(zdt));
|
||||
std::snprintf(nm, sizeof nm, "%s numeric M=%lld N=%lld K=%lld parts=%d zero %s arm %lld", row,
|
||||
(long long)M, (long long)N, (long long)K, parts, rad_dtype_name(zdt), (long long)arm);
|
||||
const RadKernelInfo* r = find(pl, row);
|
||||
if (!r || !r->layout || !r->relayout) { ok(nm, false, "row or hooks absent"); return; }
|
||||
const int64_t G = K / 128;
|
||||
@@ -6132,6 +6132,7 @@ static void wpa8i8_numeric(const Plugin& pl, int bits, int64_t M, int64_t N, int
|
||||
PS("dtype", bits == 4 ? "w4a8i8_asym" : "w5a8i8") };
|
||||
if (pb1) ps.push_back(PI("pb1", pb1));
|
||||
if (pb2) ps.push_back(PI("pb2", pb2));
|
||||
if (arm) ps.push_back(PI("arm", arm));
|
||||
RadArgs a;
|
||||
std::memset(&a, 0, sizeof(a));
|
||||
a.t = ts.data(); a.n_t = (int)ts.size();
|
||||
@@ -6230,6 +6231,9 @@ static void wpa_perf(const Plugin& pl, int64_t N, int64_t K, int64_t M, int iter
|
||||
std::vector<RadParam> ps = { PI("M", M), PI("N", N), PI("K", K), PI("group", 128),
|
||||
PS("dtype", bits == 4 ? "w4a8i8_asym" : "w5a8i8") };
|
||||
if (pb1) ps.push_back(PI("pb1", pb1));
|
||||
/* R4D_PERF_ARM pins the row's tile arm, for a sweep by hand. */
|
||||
int64_t perf_arm = 0;
|
||||
if (const char* e = std::getenv("R4D_PERF_ARM")) { perf_arm = std::atoll(e); ps.push_back(PI("arm", perf_arm)); }
|
||||
RadArgs a;
|
||||
std::memset(&a, 0, sizeof(a));
|
||||
a.t = ts.data(); a.n_t = (int)ts.size();
|
||||
@@ -6239,7 +6243,8 @@ static void wpa_perf(const Plugin& pl, int64_t N, int64_t K, int64_t M, int iter
|
||||
const int64_t sb = r->scratch(&a);
|
||||
if (sb > 0) { a.scratch = dalloc((size_t)sb); a.scratch_bytes = sb; }
|
||||
}
|
||||
for (int i = 0; i < 3; ++i) r->launch(&a, nullptr);
|
||||
if (r->launch(&a, nullptr) != RAD_OK) { std::printf("--perfwpa: arm %lld refused\n", (long long)perf_arm); return; }
|
||||
for (int i = 0; i < 2; ++i) r->launch(&a, nullptr);
|
||||
st_stream_sync(nullptr);
|
||||
st_memcpy(hy.data(), d_y, hy.size() * 2, hipMemcpyDeviceToHost);
|
||||
uint64_t hash = 1469598103934665603ull;
|
||||
@@ -33799,6 +33804,13 @@ static void device_phase(const Plugin& pl) {
|
||||
wpa8i8_numeric(pl, bits, 2100, 34816, 5120, 17408);
|
||||
wpa8i8_numeric(pl, bits, 2048, 17408, 5120);
|
||||
wpa8i8_numeric(pl, bits, 2048, 5120, 17408);
|
||||
/* The decode arms: a whole block, ragged M (a partial 16-row tile and a partial block)
|
||||
* and a partitioned weight, on every arm. */
|
||||
for (int arm = 1; arm <= 8; ++arm) {
|
||||
wpa8i8_numeric(pl, bits, 128, 1280, 1024, 0, 0, RAD_U8, arm);
|
||||
wpa8i8_numeric(pl, bits, 40, 1280, 1024, 0, 0, RAD_U8, arm);
|
||||
wpa8i8_numeric(pl, bits, 100, 2560, 1280, 1536, 0, RAD_U8, arm);
|
||||
}
|
||||
if (bits == 4) {
|
||||
/* An int4 W4A16 release imported with a u4 zero plane and no rotation: five groups
|
||||
* a row, so each zero row ends in a pad nibble; then the delta net's qkv|z, the MLP's
|
||||
|
||||
Reference in new issue
Block a user