libxe2: w4a8i8 prefill epilogue in f32 against scalar row factors

The stall samples put ~75% of the prefill GEMM in its per-group epilogue (128-wide broadcast
copies and int32 multiplies), not the DPAS. sum, zero * asum and their difference are integers
under 2^24, so forming them in f32 a row at a time gives the same values: byte-identical output
(kbench 2676/2676, greedy 8/8 identical).

Probe at M=2048: gate_up 76 -> 83, inz 75 -> 81, qg 74 -> 80 int8 TOPS. BetterBench prefill
@2000 931 -> 957 tok/s.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-11-02 04:00:41 +01:00
1 parent 4511822138
commit 49d7d0b238
1 file changed
+14 -18
+14 -18
View File
@@ -209,37 +209,33 @@ int launch_i8(sycl::queue& q, const uint8_t* ap, const int32_t* asumt, const flo
xmx::dpas_argument_type::s8>(c[i][j], B[j], Ai);
}
}
/* the group's terms ((sum - zero * asum) * a_scale) * scale, libref's chain */
/* the group's terms ((sum - zero * asum) * a_scale) * scale, libref's chain. sum,
* zero * asum and their difference are integers under 2^24 (|a| <= 127, code and
* zero <= 15, 128 a group), so they are exact in f32 and the difference is formed
* there, a row at a time against scalar row factors: the same values as the int32
* form, without 128-wide broadcast copies and int32 multiplies (the stall
* samples: ~75% of the kernel was this epilogue's ALU, not the DPAS). */
simd<int32_t, R> as = block_load<int32_t, R>(asumt + g * mpad + r0);
simd<float, R> sv = block_load<float, R>(sat + g * mpad + r0);
const simd<float, R> asf = as;
#pragma unroll
for (int j = 0; j < 2; ++j) {
simd<uint32_t, 16> w = block_load<uint32_t, 16>(sz + ((tile0 + j) * G + g) * 16);
simd<uint32_t, 16> lo = w & 0xFFFFu, hi = w >> 16;
simd<uint16_t, 16> s16 = lo, z16 = hi;
const simd<float, 16> sb = simd<half, 16>(s16.template bit_cast_view<half>());
const simd<int32_t, 16> z = simd<int32_t, 16>(simd<float, 16>(simd<half, 16>(z16.template bit_cast_view<half>()))) - 1024;
simd<int32_t, 128> zz;
simd<float, 128> sbb;
#pragma unroll
for (int m = 0; m < 8; ++m) {
zz.template select<16, 1>(m * 16) = z;
sbb.template select<16, 1>(m * 16) = sb;
}
const simd<float, 16> zf = simd<float, 16>(simd<half, 16>(z16.template bit_cast_view<half>())) - 1024.0f;
#pragma unroll
for (int i = 0; i < RB; ++i) {
simd<int32_t, 128> asr;
simd<float, 128> sar;
simd<float, 128> cf = c[i][j];
#pragma unroll
for (int m = 0; m < 8; ++m) {
asr.template select<16, 1>(m * 16) = (int32_t)as[i * 8 + m];
sar.template select<16, 1>(m * 16) = (float)sv[i * 8 + m];
const float a_s = asf[i * 8 + m], a_c = sv[i * 8 + m];
simd<float, 16> sub = cf.template select<16, 1>(m * 16) - zf * a_s;
simd<float, 16> tt = sub * a_c;
tt = tt * sb;
acc[i][j].template select<16, 1>(m * 16) += tt;
}
const simd<int32_t, 128> is = c[i][j] - zz * asr;
const simd<float, 128> sub = is;
simd<float, 128> tt = sub * sar;
tt = tt * sbb;
acc[i][j] += tt;
}
}
barrier();