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

+33 -2
View File
@@ -551,7 +551,7 @@ extern "C" int r4d_rad_ar_gather_2rank(const RadArgs* a, RadStream s) {
return RAD_OK;
}
/* ------------------------------------------------------------------ wide (4 / 8 rank) all-gather
/* ------------------------------------------------------------------ wide (3 / 4 / 8 rank) all-gather
* The gather the 2-rank one cannot be at width: its handshake is one peer flag per block, so the
* wide form takes the wide family's peer arrays and r4d_ar_handshake instead (r4d_ar_wide.h), and
* it rides the SAME instance, scratch, flags and counters as the wide one-shots above -- a slot
@@ -623,6 +623,21 @@ static int ar_gather_wide_setup(const RadArgs* a, int ws, const ArInst** out_in,
return RAD_OK;
}
extern "C" int r4d_rad_ar_gather_3rank(const RadArgs* a, RadStream s) {
const ArInst* in = nullptr;
ArCall c;
long long row = 0;
int rc = ar_gather_wide_setup(a, 3, &in, &c, &row);
if (rc != RAD_OK) return rc;
R4D_TRY("ar_gather_3rank",
r4d_ar_gather_3rank(in->peer_scratch[0], in->peer_scratch[1],
in->peer_flags[0], in->peer_flags[1],
in->my_scratch, in->my_flags, in->my_seq, in->slot16,
c.inp, c.out, c.numel, in->dtype, in->rank, (long)row,
(long)(uintptr_t)s, c.nblocks, c.nthreads, c.drain, c.acq, c.pub));
return RAD_OK;
}
extern "C" int r4d_rad_ar_gather_4rank(const RadArgs* a, RadStream s) {
const ArInst* in = nullptr;
ArCall c;
@@ -737,7 +752,7 @@ extern "C" int r4d_rad_ar_oneshot_2rank_wht6(const RadArgs* a, RadStream s) {
return RAD_OK;
}
/* ------------------------------------------------------------------ wide (4 / 8 rank)
/* ------------------------------------------------------------------ wide (3 / 4 / 8 rank)
*
* The peer arguments are ascending global rank with the current rank removed, which is exactly
* the order build() filled peer_scratch/peer_flags in. */
@@ -745,6 +760,22 @@ extern "C" int r4d_rad_ar_oneshot_2rank_wht6(const RadArgs* a, RadStream s) {
/* The one-shots run in place: the thread that stores word k of the output is the one that read
* word k of the input, for its push and again as its own term of the fold, and peers read only
* their own scratch (r4d_ar_oneshot_Nrank_exact.hip). */
extern "C" int r4d_rad_ar_oneshot_3rank_exact(const RadArgs* a, RadStream s) {
ArCall c;
int rc = ar_setup(a, &c, 0);
if (rc != RAD_OK) return rc;
if (c.in->world != 3) return RAD_E_SHAPE;
const ArInst* in = c.in;
R4D_TRY("ar_oneshot_3rank_exact",
r4d_ar_oneshot_3rank_exact(in->peer_scratch[0], in->peer_scratch[1],
in->peer_flags[0], in->peer_flags[1],
in->my_scratch, in->my_flags, in->my_seq, in->slot16,
c.inp, c.out, c.numel, in->dtype, in->rank,
(long)(uintptr_t)s, c.nblocks, c.nthreads, c.drain, c.acq,
c.pub));
return RAD_OK;
}
extern "C" int r4d_rad_ar_oneshot_4rank_exact(const RadArgs* a, RadStream s) {
ArCall c;
int rc = ar_setup(a, &c, 0);