libxe2: Phase 4 step 1 -- a bandwidth-bound decode GEMV and an ordered sum from local memory

The profile of a MiniCPM5-2B decode step on the B65 (232.8 ms) was 79% gemm_nt, reading its
weights at 62 GB/s, and 13% the norms' serial sum of squares.

- xe2_gemm_nt_gemv / xe2_logits_gemm_gemv (priority 10, M <= 16, bf16): a sub-group an output
  column, 16-byte coalesced weight loads, a tree reduction. Not libref's order: rad-kbench passes
  them at the gemm tolerance (fixture 361/361, MiniCPM5 180/180, worst rel_l2 1.6e-4), and
  XE2_EXACT=1 sends every launch to the exact kernel for bisecting.
- The norms form their squares in parallel into local memory and add them in index order: still
  bit-identical to libref.

Decode 4.2 -> 35.5 tok/s. Against a libref-only host build, over 1914 positions of the repo's docs
with every position through the GEMV: KL mean 5.9e-4, p99 3.5e-3, top-1 98.5% -- libavx's own
distance from libref is 5.7e-4 / 3.0e-3 / 98.6%. The exact path scores KL 0, top-1 100%.

docs/SYCL_PROGRESS.md: the profile, the KL bound (D13), and the user's decision to use the bf16
container for Milestone B instead of the fp8 one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018EpFgqQidSnH8zo7boVZC1
This commit is contained in:
claudeandClaude Opus 5.5 committed 2026-10-23 19:48:40 +02:00
1 parent 5da5c1ba05
commit a65ab54213
5 files changed
+196 -9

No files matched your search

+21 -7
View File
@@ -35,17 +35,31 @@ constexpr size_t kWg = 256; /* work-items a row */
* such code in some of MiniCPM5-2B's 42 layers, enough to flip a greedy near-tie later. */
inline float sigmoidf(float x) { return 1.0f / (1.0f + (float)sycl::exp((double)-x)); }
/* The sum of src(i)^2 over i < n in ascending order, f32, as libref sums it, computed by work-item
* 0 and returned to every work-item of the group. */
/* The sum of src(i)^2 over i < n in ascending order, f32, as libref sums it, returned to every
* work-item of the group. The squares are formed in parallel into local memory a chunk at a time
* and work-item 0 adds them in index order: the same additions as a serial loop, bit for bit, but
* reading local memory instead of waiting on one global load after another (that serial walk was
* 13% of a MiniCPM5 decode step, 360 us a call). */
constexpr int64_t kSqChunk = 2048;
template <class F>
inline float ordered_sumsq(const sycl::nd_item<1>& it, const F& src, int64_t n) {
auto grp = it.get_group();
float* sq = *sycl::ext::oneapi::group_local_memory_for_overwrite<float[kSqChunk]>(grp);
const int64_t t = (int64_t)it.get_local_id(0), wg = (int64_t)it.get_local_range(0);
float ss = 0.0f;
if (it.get_local_id(0) == 0)
for (int64_t i = 0; i < n; ++i) {
const float v = src(i);
ss += v * v;
for (int64_t c0 = 0; c0 < n; c0 += kSqChunk) {
const int64_t cn = sycl::min(kSqChunk, n - c0);
for (int64_t i = t; i < cn; i += wg) {
const float v = src(c0 + i);
sq[i] = v * v;
}
return sycl::group_broadcast(it.get_group(), ss, 0);
sycl::group_barrier(grp);
if (t == 0)
for (int64_t i = 0; i < cn; ++i) ss += sq[i];
sycl::group_barrier(grp);
}
return sycl::group_broadcast(grp, ss, 0);
}
/* One group's codes and scale, by the sub-group `sg` over values v(k0 + i), i < len.