ADR 0054: The incremental host engine of triad_count and the oracle’s independence from it#
Status: Accepted under delegation (2026-10-15; GOVERNANCE.md, “Delegation of technical ADRs”), technical scope only. It carries out the author’s decision D3 of 2026-10-15 (the sequential and OpenMP backends of
triad_countare incremental host engines, an untuned transliteration of ESCHER-GPU’s wedge engine with the same operations, no performance gate;dyng::testing::triad_referenceis the independent oracle) in M9a step 4 (the M9a acceptance criteria 6, 8 (host), 10 and 11). It changes no rule the author approved: the parity is exact (PLAN 8.3), the gates and their protocol are untouched, no frozen header (hypergraph/*,update.hpp,core/*,graph/*) is edited, the CUDA engine’s machine code is unchanged.Amended by: ADR 0057 (2026-10-20): the phases run
count_ownedas unsigned magnitudes with their signs beside them (the signed bins ofcount_deltarefused a phase of 2^63 or more).Date: 2026-10-15
Deciders: the AI assistant, on the author’s behalf (M9a, step host-engine-kit-mutations); the scope change against PLAN 4.6 is the author’s (D3)
Builds on: ADR 0033 (executors), ADR 0043 (the hypergraph’s update path and the kit’s axis), ADR 0049 (the oracle), ADR 0050 (the replays), ADR 0052 (the API), ADR 0053 (the CUDA port), ADR 0055 (
operators::count_delta).
Context#
PLAN 4.6 (backend matrix) makes the host backends of triad_count reference backends (“R: ESCHER
CPU reference; recount-based delta”, the OpenMP backend becoming incremental in 0.4) and the
roadmap’s 0.5 lists “an OpenMP backend for incremental triad_count”. M9a step 3 shipped that
plan: update() recounted the whole hypergraph on the host (stats::fallback_used). The author’s
decision D3 replaced it: the host backends run the incremental algorithm, a transliteration of the
CUDA engine, with no performance gate, and the oracle stays independent of both engines.
Decision#
1. The host engine (cpp/src/algorithms/triad_count/host_engine.hpp)#
ESCHER-GPU@abcf9b2’s kernel/wedge.cuh as loops over the internal row views in host memory (the
host stores use A’s layout, ADR 0042): one source is what the device engine’s threads do for
that source’s wedges.
Full mode (compute()): the sources are the keys 1..
full_count_keys(kind, views)(engine/phases.hpp, shared with the CUDA engine:views.h2v.max_keyfor type 1, the line graph’sviews.h2h.max_keyotherwise); a sourceatakes its out-wedges(a, b),b > a(fromout[a]), and closes a wedge into the triangles(a, b, k),k > b, by merging the rows ofaafterband ofbafterout[b](TriangleBody); nothing is filtered.Frontier mode (a phase of update()): the sources are the frontier’s keys; a source
ftakes every wedge of its row (fromloc[f]), skips a wedge(f, b)whenbis in the frontier andb < f, and skips a closingkwhenkis in the frontier andk < f: the predicates ofengine/ownership.hpp(min_member_skips_wedge,min_member_skips_closing), the same oneswedge.cuhcalls, withownership::min_memberpassed explicitly (invariant I2).Shapes: triangles (
motif_op, 30 bins;type3_op), pairs (type2_op: every wedge is a pair), keys (choose3_op: C(|e|, 3) of each source). The operations are the CUDA engine’s (engine/*_ops.hpp, the Op form of ADR 0053’s c6, host-and-device structs) with the host bins handle ofoperators::count_delta.Early outs as in A’s countWedgeShape: no sources (an empty frontier) and sources without a wedge (the wedges are counted first, as the device scan does); the launch counters of the result count them and the passes per (mode, shape) on every backend (criterion 9’s tests run on the host backends too).
The pass:
operators::count_delta(ADR 0055) onsequential_exec(sequential.cpp) oropenmp_exec(openmp.cpp): a static partition of the sources (chunks of 64 dealt to the threads in turn), private bins per thread, added in thread order after the pass; the sign of the phase applied once per bin into signed 64-bit bins. 1, 8 and 56 threads give identical counts and counters (tested).Errors: a pattern of no class (motif_op’s bin -1) is reported by the bins handle and raised as
internal_error(never written: tested on all 128 Venn ids); a count past the 64-bit range is acapacity_error. Both come after the commit and poison the result.
2. The problem’s hooks on the host backends (Tier A)#
The aggregate-delta template as on cuda, through the framework’s Tier A hooks:
count(-) (
triad_count.count_minus, on G_t): lease the host workspace (triad_host_workspace, pooled, ADR 0015) and reserve what both phases need before the commit (frontier keys for the larger phase, flags forviews.h2h.max_key + insertions + 1keys, the per-thread bins); the frontier of Step 0’s live distinct deletions; the subtract phase into the subtract bins.commit:
hypergraph.apply.identify_affected (
triad_count.identify_affected, new on the host): the frontier of the ids the commit ASSIGNED (triad_inserted_ids(), shared with cuda:hyper_apply_summary:: inserted_ids, on cuda their device copy). A frontier id outside[0, views.h2v.max_key)is aninternal_error(every loop indexes the rows by these keys).count(+) (
triad_count.count_plus, on G_{t+1}): the add phase into the add bins.finalize (
triad_count.finalize):apply_delta(minus, plus), the CUDA path’s: the signs checked, a bin that would go negative aninternal_errorthat poisons the result, the stats (triads_removed,triads_added,delta),fallback_usedfalse.
compute() on the host backends runs the full mode (triad_count.count). Both engines take the
phase’s sign from triad::phase_sign() and the add phase’s ids from triad_inserted_ids(), so
the recorded mutations of PLAN 8.4 act on both (ADR 0055 is the operator; criterion 11’s suite).
3. The oracle stays independent#
dyng::testing::triad_reference (ADR 0049) shares no code with either engine: its own OBJECT
library, A’s utils/reference.cpp algorithm (a brute force over the hyperedges’ vertex rows, not
the line graph’s wedges), its own class map derived from the permutation orbits; the isolation
check triad_reference_isolation (no include or link of cpp/src/algorithms/triad_count, the
engine or the container internals) is unchanged. The host engine is not an oracle: the tests
compare every backend with triad_reference (counts, removed() / added() of the phases), with
a fresh compute() and, on the golden set, with A.
4. Scope against PLAN 4.6 and the roadmap#
PLAN 4.6’s backend matrix entry for
triad_count(“R (ESCHER CPU reference; recount-based delta)”, “R (same code, OpenMP) -> real incremental in 0.4”) is superseded by D3: both host backends are incremental from 0.3.0. The plan’s recount stays the documented fallback (a backend that cannot run the engine may recount and reportfallback_used); no backend uses it.The roadmap’s 0.5 item “an OpenMP backend for incremental
triad_count” is performance tuning of this backend (D3;docs/roadmap.md): the static partition, the per-source merges and the absence of a wedge-parallel schedule are not tuned, and the host backends have no gate.PLAN 5.8 / 8.2’s oracle requirement is met by
triad_reference, not by the sequential backend.
Consequences#
stats::fallback_usedis false on every backend;triads_removed/triads_addedare the phases’ counts everywhere, so the kit’s deterministic counters include them (C3, C9) and the tests check them against the oracle on every backend.The kit runs the four patterns on sequential, openmp (8 threads: the traits’ new optional
kit_openmp_threads) and cuda.CPU parity against A (criterion 8, host):
parity/results/M9a.mdsection 4.A phase of an update on the host is limited to 2^63 - 1 triads per bin (signed bins); compute() keeps the unsigned 2^64 - 1 limit (
count_owned).
Outcome (M9a step 4)#
Exact against ESCHER-GPU@abcf9b2 on the host coverage table, by key and by content, with
integrity and a fresh compute() after every batch: sequential 120/120 (make-test and the syn100k
grid), OpenMP 142/142 at 8 threads and 142/142 at 1 thread (also the syn1m s1 grid and
coauth_b50k_s1 types 1 and 2), the two OpenMP records identical case by case. The kit passes on
the three backends; the five triad mutations and cbst_unfill_drops_last are detected on both
engines; the CUDA kernels’ machine code is unchanged (parity/results/M9a.md section 4).