Archived
libxe2: gdn_chunk_scan on DPAS -- 1100 -> 60 ms at a 2234-token prefill, KL unchanged
The exact scan runs libref's chains one work-item each: ~12.8 GFLOP of a 2234-token prefill of
Qwen3.8-27B took 1.1 s. xe2_gdn_esimd.cpp is the chunked delta rule in flash-linear-attention's
form, in two ESIMD launches:
prep every (sequence, chunk, v head) at once: U = A beta V (f32), W = -A beta e^g K,
Q' = scale e^g Q, R = scale e^{g_i - g_j} Q K^T (j <= i), KT = (e^{g_last - g} K)^T (bf16)
scan a work-group a (sequence, v head, 32 value columns), the f32 state slice in registers:
V' = U + W S, O = Q' S + R V', S = e^{g_last} S + KT V', S and V' passed between the
threads through local memory as DPAS B tiles
bf16 operands into f32, and V' regrouped (A beta V - A beta e^g K S), so it is a fast row held to
rad-kbench's gdn_chunk_scan tolerance (D13); XE2_EXACT=1 (or XE2_GDN_SCAN1=1) keeps the exact
kernel, as does any layout its 2D loads cannot take.
Checks: probe gdnp.cpp against a host copy of libref (partial chunks, 3 sequences, grouped k
heads, h0/ht): o rel_l2 3.2-3.8e-3, ht 0.5-3.0e-3 (tol 2e-2). rad-kbench fixture 30/30, worst
4.8e-3. KL against an XE2_EXACT=1 reference over the 12-document corpus (2002 positions, 2048-token
batches): mean 0.002376, top-1 96.80%, PPL x0.9991 -- with the exact scan 0.002380, 96.65%,
x0.9982. ctest -L sycl 3/3.
An ESIMD note: Lin::off indexes its shape and stride arrays at run time, which puts a private copy
of the kernel argument in memory, and a kernel that does not spill gets no scratch for it -- the
card faulted at stray addresses (device lost). cu goes in as base and stride.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6969fcf8cb
commit
8e8b4352a1
2 files changed
+493
No files matched your search
@@ -136,6 +136,13 @@ size_t groups_for(int64_t n, size_t wg) { return (size_t)((n + (int64_t)wg - 1)
|
||||
|
||||
} // namespace
|
||||
|
||||
/* xe2_gdn_esimd.cpp */
|
||||
int gdn_chunk_scan_dpas(sycl::queue& q, const uint16_t* qp, int64_t qs0, int64_t qs1, const uint16_t* kp, int64_t ks0,
|
||||
int64_t ks1, const uint16_t* vp, int64_t vs0, int64_t vs1, const uint16_t* Ap, int64_t As0,
|
||||
int64_t As1, const float* g, int64_t gs0, int64_t gs1, const float* beta, int64_t bs0,
|
||||
int64_t bs1, uint16_t* op, int64_t os0, int64_t os1, const float* h0, const int64_t* h0s,
|
||||
float* ht, const int64_t* hts, const RadTensor* cu, const char* si, uint32_t sidt, int64_t sw,
|
||||
int64_t T, int64_t N, int64_t H, int64_t Hg, float scale);
|
||||
|
||||
/* ------------------------------------------------------------------ gdn_conv_prep */
|
||||
int gdn_conv_prep(const RadArgs* a, RadStream st) {
|
||||
@@ -696,6 +703,21 @@ int gdn_chunk_scan(const RadArgs* a, RadStream st) {
|
||||
const IV cuv = iv_of(cu);
|
||||
sycl::queue* qu = queue_of(st);
|
||||
if (!qu) return RAD_E_DEVICE;
|
||||
/* The DPAS form (xe2_gdn_esimd.cpp) for the engine's operands: tolerance-held, so not under
|
||||
* XE2_EXACT=1; it refuses a layout its 2D loads cannot take, and the exact kernels run. */
|
||||
if (K == 128 && V == 128 && chunk == 64 && !exact_only() && !std::getenv("XE2_GDN_SCAN1") && qs.dt == RAD_BF16 &&
|
||||
ks.dt == RAD_BF16 && vs.dt == RAD_BF16 && As.dt == RAD_BF16 && os.dt == RAD_BF16 && gs.dt == RAD_F32 &&
|
||||
bs.dt == RAD_F32 && (!has_h0 || h0s.dt == RAD_F32) && (!has_ht || hts.dt == RAD_F32) && qv.s2 == 1 &&
|
||||
kv.s2 == 1 && vv.s2 == 1 && Av.s2 == 1 && ov.s2 == 1) {
|
||||
const int64_t h0st[4] = { h0v.s0, h0v.s1, h0v.s2, h0v.s3 }, htst[4] = { htv.s0, htv.s1, htv.s2, htv.s3 };
|
||||
const int rc = gdn_chunk_scan_dpas(*qu, (const uint16_t*)qs.p, qv.s0, qv.s1, (const uint16_t*)ks.p, kv.s0, kv.s1,
|
||||
(const uint16_t*)vs.p, vv.s0, vv.s1, (const uint16_t*)As.p, Av.s0, Av.s1,
|
||||
(const float*)gs.p, gv.s0, gv.s1, (const float*)bs.p, bv.s0, bv.s1,
|
||||
(uint16_t*)os.p, ov.s0, ov.s1, has_h0 ? (const float*)h0s.p : nullptr, h0st,
|
||||
has_ht ? (float*)hts.p : nullptr, htst, cu, has_si ? sis.p : nullptr, sis.dt,
|
||||
sw, T, N, H, Hg, scale);
|
||||
if (rc != RAD_E_UNSUPPORTED) return rc;
|
||||
}
|
||||
if (K == 128 && V % 32 == 0 && chunk == 64 && !std::getenv("XE2_GDN_SCAN1")) {
|
||||
/* A work-group of 1024 a (sequence, v head, block of 32 value columns), the chunk's k, q,
|
||||
* the block's slices of v, S, W, V' and the sA rows R in local memory (~124 KB). Each phase
|
||||
|
||||
Reference in new issue
Block a user