libr4d, arch/gemma4_bf16: the four-rank all-reduce by message size, and the 31B's junction fold to 16 rows

The four-rank exact all-reduce picks its transport and block count by message size, for every
tp-4 model; the four-rank fused junction gains its tail form (the two-shot with the junction after
it), which the 31B takes up to 16 rows. Carries rmsnorm_quant_i8's register form until that PR
merges.

Squashed from:

- libr4d: the four-rank all-reduce's fold a word at a time, 16-row standalone all-reduces on the two-shot, counters in L2
- libr4d: the standalone four-rank all-reduce takes the exact two-shot from 32768 elements
- libr4d: the four-rank exact all-reduce's two-shot takes 2 blocks at a DFlash2 verify, not 4
- libr4d: the all-reduce rows' nblocks axis offers 2 and 4
- libr4d: rmsnorm_quant_i8 at decode heights loads the row's operands before its reductions
- libr4d: the four-rank fused junction's tail form -- the two-shot with the junction after it
- arch/gemma4_bf16: the four-rank fold up to 16 rows, on libr4d's tail form

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
AshlynandClaude Opus 5.5 authored and StillDeadcode committed 2026-10-21 09:47:23 +02:00
1 parent 51db508f91
commit 239da14d17
9 files changed
+375 -50

No files matched your search

+8 -3
View File
@@ -563,10 +563,15 @@ void Gemma4Mlp::step(RadCtx* c, const RadBatch* batch, bool entry_done, bool tai
* decode step (1 row) ran 5.6% slower without it (89 against 94 tok/s), and a DFlash verify
* (16 rows) 9% faster (300 against 276): at 16 rows the standalone all-reduce is the exact
* two-shot, while the fold's one block a row each takes a fenced handshake. The per-row costs
* cross near 4-5 rows, so the fold serves up to kAr4FoldRows rows and a taller step issues the
* pair. */
* cross near 4-5 rows. From 5 rows libr4d's four-rank row takes its tail form instead (axis
* `tail`): the standalone two-shot with the junction run after it in the same launch, behind a
* card-local count, so the junction costs neither a handshake nor a launch. With it a DFlash2
* verify (8 rows) folds and gains ~1% (348 / 258 / 187 / 516 against 345 / 255 / 185 / 511 tok/s,
* code / prose / story / long, 4x R9700; replies identical), where the one-shot fold there lost
* 6%. So the fold serves up to kAr4FoldRows rows, a z-lab DFlash verify's 16 included, and a
* taller step issues the pair. */
static constexpr int64_t kArOneShotElems = 524288;
static constexpr int64_t kAr4FoldRows = 4;
static constexpr int64_t kAr4FoldRows = 16;
struct G4Junction {
rad_op op = 0;