libr4d: register form of the fused all-reduce writes with a wake store into the idle peer path

ar_hc_write / ar_gather_hc_write get a register form when every thread owns at most one
16-byte word (up to 12 rows of 2560, P2P instances): y, inj and h are loaded into registers
before the first atomic and not re-read after the handshake; LDS-only barriers instead of
__syncthreads; the flag poll is a relaxed system-scope load (the push check with retry behind
a system acquire stays). Before waiting on its chain turn each block stores one word into the
peer's memory: the P2P path between the cards goes idle after ~20 us, and the next store then
becomes visible ~4 us later; the wake store hides that. Wire format, flags, counters, check word
and arithmetic unchanged, mixable with the plain kernels on one instance; host-mailbox twins
keep the plain kernels. The chained wait the forms sit behind ends in r4d_chain_acquire (the
previous commit's s_dcache_inv). 63 new r4d_selftest cases: register form against plain form,
byte-identical, M = 1..8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Code000andClaude Opus 5.5 authored and StillDeadcode committed 2026-11-17 19:01:12 +01:00
1 parent cfec01ec8d
commit 304597970f
6 files changed
+474 -10

No files matched your search

+6 -2
View File
@@ -266,6 +266,10 @@ int ar8_settle(ArInst* in, int rank, int world) {
* counter, padded to a cache line. */
long kSeqWords(long nbw) { return 2L * nbw + 32; }
/* Behind a flags allocation's flags and check words: a 2-rank instance's wake word
* (r4d_ar_link_wake, r4d_ar_seq.h), on a line of its own. */
constexpr long kWakeBytes = 64;
/* Build the world. `max_numel` is the largest message any launch on this instance carries.
*
* One sizing rule for the whole family: a slot holds a full message. The one-shots need exactly
@@ -367,10 +371,10 @@ int build(ArInst* in, long long group, int rank, int world, long long max_numel,
if (hipGetDevice(&dev) != hipSuccess) return RAD_E_DEVICE;
if (host) {
sc = r4d_ar_host_alloc((long)nslots * in->slot_bytes);
fl = r4d_ar_host_alloc((flag_words + 2L * maxb) * 4);
fl = r4d_ar_host_alloc((flag_words + 2L * maxb) * 4 + kWakeBytes);
} else {
sc = r4d_ar_ipc_alloc((long)nslots * in->slot_bytes, 1, handle, &hlen);
fl = r4d_ar_ipc_alloc((flag_words + 2L * maxb) * 4, 1, handle, &hlen);
fl = r4d_ar_ipc_alloc((flag_words + 2L * maxb) * 4 + kWakeBytes, 1, handle, &hlen);
}
sq = r4d_ar_ipc_alloc(kSeqWords(maxb) * 4, 0, handle, &hlen));