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:
mici81andClaude Opus 5.5 authored and StillDeadcode committed 2026-10-24 11:10:08 +02:00
1 parent 5838c25343
commit 0c813784a0
8 files changed
+125 -15

No files matched your search

+13 -4
View File
@@ -25,18 +25,25 @@ public:
Arena& operator=(const Arena&) = delete;
/* `kind` is a RAD_MEM_* class: RAD_MEM_DEVICE for the device arena, RAD_MEM_HOST for the
* second arena a program with RAD_DOMAIN_HOST buffers gets. `regions` scratch regions of
* `scratch_bytes` each sit at the tail, one per lane. */
int init(int64_t plan_bytes, int64_t scratch_bytes, int kind, int regions = 1);
* second arena a program with RAD_DOMAIN_HOST buffers gets. `regions` scratch regions sit at the
* tail, one per lane: region 0 of `scratch_bytes`, the others of `scratch_bytes1` (-1: the same;
* Program::scratch_bytes_lane1). */
int init(int64_t plan_bytes, int64_t scratch_bytes, int kind, int regions = 1,
int64_t scratch_bytes1 = -1);
void release();
char* base() const { return base_; }
/* Region `r`, or region 0 when the arena holds fewer. */
void* scratch(int r = 0) const {
if (!base_) return nullptr;
return base_ + scratch_off_ + (r > 0 && r < scratch_regions_ ? r * scratch_pitch_ : 0);
return base_ + scratch_off_ +
(r > 0 && r < scratch_regions_ ? scratch_pitch_ + (r - 1) * scratch_pitch1_ : 0);
}
/* Region 0's size (the program's largest kernel), or region `r`'s. */
int64_t scratch_bytes() const { return scratch_bytes_; }
int64_t scratch_bytes(int r) const {
return r > 0 && r < scratch_regions_ ? scratch_bytes1_ : scratch_bytes_;
}
int scratch_regions() const { return scratch_regions_; }
int64_t bytes() const { return bytes_; }
bool live() const { return base_ != nullptr; }
@@ -48,6 +55,8 @@ private:
int64_t scratch_off_ = 0;
int64_t scratch_bytes_ = 0;
int64_t scratch_pitch_ = 0; /* scratch_bytes_ padded to RAD_ALIGN_UNIT */
int64_t scratch_bytes1_ = 0; /* each region past 0 */
int64_t scratch_pitch1_ = 0;
int scratch_regions_ = 1;
};