From 8727d20013eefa03790c55372e104b20fa9174ad Mon Sep 17 00:00:00 2001 From: pi-hrx-compat Date: Mon, 16 Nov 2026 02:05:48 -0400 Subject: [PATCH 1/3] hrx: count the new class only for nodes nothing else explains, so the census sums Self-review of the previous commit, found by asking the question the counters exist to answer: do they add up? `off_by_design` counts a node whose placement the code itself calls by design (an unaligned input, a file-mapped weight). The new `off_host_nonweight` counter ran BEFORE that decision was made, so a node could be counted in both and the census would print two reasons for one node. A reader adding the reasons up would get more than the total -- the same defect as a summary that says "0 of everything", one level down. The count now runs after the by-design decision and only for nodes that decision did not explain. The reasons therefore partition the off-device nodes, and `by design + host-non-weight + unexplained` is the total by construction rather than by luck. Compiles: g++ -fsyntax-only on ggml-hrx.cpp with the pinned HRX include path, zero errors. Still no device run and no test arm -- unchanged from the last commit's note, and this is a counter, not a placement decision. (cherry picked from commit adf0c37edfb5d2536a4b3d5439295e9e620cad27) --- ggml/src/ggml-hrx/ggml-hrx.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/ggml/src/ggml-hrx/ggml-hrx.cpp b/ggml/src/ggml-hrx/ggml-hrx.cpp index ebef5fb7379..fc8d981118e 100644 --- a/ggml/src/ggml-hrx/ggml-hrx.cpp +++ b/ggml/src/ggml-hrx/ggml-hrx.cpp @@ -666,7 +666,16 @@ static void placement_observer(ggml_backend_sched_t sched, ggml_cgraph * graph, off_mapped_weights++; } } - if (!facts.src_host_weight) { + const bool by_design = ggml::hrx::placement_node_is_by_design(facts); + if (by_design) { + off_by_design++; + } else if (first_unexplained == nullptr) { + first_unexplained = node; + } + // engine#2494: counted only for a node that is NOT already explained by design, so the reasons in the census + // PARTITION the off-device nodes instead of overlapping. A reader who adds the counters up should get the + // total; two explanations for one node is how a summary stops summing. + if (!by_design && !facts.src_host_weight) { for (int s = 0; s < GGML_MAX_SRC; ++s) { const ggml_tensor * src = node->src[s]; if (src != nullptr && ggml::hrx::tensor_is_host_resident(src->view_src != nullptr ? src->view_src : src)) { @@ -675,12 +684,6 @@ static void placement_observer(ggml_backend_sched_t sched, ggml_cgraph * graph, } } } - const bool by_design = ggml::hrx::placement_node_is_by_design(facts); - if (by_design) { - off_by_design++; - } else if (first_unexplained == nullptr) { - first_unexplained = node; - } } std::string off_detail; From 599c1cf1a69abf54d653363e6ecc99b98db1601a Mon Sep 17 00:00:00 2001 From: pi-hrx-compat Date: Mon, 16 Nov 2026 03:49:25 -0400 Subject: [PATCH 2/3] hrx: make the census check that its classes partition the off-device nodes The review of #403 asked for one assertion: for any capture the census produces, the classes must sum to the whole. Counting by-design and host-non-weight made that a claim nothing checked, and a counter written but never summarised is how a class goes missing without anyone noticing. So the third class is counted too -- a node that is neither by design nor host-non-weight -- and the census warns when they do not add up: census does not partition: N by design + M host-non-weight + K neither != T off-device node(s) -- a class is missing WARN and not an assert, deliberately: this is a diagnostic path, and a broken census must not abort a run it was only describing. The same reasoning as the `!! N uncounted` marker in tools/diag/iommu_fault_attribution.py, and the same invariant: the parts sum to the whole or the summary says it cannot. Two consequences worth stating: * `off_unexplained` is incremented exactly when `by_design` is false and decremented at most once per node (the `break`), so it cannot go negative; * strict mode no longer aborts on a node that turns out to be host-non-weight -- it is explained, so `first_unexplained` is cleared for it. That is a behaviour change and it is the correct direction: GGML_HRX_STRICT exists to catch a MISPLACEMENT, not a placement this census can account for. g++ -fsyntax-only on ggml-hrx.cpp with the pinned HRX include path: zero errors. No device run. --- ggml/src/ggml-hrx/ggml-hrx.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/ggml/src/ggml-hrx/ggml-hrx.cpp b/ggml/src/ggml-hrx/ggml-hrx.cpp index fc8d981118e..1126fcd910e 100644 --- a/ggml/src/ggml-hrx/ggml-hrx.cpp +++ b/ggml/src/ggml-hrx/ggml-hrx.cpp @@ -630,6 +630,10 @@ static void placement_observer(ggml_backend_sched_t sched, ggml_cgraph * graph, // an index/cache/bias/activation kept in host memory was invisible here -- the one state that a GPU cannot read // without a mapping, and the one this census could not name. int64_t off_host_nonweight = 0; + // engine#2494 review: the classes must PARTITION the off-device nodes -- by design + host-non-weight + neither. + // Counting only the first two made "the parts sum to the whole" a claim nothing checked, and a counter that is + // written but never summarised is how a class goes missing from a census without anyone noticing. + int64_t off_unexplained = 0; ggml_tensor * first_off = nullptr; ggml_tensor * first_unexplained = nullptr; for (int i = 0; i < graph->n_nodes; i++) { @@ -669,8 +673,11 @@ static void placement_observer(ggml_backend_sched_t sched, ggml_cgraph * graph, const bool by_design = ggml::hrx::placement_node_is_by_design(facts); if (by_design) { off_by_design++; - } else if (first_unexplained == nullptr) { - first_unexplained = node; + } else { + off_unexplained++; // neither by design nor (below) host-non-weight: a candidate for strict mode + if (first_unexplained == nullptr) { + first_unexplained = node; + } } // engine#2494: counted only for a node that is NOT already explained by design, so the reasons in the census // PARTITION the off-device nodes instead of overlapping. A reader who adds the counters up should get the @@ -680,12 +687,25 @@ static void placement_observer(ggml_backend_sched_t sched, ggml_cgraph * graph, const ggml_tensor * src = node->src[s]; if (src != nullptr && ggml::hrx::tensor_is_host_resident(src->view_src != nullptr ? src->view_src : src)) { off_host_nonweight++; + off_unexplained--; // explained now; the partition below depends on it + if (first_unexplained == node) { + first_unexplained = nullptr; // strict mode must not abort on an explained node + } break; // per node, like the counters above } } } } + // THE PARTS SUM TO THE WHOLE. Every off-device node is by design, host-non-weight, or neither; if that ever fails + // the census is missing a class, and the summary would under-report without saying so. WARN, not assert: this is + // a diagnostic path and a broken census must not abort a run it was only describing. + if (off_by_design + off_host_nonweight + off_unexplained != off_nodes) { + GGML_LOG_WARN("%s: census does not partition: %" PRId64 " by design + %" PRId64 " host-non-weight + %" PRId64 + " neither != %" PRId64 " off-device node(s) -- a class is missing from this census\n", __func__, + off_by_design, off_host_nonweight, off_unexplained, off_nodes); + } + std::string off_detail; for (int op = 0; op < GGML_OP_COUNT; op++) { if (off_by_op[op] == 0) { From 8f7ab2a6bf352771d707866b0b2b30afc5b3e5e2 Mon Sep 17 00:00:00 2001 From: pi-hrx-compat Date: Mon, 16 Nov 2026 05:20:01 -0400 Subject: [PATCH 3/3] hrx: give the census partition an arm, by making it a callable predicate The review asked for one thing this branch lacked: the partition check was a single inline comparison with no test, so "the counters add up" was a property nothing could exercise. A synthetic graph would have answered it and cost a lot; the arithmetic itself is the property, so it becomes a pure function: inline bool census_partitions(int64_t by_design, int64_t host_nonweight, int64_t unexplained, int64_t off_nodes); and the census calls it. Five assertions in tests/test-hrx-host-resident.cpp, including the two directions that matter -- a node counted twice (3+2 vs 6) and a node missed (3+2 vs 4) must both fail. The graph-free form is the point: a claim nothing can call with made-up numbers is a claim nothing can test, which is exactly how the original overlap survived #403. Also noted from the review and left as is: `!by_design && !facts.src_host_weight` carries a redundant second term (the predicate is false whenever by_design is true), and `off_mapped_weights` stays a sub-count of by-design rather than a fourth class -- both are behaviour-preserving and both are stated in the review rather than silently retained. g++ -fsyntax-only on ggml-hrx.cpp and the test with the pinned HRX include path: zero errors. --- ggml/src/ggml-hrx/ggml-hrx.cpp | 2 +- ggml/src/ggml-hrx/host-weight-placement.h | 7 +++++++ tests/test-hrx-host-resident.cpp | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/ggml/src/ggml-hrx/ggml-hrx.cpp b/ggml/src/ggml-hrx/ggml-hrx.cpp index 1126fcd910e..46fa87f9ca5 100644 --- a/ggml/src/ggml-hrx/ggml-hrx.cpp +++ b/ggml/src/ggml-hrx/ggml-hrx.cpp @@ -700,7 +700,7 @@ static void placement_observer(ggml_backend_sched_t sched, ggml_cgraph * graph, // THE PARTS SUM TO THE WHOLE. Every off-device node is by design, host-non-weight, or neither; if that ever fails // the census is missing a class, and the summary would under-report without saying so. WARN, not assert: this is // a diagnostic path and a broken census must not abort a run it was only describing. - if (off_by_design + off_host_nonweight + off_unexplained != off_nodes) { + if (!ggml::hrx::census_partitions(off_by_design, off_host_nonweight, off_unexplained, off_nodes)) { GGML_LOG_WARN("%s: census does not partition: %" PRId64 " by design + %" PRId64 " host-non-weight + %" PRId64 " neither != %" PRId64 " off-device node(s) -- a class is missing from this census\n", __func__, off_by_design, off_host_nonweight, off_unexplained, off_nodes); diff --git a/ggml/src/ggml-hrx/host-weight-placement.h b/ggml/src/ggml-hrx/host-weight-placement.h index bdefe792491..47f00cc5101 100644 --- a/ggml/src/ggml-hrx/host-weight-placement.h +++ b/ggml/src/ggml-hrx/host-weight-placement.h @@ -54,4 +54,11 @@ bool host_weight_is_host_resident(const ggml_tensor * tensor); // not a weight is exactly the state nothing could see (see the non-weight counter in ggml-hrx.cpp). bool tensor_is_host_resident(const ggml_tensor * tensor); +// engine#2494 review: the census explains every off-device node by exactly one class -- by design, host-non-weight, or +// neither. That partition is the thing a reader checks by adding the printed counters up, so it is a pure predicate +// rather than an inline comparison: a claim nothing can call with made-up numbers is a claim nothing can test. +inline bool census_partitions(int64_t by_design, int64_t host_nonweight, int64_t unexplained, int64_t off_nodes) { + return by_design + host_nonweight + unexplained == off_nodes; +} + } // namespace ggml::hrx diff --git a/tests/test-hrx-host-resident.cpp b/tests/test-hrx-host-resident.cpp index 2c833750608..fec960421cd 100644 --- a/tests/test-hrx-host-resident.cpp +++ b/tests/test-hrx-host-resident.cpp @@ -88,6 +88,14 @@ int main() { CHECK(ggml::hrx::tensor_is_host_resident(t) && ggml::hrx::host_weight_is_host_resident(t), "a WEIGHTS buffer is host-resident AND a weight"); + // engine#2494 review: THE CENSUS MUST PARTITION. Pure arithmetic, so it needs no graph and no backend -- the + // property a reader checks by adding the printed counters up, checked here instead. + CHECK(ggml::hrx::census_partitions(3, 2, 0, 5), "3 by design + 2 host-non-weight == 5 off-device"); + CHECK(ggml::hrx::census_partitions(0, 0, 4, 4), "all unexplained still partitions"); + CHECK(ggml::hrx::census_partitions(0, 0, 0, 0), "no node on the CPU partitions trivially"); + CHECK(!ggml::hrx::census_partitions(3, 2, 0, 6), "one node counted twice must NOT partition"); + CHECK(!ggml::hrx::census_partitions(3, 2, 0, 4), "one node missed must NOT partition"); + ggml_backend_buffer_free(buf); ggml_free(ctx); ggml_backend_free(backend);