Archived
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:
1 parent
b2228c176b
commit
7bd195d394
7 files changed
+57
-5
No files matched your search
@@ -45,6 +45,10 @@ extern "C" void rad_dev_host_wrote(void);
|
||||
* plugin measured a gain (RadArchProbe::chain_pays): with its drafter decoding speculatively, or
|
||||
* with and without one (rad_dev_chain_infer, from the engine before any row resolves). */
|
||||
extern "C" int rad_dev_chain_enabled(void);
|
||||
/* VRAM the runtime keeps resident as queue scratch on `props`' card once a kernel with a private
|
||||
* segment has run (0 on the host backend and on unified memory). Charged to the VRAM budget with
|
||||
* the hardware queues. */
|
||||
extern "C" int64_t rad_dev_resident_scratch_bytes(const RadDeviceProps* props);
|
||||
extern "C" void rad_dev_chain_infer(int pays);
|
||||
|
||||
/* One range of a ranged copy: `bytes` from source offset `src` to destination offset `dst`, all
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1753,6 +1753,7 @@ int Engine::plan() {
|
||||
for (RadStream s : q) if (s) rad_stream_destroy(s);
|
||||
}
|
||||
f.n_queues = 2 + (r->program.scratch_regions > 1 ? 1 : 0);
|
||||
f.queue_scratch = 0; /* set below, once props are read */
|
||||
/* The weights' cost, split into the fixed floor and the elastic plane
|
||||
* (weight_footprint in core/place/planner.h). Per rank, so already this card's share
|
||||
* under TP. */
|
||||
@@ -1773,6 +1774,7 @@ int Engine::plan() {
|
||||
}
|
||||
RadDeviceProps props{};
|
||||
rad_dev_props(r->device, &props);
|
||||
f.queue_scratch = rad_dev_resident_scratch_bytes(&props);
|
||||
f.capacity = props.vram_bytes;
|
||||
f.free = props.vram_free;
|
||||
/* Unified memory: the pinned host pool is the same RAM as the card, so the
|
||||
|
||||
@@ -51,8 +51,8 @@ static int resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudg
|
||||
b.arena = std::max(b.arena, f.arena);
|
||||
b.staging = std::max(b.staging, f.staging);
|
||||
b.prefetch = std::max(b.prefetch, f.prefetch);
|
||||
if ((int64_t)f.n_queues * f.queue_bytes > b.queues) {
|
||||
b.queues = (int64_t)f.n_queues * f.queue_bytes;
|
||||
if ((int64_t)f.n_queues * f.queue_bytes + f.queue_scratch > b.queues) {
|
||||
b.queues = (int64_t)f.n_queues * f.queue_bytes + f.queue_scratch;
|
||||
b.n_queues = f.n_queues;
|
||||
b.queue_bytes = f.queue_bytes;
|
||||
}
|
||||
@@ -168,7 +168,7 @@ static int resolve(Config& cfg, const std::vector<VramFacts>& per_rank, VramBudg
|
||||
" --gpu-headroom-mib %10s\n"
|
||||
" activation arena %10s (buffer plan + kernel scratch)\n"
|
||||
" step staging %10s (block tables, media and KV tier staging)\n"
|
||||
" hardware queues %10s (%d at %s each, measured)\n"
|
||||
" hardware queues %10s (%d at %s each, measured, + resident queue scratch)\n"
|
||||
" expert prefetch %10s (its ring of expert units and buffers)\n"
|
||||
" ------------------------------\n"
|
||||
" short by %10s\n"
|
||||
@@ -461,7 +461,7 @@ void vram_budget_need(const std::vector<VramFacts>& per_rank, int64_t* need, int
|
||||
arena = std::max(arena, f.arena);
|
||||
staging = std::max(staging, f.staging);
|
||||
prefetch = std::max(prefetch, f.prefetch);
|
||||
queues = std::max(queues, (int64_t)f.n_queues * f.queue_bytes);
|
||||
queues = std::max(queues, (int64_t)f.n_queues * f.queue_bytes + f.queue_scratch);
|
||||
statics = std::max(statics, f.statics);
|
||||
floor = std::max(floor, f.expert_floor);
|
||||
kv_one = std::max(kv_one, f.kv_one);
|
||||
|
||||
@@ -65,6 +65,7 @@ struct VramFacts {
|
||||
* per queue on an R9700, 8x the ring). */
|
||||
int n_queues = 0;
|
||||
int64_t queue_bytes = 0;
|
||||
int64_t queue_scratch = 0; /* resident queue scratch (rad_dev_resident_scratch_bytes), once a card */
|
||||
/* The next-layer expert prefetch's ring and buffers (xprefetch.h), when enabled; its stream is
|
||||
* one of `n_queues`. */
|
||||
int64_t prefetch = 0;
|
||||
|
||||
Reference in new issue
Block a user