libr4d: eight ranks on one card for r4d_selftest -- the eight-rank protocol testable on a box with fewer cards

The eight-rank collectives could only run on eight cards, so a change to their protocol, shard
table or arithmetic went untested until a TP8 window. Their bits do not need eight cards: a peer
on the same card is just another region of its VRAM.

build() now skips hipDeviceEnablePeerAccess for a peer on the rank's own card (the runtime refuses
it, and nothing needs it). On distinct cards nothing changes.

R4D_SELFTEST_ONE_CARD=1 lets --perfar8 run its eight ranks on the first card: each rank takes a
non-blocking stream of its own (one stream would serialise ranks that spin on each other), main()
raises GPU_MAX_HW_QUEUES to 16 before the runtime starts so the streams get queues of their own,
the block counts stay at 4 and 8 so all eight ranks' blocks are resident at once, and the workers
meet at a barrier before fini and the frees, which synchronise the card. With a card a rank the
worker keeps the legacy stream, so the timed launches are as before. On one card the results are
checked against the fold exactly as on eight; the times are not a board's, since the card runs
the eight queues in time slices of several milliseconds, and the run says so.

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 4f821ce0b9
commit b34af6c509
2 files changed
+52 -15

No files matched your search

+5 -2
View File
@@ -440,7 +440,9 @@ int build(ArInst* in, int rank, int world, long long max_numel, int dtype_code,
/* Peer access is per context, so each rank enables its own, after the publish barrier where
* peer device ordinals are known. A host can expose more HIP devices than ranks (e.g. an
* integrated GPU), so the ordinal comes from the peer rather than the rank. */
* integrated GPU), so the ordinal comes from the peer rather than the rank. A peer on this
* rank's own card needs none (the runtime refuses to enable it): r4d_selftest runs eight ranks
* on one card that way, each on its own stream. */
int j = 0;
for (int r = 0; r < world; ++r) {
if (r == rank) continue;
@@ -448,7 +450,8 @@ int build(ArInst* in, int rank, int world, long long max_numel, int dtype_code,
in->peer_scratch[j] = g_rv.scratch[r];
in->peer_flags[j] = g_rv.flags[r];
++j;
if (!host) R4D_TRY("ar_ipc_enable_peer", r4d_ar_ipc_enable_peer((long)g_rv.dev[r]));
if (!host && g_rv.dev[r] != dev)
R4D_TRY("ar_ipc_enable_peer", r4d_ar_ipc_enable_peer((long)g_rv.dev[r]));
}
/* Second barrier: no rank may launch until every rank has enabled peer access, or the first