libxe2: GDN recurrent state store through local memory, out as whole lines

The register kernel stored a lane's own 512-byte state row, so each float4 store
touched 16 cache lines. A sub-group's 16 rows now go through a 9-float4-pitch tile,
32 columns at a time, and out coalesced. Bit-identical (rad-kbench gdn rows rel_l2 0,
greedy hashes unchanged). 9B 58.9 -> 59.2 tok/s, 27B 30.4 -> 30.6 (spec off).
XE2_GDN_ROWSTORE=1 restores the row store.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
aneinanderandClaude Opus 5.5 committed 2026-11-11 20:55:00 +01:00
1 parent 0aad575475
commit 0a1fed0bcf
2 files changed
+37 -1

No files matched your search

+29
View File
@@ -1498,6 +1498,10 @@ int rec_io(const RadArgs* a, const RadTensor* t, int nt, RecIO* r, int64_t* n_se
* order on one work-item, as libref's -- and the folded fp8 group. 384 work-groups a 27B layer
* instead of 48. */
constexpr int64_t kCb = 16; /* columns a work-group of kernel A */
/* The register kernel's state store goes out through local memory (see store_rows): a sub-group's
* 16 rows, 32 columns at a time, a row 9 float4s apart -- 144 bytes, so the 16 lanes' float4 reads
* and writes fall on all 64 banks once. */
constexpr int kTrPitch = 9;
/* Whether sequence n is stepped at all -- the early returns of libref's loop, which leave its o
* rows untouched. */
@@ -1815,12 +1819,17 @@ int launch_recurrent_reg_t(sycl::queue& qu, const RecIO& r, int64_t n_seq, float
namespace intelex = sycl::ext::intel::experimental;
syclex::properties props{intelex::grf_size<256>};
int rc = RAD_OK;
/* the state store through local memory: rows of K contiguous floats (COAL); XE2_GDN_ROWSTORE=1
* keeps a lane's own row */
static const bool rowstore = std::getenv("XE2_GDN_ROWSTORE") != nullptr;
const bool tr_on = COAL && !rowstore;
/* FUSED: one launch, both phases, the gates and kernel B's epilogue in it (see launch_recurrent_wg) */
for (int phase = (r.anchor && !FUSED) ? 0 : 1; phase <= 1 && rc >= 0; ++phase)
rc = submit([&] {
qu.submit([&](sycl::handler& hd) {
sycl::local_accessor<float, 1> os(sycl::range<1>(FUSED ? (size_t)(Tk * V) : 1), hd);
const size_t wg = FUSED ? (size_t)V : (size_t)kCb;
sycl::local_accessor<sycl::float4, 1> tr(sycl::range<1>(tr_on ? wg * kTrPitch : 1), hd);
hd.parallel_for(sycl::nd_range<1>{(size_t)(n_seq * Hv * nblk) * kCb, wg}, props,
[=](sycl::nd_item<1> it) [[sycl::reqd_sub_group_size(kSub)]] {
constexpr int K = kRegK;
@@ -1845,6 +1854,7 @@ int launch_recurrent_reg_t(sycl::queue& qu, const RecIO& r, int64_t n_seq, float
const int64_t nh = FUSED ? gid : gid / nblk;
const int64_t n = nh / Hv, h = nh % Hv, hk = h / r.grp;
const int l = (int)sg.get_local_linear_id();
const int64_t sgl = (int64_t)sg.get_group_linear_id(); /* the sub-group in the work-group */
const int64_t e0 = blk * kCb, e = e0 + l;
const int64_t bos = r.cu.at(n), q_len = r.cu.at(n + 1) - bos;
if (q_len <= 0 && !r.anchor) return;
@@ -1889,6 +1899,25 @@ int launch_recurrent_reg_t(sycl::queue& qu, const RecIO& r, int64_t n_seq, float
};
auto store_rows = [&](int64_t slot) {
if constexpr (COAL) {
if (tr_on) {
/* the block's 16 rows through local memory, 32 columns at a time, and
* out as whole lines: instruction i writes rows 2i/8.. of the chunk, a
* lane a float4 (see kTrPitch) */
sycl::float4* const blkp = (sycl::float4*)((float*)sp + at4(r.stv, slot, h, e0, 0));
sycl::float4* const tb = &tr[(size_t)sgl * kCb * kTrPitch];
for (int c = 0; c < K / 32; ++c) {
for (int m = 0; m < 8; ++m)
tb[l * kTrPitch + m] = sycl::float4(st[32 * c + 4 * m], st[32 * c + 4 * m + 1],
st[32 * c + 4 * m + 2], st[32 * c + 4 * m + 3]);
sycl::group_barrier(sg);
for (int i = 0; i < 8; ++i) {
const int f = i * kSub + l, rr = f / 8, c4 = f % 8;
blkp[rr * (K / 4) + c * 8 + c4] = tb[rr * kTrPitch + c4];
}
sycl::group_barrier(sg);
}
return;
}
sycl::float4* row = (sycl::float4*)((float*)sp + at4(r.stv, slot, h, e, 0));
for (int i = 0; i < K / 4; ++i)
row[i] = sycl::float4(st[4 * i], st[4 * i + 1], st[4 * i + 2], st[4 * i + 3]);