libxe2: w4a16 decode GEMM in 16-row blocks, each group's codes decoded once

gemm_nt_q at w4a16_asym (M <= 64) ran 8-row blocks, each reading and decoding the whole 4-bit weight:
16 rows paid twice, 64 rows eight times. launch16x2 takes two 8-row bands against each group's codes,
loaded and decoded once, the activation loaded 32 columns at a time so both bands fit the default
register file (no spill). The per-row arithmetic is launch16<8>'s. XE2_W4_RB8=1 keeps 8-row blocks.

Qwen3.8-27B int4 (RedHatAI, as shipped), MTP depth 3, Arc Pro B65: 4 concurrent 256-token streams
97.6-99.2 -> 109.4-110.0 tok/s aggregate (+12%); one stream unchanged (43.1 -> 43.2). XE2_W4_CHECK=50
against libref's loop on the host: rel_l2 <= 6.6e-5 on every shape, tens of ties in ~10^5 outputs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-11-08 01:53:59 +01:00
1 parent 2f1fdd4d11
commit 6abca01f17
2 files changed
+98 -4

No files matched your search

+8 -3
View File
@@ -406,12 +406,17 @@ int gemm_nt_q_w4a16(const RadArgs* a, RadStream st) {
const uint16_t* a16 = (const uint16_t*)c.ab;
const int64_t ars = c.ars;
const int splits = w4_splits(c.G);
for (int64_t m0 = 0; m0 < c.M; m0 += 8) {
const int mm = (int)std::min<int64_t>(8, c.M - m0);
const int rcount = mm == 1 ? 1 : (mm <= 2 ? 2 : (mm <= 4 ? 4 : 8));
/* blocks of 16 rows (two 8-row bands on each decoded group), a tail of 8 or fewer as before;
* XE2_W4_RB8=1 keeps 8-row blocks */
static const bool rb8 = std::getenv("XE2_W4_RB8") != nullptr;
for (int64_t m0 = 0; m0 < c.M;) {
const int64_t left = c.M - m0;
const int mm = (int)std::min<int64_t>(rb8 || left <= 8 ? 8 : 16, left);
const int rcount = mm == 1 ? 1 : (mm <= 2 ? 2 : (mm <= 4 ? 4 : (mm <= 8 ? 8 : 16)));
const int rc = w4a16_esimd(*q, rcount, a16 + m0 * ars, a_bf16, ars, mm, (const uint32_t*)c.bb, (const uint32_t*)c.bsb,
c.N, c.K, splits, c.yb + m0 * c.ys_r * (c.ydt == RAD_F32 ? 4 : 2), c.ydt, c.ys_r);
if (rc != RAD_OK) return rc;
m0 += mm;
}
check_call(*q, c, "w4a16 fp16 DPAS", false, g_check_a16);
return RAD_OK;