Archived
libxe2: prefill GEMMs on oneMKL -- 27B prefill 208 -> 305 tok/s
oneMKL's SYCL GEMM (part of oneAPI; libxe2 links it when CMake finds it, RAD_XE2_MKL=OFF or XE2_NO_MKL=1 keep the hand-written kernels) runs the fp16 prefill GEMMs at 85-91 TFLOPS on random data at the 27B's shapes, deterministic run to run, against ~23-30 for the hand-tiled XMX kernel: xmx_f16_scaled (the m2xfp4 prefill) and xmx_f16_batched (the rotation's) go to its gemm and gemm_batch, and bf16 gemm_nt at M >= 17 to its bf16 GEMM (N = 96 had fallen to the exact kernel, 5 ms a call). The m2xfp4 weight decode to fp16 now takes a (column, 32-group) a work-item. fp16 or bf16 products with f32 accumulation, as before: the 27B's cases 133/133 (rel_l2 <= 1.42e-3), the fixture 1410/1410. Prefill GEMMs over a 1882-token prompt 4.06 -> 1.66 s. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
This commit is contained in:
1 parent
3f782b935c
commit
c81aa869a0
4 files changed
+123
-11
No files matched your search
+18
-11
@@ -514,7 +514,7 @@ int gemm_nt_q_m2_xmx(const RadArgs* a, RadStream st) {
|
||||
rad_tensor_numel(A) >= M * acols && rad_tensor_numel(AS) >= M * scols &&
|
||||
rad_tensor_numel(BS) >= N * kb &&
|
||||
(!(pb1 > 0 || pb2 > 0) || ((e1 % 16) == 0 && (e2 % 16) == 0 && !(e1 == e2 && e2 < N)));
|
||||
if (!ok || K % 16 || e1 % 64 || e2 % 64 || N % 64) return gemm_nt_q_m2(a, st);
|
||||
if (!ok || K % 16 || e1 % 64 || e2 % 64 || N % 64 || !rad_ptr_aligned(B->data, 16)) return gemm_nt_q_m2(a, st);
|
||||
sycl::queue* q = queue_of(st);
|
||||
if (!q) return RAD_E_DEVICE;
|
||||
/* fp16 operands: the activation fp16(a * a_scale / R_m), R_m = 224 * the row's largest scale
|
||||
@@ -558,18 +558,25 @@ int gemm_nt_q_m2_xmx(const RadArgs* a, RadStream st) {
|
||||
emax[i[0]] = mx;
|
||||
cs[i[0]] = sycl::ldexp(1.0f, mx - 127);
|
||||
});
|
||||
const int64_t nw = N * (K / 2); /* a work-item a code byte: two weights */
|
||||
q->parallel_for(sycl::range<1>((size_t)nw), [=](sycl::id<1> i) {
|
||||
const int64_t n = (int64_t)i[0] / (K / 2), j = (int64_t)i[0] % (K / 2);
|
||||
const uint8_t byte = codes0[n * (K / 2) + j];
|
||||
/* a work-item a (column, 32-group): its 16 code bytes, exponent and meta byte read once,
|
||||
* 32 weights stored 64 bytes at a time (a work-item a code byte re-read the group's
|
||||
* exponent and meta for every weight: ~3 of a 6.7 ms gate_up call) */
|
||||
const int64_t ng = N * kb;
|
||||
q->parallel_for(sycl::range<1>((size_t)ng), [=](sycl::id<1> i) {
|
||||
const int64_t n = (int64_t)i[0] / kb, g = (int64_t)i[0] % kb;
|
||||
constexpr float lut[16] = { 0.0f, 0.5f, 1.0f, 1.5f, 2.0f, 3.0f, 4.0f, 6.0f,
|
||||
-0.0f, -0.5f, -1.0f, -1.5f, -2.0f, -3.0f, -4.0f, -6.0f };
|
||||
const int mx = emax[n];
|
||||
for (int hh = 0; hh < 2; ++hh) {
|
||||
const int64_t k = 2 * j + hh;
|
||||
const float ev = sycl::ldexp(1.0f, (int)expe0[n * brs + (k >> 5)] - mx);
|
||||
const float km = 1.0f + 0.25f * (float)((meta0[n * kb + (k >> 5)] >> (2 * ((k & 31) >> 3))) & 3);
|
||||
w16[n * K + k] = (half)(lut[(byte >> (4 * hh)) & 0xF] * km * ev);
|
||||
const sycl::vec<uint8_t, 16> cb = *(const sycl::vec<uint8_t, 16>*)(codes0 + n * (K / 2) + g * 16);
|
||||
const float ev = sycl::ldexp(1.0f, (int)expe0[n * brs + g] - emax[n]);
|
||||
const uint32_t mt = meta0[n * kb + g];
|
||||
for (int q8 = 0; q8 < 4; ++q8) { /* 8 weights: the subgroup q8 of the group */
|
||||
const float km = 1.0f + 0.25f * (float)((mt >> (2 * q8)) & 3);
|
||||
sycl::vec<half, 8> o;
|
||||
for (int u = 0; u < 8; ++u) {
|
||||
const int kk = q8 * 8 + u;
|
||||
o[u] = (half)(lut[(cb[kk >> 1] >> (4 * (kk & 1))) & 0xF] * km * ev);
|
||||
}
|
||||
*(sycl::vec<half, 8>*)(w16 + n * K + g * 32 + q8 * 8) = o;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user