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

+80
View File
@@ -79,6 +79,86 @@ int rerank(const RadArgs* a, RadStream st, bool joined) {
float* pairs = PAIRS ? (float*)PAIRS->data : nullptr;
sycl::queue* q = queue_of(st);
if (!q) return RAD_E_DEVICE;
if (!exact_only() && R <= 32) {
/* The fast form: a work-group a row, sub-group r candidate r, its lanes along K. libref sums
* in double; here each product is split exactly (two-product) and summed as a float pair
* (two-sum), the lanes' pairs combined in a fixed tree: ~48 significant bits, rounded once,
* so the score is libref's unless its exact value sits within ~2^-24 ulp of an f32
* rounding boundary -- a fast kernel, held to the tolerance (and the drafter's acceptance
* changes only through such ties). The selection is libref's, one work-item a row. */
return submit([&] {
q->submit([&](sycl::handler& h) {
sycl::local_accessor<float, 1> scl(sycl::range<1>((size_t)R), h);
sycl::local_accessor<int32_t, 1> idl(sycl::range<1>((size_t)R), h);
h.parallel_for(sycl::nd_range<1>{(size_t)M * (size_t)R * kSub, (size_t)R * kSub},
[=](sycl::nd_item<1> it) [[sycl::reqd_sub_group_size(kSub)]] {
const int64_t m = (int64_t)it.get_group(0);
const sycl::sub_group sg = it.get_sub_group();
const int64_t r = (int64_t)sg.get_group_linear_id();
const int lane = (int)sg.get_local_linear_id();
HPlane cp, sp;
if (joined) {
cp = hplane(wb, "codes");
sp = hplane(wb, "scale");
if (!cp.p || !sp.p) return;
}
const int64_t g = ld_index(in.dtype, in.base, m * in.pitch + r);
const int64_t local = g - voff;
const bool pad = g < 0 || local < 0 || local >= NV; /* uniform in the sub-group */
auto two_sum = [](float a, float b, float& s2, float& e) {
s2 = a + b;
const float bb2 = s2 - a;
e = (a - (s2 - bb2)) + (b - bb2);
};
float hi = 0.0f, lo = 0.0f;
if (!pad)
for (int64_t k = lane; k < K; k += kSub) {
const float xv = rad_load_f32(x.base, x.dtype, m * x.pitch + k);
const float wv = joined ? cp.at(local, k) * sp.cover(local, k)
: rad_load_f32(w.base, w.dtype, local * w.pitch + k);
const float pr = xv * wv;
const float pe = sycl::fma(xv, wv, -pr);
float sv, se;
two_sum(hi, pr, sv, se);
hi = sv;
lo += se + pe;
}
for (int off = 8; off > 0; off >>= 1) {
const float h2 = sycl::shift_group_left(sg, hi, off);
const float l2 = sycl::shift_group_left(sg, lo, off);
float sv, se;
two_sum(hi, h2, sv, se);
hi = sv;
lo = lo + l2 + se;
}
if (lane == 0) {
idl[r] = pad ? -1 : (int32_t)g;
scl[r] = pad ? -INFINITY : hi + lo;
}
sycl::group_barrier(it.get_group());
if (it.get_local_id(0) != 0) return;
uint32_t used = 0;
for (int64_t o = 0; o < R; ++o) {
int64_t best = -1;
for (int64_t c = 0; c < R; ++c) {
if (((used >> c) & 1u) || idl[c] < 0) continue;
if (best < 0 || scl[c] > scl[best] || (scl[c] == scl[best] && idl[c] < idl[best])) best = c;
}
const int32_t oid = best >= 0 ? idl[best] : -1;
const float ov = best >= 0 ? scl[best] : -INFINITY;
if (best >= 0) used |= 1u << best;
st_index(idx.dtype, idx.base, m * idx.pitch + o, (int64_t)oid);
rad_store_f32(val.base, val.dtype, m * val.pitch + o, ov);
if (pairs) {
float* pp = pairs + (m * R + o) * 2;
pp[0] = sycl::bit_cast<float>(oid);
pp[1] = ov;
}
}
});
});
});
}
float* ws = workspace(*q, (size_t)(M * R * 3));
if (!ws) return RAD_E_DEVICE;
const size_t wg = 16;