libxe2: the DFlash2 path fast -- exact draft head, DPAS verify GEMV, parallel rerank

- gemm_nt_q over the zero-point grids at M <= 16 (the drafter's 2-bit vocabulary head, N=248320):
  a sub-group a column, the group sums exact integers in f32, libref's group terms added in group
  order through lane broadcasts -- bit-identical to the exact kernel on the live head (checked in
  the engine: 0 differing bytes of 3.5 MB, every round). 252 ms -> well under 1 ms a call.
- m2xfp4 at 2 <= M <= 16 (the verify width) on XMX: a lane a column decodes its codes a 64-byte line
  at a time into its sub-group's VNNI slice of local memory (subnormal-bit fp16 pairs times
  (1 + k/4) * 2^(e - e_max + 14)), eight K16 DPAS a step against the permuted fp16 activation,
  K split for narrow N, partials added in order. On the vector ALUs M = 8 cost five times M = 1;
  gate_up at M = 8 1159 -> ~490 us. rad-kbench on the 27B: 50/50, rel_l2 ~8.5e-4 (tol 4e-2).
- logit_rerank: a work-group a row, a sub-group a candidate along K, libref's double sum as a float
  pair (two-product, two-sum, a fixed lane tree), libref's selection; 136 ms -> negligible a call.
- the gated delta net's gate, beta and decay (libref's double exp / log1p) once a (token, head)
  in a prepass instead of once a column block; still bit-identical (10/10 at rel_l2 0).
- profile_decode.sh: KEEP=DIR keeps the per-geometry tables.

27B on the B65, greedy: 12.1 tok/s plain, 13.2 tok/s with the drafter (device time a token
217 -> 76 ms under speculation). The drafter's text now departs from plain decoding at a
near-tie (byte 246 of 256 tokens): the verify forward runs the M = 8 DPAS path and plain decoding
the M = 1 GEMV, whose roundings differ (~1e-3); with the exact kernels the two were identical.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
This commit is contained in:
pascallinxweilerandClaude Opus 5.5 committed 2026-10-24 04:37:16 +02:00
1 parent 07cdc546a3
commit 55a350f0c6
7 files changed
+399 -7

No files matched your search

+23 -7
View File
@@ -982,6 +982,23 @@ int launch_recurrent_wg(sycl::queue& qu, const RecIO& r, int64_t n_seq, int64_t
const int64_t nblk = V / kCb;
float* orow = workspace(qu, (size_t)(Tk * Hv * V + 64), 3);
if (!orow) return RAD_E_DEVICE;
/* Each token's gate, beta and decay -- libref's double exp / log1p, which this card emulates --
* once a (token, head) here, not once a block below: [Tk][Hv][3]. */
float* gates = workspace(qu, (size_t)(Tk * Hv * 3 + 64), 4);
if (!gates) return RAD_E_DEVICE;
if (int rc0 = submit([&] {
qu.parallel_for(sycl::range<1>((size_t)(Tk * Hv)), [=](sycl::id<1> i) {
const int64_t tok = (int64_t)i[0] / Hv, h = (int64_t)i[0] % Hv;
const float alog = r.alog.p ? r.alog.ld(h * r.alog_s) : 0.0f;
const float dtb = r.dtb.p ? r.dtb.ld(h * r.dtb_s) : 0.0f;
const float gv = -rexp(alog) * softplus(r.av.ld(at2(r.a2, tok, h)) + dtb, r.spthr);
gates[i[0] * 3 + 0] = gv;
gates[i[0] * 3 + 1] = sigm(r.bv.ld(at2(r.b2, tok, h)));
gates[i[0] * 3 + 2] = rexp(gv);
});
});
rc0 < 0)
return rc0;
/* Under `anchor` the replay is its own launch (phase 0): every block reads the stamp and the
* previous step's factors before any block of the head overwrites them in phase 1. */
int rc = RAD_OK;
@@ -1040,10 +1057,7 @@ int launch_recurrent_wg(sycl::queue& qu, const RecIO& r, int64_t n_seq, int64_t
};
load_state(slot_in);
sycl::group_barrier(grp);
const float alog = r.alog.p ? r.alog.ld(h * r.alog_s) : 0.0f;
const float dtb = r.dtb.p ? r.dtb.ld(h * r.dtb_s) : 0.0f;
auto update_col = [&](float g, float bt, float ve) {
const float dec = rexp(g);
auto update_dec = [&](float dec, float bt, float ve) {
float sk2 = 0.0f;
for (int64_t d = 0; d < K; ++d) {
St[d * kCb + l] *= dec;
@@ -1052,6 +1066,7 @@ int launch_recurrent_wg(sycl::queue& qu, const RecIO& r, int64_t n_seq, int64_t
const float uu = bt * (ve - sk2);
for (int64_t d = 0; d < K; ++d) St[d * kCb + l] += uu * kn[d];
};
auto update_col = [&](float g, float bt, float ve) { update_dec(rexp(g), bt, ve); };
if (r.anchor && phase == 0) {
for (int64_t t = 0; t < na; ++t) {
const int64_t f = fb + t * al.fstr;
@@ -1072,8 +1087,9 @@ int launch_recurrent_wg(sycl::queue& qu, const RecIO& r, int64_t n_seq, int64_t
for (int c = 0; c < 3; ++c) r.state.st(fbs[c] + al.mark, (float)(c + 1));
for (int64_t t = 0; t < q_len; ++t) {
const int64_t tok = bos + t;
const float gv = -rexp(alog) * softplus(r.av.ld(at2(r.a2, tok, h)) + dtb, r.spthr);
const float bt = sigm(r.bv.ld(at2(r.b2, tok, h)));
const float gv = gates[(tok * Hv + h) * 3 + 0];
const float bt = gates[(tok * Hv + h) * 3 + 1];
const float dec = gates[(tok * Hv + h) * 3 + 2];
sycl::group_barrier(grp);
for (int64_t d = l; d < K; d += kCb) {
qraw[d] = r.q.ld(at3(r.qv, tok, hk, d));
@@ -1092,7 +1108,7 @@ int launch_recurrent_wg(sycl::queue& qu, const RecIO& r, int64_t n_seq, int64_t
kn[d] = kraw[d] * ks;
}
sycl::group_barrier(grp);
update_col(gv, bt, r.v.ld(at3(r.vv, tok, h, e)));
update_dec(dec, bt, r.v.ld(at3(r.vv, tok, h, e)));
float oe = 0.0f;
for (int64_t d = 0; d < K; ++d) oe += St[d * kCb + l] * qn[d];
orow[(tok * Hv + h) * V + e] = oe;