vram: charge the runtime's resident queue scratch to the card budget

Once a kernel with a private segment has been dispatched (rad_step_advance has
544 bytes a lane), the HSA runtime hands its queue scratch memory and keeps it:
about +114 MiB on a card after the first speculative step, +150 MiB with a
larger segment, with or without HSA_NO_SCRATCH_RECLAIM. The VRAM budget does
not count it, so a serving process was left with only 27-65 MiB free after its
first speculative steps -- a thin margin for any kernel that later takes a
bigger private segment (the runtime then faults the queue with OUT_OF_RESOURCES
instead of failing the load).

The backend now reports rad_dev_resident_scratch_bytes(): 5 MiB per CU (160 MiB
on an R9700, which reports 32), over the measured 114-150 MiB, and 0 on the
host backend and on unified memory. The engine puts it into VramFacts::
queue_scratch, and the budget charges it with the hardware queues (the
resolver, vram_budget_need, and the report line).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Code000andClaude Opus 5.5 authored and StillDeadcode committed 2026-11-17 18:18:56 +01:00
1 parent b2228c176b
commit 7bd195d394
7 files changed
+57 -5

No files matched your search

+10
View File
@@ -934,6 +934,16 @@ int rad_event_sync(RadEvent e) {
}
void rad_dev_host_wrote(void) { dev()->host_wrote(); }
/* The VRAM the runtime keeps as queue scratch on `p`'s card once kernels with a private segment
* (spill, or a local array: step_advance's) have been dispatched: the runtime hands a queue
* scratch memory at the first such dispatch, and the card showed +114 MiB after the first
* speculative step and kept it, 150 MiB with a larger segment. The budget did not count it, so
* serving left 27-65 MiB free. 5 MiB a CU (the R9700 reports 32), 160 MiB, over the measured. */
extern "C" int64_t rad_dev_resident_scratch_bytes(const RadDeviceProps* p) {
if (!p || p->is_host_backend || p->unified) return 0;
return (int64_t)p->n_cu * (5LL * 1024 * 1024);
}
/* Whether launches chain, by engine: rad_dev_chain_infer on a thread of an engine (EngineScope)
* records that engine's answer and rad_dev_chain_enabled on any of its threads reads it. A process
* serves several models, each with its own plugin's answer; a single answer for the process was