Archived
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:
1 parent
7580ec3d17
commit
726e532114
18 files changed
+472
-54
No files matched your search
@@ -162,6 +162,96 @@ int rmsnorm(const RadArgs* a, RadStream st) {
|
||||
if (rows <= 0 || y.rows < rows) return RAD_E_SHAPE;
|
||||
sycl::queue* q = queue_of(st);
|
||||
if (!q) return RAD_E_DEVICE;
|
||||
/* The fast rows (D13): each work-item's squares added in index order, the partials by
|
||||
* reduce_over_group's tree -- not libref's order, held to rmsnorm's tolerance (bf16 4e-3, f32
|
||||
* 1e-6). libref's one chain is ~13 cycles an element on one work-item (~31 us of a 5120-wide
|
||||
* decode norm's ~40); XE2_EXACT=1 keeps it (below). Rows up to 512 wide (the per-head q / k
|
||||
* norms) take a sub-group each, wider ones a work-group. */
|
||||
if (!exact_only()) {
|
||||
if (n <= 512) {
|
||||
constexpr int64_t kRowsWg = (int64_t)kWg / kSub;
|
||||
return submit([&] {
|
||||
syclex::nd_launch(*q, sycl::nd_range<1>{(size_t)((rows + kRowsWg - 1) / kRowsWg) * kWg, kWg},
|
||||
[=](sycl::nd_item<1> it) [[sycl::reqd_sub_group_size(kSub)]] {
|
||||
const sycl::sub_group sg = it.get_sub_group();
|
||||
const int64_t r = (int64_t)it.get_group(0) * kRowsWg + (int64_t)sg.get_group_linear_id();
|
||||
if (r >= rows) return; /* uniform over the sub-group */
|
||||
const int l = (int)sg.get_local_linear_id();
|
||||
float ss = 0.0f;
|
||||
for (int64_t i = l; i < n; i += kSub) {
|
||||
const float v = rad_load_f32(x.base, x.dtype, r * x.pitch + i);
|
||||
ss += v * v;
|
||||
}
|
||||
ss = sycl::reduce_over_group(sg, ss, sycl::plus<float>());
|
||||
const float s = 1.0f / sycl::sqrt(ss / (float)n + eps);
|
||||
for (int64_t i = l; i < n; i += kSub) {
|
||||
const float gw = g.base ? rad_load_f32(g.base, g.dtype, i * g.stride) + wadd : 1.0f;
|
||||
const float v = rad_load_f32(x.base, x.dtype, r * x.pitch + i);
|
||||
rad_store_f32(y.base, y.dtype, r * y.pitch + i, v * s * gw * mult);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
/* bf16 rows up to 8192 wide: a work-item eight elements by one 16-byte load, the row in
|
||||
* registers once (the generic form below walks 20 dependent loads a work-item at n = 5120,
|
||||
* ~25 us for six rows; this is one load a work-item). */
|
||||
const int64_t nv = n / 8, wgv = (nv + kSub - 1) / kSub * kSub;
|
||||
if (x.dtype == RAD_BF16 && y.dtype == RAD_BF16 && n % 8 == 0 && wgv <= 1024 && x.pitch % 8 == 0 &&
|
||||
y.pitch % 8 == 0 && rad_ptr_aligned(x.base, 16) && rad_ptr_aligned(y.base, 16) &&
|
||||
(!g.base || ((g.dtype == RAD_F32 || g.dtype == RAD_BF16) && g.stride == 1))) {
|
||||
using V8 = sycl::vec<uint16_t, 8>;
|
||||
return submit([&] {
|
||||
syclex::nd_launch(*q, sycl::nd_range<1>{(size_t)(rows * wgv), (size_t)wgv},
|
||||
[=](sycl::nd_item<1> it) [[sycl::reqd_sub_group_size(kSub)]] {
|
||||
const int64_t r = (int64_t)it.get_group(0);
|
||||
const int64_t t = (int64_t)it.get_local_id(0);
|
||||
const bool live = t < nv;
|
||||
float v[8];
|
||||
float ss = 0.0f;
|
||||
if (live) {
|
||||
const V8 u = *(const V8*)((const uint16_t*)x.base + r * x.pitch + t * 8);
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
v[j] = sycl::bit_cast<float>((uint32_t)u[j] << 16);
|
||||
ss += v[j] * v[j];
|
||||
}
|
||||
}
|
||||
ss = sycl::reduce_over_group(it.get_group(), ss, sycl::plus<float>());
|
||||
if (!live) return;
|
||||
const float s = 1.0f / sycl::sqrt(ss / (float)n + eps);
|
||||
V8 o;
|
||||
#pragma unroll
|
||||
for (int j = 0; j < 8; ++j) {
|
||||
const int64_t i = t * 8 + j;
|
||||
const float gw = !g.base ? 1.0f
|
||||
: (g.dtype == RAD_F32 ? ((const float*)g.base)[i]
|
||||
: sycl::bit_cast<float>((uint32_t)((const uint16_t*)g.base)[i] << 16)) + wadd;
|
||||
o[j] = rad_f32_to_bf16(v[j] * s * gw * mult);
|
||||
}
|
||||
*(V8*)((uint16_t*)y.base + r * y.pitch + t * 8) = o;
|
||||
});
|
||||
});
|
||||
}
|
||||
return submit([&] {
|
||||
syclex::nd_launch(*q, sycl::nd_range<1>{(size_t)rows * kWg, kWg},
|
||||
[=](sycl::nd_item<1> it) [[sycl::reqd_sub_group_size(kSub)]] {
|
||||
const int64_t r = (int64_t)it.get_group(0);
|
||||
const int t = (int)it.get_local_id(0);
|
||||
float ss = 0.0f;
|
||||
for (int64_t i = t; i < n; i += (int64_t)kWg) {
|
||||
const float v = rad_load_f32(x.base, x.dtype, r * x.pitch + i);
|
||||
ss += v * v;
|
||||
}
|
||||
ss = sycl::reduce_over_group(it.get_group(), ss, sycl::plus<float>());
|
||||
const float s = 1.0f / sycl::sqrt(ss / (float)n + eps);
|
||||
for (int64_t i = t; i < n; i += (int64_t)kWg) {
|
||||
const float gw = g.base ? rad_load_f32(g.base, g.dtype, i * g.stride) + wadd : 1.0f;
|
||||
const float v = rad_load_f32(x.base, x.dtype, r * x.pitch + i);
|
||||
rad_store_f32(y.base, y.dtype, r * y.pitch + i, v * s * gw * mult);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
return submit([&] {
|
||||
syclex::nd_launch(*q, sycl::nd_range<1>{(size_t)rows * kWg, kWg},
|
||||
[=](sycl::nd_item<1> it) [[sycl::reqd_sub_group_size(kSub)]] {
|
||||
|
||||
Reference in new issue
Block a user