diff --git a/docs/SYCL_PROGRESS.md b/docs/SYCL_PROGRESS.md index 48791701..8fcad007 100644 --- a/docs/SYCL_PROGRESS.md +++ b/docs/SYCL_PROGRESS.md @@ -1061,9 +1061,16 @@ at ~1,170 GB/s (Xe2's lossless compression), so bandwidth probes must use random | 8 | `d35027aa` | split-KV attention up to head_dim 512 (was: the exact kernel above 256); instantiated at 16 and 32 values a lane, head_dim <= 256 unchanged | rad-kbench Gemma 4 attn 320/320 | hd512 decode 192 -> 43 us, q256 55 -> 20 ms; Gemma 4 decode 58.6 -> 63.0, prefill @2.4k 724 -> 1,537 | | 9 | `dd20835f` | sliding-window attention on the DPAS kernels (was: the SIMT kernel for any window), its own instantiation so window 0 is unchanged | Gemma 4 attn 320/320, 9B 160/160 (times = old code within 0.5%), fixture 2144/2144 | window 512 decode 101 -> 23.5 us, q512 2,833 -> 98 us; Gemma 4 decode 63.0 -> 74.4, prefill 1,537 -> 1,886; long-context retrieval checked | | 10 | `9aef2966` | the fused gated-attention prologue `qk_norm_rope_gate(+_kv_store)` (qwen35 family, Qwen4-Exp, FishOmni, MTP heads): q/k norm, partial rope from the `rope_table` plane, kv_store, one launch for five; byte-identical to libxe2's unfused ops, schemas libr4d's; the `_kv_store` row declares its chain and both describe their operands | rad-kbench fusion oracle 28/28 byte-identical on the 9B and the 27B; fixture 2144/2144; greedy hashes identical with and without, both models | 9B decode 58.3 -> 58.9 tok/s, 27B 30.1 -> 30.4 (spec off); prefill unchanged | +| 11 | (this commit) | the GDN register kernel's state store through local memory: a sub-group's 16 state rows, 32 columns at a time, out as whole cache lines instead of a lane's own 512-byte row (16 lines touched a store instruction); the loads stay a lane's row (coalescing them gained nothing in probe gdnd.cpp) | rad-kbench gdn rows rel_l2 0 (fixture 15/15, 9B 40/40); greedy hashes identical, both models | probe (27B decode shape, cold state) 24.9 -> 21.2 us a call; 9B decode 58.9 -> 59.2 tok/s, 27B 30.4 -> 30.6 (spec off, A/B x2); prefill unchanged | Escape hatches: `XE2_ATTN_SIMT=1`, `XE2_GEMV_SIMT=1`, `XE2_W4_RB8=1` restore the previous forms; -`XE2_EXACT=1` the ref rows of 4; `XE2_NO_FUSED_PROLOGUE=1` leaves the rows of 7 and 10 undeclared. +`XE2_EXACT=1` the ref rows of 4; `XE2_NO_FUSED_PROLOGUE=1` leaves the rows of 7 and 10 undeclared; +`XE2_GDN_ROWSTORE=1` restores 11's row store. + +**The GDN decode floor** (probe gdnd.cpp, 27B shape: 48 heads x 64 KB of f32 state, read and written): a plain +read-modify-write of the same 6.3 MB with random data takes 12.3-13.8 us at any thread count (a constant fill +reads 8.4 us: the card compresses it), so ~13-15 us a call is the floor, not the ~7-10 us estimated before; the +rest of the 21 us is the load -> serial libref chains -> store order a thread must keep. **27B re-bench at `47d1a952`** (bench-standard quick, spec off, run 11): decode 29.7 tok/s, prefill 1,443 / 1,068 tok/s at 2k / 64k, greedy hash `ac03957082a0` -- the same as run 5 at `6abca01f`, so diff --git a/libxe2/xe2_gdn.cpp b/libxe2/xe2_gdn.cpp index 02053525..1cb8b834 100644 --- a/libxe2/xe2_gdn.cpp +++ b/libxe2/xe2_gdn.cpp @@ -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 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 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]);