Archived
libxe2: w4a8i8 accumulators start at -zero * asum
The DPAS now leaves sum - zero * asum directly (int16 operands, |zero * asum| <= 15*127*128), so the epilogue is a convert and the two scalings: no zero-init move, no f32 multiply and subtract an element. The same integer, so the same output (2234-token continuation and greedy 8/8 identical). Probe at M = 2048: gate_up 83 -> 91, inz 81 -> 88, qg 80 -> 87, out 80 -> 86 int8 TOPS. 2234-token prompt 1001 -> 1039 tok/s. (A blocked work-group order and an L1 prefetch of the codes were tried: neither helps; down at K = 17408 stays at ~66.) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
531fda7313
commit
8bc5366045
1 file changed
+24
-23
@@ -169,7 +169,8 @@ int launch_i8(sycl::queue& q, const uint8_t* ap, const int32_t* asumt, const flo
|
||||
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, cg = (RF ? wg / RG : wg % cgw) * kWg + tl;
|
||||
const int64_t rg = RF ? wg % RG : wg / cgw, cw = RF ? wg / RG : wg % cgw;
|
||||
const int64_t cg = cw * kWg + tl;
|
||||
const bool live = cg < CG;
|
||||
const int64_t r0 = rg * R, tile0 = (live ? cg : 0) * 2;
|
||||
const unsigned sw = (unsigned)(K - 1), sh = (unsigned)(M - 1);
|
||||
@@ -190,11 +191,26 @@ int launch_i8(sycl::queue& q, const uint8_t* ap, const int32_t* asumt, const flo
|
||||
for (int64_t g = 0; g < G; ++g) {
|
||||
const int buf = (int)(g & 1);
|
||||
if (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 */
|
||||
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<float, 16> sbj[2];
|
||||
simd<int32_t, 128> c[RB][2];
|
||||
#pragma unroll
|
||||
for (int i = 0; i < RB; ++i)
|
||||
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> 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>());
|
||||
const simd<int16_t, 16> nz = 1024 - simd<int16_t, 16>(simd<half, 16>(z16.template bit_cast_view<half>()));
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 2; ++j) c[i][j] = 0;
|
||||
for (int i = 0; i < RB; ++i)
|
||||
#pragma unroll
|
||||
for (int m = 0; m < 8; ++m)
|
||||
c[i][j].template select<16, 1>(m * 16) = nz * (int16_t)as[i * 8 + m];
|
||||
}
|
||||
#pragma unroll
|
||||
for (int ks = 0; ks < 4; ++ks) {
|
||||
simd<uint32_t, 64> B[2];
|
||||
@@ -209,35 +225,20 @@ 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. 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<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);
|
||||
const simd<float, R> asf = as;
|
||||
/* the group's terms ((sum - zero * asum) * a_scale) * scale, libref's chain: the
|
||||
* integer is exact in f32 (under 2^24), scaled a row at a time */
|
||||
#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> lo = w & 0xFFFFu, hi = w >> 16;
|
||||
simd<uint16_t, 16> s16 = lo, z16 = hi;
|
||||
const simd<float, 16> sb = simd<half, 16>(s16.template bit_cast_view<half>());
|
||||
const simd<float, 16> zf = simd<float, 16>(simd<half, 16>(z16.template bit_cast_view<half>())) - 1024.0f;
|
||||
for (int j = 0; j < 2; ++j)
|
||||
#pragma unroll
|
||||
for (int i = 0; i < RB; ++i) {
|
||||
simd<float, 128> cf = c[i][j];
|
||||
#pragma unroll
|
||||
for (int m = 0; m < 8; ++m) {
|
||||
const float a_s = asf[i * 8 + m], a_c = sv[i * 8 + m];
|
||||
simd<float, 16> sub = cf.template select<16, 1>(m * 16) - zf * a_s;
|
||||
simd<float, 16> tt = sub * a_c;
|
||||
tt = tt * sb;
|
||||
simd<float, 16> tt = cf.template select<16, 1>(m * 16) * sv[i * 8 + m];
|
||||
tt = tt * sbj[j];
|
||||
acc[i][j].template select<16, 1>(m * 16) += tt;
|
||||
}
|
||||
}
|
||||
}
|
||||
barrier();
|
||||
}
|
||||
if (!live) return;
|
||||
|
||||
Reference in new issue
Block a user