radiance 1.0.9

- Pinned host memory is locked in pieces of at most 1 GiB (issue 13): an Intel VT-d host in
  scalable mode that refuses any single pin above about 2.5 GiB now takes the host pool with IOMMU
  translation, and peer-to-peer access, left on.
- Four-rank all-reduce (PR 11 by keptn42): the tiered-int8 wire serves in-place calls, so
  --tp 4 --tp-wire wht6 runs. At four and eight ranks the exact all-reduce is one-shot up to
  524288 elements and two-shot above, chosen by the selector, so the band report names the kernel
  that runs. The docs and the startup warning describe the four-rank lossy wire; eight ranks have
  none.
- A VRAM allocation the card cannot take is refused, saying what the card has left and which
  processes hold memory on it. ROCm 7.2's runtime crashes on such an allocation once a queue has
  been destroyed, which every startup does.
- rad-convert --changed FILE: with --reuse, converts only the weights that read a changed
  checkpoint tensor and copies the rest.
This commit is contained in:
Deadcode committed 2026-10-05 12:16:54 +02:00
1 parent 3e0c114cd7
commit 20d6c2119f
24 files changed
+707 -134

No files matched your search

+29 -40
View File
@@ -431,9 +431,9 @@ static int nb_for(long words16, int max_nb) {
}
/* Shared front half of every all-reduce launch: find the instance, check the message against what
* init sized for, resolve the tuned point. Two-shot rows pass want_distinct because they gather into
* the output while the input is still being read for the scatter. */
static int ar_setup(const RadArgs* a, ArCall* c, int want_distinct, int shard_nb) {
* init sized for, resolve the tuned point. Every kernel of the family runs in place (`y` absent or
* equal to `x`); each says why at its entry. */
static int ar_setup(const RadArgs* a, ArCall* c, int shard_nb) {
const ArInst* in = (const ArInst*)(a ? a->instance : nullptr);
if (!in) return RAD_E_STATE; /* init did not run: a core sequencing bug */
const RadTensor* x = r4d_opt(a, AR_X);
@@ -445,7 +445,6 @@ static int ar_setup(const RadArgs* a, ArCall* c, int want_distinct, int shard_nb
if (!r4d_contig(y)) return RAD_E_STRIDE;
if (r4d_numel(y) != r4d_numel(x)) return RAD_E_SHAPE;
}
if (want_distinct && (!y || y->data == x->data)) return RAD_E_INVAL;
const long n = (long)r4d_numel(x);
if (n <= 0) return RAD_E_SHAPE;
@@ -637,7 +636,7 @@ extern "C" int r4d_rad_ar_gather_8rank(const RadArgs* a, RadStream s) {
extern "C" int r4d_rad_ar_oneshot_2rank_exact(const RadArgs* a, RadStream s) {
ArCall c;
int rc = ar_setup(a, &c, 0, 0);
int rc = ar_setup(a, &c, 0);
if (rc != RAD_OK) return rc;
if (c.in->world != 2) return RAD_E_SHAPE;
R4D_TRY("ar_oneshot_2rank_exact",
@@ -669,7 +668,7 @@ enum { R4D_AR_WHT6_FUSED_THREADS = 512 };
extern "C" int r4d_rad_ar_oneshot_2rank_wht6(const RadArgs* a, RadStream s) {
ArCall c;
int rc = ar_setup(a, &c, 0, 0);
int rc = ar_setup(a, &c, 0);
if (rc != RAD_OK) return rc;
if (c.in->world != 2) return RAD_E_SHAPE;
if (c.in->dtype == 2) return RAD_E_DTYPE; /* the rotated wire is bf16/fp16 only */
@@ -718,34 +717,14 @@ extern "C" int r4d_rad_ar_oneshot_2rank_wht6(const RadArgs* a, RadStream s) {
* The peer arguments are ascending global rank with the current rank removed, which is exactly
* the order build() filled peer_scratch/peer_flags in. */
/* Four-rank blocks issue every all_reduce in place and without `hops`, so the exact two-shot row
* (hops=2) is never selected. Above this floor the one-shot entry runs the two-shot kernel instead:
* 1.5N rather than 3N bytes a rank, same fp32 fold order, bit-identical. In place is safe for the
* reason given at the ti8 entry. Prefill +17% at 16k/64k on 4x R9700; decode stays one-shot. */
enum { R4D_AR_EXACT_TWOSHOT_MIN_BYTES = 1024 * 1024 };
/* The one-shots run in place: the thread that stores word k of the output is the one that read
* word k of the input, for its push and again as its own term of the fold, and peers read only
* their own scratch (r4d_ar_oneshot_Nrank_exact.hip). */
extern "C" int r4d_rad_ar_oneshot_4rank_exact(const RadArgs* a, RadStream s) {
ArCall c;
int rc = ar_setup(a, &c, 0, 0);
int rc = ar_setup(a, &c, 0);
if (rc != RAD_OK) return rc;
if (c.in->world != 4) return RAD_E_SHAPE;
const long long msg_b = (long long)c.numel * c.in->esize;
if (msg_b >= R4D_AR_EXACT_TWOSHOT_MIN_BYTES && c.numel <= R4D_AR_TWOSHOT_WIDE_MAX_ELEMS &&
msg_b % 16 == 0 && (msg_b / 16) % c.in->world == 0 &&
2 * msg_b / c.in->world <= c.in->slot_bytes) { /* the two-shot's own preconditions */
ArCall t;
if (ar_setup(a, &t, 0, 1) == RAD_OK) { /* shard-scaled block count */
const ArInst* in = t.in;
R4D_TRY("ar_twoshot_4rank_exact",
r4d_ar_twoshot_4rank_exact(in->peer_scratch[0], in->peer_scratch[1], in->peer_scratch[2],
in->peer_flags[0], in->peer_flags[1], in->peer_flags[2],
in->my_scratch, in->my_flags, in->my_seq, in->slot16,
t.inp, t.out, t.numel, in->dtype, in->rank,
(long)(uintptr_t)s, t.nblocks, t.nthreads, t.drain, t.acq,
t.pub));
return RAD_OK;
}
}
const ArInst* in = c.in;
R4D_TRY("ar_oneshot_4rank_exact",
r4d_ar_oneshot_4rank_exact(in->peer_scratch[0], in->peer_scratch[1], in->peer_scratch[2],
@@ -759,7 +738,7 @@ extern "C" int r4d_rad_ar_oneshot_4rank_exact(const RadArgs* a, RadStream s) {
extern "C" int r4d_rad_ar_oneshot_8rank_exact(const RadArgs* a, RadStream s) {
ArCall c;
int rc = ar_setup(a, &c, 0, 0);
int rc = ar_setup(a, &c, 0);
if (rc != RAD_OK) return rc;
if (c.in->world != 8) return RAD_E_SHAPE;
const ArInst* in = c.in;
@@ -778,11 +757,18 @@ extern "C" int r4d_rad_ar_oneshot_8rank_exact(const RadArgs* a, RadStream s) {
}
/* The two-shots shard the message, so their block count scales with the SHARD -- a full-message
* count over-launches the whole mid band. Both refuse an in-place call; the four-rank one-shot
* entry runs the exact one in place above R4D_AR_EXACT_TWOSHOT_MIN_BYTES. */
* count over-launches the whole mid band.
*
* IN PLACE IS SAFE (r4d_ar_twoshot_Nrank_exact.hip). A thread takes one set of word offsets k
* within a shard and uses it in all three phases: the push reads word k of every peer's shard out
* of the input, the reduce reads word k of its own shard and stores the sum over it, and the
* assemble writes word k of every peer's shard. Each input word is therefore overwritten only by
* the thread that already read it, later in its own program order, and no peer reads this rank's
* input -- peers read their own scratch. The selector hands the two-shot the messages above the
* one-shot's size bound (r4d_rows.cpp, cArTsExact4). */
extern "C" int r4d_rad_ar_twoshot_4rank_exact(const RadArgs* a, RadStream s) {
ArCall c;
int rc = ar_setup(a, &c, 1, 1);
int rc = ar_setup(a, &c, 1);
if (rc != RAD_OK) return rc;
if (c.in->world != 4) return RAD_E_SHAPE;
if (c.numel > R4D_AR_TWOSHOT_WIDE_MAX_ELEMS) return RAD_E_SHAPE;
@@ -804,7 +790,7 @@ extern "C" int r4d_rad_ar_twoshot_4rank_exact(const RadArgs* a, RadStream s) {
extern "C" int r4d_rad_ar_twoshot_8rank_exact(const RadArgs* a, RadStream s) {
ArCall c;
int rc = ar_setup(a, &c, 1, 1);
int rc = ar_setup(a, &c, 1);
if (rc != RAD_OK) return rc;
if (c.in->world != 8) return RAD_E_SHAPE;
if (c.numel > R4D_AR_TWOSHOT_WIDE_MAX_ELEMS) return RAD_E_SHAPE;
@@ -829,13 +815,16 @@ extern "C" int r4d_rad_ar_twoshot_8rank_exact(const RadArgs* a, RadStream s) {
/* The tiered-int8 wire. Its slot stride is in BYTES, not 16-byte words: the wire is 38 bytes per
* group of 32 and so is not 16-byte aligned at all.
*
* Four-rank blocks issue every all_reduce in place and without `hops`, so a lossy wire lands here
* for every message. As in r4d_rad_ar_oneshot_2rank_wht6, a message under `min_bytes` (or one the
* groups do not tile) goes to the exact one-shot. In place is safe: each block reads its range of
* the input before it writes the same range of the output, and no peer reads this rank's input. */
* It is the only lossy row at four ranks, so a lossy request resolves it at every message size. As
* in r4d_rad_ar_oneshot_2rank_wht6, a message under `min_bytes` (or one the groups do not tile)
* goes to the exact one-shot. The default floor is the two-rank wire's: every block declares
* `min_bytes` from --tp-wire-min-kb, so the default serves only a caller that leaves it out, and no
* four-rank crossover has been measured to set another. In place is safe for the exact two-shot's
* reason: a thread owns the same 8 elements of a shard in all three phases, reads them from the
* input before it writes them, and no peer reads this rank's input. */
extern "C" int r4d_rad_ar_twoshot_4rank_ti8(const RadArgs* a, RadStream s) {
ArCall c;
int rc = ar_setup(a, &c, 0, 1);
int rc = ar_setup(a, &c, 1);
if (rc != RAD_OK) return rc;
if (c.in->world != 4) return RAD_E_SHAPE;
if (c.in->dtype == 2) return RAD_E_DTYPE;
+2 -4
View File
@@ -657,10 +657,8 @@ extern "C" int r4d_fuse_qk_norm_rope_gate_kv_store(const RadParam* p, int n_p, u
* 0." Leaving the key out would let a small message go out exact on one side of the
* comparison and rotated on the other.
*
* `hops` is deliberately NOT emitted. A query that omits it falls through to the one-shot rows,
* which is what this kernel is; naming it would be pinning a topology that does not exist at two
* ranks. `y` is RAD_FUSE_NONE: the fused kernel reduces in place into `x`, which is what the
* one-shot rows do and what the two-shot rows refuse by name.
* `hops` is not emitted: no libr4d row reads it, and two ranks have only the one-shot. `y` is
* RAD_FUSE_NONE: the fused kernel reduces in place into `x`, as every all-reduce row does.
*/
/* ==========================================================================================
* attn_paged_gate_quant -- attn_paged, then gate_quant_fp8 over its output.
+2 -3
View File
@@ -25,9 +25,8 @@
enum {
/* A two-shot row's constraints are a SUPERSET of the one-shot's at the same world_size, so a
* two-shot that ranked below could never be reached: every query it serves the one-shot also
* matches. `hops` is ALSO a predicate, and both mechanisms are needed -- the predicate is what
* makes a query that omits `hops` fall through to the one-shot, and the priority is what makes
* hops=2 reachable at all. */
* matches. Its lower bound on `numel` is what keeps a small message on the one-shot, and the
* priority is what hands a large one to the two-shot. */
R4D_PRIO_AR_TWOSHOT = 70,
R4D_PRIO_AR_ONESHOT = 60,
+56 -34
View File
@@ -71,6 +71,18 @@
* r4d_ar_entry.hip static_asserts the two against each other. */
#define R4D_AR_TWOSHOT_WIDE_MAX_ELEMS 20971520
/* The largest message, in elements, a 4- or 8-rank exact all-reduce keeps on the one-shot; above it
* the two-shot rows take it. 1 MiB of a 16-bit payload. The one-shot sends (ws-1)*N bytes a rank
* in one hop and the two-shot 2*(ws-1)/ws*N in two, so the one-shot wins while the second hop's
* latency outweighs the bytes it saves. The value is a separation, not a measured crossover: on
* Qwen3.8-Flash-Next (2560 wide, 5 KiB a row) the largest decode message is 640 KiB, at 32
* sequences each verifying four tokens, and a 2048-token prefill chunk is 10 MiB, so any bound
* between the two sends decode one-shot and prefill two-shot. It is a multiple of 128 for the
* reason pAllReduce's `numel` gives. */
#define R4D_AR_WIDE_ONESHOT_MAX_ELEMS 524288
#define R4D_XSTR(v) R4D_STR(v)
#define R4D_STR(v) #v
/* ==================================================================================== schemas
*
* The first plugin in hierarchy order to declare an op fixes its schema (spec §2.3), and this
@@ -617,11 +629,13 @@ static const RadOperandSpec oDflashSelect[] = {
/* ------------------------------------------------------------------------------ collectives */
static const RadParamSpec pAllReduce[] = {
{ "world_size", RAD_P_INT, RAD_REQUIRED },
/* THE LARGEST message this instance will ever carry, not the one a given step carries. init()
* sizes the peer scratch from it once and the launch reads the real count off the tensor.
* docs/OPS.md marks no parameter of `all_reduce` as ranged, and this is why that is right
* here even though the message size does vary per step: making `numel` a RANGE would put a
* RAD_C_DIV constraint on a ranged parameter, and a band is not divisible by anything. */
/* The message, in elements. Every block declares it as a RANGE -- a step carries its row
* count times the width -- so the selector cuts it into bands at the bounds the rows below
* place on it and resolves each band at its upper bound: init() sizes the peer scratch for
* that bound once, and the launch reads the real count off the tensor. A row's RAD_C_DIV on
* `numel` is therefore checked at a band's upper bound, so every bound a row here places on
* it is a multiple of 128, the largest DIV among them; a bound that was not would leave a
* band no DIV row could serve. */
{ "numel", RAD_P_INT, RAD_REQUIRED },
{ "dtype", RAD_P_STR, RAD_REQUIRED },
{ "exact", RAD_P_INT, RAD_REQUIRED },
@@ -631,12 +645,16 @@ static const RadParamSpec pAllReduce[] = {
* stops costing more than the bytes it removes, and that is a bandwidth the deployment knows
* and the library does not. An exact row ignores it -- there is nothing to fall back to. */
{ "min_bytes", RAD_P_INT, RAD_OPTIONAL },
/* A caller's request for a one-shot (1) or two-shot (2). docs/OPS.md's schema is the union of
* every plugin's parameters and libref accepts it, so it stays declared here; no row of this
* plugin reads it, because the message size picks the two-shot (the all-reduce constraints
* below). */
{ "hops", RAD_P_INT, RAD_OPTIONAL },
};
/* docs/OPS.md has `x` -> `x` (inout). The one-shot kernels reduce elementwise out[i] = in[i] +
* peer_staged[i] and are safe in place; the two-shots are not, because a rank gathers into the
* output while its own input is still being read for the scatter. So the output is an optional
* SECOND operand: absent means in place, and the two-shot shims refuse in place by name. */
/* docs/OPS.md has `x` -> `x` (inout). Every kernel here is safe in place -- the thread that
* overwrites a word of the input is the one that read it (r4d_ar_entry.hip says so per kernel) --
* and every block issues it that way. The output is an optional SECOND operand for a caller that
* wants the sum somewhere else: absent means in place. */
static const RadOperandSpec oAllReduce[] = {
{ "x", RAD_OPD_INOUT, 0 },
{ "y", RAD_OPD_OUT, 1 },
@@ -1911,8 +1929,10 @@ static const RadOpSchema kSchemas[] = {
"serial and the other K-1 rows of the score matrix are never read."),
SCHEMA("all_reduce", pAllReduce, oAllReduce,
"sum over the tensor-parallel group. `exact` separates the exact sum from the "
"quantised wire and a caller that does not declare it gets no kernel; `hops` separates "
"one-shot from two-shot at a width that has both."),
"quantised wire and a caller that does not declare it gets no kernel. At 4 and 8 ranks "
"the exact sum is one-shot up to " R4D_XSTR(R4D_AR_WIDE_ONESHOT_MAX_ELEMS) " elements and "
"two-shot above, chosen by the "
"message's band; `hops` is accepted and no row of this plugin reads it."),
SCHEMA("all_gather", pAllGather, oAllGather,
"y is [world_size * numel] with rank r's contribution at offset r * numel. The bytes are "
"moved and never summed: the vocab-parallel sampler's payload is (u32 token id, f32 "
@@ -2329,13 +2349,14 @@ static const RadConstraint cGdnGatedRmsNorm[] = {
/* ---- all-reduce ------------------------------------------------------------------------------
* `exact` separates the two, and a caller has to say which it wants: a request that does not
* declare it will accept a lossy wire format gets no kernel rather than the quantised one.
* `hops` separates the one-shot from the two-shot at a width that has both. It has to be a
* predicate and not just row order: a two-shot row's constraints are otherwise a superset of the
* one-shot's at the same world_size. Omitting `hops` still resolves to the one-shot, which is the
* latency-band default; ask for hops=2 to be handed the two-shot. On the kernel side that default
* falls out of row order; here it is R4D_PRIO_AR_TWOSHOT > R4D_PRIO_AR_ONESHOT, so the mechanism
* is written down rather than implied by position. The ti8 wire needs no such key -- exact=0
* already separates it. */
* MESSAGE SIZE separates the one-shot from the two-shot at a width that has both. The two-shot
* rows start above R4D_AR_WIDE_ONESHOT_MAX_ELEMS, which makes that bound a band edge of `numel`:
* the band at or under it resolves only the one-shot, and in the band above both rows match and
* R4D_PRIO_AR_TWOSHOT > R4D_PRIO_AR_ONESHOT hands it the two-shot. The GE is one past the bound so
* the band under it ends ON the bound, a multiple of every DIV here (see pAllReduce's `numel`). The
* choice is the selector's and so it is what the band report names; no entry point substitutes
* one kernel for another. The ti8 wire needs no such key -- exact=0 already separates it, and it
* serves its own small messages exactly. */
/* ---- all-gather -------------------------------------------------------------------------------
* The vocab-parallel sampler's candidate merge, and nothing else in the engine issues one. No
* `exact` key: a gather MOVES its payload and cannot be lossy, so there is no second row for it
@@ -2371,15 +2392,15 @@ static const RadConstraint cArExact8[] = {
C_P2P,
};
static const RadConstraint cArTsExact4[] = {
C_EQ("world_size", 4), C_EQ("exact", 1), C_EQ("hops", 2),
C_IN("dtype", "bf16 fp16 fp32"),
C_DIV("numel", 64), C_LE("numel", R4D_AR_TWOSHOT_WIDE_MAX_ELEMS),
C_EQ("world_size", 4), C_EQ("exact", 1), C_IN("dtype", "bf16 fp16 fp32"),
C_DIV("numel", 64), C_GE("numel", R4D_AR_WIDE_ONESHOT_MAX_ELEMS + 1),
C_LE("numel", R4D_AR_TWOSHOT_WIDE_MAX_ELEMS),
C_P2P,
};
static const RadConstraint cArTsExact8[] = {
C_EQ("world_size", 8), C_EQ("exact", 1), C_EQ("hops", 2),
C_IN("dtype", "bf16 fp16 fp32"),
C_DIV("numel", 64), C_LE("numel", R4D_AR_TWOSHOT_WIDE_MAX_ELEMS),
C_EQ("world_size", 8), C_EQ("exact", 1), C_IN("dtype", "bf16 fp16 fp32"),
C_DIV("numel", 64), C_GE("numel", R4D_AR_WIDE_ONESHOT_MAX_ELEMS + 1),
C_LE("numel", R4D_AR_TWOSHOT_WIDE_MAX_ELEMS),
C_P2P,
};
static const RadConstraint cArWht6[] = {
@@ -3837,13 +3858,13 @@ static const RadKernelInfo kKernels[] = {
r4d_shape_gdn_gated_rmsnorm },
/* ---------------------------------------------------------------------------- all-reduce ----
* The two-shot rows come FIRST in libr4d and outrank here, for the reason the constraint block
* above states at length. */
* The two-shot rows outrank the one-shots, for the reason the constraint block above states. */
{ "ar_twoshot_4rank_exact", "all_reduce", "ar",
"all-reduce (sum), reduce-scatter + all-gather over P2P IPC scratch, per-block pipelined "
"handshake",
"exactly 4 ranks, all peer-accessible; two hops (select with hops=2); shares the wide family's "
"flag/seq/scratch set; message must shard evenly over the ranks; cudagraph-safe",
"exactly 4 ranks, all peer-accessible; messages above "
R4D_XSTR(R4D_AR_WIDE_ONESHOT_MAX_ELEMS) " elements, two hops; shares the wide family's "
"flag/seq/scratch set; message must shard evenly over the ranks; in place; cudagraph-safe",
"bf16 / fp16 / fp32 payload, fp32 accumulate in ascending rank order, bit-identical across ranks",
RAD_DOMAIN_DEVICE, R4D_PRIO_AR_TWOSHOT,
ROW(cArTsExact4), ROW(tAr), nullptr,
@@ -3853,8 +3874,9 @@ static const RadKernelInfo kKernels[] = {
{ "ar_twoshot_8rank_exact", "all_reduce", "ar",
"all-reduce (sum), reduce-scatter + all-gather over P2P IPC scratch, per-block pipelined "
"handshake",
"exactly 8 ranks, all peer-accessible; two hops (select with hops=2); shares the wide family's "
"flag/seq/scratch set; message must shard evenly over the ranks; cudagraph-safe",
"exactly 8 ranks, all peer-accessible; messages above "
R4D_XSTR(R4D_AR_WIDE_ONESHOT_MAX_ELEMS) " elements, two hops; shares the wide family's "
"flag/seq/scratch set; message must shard evenly over the ranks; in place; cudagraph-safe",
"bf16 / fp16 / fp32 payload, fp32 accumulate in ascending rank order, bit-identical across ranks",
RAD_DOMAIN_DEVICE, R4D_PRIO_AR_TWOSHOT,
ROW(cArTsExact8), ROW(tAr), nullptr,
@@ -3916,8 +3938,8 @@ static const RadKernelInfo kKernels[] = {
{ "ar_oneshot_4rank_exact", "all_reduce", "ar",
"all-reduce (sum), one-shot push over P2P IPC scratch, per-block handshake",
"exactly 4 ranks, all peer-accessible; one scratch slot per (parity, source rank); "
"cudagraph-safe",
"exactly 4 ranks, all peer-accessible; one scratch slot per (parity, source rank); in "
"place; cudagraph-safe",
"bf16 / fp16 / fp32 payload, fp32 accumulate in ascending rank order, bit-identical across ranks",
RAD_DOMAIN_DEVICE, R4D_PRIO_AR_ONESHOT,
ROW(cArExact4), ROW(tAr), nullptr,
@@ -3926,8 +3948,8 @@ static const RadKernelInfo kKernels[] = {
{ "ar_oneshot_8rank_exact", "all_reduce", "ar",
"all-reduce (sum), one-shot push over P2P IPC scratch, per-block handshake",
"exactly 8 ranks, all peer-accessible; one scratch slot per (parity, source rank); "
"cudagraph-safe",
"exactly 8 ranks, all peer-accessible; one scratch slot per (parity, source rank); in "
"place; cudagraph-safe",
"bf16 / fp16 / fp32 payload, fp32 accumulate in ascending rank order, bit-identical across ranks",
RAD_DOMAIN_DEVICE, R4D_PRIO_AR_ONESHOT,
ROW(cArExact8), ROW(tAr), nullptr,
+2 -4
View File
@@ -1028,10 +1028,8 @@ extern "C" int r4d_shape_all_reduce(const RadParam* p, int n_p, int operand,
const uint32_t D = dt_act(p, n_p, "dtype");
const RadOpdDesc l[] = {
opd(D, numel),
/* The optional SECOND DESTINATION. Absent means in place, which is what the one-shot rows
* do; the two-shot rows are not safe in place -- a rank gathers into the output while its
* own input is still being read for the scatter -- and refuse a null by name. Passing it
* is the one description that serves every row of the op. */
/* The optional SECOND DESTINATION. Absent means in place, which every row of the op
* serves; described so a caller that passes one is checked against the same extent. */
opd(D, numel),
};
R4D_PICK(l);