Archived
libxe2: w4a8i8 prefill GEMM reads A per thread from L1, rows fastest, except a long K
The activation was staged in SLM a work-group, a group (128 of K) at a time, double-buffered behind a barrier. Each thread now loads its own A operands with 2D block loads, which hit L1 (the work-group's threads read the same rows): no staging store and no barrier a group, and the grid goes rows fastest at every width. A long K over a narrow output (down's 5120 x 17408) keeps the SLM form, where staging still pays. Probe w4p.cpp at M = 2048, int8 TOPS: gate_up 97 -> 115, inz 81 -> 96, qg 73 -> 80..98, out 90 -> 108, kv 72 -> 92, down unchanged; every output hash identical at M = 100, 517, 2048 and 4096. qwen3.8-27b-w4a16 (mtp4fc), fresh ~2.1k-token prompts: prefill ~1236 -> ~1314 tok/s; greedy 8/8 identical. Shape-only rule, so every w4a16 model's prefill takes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
10a99a5bf2
commit
9a1633596f
1 file changed
+26
-10
@@ -152,7 +152,7 @@ int launch16(sycl::queue& q, const void* av, int64_t ars, int mm, const uint32_t
|
||||
* those over one 256-column slice of the weight run together and it stays in L2 (the wide outputs).
|
||||
* Probe w4p.cpp at M = 2048, int8 TOPS: gate_up 27 -> 78, inz 27 -> 75, down 24 -> 62 (66 without
|
||||
* RF), N = 5120 K = 6144 29 -> 78 (without RF); every output identical to the first form's. */
|
||||
template <bool RF>
|
||||
template <bool RF, bool SLM>
|
||||
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) {
|
||||
@@ -166,7 +166,7 @@ int launch_i8(sycl::queue& q, const uint8_t* ap, const int32_t* asumt, const flo
|
||||
return submit([&] {
|
||||
q.parallel_for(sycl::nd_range<1>{(size_t)(RG * cgw * kWg), (size_t)kWg}, props, [=](sycl::nd_item<1> it) SYCL_ESIMD_KERNEL {
|
||||
using namespace esimd;
|
||||
slm_init<2 * kBuf>();
|
||||
if constexpr (SLM) slm_init<2 * kBuf>();
|
||||
const int tl = (int)it.get_local_id(0);
|
||||
const int64_t wg = (int64_t)it.get_group(0);
|
||||
const int64_t rg = RF ? wg % RG : wg / cgw, cw = RF ? wg / RG : wg % cgw;
|
||||
@@ -191,18 +191,23 @@ int launch_i8(sycl::queue& q, const uint8_t* ap, const int32_t* asumt, const flo
|
||||
const uint32_t* szp = sz + tile0 * G * 16;
|
||||
const int32_t* asp = asumt + r0;
|
||||
const float* sap = sat + r0;
|
||||
/* without SLM each thread reads its own A operands with 2D loads, which hit L1 (the
|
||||
* work-group's threads read the same rows): no staging store, no barrier a group */
|
||||
xesimd::config_2d_mem_access<uint32_t, 8, 8, 1> ap8((const uint32_t*)ap, sw, sh, sw, 0, (int)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) */
|
||||
if (SLM && tl < 4) { /* rows past M load as zeros (the 2D load's bounds) */
|
||||
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);
|
||||
barrier();
|
||||
if constexpr (SLM) {
|
||||
stage(0, 0);
|
||||
barrier();
|
||||
}
|
||||
for (int64_t g = 0; g < G; ++g) {
|
||||
const int buf = (int)(g & 1);
|
||||
if (g + 1 < G) stage(g + 1, buf ^ 1);
|
||||
if (SLM && g + 1 < G) stage(g + 1, buf ^ 1);
|
||||
/* 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 */
|
||||
@@ -234,7 +239,14 @@ int launch_i8(sycl::queue& q, const uint8_t* ap, const int32_t* asumt, const flo
|
||||
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));
|
||||
simd<uint32_t, 64> Ai;
|
||||
if constexpr (SLM) {
|
||||
Ai = slm_block_load<uint32_t, 64>((uint32_t)(buf * kBuf + ks * kStep + i * 256));
|
||||
} else {
|
||||
ap8.set_x((int)(g * 32 + ks * 8));
|
||||
ap8.set_y((int)(r0 + i * 8));
|
||||
Ai = xesimd::lsc_load_2d<uint32_t, 8, 8, 1>(ap8);
|
||||
}
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 2; ++j)
|
||||
c[i][j] = xmx::dpas<8, 8, int32_t, int32_t, uint32_t, uint32_t, xmx::dpas_argument_type::u4,
|
||||
@@ -255,7 +267,7 @@ int launch_i8(sycl::queue& q, const uint8_t* ap, const int32_t* asumt, const flo
|
||||
acc[i][j].template select<16, 1>(m * 16) += tt;
|
||||
}
|
||||
}
|
||||
barrier();
|
||||
if constexpr (SLM) barrier();
|
||||
}
|
||||
if (!live) return;
|
||||
#pragma unroll
|
||||
@@ -296,8 +308,12 @@ int w4a16_esimd(sycl::queue& q, int rc, const void* a, bool a_bf16, int64_t ars,
|
||||
int w4a8i8_esimd(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) {
|
||||
if (N > 8192) return launch_i8<true>(q, ap, asumt, sat, mpad, ct, sz, M, N, K, yb, ydt, yrs);
|
||||
return launch_i8<false>(q, ap, asumt, sat, mpad, ct, sz, M, N, K, yb, ydt, yrs);
|
||||
/* A staged in SLM a work-group pays only on a long K over a narrow output (down's 5120 x
|
||||
* 17408); everywhere else each thread's own L1-hit 2D loads win, rows fastest. Probe w4p.cpp at
|
||||
* M = 2048, int8 TOPS, SLM -> per-thread: gate_up 97 -> 115, inz 81 -> 96, qg 73 -> 80, out
|
||||
* 90 -> 108, kv 72 -> 92; down 77 -> 74 (kept); every output identical. */
|
||||
if (N <= 8192 && K >= 16384) return launch_i8<false, true>(q, ap, asumt, sat, mpad, ct, sz, M, N, K, yb, ydt, yrs);
|
||||
return launch_i8<true, false>(q, ap, asumt, sat, mpad, ct, sz, M, N, K, yb, ydt, yrs);
|
||||
}
|
||||
|
||||
} // namespace xe2
|
||||
Reference in new issue
Block a user