Archived
libxe2: silu_mul, add, mul and sigmoid eight bf16 values a work-item; sigmoid's float exp
The scalar elementwise kernels spent their prefill time in int64 divides and generic accessors (silu_mul ~0.7 ms a call). bf16 rows now take a 2-D range of eight columns a work-item with 16-byte loads and stores, the same per-element arithmetic. sigmoid with a bf16 output takes the float exp, libref's double chain again only near a bf16 tie (as silu does). kbench add/mul/sigmoid bit-exact; greedy 8/8 and the 2234-token prompt's continuation identical. 2234-token prompt 960 -> 1001 tok/s; decode proxy 82.5 -> 83.1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e6f4862c7e
commit
531fda7313
2 files changed
+82
-1
No files matched your search
@@ -290,6 +290,35 @@ int silu_mul(const RadArgs* a, RadStream st) {
|
||||
if (!q) return RAD_E_DEVICE;
|
||||
const int64_t total = rows * n;
|
||||
const bool bf16_out = y.dtype == RAD_BF16 && !exact_only();
|
||||
/* bf16 rows, 8-aligned: a work-item eight columns of a row, 16-byte loads and store, the
|
||||
* same per-element arithmetic (the scalar form's int64 divide a value bounded it at ~0.7 ms
|
||||
* a prefill call) */
|
||||
if (bf16_out && gu.dtype == RAD_BF16 && n % 8 == 0 && gu.pitch % 8 == 0 && y.pitch % 8 == 0 &&
|
||||
rad_ptr_aligned(gu.base, 16) && rad_ptr_aligned(y.base, 16) && n / 8 < (int64_t)1 << 30) {
|
||||
using V8 = sycl::vec<uint16_t, 8>;
|
||||
const int n8 = (int)(n / 8);
|
||||
const size_t wg8 = 128;
|
||||
return submit([&] {
|
||||
syclex::nd_launch(*q, sycl::nd_range<2>{{(size_t)rows, (size_t)((n8 + wg8 - 1) / wg8 * wg8)}, {1, wg8}},
|
||||
[=](sycl::nd_item<2> it) {
|
||||
const int c8 = (int)it.get_global_id(1);
|
||||
if (c8 >= n8) return;
|
||||
const int64_t r = (int64_t)it.get_global_id(0);
|
||||
const uint16_t* gp = (const uint16_t*)gu.base + r * gu.pitch + (int64_t)c8 * 8;
|
||||
const V8 xg = *(const V8*)gp, xu = *(const V8*)(gp + n);
|
||||
V8 o;
|
||||
#pragma unroll
|
||||
for (int e = 0; e < 8; ++e) {
|
||||
const float x = sycl::bit_cast<float>((uint32_t)xg[e] << 16);
|
||||
const float up = sycl::bit_cast<float>((uint32_t)xu[e] << 16);
|
||||
float v = x * sigmoid_fexp(x) * up;
|
||||
if (near_bf16_tie(v)) v = x * (1.0f / (1.0f + (float)sycl::exp((double)-x))) * up;
|
||||
o[e] = rad_f32_to_bf16(v);
|
||||
}
|
||||
*(V8*)((uint16_t*)y.base + r * y.pitch + (int64_t)c8 * 8) = o;
|
||||
});
|
||||
});
|
||||
}
|
||||
const size_t wg = 256, groups = (size_t)((total + 255) / 256);
|
||||
return submit([&] {
|
||||
syclex::nd_launch(*q, sycl::nd_range<1>{groups * wg, wg}, [=](sycl::nd_item<1> it) {
|
||||
|
||||
Reference in new issue
Block a user