diff --git a/libxe2/xe2_gemm_w4_esimd.cpp b/libxe2/xe2_gemm_w4_esimd.cpp index 759235b6..524095e1 100644 --- a/libxe2/xe2_gemm_w4_esimd.cpp +++ b/libxe2/xe2_gemm_w4_esimd.cpp @@ -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 as = block_load(asumt + g * mpad + r0); simd sv = block_load(sat + g * mpad + r0); + const simd asf = as; #pragma unroll for (int j = 0; j < 2; ++j) { simd w = block_load(sz + ((tile0 + j) * G + g) * 16); simd lo = w & 0xFFFFu, hi = w >> 16; simd s16 = lo, z16 = hi; const simd sb = simd(s16.template bit_cast_view()); - const simd z = simd(simd(simd(z16.template bit_cast_view()))) - 1024; - simd zz; - simd 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 zf = simd(simd(z16.template bit_cast_view())) - 1024.0f; #pragma unroll for (int i = 0; i < RB; ++i) { - simd asr; - simd sar; + simd 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 sub = cf.template select<16, 1>(m * 16) - zf * a_s; + simd tt = sub * a_c; + tt = tt * sb; + acc[i][j].template select<16, 1>(m * 16) += tt; } - const simd is = c[i][j] - zz * asr; - const simd sub = is; - simd tt = sub * sar; - tt = tt * sbb; - acc[i][j] += tt; } } barrier();