Archived
libr4d: RADIANCE_AR8_FORM -- the eight-rank two-shot's steps in ring order, or with a flag after each half instead of a handshake a step
The eight-rank two-shot reaches 56% of its link time at 16 MiB (1316 to 1340 us against 763), and measured(K) = f x link time(K) + h x (K + 1) fits f of about 1.45 and h of about 20 us a step: both the transfers and the step boundaries lose time. Two schedules of the same work go after them, each a new form beside the existing one, chosen by RADIANCE_AR8_FORM (unset or lockstep: as before) or per launch by the `form` parameter: - ring: the first hop goes to the peers in ring order from rank + 1 instead of ascending. In the lockstep order every card but rank 0 starts by writing rank 0's shard, then rank 1's, so the seven senders can converge on one receiver while the other links idle; in ring order each card receives from one peer at a time. - split: ring, and the one handshake a step, which waits until every peer has finished the whole step (next piece's first hop, this piece's reduce, the previous piece's assemble), becomes a flag after each half, awaited only before its data is read: before reducing piece j the peers' first hop of j, before assembling j their reduce of j. A card whose half is done goes on with the next piece's first hop while a slower card still reduces, so each link runs at its own pace instead of the slowest card's per step. The flags stay one monotone word per (block, source): the first hop of piece 0 at v0, of piece j + 1 at v0 + 2j + 1, the reduce of piece j at v0 + 2j + 2; the launch reserves pieces + 1 steps for its 2 pieces + 1 values, so it mixes with every other kernel on the instance. A launch still ends only after every peer has published its last reduce inside it, so the slot parity argument holds unchanged. r4d_ar_publish and r4d_ar_await (r4d_ar_wide.h) are the two halves of r4d_ar_handshake. Neither changes which rank folds a word or in what order, so all forms give the bits of the lockstep form, which compiles to the code it was. Ring and split are eight-rank only; the three- and four-rank launches stay lockstep and refuse another form. Every rank must read the same form; init compares it with the other eight-rank settings. --perfar8 numel iters dtype forms (comma-separated) times the forms side by side; the timeline prints a pair a synchronisation (K + 1 handshakes, or 2K awaits split, up to 8 pieces). r4d_selftest's weighted eight-rank runs repeat for ring and split at 1, 4 and 8 pieces over even, uneven, single-owner and zero-weight tables and with the piece count changing launch to launch, and the box's own weights run auto, duplex and off. On one card (R4D_SELFTEST_ONE_CARD) all three forms give the fold on every rank at 65536 to 8388608 elements, even and weighted, bf16 and fp32. Which form is fastest on the board is for the TP8 window to measure. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
5b9bc13e5f
commit
c25bca83d5
7 files changed
+306
-69
No files matched your search
+34
-4
@@ -79,6 +79,7 @@ struct Rendezvous {
|
||||
int w[R4D_MAX_RANKS] = { 0 };
|
||||
int pieces = 0;
|
||||
long long weights_min = 0, pieces_min = 0;
|
||||
int form = 0;
|
||||
R4DArLink link;
|
||||
} ar8[R4D_MAX_RANKS];
|
||||
int failed = 0;
|
||||
@@ -134,6 +135,8 @@ struct ArInst {
|
||||
/* Messages under these sizes (elements) run even and in one piece, whatever is configured. */
|
||||
long long weights_min = R4D_AR8_MIN_ELEMS_DEFAULT;
|
||||
long long pieces_min = R4D_AR8_MIN_ELEMS_DEFAULT;
|
||||
/* Its form (RADIANCE_AR8_FORM); a launch's `form` parameter overrides it. */
|
||||
int form = R4D_AR8_FORM_LOCKSTEP;
|
||||
};
|
||||
|
||||
/* A parameter that may be declared as a range: init gets one band's frozen geometry, and buffers
|
||||
@@ -217,6 +220,21 @@ long long ar8_min_elems(const char* name, std::once_flag* said) {
|
||||
return v;
|
||||
}
|
||||
|
||||
/* RADIANCE_AR8_FORM: lockstep (or unset), ring or split. Anything else is lockstep, with one
|
||||
* warning. */
|
||||
int ar8_form() {
|
||||
const char* e = std::getenv(R4D_AR8_FORM_ENV);
|
||||
if (!e || !*e) return R4D_AR8_FORM_LOCKSTEP;
|
||||
const int f = r4d_ar8_form_parse(e);
|
||||
if (f >= 0) return f;
|
||||
static std::once_flag said;
|
||||
std::call_once(said, [e] {
|
||||
std::fprintf(stderr, "[r4d] %s=\"%s\" ignored (needs lockstep, ring or split); the "
|
||||
"eight-rank two-shot runs in lockstep\n", R4D_AR8_FORM_ENV, e);
|
||||
});
|
||||
return R4D_AR8_FORM_LOCKSTEP;
|
||||
}
|
||||
|
||||
/* The eight-rank two-shot's choice for one message, a function of its size and the instance
|
||||
* alone: a recorded launch keeps the table and piece count it was recorded with, and replays of
|
||||
* the same size agree with it. */
|
||||
@@ -240,6 +258,7 @@ int ar8_settle(ArInst* in, int rank, int world) {
|
||||
me.pieces = ar8_pieces();
|
||||
me.weights_min = ar8_min_elems(R4D_AR8_SHARD_WEIGHTS_MIN_ENV, &said_w);
|
||||
me.pieces_min = ar8_min_elems(R4D_AR8_PIECES_MIN_ENV, &said_p);
|
||||
me.form = ar8_form();
|
||||
if ((me.mode == AR8_AUTO || me.mode == AR8_DUPLEX) && !ar8_own_link(&me.link))
|
||||
me.link = R4DArLink();
|
||||
{
|
||||
@@ -253,15 +272,24 @@ int ar8_settle(ArInst* in, int rank, int world) {
|
||||
for (int r = 0; r < world; ++r)
|
||||
if (all[r].mode != me.mode || std::memcmp(all[r].w, me.w, sizeof(me.w)) ||
|
||||
all[r].pieces != me.pieces || all[r].weights_min != me.weights_min ||
|
||||
all[r].pieces_min != me.pieces_min) {
|
||||
all[r].pieces_min != me.pieces_min || all[r].form != me.form) {
|
||||
std::fprintf(stderr, "[r4d] ranks %d and %d read different eight-rank two-shot "
|
||||
"settings (%s, %s and their _MIN_ELEMS)\n", rank, r,
|
||||
R4D_AR8_SHARD_WEIGHTS_ENV, R4D_AR8_PIECES_ENV);
|
||||
"settings (%s, %s and their _MIN_ELEMS, %s)\n", rank, r,
|
||||
R4D_AR8_SHARD_WEIGHTS_ENV, R4D_AR8_PIECES_ENV, R4D_AR8_FORM_ENV);
|
||||
return RAD_E_STATE;
|
||||
}
|
||||
in->pieces = me.pieces;
|
||||
in->weights_min = me.weights_min;
|
||||
in->pieces_min = me.pieces_min;
|
||||
in->form = me.form;
|
||||
if (me.form != R4D_AR8_FORM_LOCKSTEP) {
|
||||
static std::once_flag said_form;
|
||||
const int f = me.form;
|
||||
std::call_once(said_form, [f] {
|
||||
std::fprintf(stderr, "[r4d] eight-rank two-shot form: %s (%s)\n",
|
||||
f == R4D_AR8_FORM_RING ? "ring" : "split", R4D_AR8_FORM_ENV);
|
||||
});
|
||||
}
|
||||
|
||||
int w[R4D_MAX_RANKS] = { 0 };
|
||||
if (me.mode == AR8_SET) {
|
||||
@@ -1183,6 +1211,8 @@ extern "C" int r4d_rad_ar_twoshot_8rank_exact(const RadArgs* a, RadStream s) {
|
||||
const long long pieces = ar8_pieces_for(in, c.numel, asked);
|
||||
/* A diagnostic: a device buffer of nblocks * R4D_AR_TL_WORDS int64 stamps (r4d.h). */
|
||||
const long long timeline = r4d_pgeti_or(a->p, a->n_p, "timeline", 0);
|
||||
const long long form = r4d_pgeti_or(a->p, a->n_p, "form", in->form);
|
||||
if (form < R4D_AR8_FORM_LOCKSTEP || form > R4D_AR8_FORM_SPLIT) return RAD_E_INVAL;
|
||||
R4D_TRY("ar_twoshot_8rank_exact",
|
||||
r4d_ar_twoshot_8rank_exact(in->peer_scratch[0], in->peer_scratch[1], in->peer_scratch[2],
|
||||
in->peer_scratch[3], in->peer_scratch[4], in->peer_scratch[5],
|
||||
@@ -1193,7 +1223,7 @@ extern "C" int r4d_rad_ar_twoshot_8rank_exact(const RadArgs* a, RadStream s) {
|
||||
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, weights, (long)pieces, (long)timeline));
|
||||
c.pub, weights, (long)pieces, (long)timeline, (long)form));
|
||||
return RAD_OK;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user