diff --git a/libxe2/xe2_gemm_zp_esimd.cpp b/libxe2/xe2_gemm_zp_esimd.cpp index 4692fd24..e9997d51 100644 --- a/libxe2/xe2_gemm_zp_esimd.cpp +++ b/libxe2/xe2_gemm_zp_esimd.cpp @@ -1,9 +1,9 @@ /* xe2_gemm_zp_esimd.cpp -- the w2a8 head (the DFlash2 drafter's 2-bit vocabulary head, N = 248320) * in ESIMD, over the u2 codes stored tiled (xe2_ops.h, zp_tiled). Int8 DPAS takes 2-bit B operands * on this card, 16 codes a dword from the low end (probe dpas_u2.cpp), so the tiled codes are the B - * operand as they lie: no decode. A thread owns 16 columns; a group is group / 32 DPAS steps of one - * 128-byte block load each, against the activation staged once a work-group in local memory as the - * A operand's [step][row][32 bytes]. Each group's integer sum is exact in int32, and its term + * operand as they lie: no decode. A thread owns 16 columns; a group is group / 32 DPAS steps (a + * group of 128 one 512-byte block load), against the activation staged once a work-group of 64 + * threads in local memory as the A operand's [step][row][32 bytes]. Each group's integer sum is exact in int32, and its term * ((is - zero * a_sum) * a_scale) * scale is added in group order: zp_dpas's (and libref's) chain, * so the result is the same bit for bit. Rows past M are staged as zeros and not stored. */ #include "xe2_common.h" @@ -20,12 +20,10 @@ namespace { namespace esimd = sycl::ext::intel::esimd; namespace xmx = sycl::ext::intel::esimd::xmx; -constexpr int kWg = 16; /* threads a work-group */ constexpr int kSlm = 8 * 8192; /* the staged activation: 8 rows of up to 8192 */ -} // namespace - -int zp_esimd(sycl::queue& q, const int8_t* ab, int64_t ars, const float* sa, int64_t sa_rs, const float* asum, +template +int launch(sycl::queue& q, const int8_t* ab, int64_t ars, const float* sa, int64_t sa_rs, const float* asum, int64_t mpad, const uint32_t* bt, const char* bsb, char* yb, uint32_t ydt, int64_t ys_r, int64_t ys_c, int64_t N, int64_t K, int64_t group, int mm) { const int64_t ntile = N / 16, ng = (ntile + kWg - 1) / kWg; @@ -64,6 +62,15 @@ int zp_esimd(sycl::queue& q, const int8_t* ab, int64_t ars, const float* sa, int const uint32_t* tb = bt + tile * steps * 32; for (int64_t g = 0; g < G; ++g) { simd c = 0; + if constexpr (G4) { /* group = 128: its four steps' codes one 512-byte load */ + simd B4 = block_load(tb + g * 128); + _Pragma("unroll") for (int s = 0; s < 4; ++s) { + const simd A = slm_block_load((uint32_t)((g * 4 + s) * 256)); + const simd B = B4.template select<32, 1>(s * 32); + c = xmx::dpas<8, 8, int32_t, int32_t, uint32_t, int32_t, xmx::dpas_argument_type::u2, + xmx::dpas_argument_type::s8>(c, B, A); + } + } else for (int64_t s = 0; s < gs; ++s) { const int64_t st = g * gs + s; const simd B = block_load(tb + st * 32); @@ -112,4 +119,15 @@ int zp_esimd(sycl::queue& q, const int8_t* ab, int64_t ars, const float* sa, int }); } +} // namespace + +int zp_esimd(sycl::queue& q, const int8_t* ab, int64_t ars, const float* sa, int64_t sa_rs, const float* asum, + int64_t mpad, const uint32_t* bt, const char* bsb, char* yb, uint32_t ydt, int64_t ys_r, int64_t ys_c, + int64_t N, int64_t K, int64_t group, int mm) { + /* 64 threads a work-group share one staging of the activation (16: 1.66 ms a call, 32: 0.96, + * and with a group's codes one 512-byte load, 32: 0.77, 64: 0.74) */ + if (group == 128) return launch<64, true>(q, ab, ars, sa, sa_rs, asum, mpad, bt, bsb, yb, ydt, ys_r, ys_c, N, K, group, mm); + return launch<64, false>(q, ab, ars, sa, sa_rs, asum, mpad, bt, bsb, yb, ydt, ys_r, ys_c, N, K, group, mm); +} + } // namespace xe2