libr4d: the norms' lane sum issues its reads eight at a time

1.15's kR4dSumLanes partition folds a row's sum of squares over 256 lanes
whatever the block width, so a 1024-thread decode block reads it back with a
quarter of its threads, one read at a time: a Gemma 3 sandwich norm re-reads
the 5376-wide row it has just written twice, 21 dependent loads a lane each.
TranslateGemma 27B lost 5 % of its decode (four streams 225.0 / 227.2 tok/s a
stream against 238.2 / 239.7 on 1.14; ar_rmsnorm_post_quant_fp8 3.1 -> 5.1 ms
a step under --profile-ops).

r4d_lanes_sumsq (r4d_common.h) keeps the partition and the order of the adds
and only batches the reads, eight before their adds; libr4d is built
-ffp-contract=off, so every bit stays the same (greedy Qwen 300/300 x2 and
TranslateGemma 6/6 identical to the merge without it). Used by both
lanes_sumsq copies and rmsnorm_body's two loops. TranslateGemma back to
238.9 / 239.3.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mici81andClaude Opus 5.5 authored and StillDeadcode committed 2026-11-01 20:57:42 +01:00
1 parent b34b1ac844
commit 55da38afbd
4 files changed
+25 -19

No files matched your search

+1 -4
View File
@@ -64,10 +64,7 @@ __device__ __forceinline__ float block_sum(float v, float* lds) {
// depend on the block's width. `row` holds the row's bf16 values; when the block's threads wrote
// it, the caller issues the barrier first.
__device__ __forceinline__ float lanes_sumsq(const uint16_t* row, uint32_t n) {
float ss = 0.0f;
if (threadIdx.x < kR4dSumLanes)
for (uint32_t i = threadIdx.x; i < n; i += kR4dSumLanes) { const float f = bf2f(row[i]); ss += f * f; }
return ss;
return r4d_lanes_sumsq(row, n, [](uint16_t h) { return bf2f(h); });
}
__device__ __forceinline__ float gain(const void* w, uint32_t i, bool f32) {