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

+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);