Archived
libxe2: libref's sigmoid and silu at a third of the cost, bit-identical -- gated norm 230 -> 37 ms, gated_quant 320 -> 254 ms at 2234 tokens
libref takes exp in double and rounds once; on the B65 that is ~3x the rest of an activation. Rounded to bf16, two f32 values a few ulps apart give the same bf16 unless they straddle a rounding tie, so the activation runs with a float exp and repeats libref's double chain only where the f32 result lies within 16 ulps of a tie (near_bf16_tie, xe2_common.h). Probe silu.cpp: 0 of 21M bf16 outputs differ from libref's (the float chain alone: 85), at a third of the time. - gated_quant_fp8: the gate's sigmoid this way. - gdn_conv_prep: the convolution's silu this way. - gdn_gated_rmsnorm: 128-channel rows with a bf16 output take a sub-group a row (8 rows a work-group): the squares added in index order by lane broadcasts (libref's chain), the gate as above. The 128-item work-group a row left 127 items waiting on one's ordered sum. rad-kbench gdn + gated_quant: fixture 165/165, container 440/440, every libxe2 row of these ops at rel_l2 0; op oracle on live operands (tolerance 1e-9): 60/60 agree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5ed4ff847e
commit
6969fcf8cb
3 files changed
+73
-3
No files matched your search
+8
-2
@@ -565,8 +565,14 @@ int gated_quant_fp8(const RadArgs* a, RadStream st) {
|
||||
auto v = [&](int64_t i) {
|
||||
const float gt = rad_load_f32(gu.base, gu.dtype, r * gu.pitch + i);
|
||||
const float up = rad_load_f32(gu.base, gu.dtype, r * gu.pitch + n + i);
|
||||
const float sgm = sigmoidf(gt);
|
||||
return rad_bf16_to_f32(rad_f32_to_bf16((act == 0 ? gt * sgm : sgm) * up));
|
||||
/* a float exp, libref's double one only near a bf16 tie: the same bf16 (xe2_common.h) */
|
||||
const float sf = sigmoid_fexp(gt);
|
||||
float y = (act == 0 ? gt * sf : sf) * up;
|
||||
if (near_bf16_tie(y)) {
|
||||
const float sgm = sigmoidf(gt);
|
||||
y = (act == 0 ? gt * sgm : sgm) * up;
|
||||
}
|
||||
return rad_bf16_to_f32(rad_f32_to_bf16(y));
|
||||
};
|
||||
const int64_t k0 = gi * g, len = sycl::min(g, n - k0);
|
||||
const float sc = quant_group(sg, v, k0, len, top, qv.base, qv.dtype, r * qv.pitch,
|
||||
|
||||
Reference in new issue
Block a user