libr4d: RADIANCE_AR8_SHARD_WEIGHTS=duplex -- shard weights from the both-directions link model, 8 to 1 instead of 4 to 1

The eight-rank two-shot in pieces runs both hops on a link at once, so each direction of rank r's
link carries (1 + 6 x_r) N for a shard fraction x_r: N - x_r N out in the reduce-scatter and
7 x_r N out in the all-gather, the same in. The slowest rank sets the time. The quadratic rule
(round(4 (rate / max)^2)) gives four Gen5 x16 and four Gen5 x8 cards 4 and 1: x8 carries 1.3 N at
28.6 GB/s (763 us for 16 MiB) while x16 carries 2.2 N at 57.1 (647 us), so the x16 links idle
15% of the time.

r4d_ar_weights_duplex equalises the ranks instead: x_r = (T B_r - 1) / 6 where positive, the x
summing to 1, filled from the fastest rank down. On that board it gives x16 2/9 and x8 1/36,
weights 64 and 8, and both kinds of card carry the same time's bytes: 7/6 N / 28.6 GB/s, 685 us
for 16 MiB, 10% under the quadratic rule's 763. On the earlier board with two Gen4 x8 links it
gives 64,9,0,64,0,9,64,64: the Gen4 cards nothing, as the measured best 4,1,0,4,0,1,4,4 did, the
Gen5 x8 ones half of what it gave them.

It is a new value of the variable, not a new default: unset and "auto" keep the quadratic rule,
so nothing runs differently until a measurement on the board says so. Which rank owns a word
changes only the link it crosses, not its fold, so the bits are those of every other table.
--perfar8 reads the variable the same way. r4d_ar_links_test checks both boards, equal links and
that every rank with a shard finishes together.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
NunzeandClaude Fable 5.1 authored and StillDeadcode committed 2026-10-22 11:54:56 +02:00
1 parent 91200c900b
commit 5b9bc13e5f
5 files changed
+95 -16

No files matched your search

+30 -3
View File
@@ -77,8 +77,8 @@ std::string card(const Root& r, int i, const std::string& speed, int width) {
struct Slot { const char* speed; int width; };
/* The weights the eight cards give, or "unknown". */
std::string weights(const Root& r, const Slot* slots) {
/* The weights the eight cards give, or "unknown", by the quadratic rule or the duplex model. */
std::string weights(const Root& r, const Slot* slots, bool duplex = false) {
std::string bdf[8];
for (int i = 0; i < 8; ++i) bdf[i] = card(r, i, slots[i].speed, slots[i].width);
double gbs[8] = { 0 };
@@ -87,7 +87,8 @@ std::string weights(const Root& r, const Slot* slots) {
if (r4d_ar_link_bottleneck(r.dir, bdf[i], &l)) gbs[i] = r4d_ar_link_gbs(l);
}
int w[8];
if (!r4d_ar_weights_from_rates(gbs, 8, w)) return "unknown";
if (!(duplex ? r4d_ar_weights_duplex(gbs, 8, w) : r4d_ar_weights_from_rates(gbs, 8, w)))
return "unknown";
std::string s;
for (int i = 0; i < 8; ++i) s += (i ? "," : "") + std::to_string(w[i]);
return s;
@@ -123,6 +124,32 @@ TEST(repaired_links_give_four_and_one) {
CHECK_EQ(weights(r, s), std::string("4,1,4,4,1,1,4,4"));
}
/* The duplex model on the board after the repair: x16 holds 2/9 of the message and x8 1/36, so
* each direction of every link carries the same time's bytes; on the earlier board the Gen4 x8
* cards hold nothing (they would need T B > N) and Gen5 x8 one seventh of x16. */
TEST(the_duplex_model_balances_both_directions_of_every_link) {
Root r;
const Slot fixed[8] = { { G5, 16 }, { G5, 8 }, { G5, 8 }, { G5, 16 },
{ G5, 8 }, { G5, 8 }, { G5, 16 }, { G5, 16 } };
CHECK_EQ(weights(r, fixed, true), std::string("64,8,8,64,8,8,64,64"));
Root r2;
const Slot older[8] = { { G5, 16 }, { G5, 8 }, { G4, 8 }, { G5, 16 },
{ G4, 8 }, { G5, 8 }, { G5, 16 }, { G5, 16 } };
CHECK_EQ(weights(r2, older, true), std::string("64,9,0,64,0,9,64,64"));
Root r3;
Slot even[8];
for (Slot& x : even) x = { G5, 16 };
CHECK_EQ(weights(r3, even, true), std::string("64,64,64,64,64,64,64,64"));
/* The time each rank's bytes take, (1 + 6 x) / B, is the same for every rank with a shard. */
const double gbs[8] = { 63, 31.5, 31.5, 63, 31.5, 31.5, 63, 63 };
int w[8];
REQUIRE(r4d_ar_weights_duplex(gbs, 8, w));
double sum = 0;
for (int i = 0; i < 8; ++i) sum += w[i];
const double tf = (1 + 6 * w[0] / sum) / gbs[0], ts = (1 + 6 * w[1] / sum) / gbs[1];
CHECK(std::fabs(tf - ts) / tf < 1e-9);
}
TEST(equal_links_give_equal_weights) {
Root r;
Slot s[8];