Skip to content

ggml : allocate graphs in a context - #2392

Merged
slaren merged 8 commits into
masterfrom
ggml-ctx-graph
Jul 26, 2023
Merged

slaren merged 8 commits into
masterfrom
ggml-ctx-graph

Conversation

@slaren

@slaren slaren commented Jul 25, 2023 •

Copy link
Copy Markdown
Member
  • Adds ggml_new_object to allocate objects in a context (internal to ggml)
  • Adds ggml_new_graph, ggml_build_forward_ctx, ggml_graph_overhead to support allocating graphs in a context
  • Modifies ggml_graph_compute_with_ctx to use ggml_new_object instead of a tensor
  • Modifies llama.cpp to allocate the eval graph on the compute context

Fixes ggml-org/ggml#299

Comment thread ggml.c Resolved
Comment thread ggml.c Resolved
Comment thread ggml.c Resolved
slaren and others added 2 commits July 26, 2023 11:34
Co-authored-by: Georgi Gerganov <[email protected]>
Comment thread ggml.c Resolved
Comment thread ggml.c Resolved
@slaren
slaren merged commit 5488fb7 into master Jul 26, 2023
@slaren
slaren deleted the ggml-ctx-graph branch July 26, 2023 13:56
Seunghhon pushed a commit to Seunghhon/llama.cpp that referenced this pull request Apr 26, 2026
* ggml : graph allocation in contexts

* allocate work buffer as a ggml_object in ggml_graph_compute_with_ctx

* llama.cpp : allocate graph in the context

* add GGML_PAD

---------

Co-authored-by: Georgi Gerganov <[email protected]>
phuongncn pushed a commit to phuongncn/llama.cpp-gx10-dgx-sparks-deepseekv4 that referenced this pull request Apr 28, 2026
* ggml : graph allocation in contexts

* allocate work buffer as a ggml_object in ggml_graph_compute_with_ctx

* llama.cpp : allocate graph in the context

* add GGML_PAD

---------

Co-authored-by: Georgi Gerganov <[email protected]>
ljubomirj pushed a commit to ljubomirj/llama.cpp that referenced this pull request May 6, 2026
* ggml : graph allocation in contexts

* allocate work buffer as a ggml_object in ggml_graph_compute_with_ctx

* llama.cpp : allocate graph in the context

* add GGML_PAD

---------

Co-authored-by: Georgi Gerganov <[email protected]>
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
* ggml : graph allocation in contexts

* allocate work buffer as a ggml_object in ggml_graph_compute_with_ctx

* llama.cpp : allocate graph in the context

* add GGML_PAD

---------

Co-authored-by: Georgi Gerganov <[email protected]>
AlexiAlp pushed a commit to minghaop/llama.cpp that referenced this pull request Jun 2, 2026
* ggml : graph allocation in contexts

* allocate work buffer as a ggml_object in ggml_graph_compute_with_ctx

* llama.cpp : allocate graph in the context

* add GGML_PAD

---------

Co-authored-by: Georgi Gerganov <[email protected]>
bong-water-water-bong pushed a commit to 1bit-MONSTER/llama.cpp that referenced this pull request Nov 14, 2026
…t.stored_copy instead of labelling it

The three reviews of the label asked the right question -- is the expectation change temporary or permanent? It is
permanent (gpu-kernels#84's 306 entry claiming a 256-aligned stored-read Q4_K prefill is the shipped +25-28 %, not a
stopgap), so the case should say what the add-on path DOES rather than be excused from reaching a verdict. And asking
that question found a second, larger thing:

  with the label the case aborted at its FIRST match (:3712), so nothing ever checked what followed;
  with the assertions passing, `found` turned out to be 3 on the add-on path and 1 on Loom.

`REQUIRE(found == 1)` was arm-blind -- the weight is bound by three dispatches on the add-on path (#84's entry is
reached through them) and by one on Loom. The label had been hiding both that invariant and the kernel expectation,
for as long as it existed.

What the case now asserts, per arm:

  stored_copy_exists:
    REQUIRE(binding.layout == kNativeWeightLayout)        measured ggml-native on BOTH paths
    hip_addon_dispatch_active()  -> REQUIRE(name starts with "hip:")
    otherwise                    -> REQUIRE(name == loom_libs:...q5_k_iq4_xs..._token256) + weight_format == "4"

  final count: add-on >= 1 (measured 3), Loom == 1 (unchanged)

`>= 1` rather than `== 3` deliberately: three is a plan-shape number that moves the next time the add-on materialises
differently, while the invariant this case protects -- the weight is bound by the dispatch whose parameters were just
asserted -- is enforced per binding in both arms.

