libr4d: R4D_AR_MAX_BLOCKS, a ceiling on collective blocks for two engines on one set of cards

Every block of a collective spins until its twin on the peer card has pushed. One engine is safe
(both cards dispatch its blocks in the same order); two tensor-parallel engines on the same
cards can deadlock, one engine's spinners filling a card while their twins wait behind the
other engine's kernel. Two TP2 engines on two R9700s hung within a minute of concurrent
prefill and the failed queue eviction froze the host. Capped in both engines so their spinners
together leave part of a card free, the cycle cannot close: 15 minutes of concurrent load
clean at 64 / 16. Only launch counts shrink; each element's sum is the same. Unset, nothing
changes. GUIDE section 8 documents it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
mici81andClaude Opus 5.5 authored and StillDeadcode committed 2026-10-19 10:39:53 +02:00
1 parent fb7a30cd84
commit 1d1cb21e02
2 files changed
+30 -1

No files matched your search

+16 -1
View File
@@ -354,11 +354,26 @@ int build(ArInst* in, int rank, int world, long long max_numel, int dtype_code,
}
if (maxb <= 0) return RAD_E_DEVICE;
in->max_blocks = maxb;
/* R4D_AR_MAX_BLOCKS: a ceiling on every collective's block count, for two engines sharing one
* set of cards. Each block of a collective spins until its twin on the peer card has pushed, and
* a prefill-sized ar_rmsnorm_quant_fp8 launches up to 256 blocks of 16 waves, twice what an
* R9700 holds. One engine survives that (both cards dispatch blocks in the same order, so the
* lowest unfinished block is resident on both); two engines do not: one engine's spinning blocks
* fill a card while their twins wait behind the other engine's kernel on the peer card, which
* waits for a slot on the full card. Two TP2 engines on two R9700s (Qwen3.8-27B and Gemma 3 27B)
* hung within a minute of concurrent prefill; MES then failed to evict the queues and the
* failed reset froze the host. Capped in both engines so that their spinners together cannot
* fill a card, the cycle cannot close. The flag and counter arrays keep their full size (maxb);
* only the launch counts shrink, and each element's sum is the same. Unset, nothing changes. */
if (const char* e = std::getenv("R4D_AR_MAX_BLOCKS")) {
const int cap = std::atoi(e);
if (cap > 0 && cap < in->max_blocks) in->max_blocks = cap;
}
/* Launch ceilings: 24 at two ranks, the library's design count at width. The compressed
* 2-rank wire uses up to 48, set at its own call site: it moves three eighths of the bytes, so
* it needs more blocks to saturate the link. */
in->nb_cap = (world == 2) ? 24 : (nb_design > 0 ? nb_design : maxb);
if (in->nb_cap > maxb) in->nb_cap = maxb;
if (in->nb_cap > in->max_blocks) in->nb_cap = in->max_blocks;
/* Slots: one per (parity, source rank) at width; two at world 2, where there is one remote
* writer. Flags: one word per (block, source rank) at width, one per block at world 2.