From 6a6c50e718b58bf925f592a08da6bacd2526efa7 Mon Sep 17 00:00:00 2001 From: keptn42 Date: Sat, 24 Oct 2026 03:00:58 +0200 Subject: [PATCH] arch: RADIANCE_PREFETCH_BESIDE=0 turns prefetch_beside off Beside another server on the same card the lane-1 read costs more than it gains: the card has fewer hardware queue slots than the two servers have queues, and the join puts a queue switch into every decode step. --- arch/common/rad_arch.h | 12 +++++++++++- docs/GUIDE.md | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/arch/common/rad_arch.h b/arch/common/rad_arch.h index 6cd85d27..aa20f665 100644 --- a/arch/common/rad_arch.h +++ b/arch/common/rad_arch.h @@ -608,8 +608,18 @@ constexpr int64_t kPrefetchRows = 16; * would read in series on lane 0, so elsewhere the read goes on lane 1, behind a join from lane * 0. */ inline bool prefetch_lane0() { return rad_chain_on() != 0; } +/* RADIANCE_PREFETCH_BESIDE=0 issues none of these reads. Beside another server on the same card + * the lane-1 form costs more than it gains: the card has fewer hardware queue slots than the two + * servers have queues, and the join puts a queue switch into every decode step. */ +inline bool prefetch_beside_on() { + static const bool on = [] { + const char* e = std::getenv("RADIANCE_PREFETCH_BESIDE"); + return !(e && e[0] == '0' && e[1] == 0); + }(); + return on; +} inline void prefetch_beside(RadCtx* c, rad_op op, rad_weight w, int64_t T) { - if (!op || T > kPrefetchRows) return; + if (!op || T > kPrefetchRows || !prefetch_beside_on()) return; if (prefetch_lane0()) { RAD_ISSUE(c, op, RAD_W(w)); return; diff --git a/docs/GUIDE.md b/docs/GUIDE.md index 82d10fde..1bb8efed 100644 --- a/docs/GUIDE.md +++ b/docs/GUIDE.md @@ -3460,6 +3460,7 @@ rad-kbench --home $RADIANCE_HOME --max-cases 1 # are the kernels correct? | `HF_TOKEN` | for `scripts/hfget.sh` and `--model ` on a gated or private repo | | `XDG_CACHE_HOME` | where `--model ` 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). The MoE models' hyper-connection gathers keep the minimum their LDS table needs. Unset, nothing changes | +| `RADIANCE_PREFETCH_BESIDE` | `0` issues no weight prefetch beside the decode collectives. For an engine that shares its cards with another server (below); alone it costs a few percent of decode. 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 @@ -3472,7 +3473,7 @@ low enough that their spinners together leave part of a card free, the cycle can 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. +10.3 s at 32. Give the engine started first its `--gpu-headroom-mib` for the second. A model whose decode reads weights ahead on a second queue (Gemma 4 without chained launches) slows sharply beside a second server: an R9700 has four compute queue slots and the two servers hold eight, so every decode step waits for a queue switch. Gemma 4 31B at TP4 beside an idle Qwen3.8-Flash-Next went from 13 ms to 41 ms a step; with `RADIANCE_PREFETCH_BESIDE=0` in the Gemma engine it took 13.8 ms. **Tooling**