four-rank ar_gather_hc_write: the MoE gather in front of the exact one-shot write

At --tp 4 each MoE connection ran moe_gather and the fused write as two
launches, three or four with the inverse table. ar_gather_hc_write_4rank
runs r4d_ar_gather_word as the prologue of ar_hc_write_4rank, with the
two-rank slot table and grid rule. The arithmetic is moe_gather's plus
ar_hc_write_4rank's, so the bytes are unchanged. One and two ranks unchanged.
This commit is contained in:
keptn42 authored and StillDeadcode committed 2026-10-05 12:52:54 +02:00
1 parent c36e6fa2b3
commit 2f56e3c477
12 files changed
+415 -36

No files matched your search

+6 -4
View File
@@ -317,9 +317,10 @@ inline int HyperConn::declare(RadBuilder* b, Names& nm, const Geom& geom, const
inline int HyperConn::declare_gather(RadBuilder* b, const GatherSrc& src) {
if (!op_ar_write || src.top_k <= 0 || !src.ye || !src.ew || !src.sorted) return RAD_OK;
/* Two ranks only: there is no four-rank gather form yet, so there the block keeps its gather
* and this write takes the reduction alone (both bounds stay 0). */
if (g.world != 2) return RAD_OK;
/* Two ranks, and four on the exact wire: there the fused write exists in its exact form only,
* so the gather does too -- op_ar_write6 is 0 at four and the rotated form below is never
* declared. Any other width keeps its gather and both bounds stay 0. */
if (g.world != 2 && g.world != 4) return RAD_OK;
const bool shared = src.sh && src.sg;
gsrc = src;
/* EVERY ROW COUNT ONE PASS CARRIES, prefill chunks included: the kernel reads its slots from
@@ -386,7 +387,8 @@ inline void HyperConn::write(RadCtx* c_, int64_t T, int64_t r0, int64_t rows) co
if (takes_gather(T)) {
const int64_t k = gsrc.top_k;
const bool shared = gsrc.sh && gsrc.sg;
RAD_ISSUE_N(c_, ar_wire_is_exact(g, T) ? op_ar_gather_write : op_ar_gather_write6, rows,
const rad_op op = ar_exact_write_takes(g, T) ? op_ar_gather_write : op_ar_gather_write6;
RAD_ISSUE_N(c_, op, rows,
brows(gsrc.ye, rows * k), brow_slice(gsrc.ew, r0, rows, k),
brows(gsrc.sorted, rows * k),
shared ? brow_slice(gsrc.sh, r0, rows, g.n_embd) : RAD_NONE,
+4 -2
View File
@@ -388,11 +388,13 @@ inline bool ar_taken(const Geom& g, int64_t T, bool out, int take) {
/* WHETHER A MoE BLOCK'S GATHER RIDES IN FRONT OF THE REDUCTION THAT FOLLOWS IT (ar_gather_hc_write).
* `rows` and `rows6` are the bounds the fused op was declared for on the exact and on the rotated
* wire, 0 where it was not: at most the tokens one MoE pass carries, so a step it serves is one
* pass whose gather is the whole step's. The wire the step's message goes out on picks the bound.
* pass whose gather is the whole step's. The wire the step's message goes out on picks the bound:
* the exact one wherever the exact fused write takes the step (ar_exact_write_takes -- at two
* ranks ar_wire_is_exact itself, at four the exact one-shot's steps, where `rows6` is always 0).
* The block that would issue the gather and the write that would absorb it ask this of the same T
* and the same bounds, so neither can skip it while the other issues it. */
inline bool gather_taken(const Geom& g, int64_t T, int64_t rows, int64_t rows6) {
const int64_t r = ar_wire_is_exact(g, T) ? rows : rows6;
const int64_t r = ar_exact_write_takes(g, T) ? rows : rows6;
return r > 0 && T <= r;
}