Archived
libxe2: givens_dense_quant on XMX for prefill rows -- 2.07 -> 0.70 s over a 1792-token prefill
For 17 or more rows the rotation is a batch of GEMMs, one a (part, 128-column group): the input fp16(x / D) per part, the f16 rotation as B, a batched form of the tiled fp16 XMX kernel (xmx_f16_batched) into f32, then libref's quantiser a (row, part, group). The input rounded once to fp16 where libref sums in double: a fast kernel. KL against the exact reference: mean 0.0037, top-1 97.2% (0.0035 / 95.6% before: within the noise of 250 positions). Up to 16 rows the float-pair kernel stays. 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
57f02bc12d
commit
5720a958e4
3 files changed
+127
No files matched your search
@@ -251,6 +251,84 @@ int xmx_f16_tiled(sycl::queue& q, const sycl::half* ab, int64_t ars, const sycl:
|
||||
});
|
||||
}
|
||||
|
||||
/* The same tiling, batched and unscaled: batch b multiplies A + b * a_bs by B + b * b_bs into the
|
||||
* f32 C + b * c_bs, [M, N] row-major (ldc = N). N a multiple of 128, K of 32. */
|
||||
int xmx_f16_batched(sycl::queue& q, const sycl::half* ab, int64_t ars, int64_t a_bs, const sycl::half* bb,
|
||||
int64_t brs, int64_t b_bs, float* cb, int64_t c_bs, int64_t M, int64_t N, int64_t K,
|
||||
int64_t batch) {
|
||||
using hf = sycl::half;
|
||||
constexpr int BM = 128, BN = 128, BK = 32, SGM = 32, SGN = 64;
|
||||
const size_t gm = (size_t)((M + BM - 1) / BM), gn = (size_t)(N / BN);
|
||||
namespace intelex = sycl::ext::intel::experimental;
|
||||
syclex::properties props{intelex::grf_size<256>};
|
||||
return submit([&] {
|
||||
q.submit([&](sycl::handler& h) {
|
||||
sycl::local_accessor<hf, 1> As(sycl::range<1>(2 * BM * BK), h);
|
||||
sycl::local_accessor<uint32_t, 1> Bs(sycl::range<1>(2 * (BK / 2) * BN), h);
|
||||
h.parallel_for(sycl::nd_range<3>{{(size_t)batch, gm, gn * 128}, {1, 1, 128}}, props,
|
||||
[=](sycl::nd_item<3> it) [[sycl::reqd_sub_group_size(kSub)]] {
|
||||
const sycl::sub_group sg = it.get_sub_group();
|
||||
const int s = (int)sg.get_group_linear_id(), t = (int)it.get_local_id(2);
|
||||
const int sm = s / 2, sn = s % 2;
|
||||
const int64_t bt = (int64_t)it.get_group(0);
|
||||
const hf* a0 = ab + bt * a_bs;
|
||||
const hf* b0 = bb + bt * b_bs;
|
||||
float* c0 = cb + bt * c_bs;
|
||||
const int64_t mb0 = (int64_t)it.get_group(1) * BM, nb0 = (int64_t)it.get_group(2) * BN;
|
||||
jm::joint_matrix<sycl::sub_group, hf, jm::use::a, 8, 16, jm::layout::row_major> ma[4];
|
||||
jm::joint_matrix<sycl::sub_group, hf, jm::use::b, 16, 16, jm::layout::ext_intel_packed> mb;
|
||||
jm::joint_matrix<sycl::sub_group, float, jm::use::accumulator, 8, 16> mc[4][4];
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (int j = 0; j < 4; ++j) jm::joint_matrix_fill(sg, mc[i][j], 0.0f);
|
||||
auto stage_in = [&](int buf, int64_t k0) {
|
||||
for (int r = 0; r < 4; ++r) {
|
||||
const int idx = t + r * 128;
|
||||
const int row = idx / 4, kc = (idx % 4) * 8;
|
||||
const int64_t gm_ = mb0 + row;
|
||||
sycl::vec<uint32_t, 4> v(0u, 0u, 0u, 0u);
|
||||
if (gm_ < M) v = *(const sycl::vec<uint32_t, 4>*)(a0 + gm_ * ars + k0 + kc);
|
||||
*(sycl::vec<uint32_t, 4>*)&As[buf * BM * BK + row * BK + kc] = v;
|
||||
}
|
||||
for (int r = 0; r < 2; ++r) {
|
||||
const int idx = t + r * 128;
|
||||
const int n = idx / 2, kc = (idx % 2) * 16;
|
||||
const sycl::vec<uint32_t, 8> v = *(const sycl::vec<uint32_t, 8>*)(b0 + (nb0 + n) * brs + k0 + kc);
|
||||
for (int u = 0; u < 8; ++u) Bs[buf * (BK / 2) * BN + (kc / 2 + u) * BN + n] = v[u];
|
||||
}
|
||||
};
|
||||
stage_in(0, 0);
|
||||
int buf = 0;
|
||||
for (int64_t k0 = 0; k0 < K; k0 += BK) {
|
||||
sycl::group_barrier(it.get_group());
|
||||
if (k0 + BK < K) stage_in(buf ^ 1, k0 + BK);
|
||||
for (int kk = 0; kk < BK; kk += 16) {
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
auto la = sycl::address_space_cast<sycl::access::address_space::local_space,
|
||||
sycl::access::decorated::no>(&As[buf * BM * BK + (sm * SGM + i * 8) * BK + kk]);
|
||||
jm::joint_matrix_load(sg, ma[i], la, BK);
|
||||
}
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
auto lb = sycl::address_space_cast<sycl::access::address_space::local_space,
|
||||
sycl::access::decorated::no>(
|
||||
(hf*)&Bs[buf * (BK / 2) * BN + (kk / 2) * BN] + (sn * SGN + j * 16) * 2);
|
||||
jm::joint_matrix_load(sg, mb, lb, BN * 2);
|
||||
for (int i = 0; i < 4; ++i) jm::joint_matrix_mad(sg, mc[i][j], ma[i], mb, mc[i][j]);
|
||||
}
|
||||
}
|
||||
buf ^= 1;
|
||||
}
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
const int64_t m0 = mb0 + sm * SGM + i * 8, n0 = nb0 + sn * SGN + j * 16;
|
||||
auto gc = sycl::address_space_cast<sycl::access::address_space::global_space,
|
||||
sycl::access::decorated::no>(c0 + m0 * N + n0);
|
||||
jm::joint_matrix_store(sg, mc[i][j], gc, (size_t)N, jm::layout::row_major);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
int xmx_f16_scaled(sycl::queue& q, const sycl::half* ab, int64_t ars, const sycl::half* bb, int64_t brs,
|
||||
char* yb, uint32_t ydt, int64_t yrs, int64_t ycs, int64_t M, int64_t mpad, int64_t N,
|
||||
int64_t K, const float* rs, const float* cs) {
|
||||
|
||||
Reference in new issue
Block a user