libxe2, arch/common: the 28 Oct pending set, the bf16 cast fused, the vectorized norm, a draft-vocab prefix

- gdn_kkt_solve on DPAS (~0.4 ms at 2048 tokens against 7.7), the int8 head's DPAS forms at 9-16
  rows (verify past depth 7), the plain block norm (RadBuildCtx::plain_norm, set on the SYCL
  backend: `add` + `rmsnorm` where no reader takes the E4M3 codes) with the fast rmsnorm rows.
- rmsnorm's bf16 rows up to 8192 wide: a work-item eight elements by one 16-byte load (the generic
  form walked 20 dependent loads a work-item): 24.7 -> 3.3 us a decode norm, ~3.5 ms a round.
- w4a16: a bf16 activation narrowed to fp16 at the kernel's own load (the separate cast launch
  before every GEMM is gone), bit for bit the same.
- RADIANCE_MTP_DRAFT_VOCAB=N: the 2-bit draft head over the vocabulary's first N ids (a prefix
  shortlist, GRIMOIRE's idea); the u2 layout hook takes an op N below the weight's rows. 131072:
  greedy acceptance identical on the decode proxy, draft head 650 -> 351 us a pass.

KL against the exact-kernel reference (2002 positions): 0.002386, top-1 97.30% (was 0.002376 /
96.80%). Decode proxy (greedy, depth 5, mtp4): 72.0 -> 74.3 tok/s with the prefix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-11-02 01:52:01 +01:00
1 parent 7580ec3d17
commit 726e532114
18 files changed
+472 -54

No files matched your search

+6 -22
View File
@@ -40,7 +40,7 @@
namespace xe2 {
/* xe2_gemm_w4_esimd.cpp */
int w4a16_esimd(sycl::queue& q, int rc, const sycl::half* a, int64_t ars, int mm, const uint32_t* ct,
int w4a16_esimd(sycl::queue& q, int rc, const void* a, bool a_bf16, int64_t ars, int mm, const uint32_t* ct,
const uint32_t* sz, int64_t N, int64_t K, int splits, char* yb, uint32_t ydt, int64_t yrs);
int w4a8i8_esimd(sycl::queue& q, const uint8_t* ap, const int32_t* asumt, const float* sat, int64_t mpad,
const uint32_t* ct, const uint32_t* sz, int64_t M, int64_t N, int64_t K, char* yb, uint32_t ydt,
@@ -394,8 +394,8 @@ int gemm_nt_q_w4a16(const RadArgs* a, RadStream st) {
W4Call c;
if (int rc = w4_parse(a, &c); rc != RAD_OK) return rc;
/* A bf16 activation (arch/common since upstream 492d33c, which dropped the separate cast) is
* narrowed to f16 round-to-nearest-even into a workspace first: the cast it replaced, bit for
* bit. TODO: narrow in the kernel's activation load instead. */
* narrowed to f16 round-to-nearest-even at the kernel's activation load: the cast it replaced,
* bit for bit. */
const bool a_bf16 = c.adt == RAD_BF16;
if (c.kind != W4::F16 || !c.tl || (c.adt != RAD_F16 && !a_bf16) || c.M > 64 || c.ys_c != 1 ||
(c.ydt != RAD_BF16 && c.ydt != RAD_F32) || (c.ars * 2) % 16 || !rad_ptr_aligned(c.ab, 64) ||
@@ -403,29 +403,13 @@ int gemm_nt_q_w4a16(const RadArgs* a, RadStream st) {
return gemm_nt_q_w4(a, st);
sycl::queue* q = queue_of(st);
if (!q) return RAD_E_DEVICE;
const sycl::half* a16 = (const sycl::half*)c.ab;
int64_t ars = c.ars;
if (a_bf16) {
const int64_t M = c.M, K = c.K, src_rs = c.ars;
ars = (K + 31) / 32 * 32;
sycl::half* buf = (sycl::half*)workspace(*q, (size_t)((M * ars + 1) / 2), 9);
if (!buf) return RAD_E_DEVICE;
const uint16_t* src = (const uint16_t*)c.ab;
const int rc = submit([&] {
q->parallel_for(sycl::range<1>((size_t)(M * K)), [=](sycl::id<1> id) {
const int64_t i = (int64_t)id[0], m = i / K, k = i % K;
const uint32_t bits = (uint32_t)src[m * src_rs + k] << 16;
buf[m * ars + k] = sycl::half(sycl::bit_cast<float>(bits));
});
});
if (rc != RAD_OK) return rc;
a16 = buf;
}
const uint16_t* a16 = (const uint16_t*)c.ab;
const int64_t ars = c.ars;
const int splits = w4_splits(c.G);
for (int64_t m0 = 0; m0 < c.M; m0 += 8) {
const int mm = (int)std::min<int64_t>(8, c.M - m0);
const int rcount = mm == 1 ? 1 : (mm <= 2 ? 2 : (mm <= 4 ? 4 : 8));
const int rc = w4a16_esimd(*q, rcount, a16 + m0 * ars, ars, mm, (const uint32_t*)c.bb, (const uint32_t*)c.bsb,
const int rc = w4a16_esimd(*q, rcount, a16 + m0 * ars, a_bf16, ars, mm, (const uint32_t*)c.bb, (const uint32_t*)c.bsb,
c.N, c.K, splits, c.yb + m0 * c.ys_r * (c.ydt == RAD_F32 ? 4 : 2), c.ydt, c.ys_r);
if (rc != RAD_OK) return rc;
}