libr4d: the eight-rank two-shot's timeline -- where a 16 MiB all-reduce spends 1.36 ms against 0.76 ms of link time

At 4 x Gen5 x16 + 4 x Gen5 x8 the weighted two-shot moves a 16 MiB message in 1316 to 1340 us
(K4 to K8, --perfar8), against 763 us that the x8 cards' links need for its bytes, 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
handshake. Whether that is link efficiency, waiting for the slowest rank, the local reduce or the
step boundaries cannot be told from the period alone.

A launch now takes an optional `timeline` parameter, a device buffer of nblocks x
R4D_AR_TL_WORDS int64 (r4d_ar_shards.h). Every block of the eight-rank two-shot stamps the device
wall clock after its sequence step, at each handshake when all its stores have drained (arrive)
and when every peer's flag has been seen (release), and after its last local work. The stamps sit
in r4d_ar_handshake behind a null check, so a launch without the parameter pays a branch per
handshake; no value changes either way.

r4d_selftest --perfar8 --timeline launches each two-shot point once more with the stamps on and
prints, per rank, the first push, every step's work and wait, and the final assemble. In one piece
that is the reduce-scatter's send, its receipt, the reduce with the all-gather's send, its receipt
and the local assemble, so the two hops are measured apart; in K pieces it shows which rank works
while the others wait.

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 b34af6c509
commit 91200c900b
6 files changed
+138 -17

No files matched your search

+14 -1
View File
@@ -16,6 +16,7 @@
#include <stdexcept>
#include <string>
#include "r4d_ar_seq.h"
#include "r4d_ar_shards.h"
#define R4D_AR_SPIN_MAX 4000000000ULL
#define R4D_AR_WIDE_MAX_BLOCKS 64
@@ -66,14 +67,19 @@ __device__ __forceinline__ void r4d_ar_acquire(int acq) {
// words has reached or passed it (peers may be a step ahead; counters only grow). One spin lane
// per source, wrap-safe monotonic compare, never equality. Every rank publishes before it waits,
// so there is no cycle; a handshake that cannot complete traps.
//
// `tl`, when not null, takes two wall-clock stamps: when the whole block has issued and drained
// its stores, and when every peer's flag has been seen. A diagnostic: the eight-rank two-shot
// passes it only for a launch asking for its timeline (r4d_ar_tl_stamp).
template <int WS, typename S, int NPEERS>
__device__ __forceinline__ void r4d_ar_handshake(const R4DArWidePeers<S, NPEERS>& peers,
unsigned int* __restrict__ my_flags, int b,
int rank, unsigned int val, int drain, int acq,
int pub) {
int pub, long long* tl = nullptr) {
r4d_ar_drain(drain);
__syncthreads();
const int tid = threadIdx.x;
if (tl && tid == 0) tl[0] = (long long)wall_clock64();
if (tid == 0) {
if (drain == 2) __threadfence_system();
if (pub == 2) {
@@ -107,9 +113,16 @@ __device__ __forceinline__ void r4d_ar_handshake(const R4DArWidePeers<S, NPEERS>
}
}
__syncthreads();
if (tl && tid == 0) tl[1] = (long long)wall_clock64();
r4d_ar_acquire(acq);
}
// The two-shot timeline (layout in r4d_ar_shards.h), one stamp of the device wall clock.
static_assert(R4D_AR_TL_BLOCKS == R4D_AR_WIDE_MAX_BLOCKS, "r4d_ar_shards.h restates the ceiling");
__device__ __forceinline__ void r4d_ar_tl_stamp(long long* tl, int i) {
if (tl && threadIdx.x == 0) tl[i] = (long long)wall_clock64();
}
// Host side: checks stride and grid against the real allocations. Every scratch, flag and seq
// pointer comes from hipMalloc / hipIpcOpenMemHandle, so the runtime can report its extent; a
// pointer it cannot size is refused.