abi, sched: RadBatch::anchor_rows, ABI 36

A block drafter's query pass gets, for each drafting sequence, the row of its last committed
position in the context pass just run (StepSlot::hrow, written by the advance on the card).
LiLiCorr's correlator reads the context state there. Appended after bidi_used; main ships
ABI 35 and an appended field is read past the end of an older engine's copy, so the version is
36 and the layout table follows. The pass key reads the pointer.
This commit is contained in:
keptn42 committed 2026-11-04 22:08:06 +01:00
1 parent a1b7643310
commit dccc6329a9
10 files changed
+40 -8

No files matched your search

+1 -1
View File
@@ -19,7 +19,7 @@ extern "C" {
* version is refused at load with both versions printed. Each also exports the layout's fingerprint
* (rad_abi_layout.h), so two layouts given one number are refused as well. A new optional export
* (e.g. rad_plugin_reference) is not a change of shape: a plugin without it gets the default. */
#define RAD_ABI_VERSION 35u
#define RAD_ABI_VERSION 36u
/* ================================================================== plugin identity */
/* One value per plugin, not flags (QUANT is 3). RAD_PLUGIN_QUANT is a quantiser plugin:
+1
View File
@@ -104,6 +104,7 @@ ABI_FIELD(RadBatch, bidi_row)
ABI_FIELD(RadBatch, bidi_n)
ABI_FIELD(RadBatch, bidi_seq)
ABI_FIELD(RadBatch, bidi_used)
ABI_FIELD(RadBatch, anchor_rows)
ABI_STRUCT(RadBufDecl)
ABI_FIELD(RadBufDecl, dtype)
ABI_FIELD(RadBufDecl, rank)
+7
View File
@@ -356,6 +356,13 @@ typedef struct RadBatch {
const int32_t* bidi_n; /* host */
const int32_t* bidi_seq; /* host */
const int32_t* bidi_used; /* device */
/* ---- appended in ABI 36 (a block drafter's anchor row) */
/* A block drafter's query pass (draft_pass 1): [n_seq] device, for each drafting sequence the
* row of its last committed position in the context pass just run, whose rows are the verify
* step's in order. -1 for a row the card did not position. A drafter that conditions on the
* context state at the anchor (LiLiCorr) gathers it there; the query rows themselves sit past
* that position. Null on every other pass. */
const int32_t* anchor_rows;
} RadBatch;
/* What a generator pass carries beside the step batch's own fields, which keep their meanings:
+3 -1
View File
@@ -968,7 +968,7 @@ int Ctx::lane_join(int from, int to) {
* geometries fail closed via the pass-key contract, while Qwen keys its full-group maximum in the
* architecture callback. `agen_b`, `vgen_b` and `sgen_b` are set only on generator passes, which are
* never recorded (below). */
static_assert(sizeof(void*) != 8 || sizeof(RadBatch) == 472,
static_assert(sizeof(void*) != 8 || sizeof(RadBatch) == 480,
"RadBatch changed: check that Ctx::pass_key reads every new field a pass depends on");
static_assert(sizeof(void*) != 8 || sizeof(RadKVGroupBatch) == 88,
"RadKVGroupBatch changed: check that Ctx::pass_key reads every new field");
@@ -1011,6 +1011,8 @@ uint64_t Ctx::pass_key(const RadBatch* b) const {
ptr(b->token_ids); ptr(b->positions); ptr(b->cu_seqlens); ptr(b->seq_ids);
ptr(b->out_ids); ptr(b->q_lens); ptr(b->ctx_lens); ptr(b->num_accepted);
ptr(b->spec_parent); ptr(b->checkpoint_tok); ptr(b->checkpoint_slot); ptr(b->draft_out_ids);
/* A block drafter's query pass reads it (null on every other pass). */
ptr(b->anchor_rows);
/* Null on a step with no adapter row, which then issues no adapter op (Ctx::issue_lora): the
* two are different passes. The slots themselves are read on the card. */
ptr(b->lora_slot);
+6 -1
View File
@@ -48,7 +48,11 @@ struct StepSlot {
* drafter's context rows by it. 0 after a chain verify, which needs neither. */
int32_t npath;
int32_t path[RAD_SCHED_MAX_SPEC];
int32_t pad[2];
/* The last verify step's row of its last committed position, in that step's own row order,
* which a block drafter's context pass mirrors. ADV_BLOCK hands it to the query pass
* (RadBatch::anchor_rows): LiLiCorr's correlator reads the context state there. */
int32_t hrow;
int32_t pad[1];
};
enum AdvMode : int32_t {
@@ -115,6 +119,7 @@ struct AdvanceArgs {
int32_t n_groups = 0;
char* slab = nullptr; /* this rank's device slab */
int64_t tok_off = 0, pos_off = 0, ctx_off = 0, acc_off = 0, out_off = 0;
int64_t arow_off = -1; /* [n_seq] ADV_BLOCK: each row's StepSlot::hrow; -1 when not carved */
int64_t sid_off = 0, cu_off = 0, q_off = 0;
/* [4][row_pitch] int32: device-row flag; the verify step's token row of the row's first
* verified position; its first sampled row, or -1 for a row that sampled nothing; and one
+3
View File
@@ -153,6 +153,7 @@ RAD_ADV_FN void adv_row(const AdvanceArgs& a, int i) {
S.ctx = head + 1;
S.n_acc = acc + 1;
S.tok[0] = y[acc == 0 ? 0 : S.path[acc - 1]];
S.hrow = rtok + (acc == 0 ? 0 : S.path[acc - 1]); /* rows are nodes, in order */
S.npath = acc;
return;
}
@@ -167,6 +168,7 @@ RAD_ADV_FN void adv_row(const AdvanceArgs& a, int i) {
const int32_t head = ctx[i] + (rtok - k) + acc;
S.acc = acc;
S.head = head;
S.hrow = rtok + acc;
S.ctx = head + 1;
S.n_acc = acc + 1;
S.tok[0] = y[acc];
@@ -296,6 +298,7 @@ RAD_ADV_FN void adv_row(const AdvanceArgs& a, int i) {
for (int32_t j = 1; j < n; ++j) tok[k + j] = aux;
for (int32_t j = 0; j < n; ++j) adv_pos(a, pos, k + j, base + j);
ctx[i] = base;
if (a.arow_off >= 0) adv_i32(a, a.arow_off)[i] = S.hrow;
adv_groups(a, i, k, base, n);
return;
}
+5
View File
@@ -123,6 +123,7 @@ void BatchBuilder::carve(Set& s, char* h) {
/* The advance's per-sequence runtime-window data (advance.h); 0 when there is none. */
pair(&s.h_rpos, &s.d_rpos, S);
pair(&s.h_tlen, &s.d_tlen, S);
pair(&s.h_arow, &s.d_arow, S);
s.h_grp = ::rad::carve<AdvGroup>(h, oh, (int64_t)s.groups.size());
s.d_grp = ::rad::carve<AdvGroup>(d, od, (int64_t)s.groups.size());
for (size_t gi = 0; gi < s.groups.size(); ++gi) {
@@ -1107,6 +1108,7 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
s.h_q[i] = e.n_tokens;
s.h_ctx[i] = e.ctx_len;
s.h_acc[i] = e.n_accepted;
s.h_arow[i] = -1;
if (e.is_prefill) { if (e.n_tokens > max_q_pf) max_q_pf = e.n_tokens; }
else { if (e.n_tokens > max_q_dec) max_q_dec = e.n_tokens; }
}
@@ -1264,6 +1266,8 @@ const RadBatch* BatchBuilder::build(const StepPlan& plan, const IKVManager& kv,
B.num_accepted = cfg_.n_spec > 0 ? on_rank(base, b0, s.d_acc) : nullptr;
/* Staged above on a tree step: each row's parent row, -2 for an ordinary causal one. */
B.spec_parent = plan.spec_is_tree ? on_rank(base, b0, s.d_parent) : nullptr;
/* Pass 1 is a block drafter's query pass (a serial head has no pass 1). */
B.anchor_rows = plan.draft_pass == 1 ? on_rank(base, b0, s.d_arow) : nullptr;
B.rope_pos = mm_on_ ? on_rank(base, b0, s.d_rope) : nullptr;
B.rope_mixed = rope_mixed;
B.n_mm_rows = n_mm;
@@ -1348,6 +1352,7 @@ AdvanceArgs BatchBuilder::advance_args(int rank) const {
a.ctx_off = off(s.d_ctx);
a.acc_off = off(s.d_acc);
a.out_off = off(s.d_out);
a.arow_off = off(s.d_arow);
a.sid_off = off(s.d_sid);
a.cu_off = off(s.d_cu);
a.q_off = off(s.d_q);
+3
View File
@@ -220,6 +220,9 @@ private:
* runtime window (advance.h). Per sequence because each prompt has its own floor. */
int32_t *h_rpos = nullptr, *d_rpos = nullptr;
int32_t *h_tlen = nullptr, *d_tlen = nullptr;
/* [max_seqs] a block drafter's query pass: each row's last committed row in the context
* pass just run (RadBatch::anchor_rows), written on the card by ADV_BLOCK. */
int32_t *h_arow = nullptr, *d_arow = nullptr;
char* h_derived = nullptr; /* derivation staging, byte-addressed */
/* [3][n_tok] rotary positions and [n_tok] encoder-row targets (RadBatch::rope_pos,
+8 -2
View File
@@ -1,4 +1,4 @@
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 35 and
/* abi_layout_table.h -- every abi/ struct's size and field offsets at RAD_ABI_VERSION 36 and
* RAD_FORMAT_VER 2, as { type, field, offset, size } rows ("" is the struct itself). A snapshot
* of the headers on x86-64 Linux, which abi_layout_test.cpp holds the layout to; regenerate it
* from the test's printout only together with a version bump. */
@@ -35,7 +35,7 @@
{ "RadArgs", "world_size", 60, 4 },
{ "RadArgs", "kv_used_max_h", 64, 4 },
{ "RadArgs", "wgp_count", 68, 4 },
{ "RadBatch", "", 0, 432 },
{ "RadBatch", "", 0, 480 },
{ "RadBatch", "phase", 0, 4 },
{ "RadBatch", "step", 4, 4 },
{ "RadBatch", "n_tok", 8, 8 },
@@ -95,6 +95,12 @@
{ "RadBatch", "sgen_b", 408, 8 },
{ "RadBatch", "kv_used_max_h", 416, 8 },
{ "RadBatch", "positions_h", 424, 8 },
{ "RadBatch", "n_bidi", 432, 8 },
{ "RadBatch", "bidi_row", 440, 8 },
{ "RadBatch", "bidi_n", 448, 8 },
{ "RadBatch", "bidi_seq", 456, 8 },
{ "RadBatch", "bidi_used", 464, 8 },
{ "RadBatch", "anchor_rows", 472, 8 },
{ "RadBufDecl", "", 0, 80 },
{ "RadBufDecl", "dtype", 0, 4 },
{ "RadBufDecl", "rank", 4, 4 },
+3 -3
View File
@@ -8,7 +8,7 @@
*
* Checked: a C translation unit (abi_c_test.c, strict C11) lays every struct out as C++ does; every
* struct's listed fields account for its size, so the list in rad_abi_layout_rows.h is complete; and
* the layout agrees with the table below, taken at RAD_ABI_VERSION 35 and RAD_FORMAT_VER 2. Under
* the layout agrees with the table below, taken at RAD_ABI_VERSION 36 and RAD_FORMAT_VER 2. Under
* those versions a listed field may not move or change size, an ABI struct may only grow by fields
* past its old end, and an on-disk struct may not change at all. The table is a snapshot of the
* headers: nothing else states the layout. When it disagrees the test prints the live table.
@@ -58,8 +58,8 @@ std::vector<Row> cpp_rows() {
};
}
/* The layout at RAD_ABI_VERSION 35 / RAD_FORMAT_VER 2 (see the file header). */
constexpr uint32_t kTableAbi = 35, kTableFormat = 2;
/* The layout at RAD_ABI_VERSION 36 / RAD_FORMAT_VER 2 (see the file header). */
constexpr uint32_t kTableAbi = 36, kTableFormat = 2;
const AbiRow kTable[] = {
#include "abi_layout_table.h"
};