What the add-on arm cannot do, stated so nobody assumes otherwise: it cannot name the kernel, because add-on ids are
hashed by design (ggml-org#2392) and this one moves with any kernel edit. The specific choice stays pinned by
GGML_HRX_HIP_DENSE_PREFILL_Q4K_STORED=0 (gpu-kernels#85's opt-out, which flips the row back to the Loom kernel) and by
gpu-kernels' own tile probes.

Verified (add-on build at the pin):
  add-on row   [PASS] 1 passed, 0 failed, 0 known-fail, 0 unexpected-pass
  -loom row    [PASS] 1 passed, 0 failed, 0 known-fail, 0 unexpected-pass   (GGML_HRX_DISABLE_DISPATCH=hip.)
  (the hip_addon_known_fail entry is removed: with the case passing in both arms it would report UNEXPECTED-PASS)

Refs gpu-kernels#84 (the 306 entry), gpu-kernels#85 (the opt-out and the tile probes), engine#2392 (why add-on ids are
hashed, and the UNEXPECTED-PASS rule that retires a stale label), gpu-kernels#86 where the failure was reported.
bong-water-water-bong added a commit to 1bit-MONSTER/llama.cpp that referenced this pull request Nov 14, 2026
… add-on path (gpu-kernels#84's 306 entry) (#386)

* hrx-backend-test: label q4k_aligned_prefill_layout.stored_copy on the add-on path (gpu-kernels#84)

gpu-kernels#84 registered a matcher at priority 306 that claims "a 256-aligned batch of a Q4_K weight Loom
reads STORED" and routes it to hip.dense_prefill.mm_q4k_stored -- the +25-28 % prefill change. That is exactly
this case's stored-copy arm, which asserts the Loom q5_k/iq4_xs form instead:

  tests/hrx-backend-test.cpp:3712: name == "loom_libs:ggml_mul_mat_q5_k_iq4_xs_q8_1_x4_wmma_token256"

So with the add-on at the pin the case is red, and the loom-only build is untouched. Measured, in this order:

  add-on gk-b0ed206 (before #84)                    [PASS]
  add-on 6105368 (the pin)                          [FAIL] :3712
     ... with GGML_HRX_HIP_DENSE_PREFILL_Q4K_STORED=0  [PASS]   <- gpu-kernels#85's own opt-out bisects it

A label rather than a rewritten assertion because the alternative is not reachable in-process: the policy
knobs are read into static storage once per process (swiglu-tile-probe documents the same constraint for its
two runs), so the case cannot flip the opt-out mid-run. Doing it properly needs a child process per policy --
what llama.cpp#383 just established for the arch table -- and that is a follow-up, not a reason to leave the
suite red.

The `expect` fragment is the :3712 requirement itself, so any OTHER failure in this case still surfaces as
UNEXPECTED-FAIL instead of being absorbed by the label. Arm-scoping is hip_addon_dispatch_active(), which is
why the loom-only row still asserts the Loom kernel; 22 labels already exist and the loom row reports 0
known-fail, so that gate is demonstrably working.

Verified on the add-on build at the pin:
  one case:           1 known-fail, 0 unexpected-pass
  full host tier:     68 passed, 0 failed, 24 known-fail, 0 unexpected-pass of 92, zero UNEXPECTED-FAIL lines
  (was 68/1/23 of 92 -- the single failure becomes the label, nothing else moves)

Refs gpu-kernels#84 (the 306 entry), gpu-kernels#85 (the opt-out used to prove it), engine#2392 (this
labelling + UNEXPECTED-FAIL enforcement), gpu-kernels#86 where the failure was first reported as a control arm.

* hrx-backend-test: assert the add-on path in q4k_aligned_prefill_layout.stored_copy instead of labelling it

The three reviews of the label asked the right question -- is the expectation change temporary or permanent? It is
permanent (gpu-kernels#84's 306 entry claiming a 256-aligned stored-read Q4_K prefill is the shipped +25-28 %, not a
stopgap), so the case should say what the add-on path DOES rather than be excused from reaching a verdict. And asking
that question found a second, larger thing:

  with the label the case aborted at its FIRST match (:3712), so nothing ever checked what followed;
  with the assertions passing, `found` turned out to be 3 on the add-on path and 1 on Loom.

`REQUIRE(found == 1)` was arm-blind -- the weight is bound by three dispatches on the add-on path (#84's entry is
reached through them) and by one on Loom. The label had been hiding both that invariant and the kernel expectation,
for as long as it existed.

What the case now asserts, per arm:

  stored_copy_exists:
    REQUIRE(binding.layout == kNativeWeightLayout)        measured ggml-native on BOTH paths
    hip_addon_dispatch_active()  -> REQUIRE(name starts with "hip:")
    otherwise                    -> REQUIRE(name == loom_libs:...q5_k_iq4_xs..._token256) + weight_format == "4"

  final count: add-on >= 1 (measured 3), Loom == 1 (unchanged)

`>= 1` rather than `== 3` deliberately: three is a plan-shape number that moves the next time the add-on materialises
differently, while the invariant this case protects -- the weight is bound by the dispatch whose parameters were just
asserted -- is enforced per binding in both arms.

What the add-on arm cannot do, stated so nobody assumes otherwise: it cannot name the kernel, because add-on ids are
hashed by design (ggml-org#2392) and this one moves with any kernel edit. The specific choice stays pinned by
GGML_HRX_HIP_DENSE_PREFILL_Q4K_STORED=0 (gpu-kernels#85's opt-out, which flips the row back to the Loom kernel) and by
gpu-kernels' own tile probes.

Verified (add-on build at the pin):
  add-on row   [PASS] 1 passed, 0 failed, 0 known-fail, 0 unexpected-pass
  -loom row    [PASS] 1 passed, 0 failed, 0 known-fail, 0 unexpected-pass   (GGML_HRX_DISABLE_DISPATCH=hip.)
  (the hip_addon_known_fail entry is removed: with the case passing in both arms it would report UNEXPECTED-PASS)

Refs gpu-kernels#84 (the 306 entry), gpu-kernels#85 (the opt-out and the tile probes), engine#2392 (why add-on ids are
hashed, and the UNEXPECTED-PASS rule that retires a stale label), gpu-kernels#86 where the failure was reported.

---------

Co-authored-by: bcloud <agent@local>
bong-water-water-bong added a commit to 1bit-MONSTER/llama.cpp that referenced this pull request Nov 21, 2026
…r is green (engine#3129) (#474)

`qwen_flash_attention_dispatch` was baselined as [ggml-org#2392 add-on plans this node] expecting
`ggml_flash_attention_decode_split_f32_f16_wmma_next_q8`; it now passes on the add-on path, so the runner
reports it as an UNEXPECTED-PASS and returns 1. The table's own rule says what to do about that -- "A row is
removed when its mechanism's fix lands: the case then passes on the add-on path (UNEXPECTED-PASS)" -- so
the row goes, with the measurement recorded in its place.

Measured at the current pin, built fresh, run with no device (the configuration this file's no-device
branch describes):
  before: host: 76 passed, 0 failed, 22 known-fail, 1 unexpected-pass, 99 total   rc 1
  after:  host: 77 passed, 0 failed, 22 known-fail, 0 unexpected-pass, 99 total   rc 0

What made it visible: nothing in CI selects these rows (`LABELS "hrx"` vs the workflows' `ctest -L main`,
and this target had not even compiled since #438 until #468), so the baseline drifted unwatched. That is
engine#3129's thesis, and this is the one edit that makes the target green before anyone spends runner
time gating it.

Co-authored-by: pi-i679 <[email protected]>
bong-water-water-bong added a commit to 1bit-MONSTER/llama.cpp that referenced this pull request Nov 21, 2026
… not to the row (engine#3120) (#475)

Eight `dense_matmul_swiglu.q4_k.q4_k.*` rows failed on
`hrx-ops-test.cpp:453  binding.layout == ggml::hrx::kQ4KPackedK256Row64Layout` in the add-on build, *after*
the per-row acceptance (#465) had already granted the route -- measured at the pin on 2026-11-21:

  engine#3120: loom_libs:ggml_mul_mat_swiglu_q4_q8_1_x4_lowtoken_dot is served by the HIP add-on
               (kquant_tokens_q8, hip:k_61d118a92b4c) -- comparing the value
  hrx-ops-test.cpp:453: requirement failed: binding.layout == kQ4KPackedK256Row64Layout

The packed K256/row64 layout is a fact about the LOOM kquant route; the add-on's kernels read the weight
*stored* (the distinction `hrx-backend-test` labels "ggml-org#2392 add-on reads the weight stored"). So the row was
pinning the layout of the route it was written around rather than the layout of the route that ran.

It now asks `route_outcome(...)` -- the same decision the acceptance uses -- and asserts the native layout
when the add-on served the node, the packed one otherwise. Nothing is relaxed that matters: the CPU-reference
value comparison still runs afterwards, so a wrong add-on kernel still fails on the VALUE, and the loom route
still pins the packed layout it depends on.

Co-authored-by: pi-i679 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ggml : improve API to allow allocating compute graphs on the heap

2 participants