diff --git a/libxe2/xe2_gemm_w4_esimd.cpp b/libxe2/xe2_gemm_w4_esimd.cpp index 3d2af86d..044a710e 100644 --- a/libxe2/xe2_gemm_w4_esimd.cpp +++ b/libxe2/xe2_gemm_w4_esimd.cpp @@ -156,7 +156,7 @@ template 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 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 a = load_2d((const uint32_t*)ap, sw, sh, sw, - (int)(g * 32 + tl * 8), (int)r0); - slm_block_store((uint32_t)(buf * kBuf + tl * kStep), a); + apl.set_x((int)(g * 32 + tl * 8)); + simd a = xesimd::lsc_load_2d(apl); + slm_block_store((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 as = block_load(asumt + g * mpad + r0); - simd sv = block_load(sat + g * mpad + r0); + simd as = block_load(asp); + simd sv = block_load(sap); + asp += mpad; + sap += mpad; simd sbj[2]; simd c[RB][2]; #pragma unroll for (int j = 0; j < 2; ++j) { - simd w = block_load(sz + ((tile0 + j) * G + g) * 16); + simd w = block_load(szp + j * G * 16); simd lo = w & 0xFFFFu, hi = w >> 16; simd s16 = lo, z16 = hi; sbj[j] = simd(s16.template bit_cast_view()); @@ -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 B[2]; #pragma unroll - for (int j = 0; j < 2; ++j) B[j] = block_load(ct + ((tile0 + j) * (K / 8) + g * 16 + ks * 4) * 16); + for (int j = 0; j < 2; ++j) B[j] = block_load(cbp + j * kr * 16 + ks * 64); #pragma unroll for (int i = 0; i < RB; ++i) { simd Ai = slm_block_load((uint32_t)(buf * kBuf + ks * kStep + i * 256));