the second lane's window (rad_lane1_window_begin / _end): concurrent buffers live across it, not the whole program

rad_buf_concurrent held a buffer for the whole program because the planner cannot tell when lane 1
runs. An architecture whose lane-1 work lies in one stretch of its declared ops now declares it, and
its concurrent buffers live across that window and their own uses, so the drafter's and the heads'
buffers share their bytes again. Ctx holds it: an op on lane 1 outside the window fails the step by
name, and the first lane-0 op past it joins lane 1 first when work is pending there. qwen35_fp8 and
gemma3 declare it from the embedding's all-reduce to the final norm. Qwen3.8 + DFlash2 at 64
sequences with speculation: activation arena 633.99 -> 526.32 MiB a card, upstream's exactly (with
the second lane's own scratch region, KV 86208 -> 93856 tokens against upstream's 95520).
arch_test's fake builder applies the window too, so the pinned steps check every plugin touches its
concurrent buffers only inside it.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
mici81andClaude Opus 5.5 authored and StillDeadcode committed 2026-10-24 11:10:08 +02:00
1 parent 0c813784a0
commit 0d2b502d51
13 files changed
+201 -6

No files matched your search

+3
View File
@@ -140,6 +140,7 @@ public:
int op_reads (rad_op h, const rad_buf* b, int n);
int op_writes(rad_op h, const rad_buf* b, int n);
int buf_concurrent(rad_buf b);
int lane1_window(bool end);
int weight_shard_span(rad_weight w, int64_t lo, int64_t hi);
int weight_shard_span_parts(rad_weight w, const int64_t* lo, const int64_t* hi,
const int64_t* total, int n);
@@ -220,6 +221,8 @@ private:
/* Buffers touched from the second lane (rad_buf_concurrent). Their declared op range does not
* bound when their bytes are in use, so they are live for the whole program. */
std::set<rad_buf> concurrent_bufs_;
/* The second lane's window (rad_lane1_window_begin), first and last op handle; -1 when none. */
int32_t lane1_w0_ = -1, lane1_w1_ = -1;
/* Parallel to prog_.kv_groups: where in the op list the group was declared, and the op found
* to consume it. Declaration order is the only link between an op and a group; see
+43 -1
View File
@@ -841,6 +841,26 @@ int Builder::buf_concurrent(rad_buf b) {
return RAD_OK;
}
/* See rad_lane1_window_begin. The window is the ops declared between the two calls. */
int Builder::lane1_window(bool end) {
if (finished_) { err(RAD_E_STATE, "rad_lane1_window after declare finished"); return RAD_E_STATE; }
const int32_t next = (int32_t)prog_.ops.size(); /* the next op's handle */
if (!end) {
if (lane1_w0_ >= 0) {
err(RAD_E_STATE, "rad_lane1_window_begin called twice: one window a program");
return RAD_E_STATE;
}
lane1_w0_ = next;
} else {
if (lane1_w0_ < 0 || lane1_w1_ >= 0 || next - 1 < lane1_w0_) {
err(RAD_E_STATE, "rad_lane1_window_end without a begin, twice, or around no op");
return RAD_E_STATE;
}
lane1_w1_ = next - 1;
}
return RAD_OK;
}
/* See rad_weight_shard_span. Checked against the declaration here, where the plugin can be named;
* the loader checks it against the container. */
int Builder::weight_shard_span(rad_weight h, int64_t lo, int64_t hi) {
@@ -2178,6 +2198,10 @@ void Builder::finish_buffer_liveness() {
/* A second lane, signalled by any concurrent buffer, gets a second scratch region
* (Program::scratch_regions). */
prog_.scratch_regions = concurrent_bufs_.empty() ? 1 : 2;
if (lane1_w0_ >= 0 && lane1_w1_ < 0)
err(RAD_E_STATE, "rad_lane1_window_begin without rad_lane1_window_end");
prog_.lane1_w0 = lane1_w1_ >= 0 ? lane1_w0_ : -1;
prog_.lane1_w1 = lane1_w1_;
/* Each buffer's first and last declaring op, in one pass over the op lists. */
const size_t nb = prog_.buffers.size();
@@ -2195,11 +2219,19 @@ void Builder::finish_buffer_liveness() {
* rule); a buffer on the second lane, whose declared range does not bound when its bytes
* are in use; and one with no declared use, since an op may issue any handle in any
* order (--debug-graph reports the cost). */
if (b.decl.kind != RAD_BUF_TRANSIENT || concurrent_bufs_.count((rad_buf)i) || first[i] < 0) {
if (b.decl.kind != RAD_BUF_TRANSIENT || first[i] < 0 ||
(concurrent_bufs_.count((rad_buf)i) && lane1_w1_ < 0)) {
b.first_def = 0;
b.last_use = last_op;
continue;
}
/* A concurrent buffer under a declared window (rad_lane1_window_begin): live across the
* window, when lane 1 may touch it, and over its own uses. */
if (concurrent_bufs_.count((rad_buf)i)) {
b.first_def = std::min(first[i], lane1_w0_);
b.last_use = std::max(last[i], lane1_w1_);
continue;
}
b.first_def = first[i];
b.last_use = last[i];
@@ -2361,6 +2393,16 @@ int rad_buf_concurrent(RadBuilder* b, rad_buf buf) {
return B(b)->buf_concurrent(buf);
}
int rad_lane1_window_begin(RadBuilder* b) {
if (!b) return RAD_E_INVAL;
return B(b)->lane1_window(false);
}
int rad_lane1_window_end(RadBuilder* b) {
if (!b) return RAD_E_INVAL;
return B(b)->lane1_window(true);
}
int rad_weight_shard_span(RadBuilder* b, rad_weight w, int64_t lo, int64_t hi) {
if (!b) return RAD_E_INVAL;
return B(b)->weight_shard_span(w, lo, hi);
+3
View File
@@ -463,6 +463,9 @@ public:
* with any other transient buffer never runs there; one naming no transient buffer counts.
* At most scratch_bytes; -1 (a program not built by the Builder) means scratch_bytes. */
int64_t scratch_bytes_lane1 = -1;
/* The second lane's window (rad_lane1_window_begin): the first and last op handle lane 1 may run;
* -1 when the architecture declared none (concurrent buffers then live for the whole program). */
int32_t lane1_w0 = -1, lane1_w1 = -1;
/* Everything that resolved to nothing, reported whole rather than stopping at the first
* failure (spec §3.1). Structured because the domains are reported differently: a device miss
+3
View File
@@ -331,6 +331,8 @@ int Ctx::bind_ops() {
p.billed = (oi.op == "all_reduce");
p.collective = p.billed;
p.lora_site = oi.lora_site;
p.order = oi.anchor > 0 && (size_t)oi.anchor < P.ops.size() ? P.ops[(size_t)oi.anchor].index
: oi.index;
for (const Band& b : oi.bands) band_table_.push_back(b.hi);
@@ -906,6 +908,7 @@ int Ctx::lane_join(int from, int to) {
RAD_TRY(rad_event_record(lane_ev_[from], fs));
RAD_TRY(rad_event_wait(ts, lane_ev_[from]));
scratch_open_[from] = false; /* `to` is now behind every scratch user `from` issued */
if (from == 1 && to == 0) lane1_pending_ = false;
return RAD_OK;
}
+7 -1
View File
@@ -88,6 +88,9 @@ struct OpPlan {
bool billed = false;
/* Runtime LoRA: this gemm's row in Program::lora_sites, -1 for every op that is not one. */
int32_t lora_site = -1;
/* Its position in the declared order, or its anchor's for a core-appended op: what the second
* lane's window (Program::lane1_w0..lane1_w1) is checked against. */
int32_t order = 0;
};
/* ------------------------------------------------------------------ routing handoff */
@@ -619,7 +622,8 @@ private:
* 3. The buffer planner packs from one linear order, so two lanes can alias arena bytes
* through buffers with disjoint declared lifetimes. The architecture passes every buffer
* its second lane touches to `rad_buf_concurrent`, which makes it live for the whole
* program.
* program, or, where the architecture declares the second lane's window
* (rad_lane1_window_begin / _end), across the window and its own declared uses.
*
* 4. A slice must land in the same bucket-table band as the whole, or it picks a kernel with
* a different summation order and silently changes output. `--debug-graph` prints a model's
@@ -641,6 +645,8 @@ private:
bool own_lane1_ = false;
int lane_ = 0;
RadEvent lane_ev_[2] = { nullptr, nullptr };
/* An op was issued on lane 1 since lane 1 was last joined into lane 0 (the window's join). */
bool lane1_pending_ = false;
/* The last device op on each lane that touched host-domain memory. A host op runs at issue on
* this thread and must be ordered behind every earlier device op that touched the host arena;
* on each lane those complete no later than the last one. So a device op with a host-domain
+17
View File
@@ -592,6 +592,23 @@ int Ctx::issue_body(rad_op h, const RadOperand* opd, int n_opd, int64_t n) {
? "has no host kernel for this band, and the placement planner put "
"it on the host anyway"
: "has no device kernel for this band");
/* The second lane's window (rad_lane1_window_begin): its concurrent buffers are live only across
* it, so lane 1 runs nothing outside it, and lane 1 is joined before lane 0 runs past it. */
if (program_ && program_->lane1_w1 >= 0) {
if (lane_ == 1 && (p.order < program_->lane1_w0 || p.order > program_->lane1_w1))
return abort_step_msg(h, RAD_E_STATE,
fmt("issued on the second lane outside its declared window (ops "
"%d..%d, this one %d): the buffers it may touch there are "
"live only across the window",
(int)program_->lane1_w0, (int)program_->lane1_w1, (int)p.order));
if (lane_ == 0 && lane1_pending_ && p.order > program_->lane1_w1) {
const int js = lane_join(1, 0);
if (js < 0)
return abort_step_msg(h, js, "joining the second lane at its window's end failed");
}
}
if (lane_ == 1) lane1_pending_ = true;
/* The row's DIV on the ranged parameter held at the band's upper bound, maybe not here. */
if (ip.ranged_div > 1 && n % ip.ranged_div != 0)
return abort_step_msg(h, RAD_E_SHAPE,