Merge upstream main (v1.12 -> v1.15.1, 408 commits) into the SYCL port

Conflicts from the old m2xfp branch take upstream's version. Two libxe2 fixes the merge needs:
- rad_plugin_abi_layout: the plugin now exports the ABI layout hash the loader checks.
- gemm_nt_q_w4a16: upstream 492d33c sends bf16 activations to the w4a16 GEMM (the separate cast
  is gone); the fast kernel took only f16, so every call fell back to the exact path (decode
  ~2.5 tok/s). A bf16 activation is narrowed to f16 (round to nearest even) into a workspace first,
  the dropped cast bit for bit; decode back to ~57 tok/s on one request.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-11-02 00:25:57 +01:00
commit 7580ec3d17
937 files changed
+285776 -8914

No files matched your search

+24 -3
View File
@@ -393,18 +393,39 @@ int gemm_nt_q_w4a16(const RadArgs* a, RadStream st) {
if (exact_only() || std::getenv("XE2_W4_EXACT")) return gemm_nt_q_w4(a, st);
W4Call c;
if (int rc = w4_parse(a, &c); rc != RAD_OK) return rc;
if (c.kind != W4::F16 || !c.tl || c.adt != RAD_F16 || c.M > 64 || c.ys_c != 1 ||
/* 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. */
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) ||
!rad_ptr_aligned(c.bb, 64) || !rad_ptr_aligned(c.bsb, 64))
return gemm_nt_q_w4(a, st);
sycl::queue* q = queue_of(st);
if (!q) return RAD_E_DEVICE;
const int splits = w4_splits(c.G);
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 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 * c.ars, c.ars, mm, (const uint32_t*)c.bb, (const uint32_t*)c.bsb,
const int rc = w4a16_esimd(*q, rcount, a16 + m0 * ars, 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;
}