Repository navigation
Description
Symptom
In a plain -ngl 0 run of a 4B at -c 4096, half of the KV-sized staging buffers the executor allocates are never
uploaded and never downloaded. They are bound to the program, occupy device memory (GTT) for the lifetime of the
cached shape, and carry no data in either direction.
Measurement (this box, pin d8bd0ff6052a, no-SVM trio, gpu-hold)
GGML_HRX_HOST_STAGING_TRACE=1, Qwen3-4B-Q4_K_M, -ngl 0 -fit off -c 4096 -n 8:
$ grep -o 'value [0-9]* [0-9]* B upload=[01] download=[01] mapped=[01]' <run>.err \
| awk '$4==8388608' | sort | uniq -c
72 value 7 8388608 B upload=0 download=0 mapped=0
72 value 8 8388608 B upload=1 download=1 mapped=0
36 value 12 8388608 B upload=0 download=0 mapped=0
36 value 13 8388608 B upload=1 download=1 mapped=0
- 144 staging buffers of 8 388 608 B in that run, in 36 prepared programs (4 per program: the K and V cache tensors bound
in two views each). - Two of those four per program (values 7 and 12) are
upload=0 download=0: 16 MiB per prepared program, 576 MiB
per run of device memory that is allocated, bound, and never touched in either direction. - The per-batch summary line says the same thing arithmetically:
11 buffers, 33562664 B staged, 16785448 B uploaded, 16777216 B downloaded— the transfers account for exactly two of the four big buffers. - The
amdgpu_bo_createhistogram of the same run shows the device side of it:8388608 B x 144BOs, i.e. the
never-transferred half is 72 BOs = 576 MiB of the run's 4705 MiB peak GTT.
Root cause
materialize_host_bindings (ggml/src/ggml-hrx/runtime/command-program-executor.cpp:569) decides per binding, and it
stages every binding that carries host data (requires_materialization() is host_data != nullptr) — regardless of
whether any command in the program refers to the value:
:519-576collect_graph_value_access()buildsaccess_by_valueonly from the bindings that appear in
initialization_commandsandcommands, so a value that no command references has no entry.:580-581falls back to a default-constructedGraphValueAccess{}for it, i.e.read = false, write = false.:637then allocates the staging buffer anyway, and:646-647setsstaging.upload = access.read(false) and
staging.download = access.write && !binding.graph_input(false).
So the two flags are the symptom; the cause is that "no command references this value" is not a reason to materialise it.
What the extra two buffers are, stated only as far as the dump proves it: they are 8 MiB, exactly the KV tensor size at
this shape (n_head_kv 8 x key_length 128 x 2 B x n_ctx 4096), and in the ggml_rope_set_rows_f32 / ggml_set_rows
program the commands bind only the ReadWrite views (program.json, command_shape:
b:cache:8:0:0:8388608:2 and b:cache:13:0:0:8388608:2). Values 7 and 12 appear in no command's binding list at all
— they are graph values that ggml hands to the program, so the executor stages them, but nothing in the program refers to
them. Value ids are per program, so the pair is "the two 8 MiB bindings this shape does not reference", not a fixed id.
(Both are host bindings because at -ngl 0 the KV cache stays in host memory — which is also why the staging path runs
at all.)
Note the guard is not upload == 0 && download == 0: a value that a kernel writes and that is also a graph input has
those flags too and must be device-writable. The safe test is "absent from access_by_value".
Expected
A binding that no command in the program references should be passed through unchanged, exactly as the code already does
when allocate_host_staging_buffer fails (:638-643). Nothing reads or writes that value, so no device copy is needed.
Impact
Not a correctness bug (the buffer is never used), but it makes every large-context shape cost 2 x n_kv_tensor_bytes
more GTT than it needs: 576 MiB at 4B/ctx 4096 for the run above, and, because a staging buffer is retained per cached
graph program, up to ~1 GiB at the 64-program bound. It also inflates what GGML_HRX_GRAPH_PROGRAM_CACHE_MB has to
account for (#841).
Fix and before/after numbers in the PR that closes this.
Activity
bong-water-water-bong commentedon Nov 3, 2026
Verified at the pin (
third_party/llama.cpp=d8bd0ff6052a), and the code path is exactly as reported — with one addition that makes the fix cheaper than the report implies.ggml/src/ggml-hrx/runtime/command-program-executor.cpp::576access_by_value = collect_graph_value_access(commands)— built only from the commands' bindings.:579-581a value with no entry gets a default-constructedGraphValueAccess{}, i.e.read=false, write=false.:581-585the early "keep it as-is" branch isbinding.length == 0 || (!requires_materialization() && !materialize_weight)— note neither term can be true for an unreferenced binding that carries host data, so it cannot be skipped here.:646allocate_host_staging_buffer(...),:652-654staging.upload = access.read,staging.download = access.write && !binding.graph_input.So the flags are the symptom and the allocation is the cost, as the report says. The addition: the missing condition is precisely
found_access == access_by_value.end(), and it is available at:578before anything is allocated — so the smallest fix is one extra term on the:583skip ("and no command in this program references this value"), no allocator change and no change to the flag semantics. I agree with the report's warning thatupload == 0 && download == 0is not the predicate: a write-only graph input hasdownload=falseby construction at:654and must still be materialised.Labels:
bug+hrx. The file is the fork's, so this closes on allama.cppPR plus an engine pin bump — an A row that is pin-blocked, and it is now the fifth of them (#841, #894, #895, #900). That is the thing to say to the orchestrator: five A rows are queued behind one pin move, not behind review.I have recorded the 576 MiB/run on the board row with the report's own arithmetic (72 BOs of 8 388 608 B in a 4 705 MiB peak) so no lane budgets GTT without it.
bong-water-water-bong commentedon Nov 4, 2026
Merged and re-measured in the shipped tree (2026-11-04 17:2x AST):
llama.cpp#176landed as6156b8232c, base head1bit/hrx-vulkan-patched@428937ae. Build of that tree with the pin's CMake configuration (~/wt/postmerge), onegpu-holdticket, 4B Q4_K_M,-dev HRX0 -ngl 0 -c 4096 -fit off -n 8, no-SVM trio,amdgpu_bo_createtracepoint plusthe executor's staging census in the same run, pin binary (
d8bd0ff60) as the before arm:upload=0 download=0drm-total-gtt-n 8greedyOkay, the user is askingBoth accounting paths move by the same 1890.0 MiB, so this is the fix and not a sampling difference; the arithmetic
closes as the PR said (216 × 8 MiB + 81 × 2 MiB of slabs the dropped allocations no longer pull in), the coherent sibling
class is untouched, and every other BO class ≥ 2 MiB is identical.
Also, the merged tree's own device-free test passes:
test-hrx-graph-program-budget: all checks passed,test-hrx-arena-refusal: all cases ok (5 arms)— so nothing in the merge (which also carries other PRs) broke the codeunder review.
Written up as §7.21(a) of
~/amd-oss/hrx-study/FACTS-memory.md; evidence~/amd-oss/hrx-study/evidence/memory/postmerge-20261104-1721.log.bong-water-water-bong commentedon Nov 5, 2026
Closing: fixed by
1bit-MONSTER/llama.cpp#176(merged 2026-11-04 19:05Z, head7cbbac1ac9), and the fix wasre-verified in the merged tree (built
428937ae, its owntest-hrx-graph-program-budgetpasses).Measured before/after on this box, Qwen3-4B,
-ngl 99, onegpu-hold, staging census +amdgpu_bo_createclass +own peak
drm-total-gtt, generated text identical in every pair:upload=0 download=08388608 Bplain BOs-n 8/-n 16Okay, the user is asking/…for the capital of France. I needThree arm-pairs on two tickets: same peak to the MiB, delta exactly −1890.0 MiB twice
(216 x 8 MiB + 81 x 2 MiB). The coherent 8 MiB sibling (
8704flags, 721 BOs) is untouched, which is the check thatthe guard is narrow. Detail:
~/amd-oss/hrx-study/FACTS-memory.md§7.13.