libxe2: w4a8i8 prefill GEMM's load addresses in a 2D payload and moving pointers

The loop is ALU-bound and rebuilding each load's 64-bit address was a third of its
instructions. Probe at M = 2048, int8 TOPS: gate_up 91 -> 98, inz 74 -> 81, down 64 -> 76,
out 86 -> 90; outputs bit-identical. A 2234-token prefill 1063 -> 1127 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 06:40:58 +01:00
1 parent d63b985161
commit b5f116e797
1 file changed
+24 -8
+24 -8
View File
@@ -156,7 +156,7 @@ template <bool RF>
int launch_i8(sycl::queue& q, const uint8_t* ap, const int32_t* asumt, const float* sat, int64_t mpad,
const uint32_t* ct, const uint32_t* sz, int64_t M, int64_t N, int64_t K, char* yb, uint32_t ydt,
int64_t yrs) {
constexpr int RB = 2, R = RB * 8; /* rows a work-group */
constexpr int RB = 2, R = RB * 8; /* rows a work-group (32 rows on the 256-register file: 0.6x) */
constexpr int kWg = 8; /* threads a work-group, two tiles each */
constexpr int kStep = R * 32, kBuf = 4 * kStep;
const int64_t G = K / 128, RG = (M + R - 1) / R, CG = N / 32;
@@ -179,11 +179,23 @@ int launch_i8(sycl::queue& q, const uint8_t* ap, const int32_t* asumt, const flo
for (int i = 0; i < RB; ++i)
#pragma unroll
for (int j = 0; j < 2; ++j) acc[i][j] = 0.0f;
/* the loads' addresses in a 2D payload and pointers that only move: rebuilt a load at a
* time, the 64-bit address math was a third of the loop's instructions, and the loop is
* ALU-bound (stall samples: 72% active). Probe w4p.cpp at M = 2048, int8 TOPS: gate_up
* 91 -> 98, inz 74 -> 81, down 64 -> 76, out 86 -> 90. (One 16 x 16 2D load of a tile's
* group instead of four block loads: down 71, out 74.) */
namespace xesimd = sycl::ext::intel::experimental::esimd;
xesimd::config_2d_mem_access<uint32_t, 8, R, 1> apl((const uint32_t*)ap, sw, sh, sw, tl * 8, (int)r0);
const uint32_t* cb0 = ct + tile0 * (K / 8) * 16;
const int kr = (int)(K / 8);
const uint32_t* szp = sz + tile0 * G * 16;
const int32_t* asp = asumt + r0;
const float* sap = sat + r0;
auto stage = [&](int64_t g, int buf) SYCL_ESIMD_FUNCTION {
if (tl < 4) { /* rows past M load as zeros (the 2D load's bounds) */
simd<uint32_t, R * 8> a = load_2d<uint32_t, 8, R, 1, false>((const uint32_t*)ap, sw, sh, sw,
(int)(g * 32 + tl * 8), (int)r0);
slm_block_store<uint32_t, 128>((uint32_t)(buf * kBuf + tl * kStep), a);
apl.set_x((int)(g * 32 + tl * 8));
simd<uint32_t, R * 8> a = xesimd::lsc_load_2d<uint32_t, 8, R, 1>(apl);
slm_block_store<uint32_t, R * 8>((uint32_t)(buf * kBuf + tl * kStep), a);
}
};
stage(0, 0);
@@ -194,13 +206,15 @@ int launch_i8(sycl::queue& q, const uint8_t* ap, const int32_t* asumt, const flo
/* the accumulators start at -zero * asum (int16 operands, exact: |zero * asum| <=
* 15 * 127 * 128), so the DPAS leaves sum - zero * asum, the integer libref's chain
* forms first, and the epilogue only converts and scales */
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);
simd<int32_t, R> as = block_load<int32_t, R>(asp);
simd<float, R> sv = block_load<float, R>(sap);
asp += mpad;
sap += mpad;
simd<float, 16> sbj[2];
simd<int32_t, 128> c[RB][2];
#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> w = block_load<uint32_t, 16>(szp + j * G * 16);
simd<uint32_t, 16> lo = w & 0xFFFFu, hi = w >> 16;
simd<uint16_t, 16> s16 = lo, z16 = hi;
sbj[j] = simd<half, 16>(s16.template bit_cast_view<half>());
@@ -211,11 +225,13 @@ int launch_i8(sycl::queue& q, const uint8_t* ap, const int32_t* asumt, const flo
for (int m = 0; m < 8; ++m)
c[i][j].template select<16, 1>(m * 16) = nz * (int16_t)as[i * 8 + m];
}
szp += 16;
const uint32_t* cbp = cb0 + g * 256;
#pragma unroll
for (int ks = 0; ks < 4; ++ks) {
simd<uint32_t, 64> B[2];
#pragma unroll
for (int j = 0; j < 2; ++j) B[j] = block_load<uint32_t, 64>(ct + ((tile0 + j) * (K / 8) + g * 16 + ks * 4) * 16);
for (int j = 0; j < 2; ++j) B[j] = block_load<uint32_t, 64>(cbp + j * kr * 16 + ks * 64);
#pragma unroll
for (int i = 0; i < RB; ++i) {
simd<uint32_t, 64> Ai = slm_block_load<uint32_t, 64>((uint32_t)(buf * kBuf + ks * kStep + i * 256));