Archived
core: the second lane's scratch region sized by the ops it may issue
A program naming a buffer to rad_buf_concurrent got two scratch regions of the program's largest kernel scratch each, though by Ctx::lane1_ rule 3 an op on the second lane touches only rad_buf_concurrent buffers. Program::scratch_bytes_lane1 is the largest device scratch of such an op (or one naming no transient buffer); the Arena takes per-region sizes, arena_plan_bytes counts them for the VRAM budget, and Ctx::issue refuses a larger lane-1 request by name instead of overrunning the region. Qwen3.8 with its drafter: region 1 0 B instead of 50 MiB (17 MiB without speculation). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
5838c25343
commit
0c813784a0
8 files changed
+125
-15
No files matched your search
+13
-2
@@ -874,7 +874,18 @@ int Ctx::issue_body(rad_op h, const RadOperand* opd, int n_opd, int64_t n) {
|
||||
* correctness. That also covers lane 0 before lane 1 exists, since a lane built later has
|
||||
* nothing ordering it behind lane 0's earlier work. */
|
||||
if (ip.args.scratch_bytes > 0 && dom != RAD_DOMAIN_HOST && arena_.scratch_regions() > 1) {
|
||||
/* Per-lane regions: nothing to order. */
|
||||
/* Per-lane regions: nothing to order. Region 1 holds what an op the second lane may issue
|
||||
* asked for at declare (Program::scratch_bytes_lane1); a larger request there comes from an
|
||||
* op with a transient buffer outside rad_buf_concurrent, which breaks Ctx::lane1_'s rule 3
|
||||
* in its buffers too, so it is refused by name rather than let overrun the region. */
|
||||
if (ip.args.scratch_bytes > arena_.scratch_bytes(lane_)) {
|
||||
return abort_step_msg(h, RAD_E_SCRATCH,
|
||||
fmt("kernel %s at n=%lld asks for %lld bytes of scratch on lane %d, whose region "
|
||||
"holds %lld: an op on the second lane may touch only buffers named to "
|
||||
"rad_buf_concurrent (Ctx::lane1_ rule 3)",
|
||||
ip.row && ip.row->info ? ip.row->info->name : "?", (long long)n,
|
||||
(long long)ip.args.scratch_bytes, lane_, (long long)arena_.scratch_bytes(lane_)));
|
||||
}
|
||||
ip.args.scratch = scratch_take(lane_, ip.args.scratch_bytes);
|
||||
} else if (ip.args.scratch_bytes > 0 && dom != RAD_DOMAIN_HOST) {
|
||||
ip.args.scratch = scratch_take(0, ip.args.scratch_bytes);
|
||||
@@ -1048,7 +1059,7 @@ void* Ctx::scratch_take(int region, int64_t bytes) {
|
||||
constexpr int64_t kAlign = 256;
|
||||
const int64_t need = (bytes + kAlign - 1) / kAlign * kAlign;
|
||||
int64_t off = scratch_cur_[region];
|
||||
if (off + need > arena_.scratch_bytes()) off = 0;
|
||||
if (off + need > arena_.scratch_bytes(region)) off = 0;
|
||||
scratch_cur_[region] = off + need;
|
||||
return (char*)arena_.scratch(region) + off;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user