This repository has been archived on 2026-11-24. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
radiance-sycl/core/engine_priv.h
T
Deadcode b93b531f63 radiance 1.5.0
- Gemma 4 31B (PRs #74, #75, #81, #86; sfjes, keptn42): sliding and global attention with their
  own kernels, the assistant head as a drafter that reads the trunk's cache, the vision tower, a
  fused w4a8 decode step, bf16 and compressed-tensors int4 checkpoints, and window snapshots so a
  prefix hit on a sliding-window model resumes instead of prefilling again.
  deploy/compose/gemma4-31b-w4a8.yaml serves keptn42's container on two cards
- ParoQuant (PRs #65, #66, #67; malic): Qwen3.8-27B checkpoints with learned Givens rotations,
  as int4, int5 and MXFP4, imported without re-quantising, the prefill's rotations on the matrix
  cores. deploy/compose/qwen3.8-27b-paro.yaml serves them on one card. A ParoQuant container made
  with the PR builds is refused: convert it again with --reuse <old container>
- Gemma 4 26B-A4B with z-lab's DFlash drafter (PR #88; Perire): arch/gemma4 serves Google's bf16
  checkpoint with the routed experts in block fp8 or bf16 (data/recipes/gemma4-26b-a4b-df*.recipe),
  and libr4d gains its windowed paged attention, the fused sandwich-norm joins, expert_scale and
  the sharded draft head's pair_argmax. A prefill chunk runs as two slices with its all-reduces
  beside the compute, bit-exact with the whole step. The 31B's global layers take the windowed
  attention too: an 11.5K-token prefill on two R9700s in 3.1 s instead of 4.9
- a startup that logs nothing for two minutes says where it waits (#89): the system call (a KFD
  request by name), the library that made it, and its stack, which addr2line resolves against the
  binary
- the prefix cache is kept in VRAM and host memory only (#70): the disk tier wrote every block and
  snapshot a prompt produced, and its copies never outlived the process. --prefix-cache-host-mib
  is renamed --prefix-cache-mib; --prefix-cache-dir and --prefix-cache-disk-mib are removed, and
  startup refuses all three with what replaced them. The compose files no longer mount /data, and
  .env no longer needs RADIANCE_STATE
- --prefix-cache-ttl S (default 3600, 0 never): a conversation no request has used for that long
  leaves the cache, whichever tier holds it; radiance:prefix_cache_expired_total counts them. A
  full host tier now drops its least recently used conversations
- --vision-tower-placement vram|ram (#84): ram keeps an encoder tower in pinned host memory and
  gives its VRAM to the KV cache, read over the link once an image
- timings carry ttft_ms and total_ms (#85): the server's own time from the request body's arrival
  to the first and the last token, queueing and tokenisation included
- a KV-cache recall that found a moved expert with nowhere to go stopped halfway and leaked the
  slots it had already freed: after it every recall failed, the cache stayed short until a
  restart, and requests failed with HTTP 500. A recall now waits for the slots it is owed and
  always finishes
- a tool result or tool-call arguments that are not JSON are no longer refused as nesting past
  1024 levels for their unmatched brackets (#90): only text that parses as JSON is held to the
  bound, since nothing else is parsed into a tree
- the host-pool refusal names the limit that applies to pinned memory (RAM less 1/64 and
  1.5 GiB), not ttm.pages_limit
- --embedding-placement auto, removed in 1.3.0, is refused with what replaced it
- for out-of-tree kernel libraries: gemm_nt_q gains two operands (pb1, pb2, the part bounds), and
  the loader requires identical op schemas, so a library built against 1.4.0 must be rebuilt. For
  architecture plugins, rad_op_declared(b, op) asks whether an op is in the loaded vocabulary
  without declaring it
2026-10-13 19:35:16 +02:00

117 lines
6.1 KiB
C++

/* engine_priv.h -- what the Engine's translation units share and nothing outside them sees.
*
* `Engine` is one class across four files because its phases have almost nothing to say to each
* other: bring-up runs once and touches every subsystem; the step loop runs a thousand times a
* second and touches four; the drafters are two shapes of extra pass; the probe is debug-only and
* reads everything. Splitting them is not decomposition of the class -- the public surface in
* engine.h is unchanged -- it is putting each phase where it can be read on its own.
*
* `Engine::Rank` lives here rather than in engine.h because it names every subsystem's concrete
* type, and engine.h is included by main.cpp and the tools: a forward declaration there is what
* keeps a caller that only wants to serve a model from compiling the pool allocator.
*/
#pragma once
#include "engine.h"
#include "mem/pools.h"
#include "mem/kv.h"
#include "mem/prefix.h"
#include "mem/kvtier.h"
#include "runtime/tierexec.h"
#include "build/rad_build.h"
#include "place/heat.h"
#include "place/planner.h"
#include "place/mover.h"
#include "place/stager.h"
#include "runtime/ctx.h"
#include "sample/sampler.h"
#include "sched/advance.h"
namespace rad {
/* ================================================================== per-rank state */
/* One thread per tensor-parallel rank, each owning one device. No IPC, no shared-memory
* handshake, no serialisation between ranks -- which is most of what a Python engine spends its
* multiprocessing budget on. Because the ranks share an address space, the step batch is shared
* BY POINTER rather than broadcast (spec §1). */
struct Engine::Rank {
int index = 0;
int device = 0;
Program program; /* declare runs once PER RANK: dimensions are already divided */
Plan plan;
Pools pools;
Mover mover;
/* THE POLICY HALF OF TIERED PLACEMENT. Bound to the plan at bringup and off unless the plan
* is dynamic; `heat_seen[l]` is the last step whose histogram layer l has already been
* credited, because a histogram sits in its bank until the NEXT report overwrites it and
* crediting it twice would double every count. */
HeatEngine heat;
std::vector<int> heat_seen;
/* One sweep's histograms, found before any is credited; kept so a sweep allocates nothing. */
struct HeatRow { int layer; int bank; const int32_t* h; };
std::vector<HeatRow> heat_rows;
/* WHY A LAYER'S HISTOGRAM WENT UNCREDITED, which the credited total cannot separate on its
* own. A histogram is skipped either because its copy has not landed yet or because the bank
* still holds a step already credited, and those are different faults: the first says the host
* ran ahead of the device and the sample was lost, the second says the layer did not route.
* Without the split, a placement engine starved of evidence reads exactly like a model whose
* layers are idle. */
uint64_t heat_credited = 0, heat_idle = 0;
/* Trunk steps in a row whose pass the prefill stager did not arm (Engine::tiering_dispatch). */
int unstaged_steps = 0;
Residency residency;
KVManager kv;
PrefixCache prefix;
/* THE IDLE SESSION TIERS (spec 7.3). Rank 0 owns the policy and the session index,
* because they describe CONVERSATIONS and a conversation is not sharded -- but the
* transfer is per rank, since each rank holds its own shard of every KV block and
* has its own pool to gather out of. Both are inert unless --prefix-cache-mib gave the
* host tier a size. */
IdleTiers tiers;
TierExec tierx;
/* The activation arena's smaller levels, smallest step first (Engine::probe_arena_levels). */
std::vector<ArenaLevel> arena_levels;
/* Per Ctx level (0 is the full plan): the bytes at the top of this rank's arena that level
* leaves to the expert slab. */
std::vector<int64_t> arena_lent;
/* THE PREFILL STAGER (core/place/stager.h): the next routed layer's pooled experts, copied into
* the top of this rank's arena while a full-plan step runs the layer before. */
PrefillStager stager;
/* THE FILE STAGER (core/place/stager.h): a routed layer's file-tier experts, read from the
* container into one of the mover's two file buffers before the layer's first expert op, on
* every pass. With both stagers in use the chain hands each the passes it armed for. */
FileStager fstager;
StagerChain stagers;
Ctx ctx;
Sampler sampler; /* one per rank: each samples its own vocab shard (spec §9) */
/* THE SCORED ROWS' LOGITS (Request::token_scores), this rank's vocabulary shard of each,
* copied into pinned memory ahead of the sampler. Grown to the most rows a step has scored. */
float* score_host = nullptr;
int64_t score_rows_cap = 0;
rad_buf tok_buf = 0; /* where the chain writes the sampled ids */
/* THE CARD'S STEP STATE (sched/advance.h): one StepSlot a scheduler slot, and the
* end-of-generation ids acceptance stops at, sorted. Every rank keeps its own and computes the
* same values from the same sampled ids. */
StepSlot* step_slots = nullptr;
int32_t* eog = nullptr;
int32_t n_eog = 0;
};
/* THE TIERS' WORK IN FLIGHT (Engine::tier_tick). One copy batch out on every rank's transfer
* stream at a time, with each rank's answer kept until all of them have one -- a rank that has
* landed must not be asked again and forget it failed. */
struct TierPump {
std::vector<TierJob> copy;
std::vector<int> copy_st; /* per rank: 0 in flight, 1 landed, negative failed */
int64_t max_copy = 0;
int slow_budget = 0; /* capacity drops one plan may make */
};
/* THE BUFFER PROBE (engine_probe.cpp). Declared here because three files call it: the step
* loop dumps after a trunk step, and each drafter dumps after its own passes -- a drafter that
* runs as extra passes leaves every one of its buffers holding the PREVIOUS step's values at the
* moment the step loop dumps. */
void dump_buffers(Ctx& ctx, int step, const char* names, const char* phase = "");
} /* namespace rad */