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

+14
View File
@@ -2651,6 +2651,20 @@ rad-kbench --home $RADIANCE_HOME --max-cases 1 # are the kernels correct?
| `ROCM_PATH` | where ROCm lives, if not `/opt/rocm` (build time) |
| `HF_TOKEN` | for `scripts/hfget.sh` and `--model <owner/name>` on a gated or private repo |
| `XDG_CACHE_HOME` | where `--model <owner/name>` fetches to without `--download-dir` (`$XDG_CACHE_HOME/radiance/hf`, else `~/.cache/radiance/hf`) |
| `R4D_AR_MAX_BLOCKS` | a ceiling on libr4d's collective block counts, for two tensor-parallel engines on one set of cards; set it in both (below). Unset, nothing changes |
**Two engines on one set of cards.** Every block of a libr4d collective spins until its twin on the
peer card has pushed, and a prefill-sized fused all-reduce launches more blocks than a card holds at
once. 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 fill a card while their twins wait
behind the other engine's kernel on the peer, which waits for a slot on the full card. On two R9700s
(Qwen3.8-27B and a Gemma 3 27B, both `--tp 2`) that hung within a minute of concurrent prefill, and
the driver's attempt to evict the queues froze the host. With `R4D_AR_MAX_BLOCKS` in both engines
low enough that their spinners together leave part of a card free, the cycle cannot close: 64 for
Qwen3.8-27B (its decode at 16 sequences x 4 rows stays uncapped) and 16 for the Gemma ran 15
minutes of concurrent long prompts on both without a stall. The ceiling costs prefill time, the
reductions running on fewer blocks: Qwen3.8-27B's 41k-token prefill 9.5 s uncapped, 9.8 s at 64,
10.3 s at 32. Give the engine started first its `--gpu-headroom-mib` for the second.
**Tooling**
+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.