libr4d: all-reduce and all-gather at three ranks

Instantiate the wide one-shot all-reduce at WS=3 and add an all-gather on the
wide transport (ar_gather_3rank), with dispatch rows for world_size 3, so a
three-card box resolves 'all_reduce' and the vocab-parallel sampler's
'all_gather'. The two-shot is not instantiated at 3: it shards the message
world ways and the residual width does not divide. Selftest: 3-rank sum,
block-count sweep and both gather placements (skipped on fewer than 3 cards).

Local lab build on top of 1.0.3 (f487864); not submitted upstream.

(cherry picked from commit a76f2ab66500b9a7711b8f52abbf48eb88758359)
This commit is contained in:
baKon authored and StillDeadcode committed 2026-10-05 19:31:12 +02:00
1 parent 709d9beb1b
commit b60e329d93
8 files changed
+302 -19

No files matched your search

+19 -2
View File
@@ -1,5 +1,5 @@
// r4d_ar_oneshot_Nrank_exact.hip: r4d_ar_oneshot_4rank_exact,
// r4d_ar_oneshot_8rank_exact -- one-shot P2P push all-reduce, 4 or 8
// r4d_ar_oneshot_Nrank_exact.hip: r4d_ar_oneshot_3rank_exact, r4d_ar_oneshot_4rank_exact,
// r4d_ar_oneshot_8rank_exact -- one-shot P2P push all-reduce, 3, 4 or 8
// ranks, gfx1201. WS is compile-time; the 2-rank kernel keeps its own file.
//
// Per-block handshake: block b waits only on the peers' block b, so push
@@ -344,6 +344,23 @@ static void ar_wide_launch(const long* peer_scratch, const long* peer_flags, lon
#undef R4D_AR_WIDE_LAUNCH
}
// Three ranks: the same kernel at WS=3. Nothing in the push, the handshake or the ascending-rank
// reduce assumes a power of two -- the peer bundle is WS-1 wide and the slot/flag layout is
// parity x source rank -- so this is an instantiation, not a variant. It exists because a 3-card
// box is a real configuration (three R9700s) and the two-shot cannot serve it: that one shards the
// message `world` ways and a residual width of 2560 does not divide by 3.
void r4d_ar_oneshot_3rank_exact(long peer_scratch0, long peer_scratch1,
long peer_flags0, long peer_flags1,
long my_scratch, long my_flags, long seq_ctrs, long slot_stride16,
long inp, long out, long n_elem, long dtype, long rank,
long stream, long nblocks, long nthreads, long drain, long acq,
long pub) {
const long ps[2] = {peer_scratch0, peer_scratch1};
const long pf[2] = {peer_flags0, peer_flags1};
ar_wide_launch<3>(ps, pf, my_scratch, my_flags, seq_ctrs, slot_stride16, inp, out, n_elem,
dtype, rank, stream, nblocks, nthreads, drain, acq, pub);
}
void r4d_ar_oneshot_4rank_exact(long peer_scratch0, long peer_scratch1, long peer_scratch2,
long peer_flags0, long peer_flags1, long peer_flags2,
long my_scratch, long my_flags, long seq_ctrs, long slot_stride16,