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

+32
View File
@@ -16,6 +16,7 @@
#include <string>
#include <sys/stat.h>
#include <unistd.h>
#include <unordered_set>
#include <vector>
using namespace rad;
@@ -262,6 +263,37 @@ TEST(an_expert_is_its_slice_of_a_stack) {
remove_checkpoint(dir);
}
/* A CHANGED TENSOR IS NAMED AS THE CHECKPOINT NAMES IT. An expert is a slice "exps[2]" of its
* stack, and it reads "exps"; a block-FP8 weight reads its scale plane as well as its codes, so a
* changed scale changes the weight. */
TEST(a_weight_reads_the_checkpoint_tensors_its_pieces_and_scales_come_from) {
const std::string dir = write_checkpoint(
{ bf16("exps", { 4, 2, 3 }, 0.0f), fp8("q.weight", { 2, 128, 128 }),
bf16("q.weight_scale_inv", { 2, 1, 1 }, 7.0f), bf16("a.weight", { 2, 3 }, 0.0f),
bf16("b.weight", { 2, 3 }, 0.0f) }, kConfig);
Checkpoint ck;
REQUIRE_EQ(ck.open(dir), RAD_OK);
Program prog;
prog.name_map.push_back(map("e2", RAD_MAP_COPY, { "exps" }, { 2 }));
prog.name_map.push_back(map("q1", RAD_MAP_COPY, { "q.weight" }, { 1 }));
prog.name_map.push_back(map("ab", RAD_MAP_CONCAT, { "a.weight", "b.weight" }));
CkptWeight e2, q1, ab;
std::string why;
REQUIRE_EQ(ckpt_resolve(ck, prog, "e2", false, &e2, &why), RAD_OK);
REQUIRE_EQ(ckpt_resolve(ck, prog, "q1", false, &q1, &why), RAD_OK);
REQUIRE_EQ(ckpt_resolve(ck, prog, "ab", false, &ab, &why), RAD_OK);
CHECK_EQ(ckpt_tensor_of(*e2.pieces[0]), std::string("exps"));
std::unordered_set<std::string> hit;
CHECK(ckpt_reads_any(e2, { "exps" }, &hit));
CHECK(!ckpt_reads_any(e2, { "exps[2]" })); /* a slice is not a checkpoint name */
CHECK(ckpt_reads_any(q1, { "q.weight_scale_inv" }, &hit));
CHECK(ckpt_reads_any(ab, { "b.weight" }, &hit)); /* one changed piece of a join */
CHECK(!ckpt_reads_any(ab, { "q.weight", "exps" }));
CHECK_EQ(hit.size(), (size_t)3);
remove_checkpoint(dir);
}
/* A COPY's sources are alternatives, first present wins: a tied head reads the embedding where
* the checkpoint ships no head of its own. */
TEST(alternatives_take_the_first_tensor_present) {
+75
View File
@@ -159,6 +159,81 @@ TEST(alloc_free_roundtrip) {
CHECK(rad_dev_host_ptr(nullptr) == nullptr);
}
/* A pinned range larger than one pin is locked in several (core/device/aql.cpp, pin_pieces), and
* nothing above the device layer may be able to tell: one base, every byte of it at the same
* address on the card, copies and fills that cross a piece boundary landing whole, and none of
* them taken for pageable memory -- a fill of pageable memory is refused, so the fill is the
* check. 2.5 GiB is the single-pin size an Intel VT-d host refused; the boundaries crossed are
* the whole GiBs. */
TEST(a_pinned_range_larger_than_one_pin_is_one_range_on_the_card) {
const int64_t gib = (int64_t)1 << 30;
const int64_t n = 5 * (gib / 2) + 4096 + 17;
const int64_t w = 8 << 20;
Stream st;
auto* h = (uint8_t*)rad_dev_alloc(n, RAD_MEM_HOST_MAPPED);
auto* d = (uint8_t*)rad_dev_alloc(w, RAD_MEM_DEVICE);
CHECK(h != nullptr);
CHECK(d != nullptr);
if (!h || !d) {
rad_dev_free(h, RAD_MEM_HOST_MAPPED);
rad_dev_free(d, RAD_MEM_DEVICE);
return;
}
/* The host backend resolves only an allocation's base, so the interior addresses are a card's
* question. */
CHECK_EQ(rad_dev_device_ptr(h), (void*)h);
if (!rad::device_is_host())
for (int64_t off : { gib - 1, gib, 2 * gib - 4096, 2 * gib, n - 1 })
CHECK_EQ(rad_dev_device_ptr(h + off), (void*)(h + off));
std::string expect((size_t)w, '\0');
for (int64_t b : { gib, 2 * gib }) {
uint8_t* span = h + b - w / 2;
fill(span, w, (uint32_t)(b >> 20));
std::memcpy(expect.data(), span, (size_t)w);
CHECK_OK(rad_memcpy_async(d, span, w, st.s));
CHECK_OK(rad_stream_sync(st.s));
std::memset(span, 0, (size_t)w);
CHECK_OK(rad_memcpy_async(span, d, w, st.s));
CHECK_OK(rad_stream_sync(st.s));
CHECK_EQ(std::memcmp(span, expect.data(), (size_t)w), 0);
CHECK_OK(rad_memset_async(span, 0xA5, w, st.s));
CHECK_OK(rad_stream_sync(st.s));
CHECK(span[0] == 0xA5 && span[w / 2 - 1] == 0xA5 && span[w / 2] == 0xA5 && span[w - 1] == 0xA5);
}
rad_dev_free(d, RAD_MEM_DEVICE);
rad_dev_free(h, RAD_MEM_HOST_MAPPED);
}
/* A DEVICE ALLOCATION THE CARD CANNOT TAKE IS AN ERROR, AND STAYS ONE AFTER A QUEUE HAS BEEN
* DESTROYED. ROCm 7.2's runtime answers a VRAM allocation the driver refuses by walking every queue
* the process ever created, destroyed ones included, and dies of SIGSEGV there; the backend refuses
* such a request itself, before the runtime is asked (core/device/aql.cpp, "the room check"). A
* stream is made and destroyed first, so the walk would have a freed queue to touch, and then the
* whole card is asked for: more than the driver has left, since this process already holds some of
* it, and no more than one allocation may be, so without the check it reaches the driver. */
TEST(an_allocation_the_card_cannot_take_is_refused_after_a_queue_was_destroyed) {
if (rad::device_is_host()) {
std::fprintf(stderr, " SKIP an_allocation_the_card_cannot_take_is_refused_after_a_queue_"
"was_destroyed: a card only\n");
return;
}
{ Stream st; CHECK(st.s != nullptr); }
RadDeviceProps p{};
CHECK_OK(rad_dev_props(0, &p));
void* d = rad_dev_alloc(p.vram_bytes, RAD_MEM_DEVICE);
CHECK(d == nullptr);
const char* why = rad_dev_last_error();
CHECK(std::strstr(why, "on card 0: the driver has") != nullptr);
CHECK(std::strstr(why, "this process") != nullptr);
if (d) rad_dev_free(d, RAD_MEM_DEVICE);
/* And the card still serves an allocation it can take. */
void* ok = rad_dev_alloc(8 << 20, RAD_MEM_DEVICE);
CHECK(ok != nullptr);
rad_dev_free(ok, RAD_MEM_DEVICE);
}
TEST(device_allocation_moves_vram_free) {
/* On a card, other processes move it too. */
if (!rad::device_is_host()) {
+66 -2
View File
@@ -19,6 +19,7 @@
#include <nlohmann/json.hpp>
#include <dlfcn.h>
#include <unistd.h>
#include <cstdlib>
#include <string>
@@ -488,8 +489,8 @@ TEST(every_constraint_operator_refuses_with_its_own_reason) {
g = attn_geom(); g.set_s("kv_dtype", "f32");
CHECK(has(refusal(r, "t_attn", g), "kv_dtype in {bf16 fp8_e4m3}, have f32"));
/* A constraint whose key the geometry lacks does NOT hold -- libr4d's rule, and the reason its
* two-shot all-reduce rows can be reached at all. */
/* A constraint whose key the geometry lacks does NOT hold -- libr4d's rule: a row that needs
* a parameter the caller did not state is not a match. */
Geometry partial;
partial.set_i("q_len", 8);
CHECK(has(refusal(r, "t_attn", partial), "did not name head_dim"));
@@ -817,4 +818,67 @@ TEST(a_device_fact_constraint_is_matched_against_the_machine) {
CHECK(has(why, "measured at launch"));
}
/* THE SHIPPED libr4d PICKS THE ALL-REDUCE BY MESSAGE SIZE, and the selector is what says so. At 4
* and 8 ranks the exact sum is a one-shot for a decode-sized message and a two-shot for a prefill
* chunk; the two-shot rows start one element above the one-shot bound, so that bound is a band
* edge of the blocks' ranged `numel`. The band at or under the edge has to stay resolvable for
* every row that places a DIV on `numel` -- the two-rank wht6 wire (64) and the four-rank ti8 wire
* (128) among them -- or a lossy two-rank serve would lose its decode band. Checked here against
* the real plugin, because nothing else can run a four- or eight-rank resolution on a two-card
* machine. Geometry is Qwen3.8-Flash-Next's: 2560 wide, a 2048-token chunk. */
TEST(libr4d_resolves_the_all_reduce_by_message_size) {
const std::string so = home() + "/kernels/libr4d.so";
if (access(so.c_str(), R_OK) != 0) {
fprintf(stderr, " SKIP %s: no %s (a build without HIP)\n", ::radtest::current(),
so.c_str());
return;
}
Registry r;
CHECK(r.load_plugin(so, 0) >= 0);
r.set_device_fact(RAD_FACT_P2P, 1);
const int64_t width = 2560, chunk = 2048;
auto bands = [&](int world, int exact, int64_t max_tok) {
Geometry g;
g.set_i("world_size", world);
g.set_s("dtype", "bf16");
g.set_i("exact", exact);
g.set_i("min_bytes", 128 * 1024);
return r.build_bands("all_reduce", "numel", width, max_tok * width, g);
};
auto names = [](const std::vector<Band>& b) {
std::string s;
for (const Band& x : b)
s += fmt("%lld:%s ", (long long)x.hi, picked(x.dom[RAD_DOMAIN_DEVICE].row).c_str());
return s;
};
CHECK_EQ(names(bands(4, 1, chunk)),
"524288:ar_oneshot_4rank_exact 5242880:ar_twoshot_4rank_exact ");
CHECK_EQ(names(bands(8, 1, chunk)),
"524288:ar_oneshot_8rank_exact 5242880:ar_twoshot_8rank_exact ");
CHECK_EQ(names(bands(4, 0, chunk)),
"524288:ar_twoshot_4rank_ti8 5242880:ar_twoshot_4rank_ti8 ");
CHECK_EQ(names(bands(2, 0, chunk)),
"524288:ar_oneshot_2rank_wht6 5242880:ar_oneshot_2rank_wht6 ");
CHECK_EQ(names(bands(2, 1, chunk)),
"524288:ar_oneshot_2rank_exact 5242880:ar_oneshot_2rank_exact ");
/* Above the two-shot's cap the one-shot takes the message back. */
CHECK_EQ(names(bands(4, 1, 16384)),
"524288:ar_oneshot_4rank_exact 20971520:ar_twoshot_4rank_exact "
"41943040:ar_oneshot_4rank_exact ");
/* A step that never exceeds the bound has one band, and it is the one-shot's. */
CHECK_EQ(names(bands(4, 1, 128)), "327680:ar_oneshot_4rank_exact ");
/* Eight ranks have no lossy wire: every band is a miss that names the request. */
const std::vector<Band> none = bands(8, 0, chunk);
CHECK(!none.empty());
for (const Band& b : none) {
CHECK(!b.dom[RAD_DOMAIN_DEVICE]);
CHECK(has(b.miss[RAD_DOMAIN_DEVICE], "exact"));
}
}
RAD_TEST_MAIN()
+1 -2
View File
@@ -343,8 +343,7 @@ TEST(a_zero_divisor_holds_for_nothing_rather_than_faulting) {
}
/* A CONSTRAINT WHOSE KEY THE GEOMETRY DOES NOT CARRY DOES NOT HOLD. The header names what this
* buys: libr4d's two-shot all-reduce rows are reachable only by a query that asks for `hops`,
* because a query that omits it fails the more constrained row. */
* buys: a row that constrains an optional parameter serves only a caller that states it. */
TEST(an_absent_key_fails_every_constraint) {
Geometry g;
g.set_i("M", 64);