radiance 1.4.0

- Qwen3.8-Flash-Next on one card: the heat engine moves 64 experts a step (was 8), its copies and
  the prefill's expert staging run on the card's DMA engines instead of as copy kernels, and at
  decode the next layer's likeliest experts are copied onto the card ahead of its GEMMs. Against
  1.3.0 at --tp 1: prefill +17-20% from 8K tokens up, throughput under load +16-20%
- deploy/compose/flashnext-tp1.yaml: Qwen3.8-Flash-Next on one card and 64 GB of host RAM
  (4096-token prefill steps, 4 sequences, a 301K-token cache)
- #61: --busy-prefill-chunk (default auto): a long prefill leaves the rest of the step to the
  requests decoding beside it and to new arrivals, instead of taking all of it (baKon)
- LiquidAI's LFM2 and LFM2-VL, and d1's /v1/systemone (after zivius's PR #50)
- a startup report: every option with its value and where it came from, the hardware, and what
  on it costs speed with the fix; /diagnostics serves it (behind the API key; without one, only
  to the same machine)
- #69: a GPU memory fault names the buffer and kernel argument behind it and ends the server at
  once (exit status 70), instead of hanging or writing a core of tens of gigabytes
- #64: a card without Resizable BAR is refused at startup, naming what to turn on, instead of
  crashing at the first launch
- the image is built with ROCm 10.1 (the host's amdgpu driver must support it), with ROCm's
  libLLVM rebuilt so the same source compiles to the same kernels every time; a source build
  takes ROCm 10.1 or 7.2
- #71: the image ships curl, jq and a CA bundle, so --model <HF repo id> works in the container,
  and hfget.sh runs under its busybox (baKon)
- --profile-ops shows how long each op's lane sat idle before it; cardclock.py skips an
  integrated GPU instead of stopping
This commit is contained in:
Deadcode committed 2026-10-12 11:46:14 +02:00
1 parent d5b65cddc6
commit dc339b4cd2
153 files changed
+12956 -1067

No files matched your search

+974 -2
View File
File diff suppressed because it is too large. Load diff
+108
View File
@@ -58,6 +58,79 @@ struct RadCopyRange {
extern "C" int rad_memcpy_ranges_async(void* dst, const void* src, int64_t prefix,
const RadCopyRange* ranges, int n, RadStream s);
/* ONE COPY OF A LIST: `bytes` from `src` to `dst`, both absolute addresses. */
struct RadCopySeg {
const void* src;
void* dst;
int64_t bytes;
};
/* MANY UNRELATED COPIES, IN LIST ORDER ON THE STREAM, on the card's DMA engine where the backend
* has one. The list is read at the call, so it need not outlive it; the bytes it names do, like
* any copy's. A backend without a DMA engine copies the segments one by one, in order. An empty
* list puts nothing on the stream, and readies what the backend's first list on that stream's card
* would otherwise set up, so a caller can take that cost at bring-up.
*
* It exists for bulk copies across the link while the card computes -- the prefill stager's,
* a layer's pooled experts a call. A copy as a kernel holds a compute unit's slot for as long as
* the link takes, and waits for one to free up at every launch: beside kernels that keep every unit
* busy, 1.3 MB copies from pinned host memory ran at 2.3 GB/s as kernels and at 28.7 GB/s -- the
* link -- on the DMA engine, which cost those kernels nothing (aql.cpp, "the DMA lane").
*
* RAD_COPY_YIELD makes the list give way to the card's collectives: it waits, between pieces of
* about a megabyte, while a stream of that card holds the link (rad_link_hold). */
#define RAD_COPY_YIELD 1u
extern "C" int rad_memcpy_list_async(const RadCopySeg* segs, int n, unsigned flags, RadStream s);
/* THE CARD'S LINK, HELD BY A STREAM FOR WHAT IT ISSUES BETWEEN TWO CALLS: `on` 1 at the point in
* `s` where traffic the step waits on starts to cross the card's link -- a collective -- and 0
* where it ends, or 2 where the work in between ended the hold itself (rad_link_gate). Lists issued
* RAD_COPY_YIELD for that card stop between pieces while it is held. The holds of one card
* alternate, on then off, in the order they are issued across all its streams: they never nest or
* overlap. And the holding stream must not wait, between the two
* calls, on anything behind a yielding list -- the list would wait for the hold to end, and the
* hold for the list. A backend without a DMA engine holds nothing.
*
* WHY: a card's inbound link carries a collective's peer bytes and the stager's copies alike, and
* the DMA engine takes its share at the link's full rate. A 4 MB all-reduce message that crosses in
* 165 us on its own took 301 us beside a layer's copies, and the step waits on every one; the
* copies have the rest of the layer to finish in. */
extern "C" int rad_link_hold(RadStream s, int on);
/* THE WORD THE HOLD IS KEPT IN, for a launch that ends its own: a 64-bit word in memory every
* engine and kernel of the card reaches, odd while the link is held. rad_link_hold(s, 2) after a
* launch that was handed this address records that the launch released the hold itself, by taking
* one off the word -- once, and only if it found it odd -- as soon as the bytes it waited for had
* landed. Null where the backend holds nothing. */
extern "C" void* rad_link_gate(RadStream s);
/* THE EXPERT PREFETCH'S DEVICE HALF (core/runtime/xprefetch.cpp). A backend that cannot make a
* dispatch complete a signal, or has no DMA engine to spare for it, leaves these out:
* rad_xp_supported is then 0 and the prefetch is off.
*
* A RIDE is a signal the next dispatch issued on a stream completes -- that dispatch keeps its
* ordering bit, so the signal stands for everything before it on the stream -- in place of a
* barrier packet of its own between two kernels. rad_ride_wait puts a barrier on another stream
* that waits for it and gives the signal back behind that barrier; a ride the DMA engine polls
* instead goes back with rad_ride_release once nothing can poll it: at once (`after` null) when the
* list that polled it has finished, else once `after` is `packets` dispatches further on, which is
* long after the ridden dispatch has completed it.
*
* rad_xp_list hands the card's prefetch DMA queue a list: wait for `mark` (a ride, or null), copy
* the `n` ranges, then write `done_val` to `done` (pinned host memory, or null). rad_xp_behind is how
* many lists the queue has been handed and not yet finished. The prefetch's ring is uncached device
* memory (rad_dev_alloc_uncached): the engine writes it and kernels read it, and no cache may hold
* what a slot held before. */
extern "C" int rad_xp_supported(int device);
extern "C" int rad_xp_stream_create(RadStream* out);
extern "C" int rad_ride(RadStream s, void** token);
extern "C" int rad_ride_wait(RadStream s, void* token);
extern "C" void rad_ride_release(void* token, RadStream after, int64_t packets);
extern "C" int rad_xp_list(int device, void* mark, int n, const uint64_t* src, const uint64_t* dst,
const uint64_t* bytes, uint32_t* done, uint32_t done_val);
extern "C" int64_t rad_xp_behind(int device);
extern "C" void* rad_dev_alloc_uncached(int64_t bytes);
extern "C" void rad_dev_free_uncached(void* p);
namespace rad {
/* A recorded pass, owned by the backend that recorded it. See DeviceBackend::tape_begin. */
@@ -128,6 +201,9 @@ struct DeviceBackend {
int (*memset_async)(void* dst, int value, int64_t bytes, RadStream s);
int (*memcpy_ranges_async)(void* dst, const void* src, int64_t prefix,
const RadCopyRange* ranges, int n, RadStream s);
int (*memcpy_list_async)(const RadCopySeg* segs, int n, unsigned flags, RadStream s);
int (*link_hold)(RadStream s, int on);
void* (*link_gate)(RadStream s);
/* ---- recorded passes. A backend with none leaves these null, and the run phase then issues
* every pass; see Ctx::run_step for what a tape is for and when one is kept.
@@ -228,6 +304,32 @@ struct DeviceBackend {
* the backend cannot say. Asked, not enabled: rad_dev_enable_peer is the call that maps the
* memory. Null on a backend whose devices share one address space, which answers 1. */
int (*peer_access)(int self, int peer);
/* ---- the card's PCI address, "0000:03:00.0", into `out`; RAD_E_UNSUPPORTED from a backend
* whose devices are not PCI devices. It is what joins the runtime's device index to the
* kernel's description of the same card -- its link, its power limits, its IOMMU group -- in
* the startup report (core/diag/diag.h). */
int (*pci_address)(int device, char* out, int cap);
/* ---- the device runtime's name and version, "HIP 7.2.25403", into `out`. Null on a backend
* with no runtime behind it. */
int (*runtime_version)(char* out, int cap);
/* ---- what carries the engine's copy lists for `device` (rad_memcpy_list_async), into `out`:
* the card's DMA engine on a queue of the process's own, or why not. Null on a backend that
* copies every list segment by segment. */
int (*dma_lane)(int device, char* out, int cap);
/* ---- the expert prefetch's device half: see rad_xp_supported. Last in the table, so a backend
* listing its entries in order leaves them null. */
int (*xp_supported)(int device);
int (*xp_stream_create)(RadStream* out);
int (*ride)(RadStream s, void** token);
int (*ride_wait)(RadStream s, void* token);
void (*ride_release)(void* token, RadStream after, int64_t packets);
int (*xp_list)(int device, void* mark, int n, const uint64_t* src, const uint64_t* dst,
const uint64_t* bytes, uint32_t* done, uint32_t done_val);
int64_t (*xp_behind)(int device);
void* (*alloc_uncached)(int64_t bytes);
void (*free_uncached)(void* p);
};
@@ -260,6 +362,12 @@ int dev_code_runs(size_t from, size_t to, int device, std::string* why);
/* The current backend's DeviceBackend::integrated. */
bool dev_integrated(int device);
/* The current backend's DeviceBackend::pci_address and runtime_version, "" where it has none. */
std::string dev_pci_address(int device);
std::string dev_runtime_version();
/* The current backend's DeviceBackend::dma_lane, "" where it has none. */
std::string dev_dma_lane(int device);
/* THE LONGEST RUN OF DISPATCHES A PLAYED TAPE LEAVES UNORDERED. Of any kTapeOverlapRun + 1
* consecutive packets on a queue, one carries the barrier bit, so a packet having been launched
* still proves that everything more than that many packets before it has completed -- which is
+86 -2
View File
@@ -67,13 +67,16 @@ static std::string device_inventory(const DeviceBackend* b) {
return s;
}
#if defined(RAD_HAVE_HIP) && RAD_HAVE_HIP
/* COMPUTE WAVE SAVE/RESTORE OFF IS A GPU HANG WAITING FOR AN EVICTION. The driver evicts a
* process's queues whenever host memory the card maps is moved or reclaimed under memory pressure,
* and a serve with a host pool or a host KV tier maps gigabytes of it. With
* amdgpu.cwsr_enable=0 it cannot preempt a running queue and waits for it to drain, which a queue
* a serve keeps fed never does: the queue stops inside whatever kernel it was running, MES fails
* REMOVE_QUEUE, and the driver resets the card. Said at startup because nothing later can tell
* that hang from a kernel bug. */
* that hang from a kernel bug -- and said here, as the backend comes up, and not only in the
* startup report: a hang during the load ends the process before the report prints, and the
* tools that bring a backend up (rad-kbench, rad-tune) print no report at all. */
static void warn_cwsr_off() {
FILE* f = std::fopen("/sys/module/amdgpu/parameters/cwsr_enable", "r");
if (!f) return;
@@ -87,7 +90,6 @@ static void warn_cwsr_off() {
"amdgpu.cwsr_enable=1 (module option, then rebuild the initramfs and reboot)");
}
#if defined(RAD_HAVE_HIP) && RAD_HAVE_HIP
/* THE HOST BACKEND IN A BUILD THAT HAS HIP STILL COUNTS THE GPU CODE PLUGINS BRING. The
* registration hooks are this build's own exported symbols and see every dlopen'ed kernel
* library's fat binaries, card or no card, so the plugin loader can bracket each dlopen and know
@@ -535,6 +537,39 @@ int tape_set_overlap(RadTape t, int i, bool on) {
return dev()->tape_set_overlap ? dev()->tape_set_overlap(t, i, on ? 1 : 0) : RAD_E_UNSUPPORTED;
}
bool dev_integrated(int device) { return dev()->integrated && dev()->integrated(device) > 0; }
/* A FAILURE ANSWERED HERE, as "", is not one for the next reader of rad_dev_last_error: that
* reader is reporting a failure of its own and would name this one instead. The slot is put back
* as the call found it. */
std::string dev_pci_address(int device) {
char buf[64] = { 0 };
if (!dev()->pci_address) return std::string();
const std::string before = t_last_error;
if (dev()->pci_address(device, buf, (int)sizeof buf) < 0) {
t_last_error = before;
return std::string();
}
return buf;
}
std::string dev_dma_lane(int device) {
char buf[256] = { 0 };
if (!dev()->dma_lane) return std::string();
const std::string before = t_last_error;
if (dev()->dma_lane(device, buf, (int)sizeof buf) < 0) {
t_last_error = before;
return std::string();
}
return buf;
}
std::string dev_runtime_version() {
char buf[128] = { 0 };
if (!dev()->runtime_version) return std::string();
const std::string before = t_last_error;
if (dev()->runtime_version(buf, (int)sizeof buf) < 0) {
t_last_error = before;
return std::string();
}
return buf;
}
int dev_peer_access(int self, int peer) {
if (self == peer) return 1;
return dev()->peer_access ? dev()->peer_access(self, peer) : 1;
@@ -589,6 +624,55 @@ int rad_memcpy_ranges_async(void* dst, const void* src, int64_t prefix,
const RadCopyRange* ranges, int n, RadStream s) {
return dev()->memcpy_ranges_async(dst, src, prefix, ranges, n, s);
}
int rad_memcpy_list_async(const RadCopySeg* segs, int n, unsigned flags, RadStream s) {
if (const auto f = dev()->memcpy_list_async) return f(segs, n, flags, s);
for (int i = 0; i < n; ++i) RAD_TRY(dev()->memcpy_async(segs[i].dst, segs[i].src, segs[i].bytes, s));
return RAD_OK;
}
int rad_link_hold(RadStream s, int on) {
if (const auto f = dev()->link_hold) return f(s, on);
return RAD_OK;
}
void* rad_link_gate(RadStream s) {
if (const auto f = dev()->link_gate) return f(s);
return nullptr;
}
int rad_xp_supported(int device) {
const auto* d = dev();
return d->xp_supported && d->xp_stream_create && d->ride && d->ride_wait && d->ride_release && d->xp_list &&
d->xp_behind && d->alloc_uncached && d->free_uncached && d->xp_supported(device);
}
int rad_xp_stream_create(RadStream* out) {
if (const auto f = dev()->xp_stream_create) return f(out);
return RAD_E_UNSUPPORTED;
}
int rad_ride(RadStream s, void** token) {
if (const auto f = dev()->ride) return f(s, token);
return RAD_E_UNSUPPORTED;
}
int rad_ride_wait(RadStream s, void* token) {
if (const auto f = dev()->ride_wait) return f(s, token);
return RAD_E_UNSUPPORTED;
}
void rad_ride_release(void* token, RadStream after, int64_t packets) {
if (const auto f = dev()->ride_release) f(token, after, packets);
}
int rad_xp_list(int device, void* mark, int n, const uint64_t* src, const uint64_t* dst, const uint64_t* bytes,
uint32_t* done, uint32_t done_val) {
if (const auto f = dev()->xp_list) return f(device, mark, n, src, dst, bytes, done, done_val);
return RAD_E_UNSUPPORTED;
}
int64_t rad_xp_behind(int device) {
if (const auto f = dev()->xp_behind) return f(device);
return 0;
}
void* rad_dev_alloc_uncached(int64_t bytes) {
if (const auto f = dev()->alloc_uncached) return f(bytes);
return nullptr;
}
void rad_dev_free_uncached(void* p) {
if (const auto f = dev()->free_uncached) f(p);
}
/* Cleared by reading it, per the header. Never null: a caller printing "%s" on a path where
* nothing failed should get an empty line, not a segfault. */
+27 -1
View File
@@ -258,6 +258,30 @@ int d_peer_access(int self, int peer) {
return can ? 1 : 0;
}
/* The runtime's bus id, rewritten in the kernel's spelling (lower case, four-digit domain) so it
* names the same directory under /sys/bus/pci/devices. */
int d_pci_address(int device, char* out, int cap) {
if (!out || cap <= 0) return RAD_E_INVAL;
char bus[64] = { 0 };
HIP_TRY(hipDeviceGetPCIBusId(bus, (int)sizeof bus, device));
unsigned dom = 0, b = 0, d = 0, f = 0;
if (std::sscanf(bus, "%x:%x:%x.%x", &dom, &b, &d, &f) != 4) {
device_set_error("hipDeviceGetPCIBusId(%d): '%s' is not a PCI address", device, bus);
return RAD_E_IO;
}
std::snprintf(out, (size_t)cap, "%04x:%02x:%02x.%x", dom, b, d, f);
return RAD_OK;
}
/* HIP_VERSION's encoding: major * 10^7 + minor * 10^5 + patch. */
int d_runtime_version(char* out, int cap) {
if (!out || cap <= 0) return RAD_E_INVAL;
int v = 0;
HIP_TRY(hipRuntimeGetVersion(&v));
std::snprintf(out, (size_t)cap, "HIP %d.%d.%d", v / 10000000, (v / 100000) % 100, v % 100000);
return RAD_OK;
}
int d_enable_peer(int self, int peer) {
if (self == peer) return RAD_OK;
int can = 0;
@@ -360,7 +384,7 @@ const DeviceBackend g_hip = {
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr,
nullptr,
nullptr, nullptr, nullptr, nullptr,
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
/* Recorded passes: likewise the AQL backend's. */
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,
@@ -373,6 +397,8 @@ const DeviceBackend g_hip = {
nullptr, nullptr,
d_integrated,
d_peer_access,
d_pci_address,
d_runtime_version,
};
} /* namespace */
+14
View File
@@ -663,6 +663,18 @@ int h_memcpy_ranges_async(void* dst, const void* src, int64_t prefix, const RadC
return stream_push((HostStream*)st, t);
}
/* A copy a segment, queued in list order: this stream has no dispatch to save, and a task holds
* no list, so the list is read here, at the call, as the device backend reads it. */
int h_memcpy_list_async(const RadCopySeg* segs, int n, unsigned, RadStream st) {
RAD_TRY(check_stream(st, "rad_memcpy_list_async"));
if (n < 0 || (n > 0 && !segs)) {
device_set_error("rad_memcpy_list_async: %d segments at %p", n, (const void*)segs);
return RAD_E_INVAL;
}
for (int i = 0; i < n; ++i) RAD_TRY(h_memcpy_async(segs[i].dst, segs[i].src, segs[i].bytes, st));
return RAD_OK;
}
int h_memset_async(void* dst, int value, int64_t bytes, RadStream st) {
RAD_TRY(check_stream(st, "rad_memset_async"));
if (bytes == 0) return RAD_OK;
@@ -775,6 +787,8 @@ const DeviceBackend g_host = {
h_event_query, h_event_sync, h_event_elapsed_ms,
h_host_wrote,
h_memcpy_async, h_memcpy_2d_async, h_memset_async, h_memcpy_ranges_async,
h_memcpy_list_async,
nullptr, nullptr, /* no DMA engine, so no link to hold */
/* No recorded passes: a host stream runs its work as it is issued, so there is no queue to
* write a recording into, and every pass is issued. */
nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr,