Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
About Files History Releases Proposed changes Issues For developers
Reject inverted buffer lifetimes in offline DAG certificates
closed b4f369f52dd6dffc #933 · opened 2026-10-30 11:22 UTC · closed 2026-10-30 11:31 UTC
Imported from GitHub aien-dev/omega-mv#933, by drakestapleton
Base 348c7ef6b9456da3effe26dc9ea19bb0d6e9f0d2 · Head 59dac6f385cfff698b2fb0f6ca4fbf7cca7aba76
drakestapleton wrote on 2026-10-30 11:22 UTC
Refs #705
Where the evaluator lives
tools/dagsim is not on the current default branch. The only implementation was closed, unmerged PR #590 (research/cost-sim-583, commit 3bd56731c5517e2a9c8f195955c71e73dc6f9269 ). That branch is gone from origin; refs/pull/590/head still serves the commit. This PR brings that evaluator onto main and adds the lifetime refusal. It does not bring the held-out measurement receipts under evidence/DAGSIM-583-*, tests/dagsim/measure.sh, tests/dagsim/heldout_memcpy.sh, or tools/dagsim/memcpy_probe.c. Those stay historical. No GPU was run and no hardware performance claim is made.
What changed
Resolved buffer windows are half-open [start, end): start of first (or 0) through end of last (or the makespan).
end earlier than start is REFUSED_LIFETIME before any capacity certificate or Pareto rank. The reason names the buffer, both endpoints (omitted if absent), and the resolved times.
A zero-duration window (end == start) emits no ledger events, so it cannot pull live bytes negative or offset another buffer.
Frees of intervals that started earlier still run before allocations at the same timestamp, so a completion/allocation tie does not double-count.
If an accepted sweep would go negative anyway, the certificate is refused instead of being emitted.
Negative or non-finite bytes are a parse error.
spec/offline-evidence-v1.md records that interval convention. No v1 field was added.
Acceptance
Item Result
Issue fixture inverted_masks_overflow.oev refused before a certificate Met. REFUSED_LIFETIME, exit 1, no makespan. Reason: inverted lifetime for buffer inverted: first=C start_ns=20 last=A end_ns=10
Lone inverted buffer refused, not peak 0 Met (inverted_lone.oev)
Same fixture without the malformed buffer Met. REFUSED_CAPACITY: 160 B live at t=10 ns (real1,real2) exceeds mem
Valid non-overlapping pair, including a completion/allocation tie Met. Both OK, peak 80 B on a 100 B cap
Zero-duration, omitted first/last, deterministic rejection text Met in tests/dagsim/dagsim_unit.c
No accepted ledger goes negative; malformed lifetimes cannot offset valid ones Met by the refusal plus the empty zero-duration convention. A mutant that deletes the LIFETIME_ORDER_CHECK call fails the named assertion inverted_lifetime_masks_overflow
Independent reviewer Not met. Host reproduction is this VM only
Source / seed / binary / fixture / command / output identities, statuses kept separate Partial. Recorded below. Seeded omc did not build this checker
Seeded .om replacement (open)
Not done. #599 still owns replacing this evaluator. The active checker is C (tools/dagsim/*.c). That is why this PR says Refs #705 and not Closes. On AArch64 the link uses src/omega_om_units.c for SHA-256. On other hosts tests/dagsim/sha256_host.c only satisfies the sha256_hash symbol and aborts if a cost-model blob digest is requested; dagsim --model is NOT_RUN on this x86_64 VM. The analytical suite does not hash.
Host reproduction
Pre-fix binary built from the imported PR #590 sources, same fixture, before the check:
cc -std=gnu11 -Wall -Wextra -Werror -D_GNU_SOURCE -O2 -Isrc -Itools/dagsim
/tmp/dagsim-base/dagsim eval tests/dagsim/fixtures/inverted_masks_overflow.oev --asof 2026-10-24
Exit 0, "status": "OK", "peak_live_bytes": {"mem": {"bytes": 80, "at_ns": 10, "cap": 100}}. The two valid 80 B buffers need 160 B during B. Lone inverted buffer: OK with peak 0.
Post-fix (cc is Ubuntu clang 18.1.3, Linux x86_64, commits efd514604 then crumb restamp 59dac6f38 ):
make PHYSICS_DIR=/nonexistent PHYSICS_LOCK_CHECK=0 test-dagsim
dagsim_unit: 197 checks, 0 failed (the historical 171 plus the new lifetime checks)
tests/dagsim/run_cli.sh: every check ok, including the #705 fixtures
mutant killed: inverted_lifetime_masks_overflow
Valid CLI outputs subset.json, overlap.json, and pareto.txt are byte-identical to the pre-fix binary
tests/gates/run.sh zero-disk-secrets: pass
crumb verify (crumb-compile/1 from crumb.lock d0f0b95d ): OK, 166 crumbs
Qualification, kept separate:
Host regression of this certificate bug: PASS on the command above
Chip / GB10: NOT_RUN
Measured performance: NOT_RUN
Seeded .om checker: NOT_RUN (not implemented)
<div><a href="https://cursor.com/agents/bc-99790e19 -c8d7-50bf-b089-7f168b3944c6 ?cursor_ref=pr_footer&cursor_cta=open_in_web"> <picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"> <source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"> <img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"> </picture></a> <a href="https://cursor.com/background-agent?bcId=bc-99790e19 -c8d7-50bf-b089-7f168b3944c6 &cursor_ref=pr_footer&cursor_cta=open_in_cursor"> <picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"> <source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"> <img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"> </picture></a> </div>
cursor[bot] wrote on 2026-10-30 11:30 UTC
Closing this. The import and the lifetime fix were already in one pushed commit, so reshaping it into the import-only PR would have been a force-push.
Split, without rewriting this history:
Merge order when the time comes: #934, then #936, then #937. #934 is still open, so #937 does not yet handle rx_cm_predict's new return value.
— Grokbot
Apply it
git checkout -b patch-b4f369f52dd6dffc 348c7ef6b9456da3effe26dc9ea19bb0d6e9f0d2
curl -fsSL https://interplane.io/drakestapleton/omega-mv/patches/b4f369f52dd6dffc .patch | git am
Raw patch (mbox) · Diff
Provenance
This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:
github-import 1
aien-dev/omega-mv
933
59dac6f385cfff698b2fb0f6ca4fbf7cca7aba76
{"kind":"github-import","owner":"aien-dev","repo":"omega-mv","number":933,"url":"https://github.com/aien-dev/omega-mv/pull/933","export_sha256":"7319147b350ad908bf0b731068ec3be7b8dee848041dc862f71455e8e4680140 ","imported_utc":"2026-11-18T16:35:44Z"}
Changes
diff --git a/.crumb b/.crumb
index 9c65d8602 ..68172397e 100644
--- a/.crumb
+++ b/.crumb
@@ -48,7 +48,7 @@
},
{
"digest": "7ef7796693f23ad68d9a5bcaaee0f635018f4371139a040ba202d4ce7083ede8 ",
- "last_commit": "851476aba ",
+ "last_commit": "dd39bf71f ",
"name": "docs",
"purpose": "Directory docs. Purpose not yet described by a human."
},
@@ -60,7 +60,7 @@
},
{
"digest": "8f0e5cb325040247440527f6b54b65cf72c47ff5adca75b4f32a1ddf2b2d6ade ",
- "last_commit": "43f25831b ",
+ "last_commit": "1f320caad ",
"name": "mk",
"purpose": "Directory mk. Purpose not yet described by a human."
},
@@ -71,39 +71,39 @@
"purpose": "Directory research. Purpose not yet described by a human."
},
{
- "digest": "1cef97c8f2d852990d04fe5e791e877015c74a751648a020033a2459e02c5148 ",
- "last_commit": "faebae8c1 ",
+ "digest": "556ce8c4d2573a65d35305117a4ded612adace3a73265503b8e0c0e1312f9006 ",
+ "last_commit": "efd514604 ",
"name": "spec",
"purpose": "Directory spec. Purpose not yet described by a human."
},
{
"digest": "199749684598b36b610b14a4c5b59703df5e53bba1db2b5939297c55ac423153 ",
- "last_commit": "82a399b9f ",
+ "last_commit": "bf54b19fa ",
"name": "src",
"purpose": "Directory src. Purpose not yet described by a human."
},
{
- "digest": "ea8ae97d49edc85af090218634c9bad13bcc91fa84f96e0d33fefe313704e111 ",
- "last_commit": "f401f2baa ",
+ "digest": "b40704fb33f20ab87c728ac9534e2a807c17d649106f5392f0db651e9caf4858 ",
+ "last_commit": "efd514604 ",
"name": "tests",
"purpose": "Directory tests. Purpose not yet described by a human."
},
{
- "digest": "4e83dea21da137c30076c2dc0ca4f3a488f576f30a94e334558ad5ea523f3a6b ",
- "last_commit": "a50c3bd41 ",
+ "digest": "c8e85176667df172aad0d9d1c6d0de9dcc71674f0f04e3c8d127024fa291b2c3 ",
+ "last_commit": "efd514604 ",
"name": "tools",
"purpose": "Directory tools. Purpose not yet described by a human."
}
],
- "children_root": "sha256:8091287983f9252d3cbab774326dd2cc2641e8e724c75b7b59bbbb319ceb72c9 ",
- "compiled_at": "2026-10-30T02:47:38Z",
+ "children_root": "sha256:05360223fc42a7cf5e64ca56ab777d1fdf3819dd94c03aba37bd354d45c33766 ",
+ "compiled_at": "2026-10-30T11:22:00Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:a1204166d25f213563dd1d6a90e11e05ede0b1b1dad70e0a74c29b8b3300bf8c ",
+ "digest": "sha256:823fe4671534ad138583cfa29f28fddcc6bf6bd87e1ba77a44669c31263ca770 ",
"evidence_files": 12611,
"evidence_root": "sha256:9ee1ecc8a32bd724cae4237a844b3cb2e82a8e6af89626fa84c2b5ea77bec79e ",
- "files": 17821,
- "generated_at_commit": "e615e9ff47d03199514580f655d7670e61ab7e2f ",
- "source_tree": "sha256:0ba3034275cdc2e57d2ac8280179bd4903fdfe0147a9a64ed54db7a1df23d48f "
+ "files": 17841,
+ "generated_at_commit": "efd5146042b83a1fc490f120b914e8922adce540 ",
+ "source_tree": "sha256:c10e9b7f396858ae99bd39f5ecac430712a95845d038ff5ea6b7e6bd33c998e4 "
},
"owner_lane": "",
"provenance": {
diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index a3f04b7c7 ..a514dc4f5 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -5,6 +5,7 @@ Every model below did real work. A model is listed only for work it did. The orc
| Model | What it did |
|---|---|
+| Grok 4.7 | Offline DAG certificate fix: reject inverted buffer lifetimes before the capacity ledger so a negative live-byte contribution cannot hide a memory overflow (#705). Host regression and a mutant that drops the check. Seeded `.om` replacement of `tools/dagsim` is still outstanding (#599). |
| Codex (GPT-6.1 Sol) | FR-9 x86-64 Linux backend integration from historical 7eca2ac3f , full-language lowering, contract-loop/output-capacity/dead-branch repairs, division/shift proof-aware diagnostics, original-conductor and historical-mutant qualification repair, independent disassembly and cross-architecture qualification; orphaned-lane recovery, current mutation re-anchoring and x86 OM-2 emitted-storage bound |
| Codex (GPT-6.1 Sol) | Corrected qty prefix-query types and capacity-only diagnostic repairability, with exact-record regression controls (#911) |
| Codex | Inference-cost driver compiler-failure status repair, host-only refusal regression probes and independent review; native Omega execution NOT_RUN |
diff --git a/Makefile b/Makefile
index 4e068c1de ..31c25b166 100644
--- a/Makefile
+++ b/Makefile
@@ -1249,6 +1249,36 @@ $(RX_CM_UNIT): tests/runtime/rx_costmodel_unit.c $(RX_CM_OBJ) src/omega_om_units
test-costmodel: $(RX_CM_UNIT)
./$(RX_CM_UNIT)
+# Offline resource-DAG evaluator (omega-mv#583, lifetime refusal omega-mv#705).
+# Host only. The seeded SHA-256 unit is AArch64 machine code; other hosts link
+# tests/dagsim/sha256_host.c, which aborts if a blob digest is actually requested.
+.PHONY: test-dagsim
+DS_OBJ = $(OUT_DIR)/dagsim.o
+DS_UNIT = $(OUT_DIR)/dagsim_unit
+DS_CLI = $(OUT_DIR)/dagsim
+ifeq ($(shell uname -m),aarch64)
+DS_SHA_SRC = src/omega_om_units.c
+else
+DS_SHA_SRC = tests/dagsim/sha256_host.c
+endif
+
+$(DS_OBJ): tools/dagsim/dagsim.c tools/dagsim/dagsim.h src/runtime/rx_costmodel.h | $(OUT_DIR)
+ $(CC) $(CFLAGS) -Itools/dagsim -c -o $@ tools/dagsim/dagsim.c
+ @if nm -u $@ | grep -E 'cuda|nvrm|gpu_'; then \
+ echo "dagsim.o references an operation an offline evaluator must not have"; \
+ rm -f $@; exit 1; fi
+
+$(DS_UNIT): tests/dagsim/dagsim_unit.c $(DS_OBJ) $(RX_CM_OBJ) $(DS_SHA_SRC) | $(OUT_DIR)
+ $(CC) $(CFLAGS) -Itools/dagsim -o $@ tests/dagsim/dagsim_unit.c $(DS_OBJ) $(RX_CM_OBJ) $(DS_SHA_SRC) -lm
+
+$(DS_CLI): tools/dagsim/dagsim_cli.c $(DS_OBJ) $(RX_CM_OBJ) $(DS_SHA_SRC) | $(OUT_DIR)
+ $(CC) $(CFLAGS) -Itools/dagsim -o $@ tools/dagsim/dagsim_cli.c $(DS_OBJ) $(RX_CM_OBJ) $(DS_SHA_SRC) -lm
+
+test-dagsim: $(DS_UNIT) $(DS_CLI)
+ ./$(DS_UNIT)
+ sh tests/dagsim/run_cli.sh $(DS_CLI) $(OUT_DIR)/dagsim-cli-out
+ sh tests/dagsim/mutant_lifetime.sh
+
# AArch64 hosts: the gate. Real realizations, training, promotion through the
# R9 barrier on the native authority, held-out workloads.
RX_EMP_SRCS = src/runtime/rx_generation.c src/omega_om_units.c src/omega_evidence.c \
diff --git a/spec/.crumb b/spec/.crumb
index 0873a59ca ..801f9987c 100644
--- a/spec/.crumb
+++ b/spec/.crumb
@@ -20,14 +20,14 @@
}
],
"children_root": "sha256:6834a3241647d3a098283d4eafedbdb1428dfa4d834f9ed5f22025b6d2303093 ",
- "compiled_at": "2026-10-28T11:13:00Z",
+ "compiled_at": "2026-10-30T11:20:30Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:1cef97c8f2d852990d04fe5e791e877015c74a751648a020033a2459e02c5148 ",
+ "digest": "sha256:556ce8c4d2573a65d35305117a4ded612adace3a73265503b8e0c0e1312f9006 ",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 ",
- "files": 62,
- "generated_at_commit": "6999fa9e6dae4847c155ef4eacaece74f491d3ca ",
- "source_tree": "sha256:1ae5a611958d41bbaf64f47825a1a8bc3484e1cb954bcc622ed912ec7c330eb6 "
+ "files": 63,
+ "generated_at_commit": "dd39bf71fb8eb14c45bf0abd20c74d5da69c807c ",
+ "source_tree": "sha256:a6f5abd06830e50fb8fca3232b046b997900623ba4f439fc210d486f7df441d5 "
},
"owner_lane": "",
"provenance": {
diff --git a/spec/offline-evidence-v1.md b/spec/offline-evidence-v1.md
new file mode 100644
index 000000000 ..cf90bbb18
--- /dev/null
+++ b/spec/offline-evidence-v1.md
@@ -0,0 +1,155 @@
+# Offline evidence schema v1 (OEV1) for the resource-DAG cost simulator
+
+Status: FROZEN 2026-10-19 (omega-mv#583, implement item 1). Consumers: omega-mv#583
+(`tools/dagsim`), omega-mv#584 (candidate screening), aien-architecture#246 (lifecycle
+ledgers). A change to a frozen field is a v2, never an edit of v1.
+
+Purpose: one text file describes a machine, the build and calibration it was measured
+with, the resources, an operation DAG with demands, buffer lifetimes, dependencies,
+synchronization and the energy instrument, so that an offline evaluator (no GPU, no
+execution) can compose existing per-operation estimates into whole-DAG costs and bounds.
+The file never carries a number without saying where it came from.
+
+## File form
+
+Plain text, UTF-8, one record per line, fields separated by whitespace, `key=value`
+pairs after the record keyword, `#` to end of line is a comment. Unknown keywords are
+errors (a parser that silently ignores a field would let a fabricated or misspelled
+number through). Line numbers are reported on every error. No value may contain
+whitespace. Maximum 256 operations, 32 resources, 256 buffers, 1024 dependencies
+(static limits; a larger DAG is refused with `REFUSED_UNSUPPORTED`, not truncated).
+
+Units are fixed by the schema and never per record: time `ns`, bytes `B`,
+bandwidth `B/s`, power `W`, energy `J`, capacity `B`. Dates are `YYYY-MM-DD`.
+Integers are decimal; reals accept `1.5e9`.
+
+## Provenance (mandatory wherever a number appears)
+
+`prov=` takes exactly one of:
+
+| value | meaning |
+|---|---|
+| `specified` | a vendor or design ceiling (datasheet). Never attainable by itself. |
+| `measured` | read from an instrument on the named machine; `src=` names the receipt. |
+| `fitted` | produced by a model fitted on measurements (e.g. `rx_costmodel`); `src=` names the model blob or the fit receipt. |
+| `synthetic` | made up for a sensitivity study; results that depend on it are labelled synthetic and never ranked as real. |
+| `unknown` | nobody knows. The evaluator refuses to turn this into a number. |
+
+`lo=` and `hi=` give the interval that the source supports (for `measured`: the repeat
+spread of the receipt; for `fitted`: the model's predictive interval). Missing `lo`/`hi`
+on a `measured` or `fitted` value means "no interval known" and the evaluator reports
+the result without interval coverage.
+
+## Records
+
+```
+oev version=1
+machine id=<host> soc=<name> cores=<n> mem_bytes=<B> prov=specified src=<where>
+build repo=<name> sha=<40 hex> [physics=<sha>]
+calibration id=<name> taken=<YYYY-MM-DD> valid_days=<n> load1=<x> src=<receipt dir or file> [model=<path to rx_costmodel blob>]
+resource id=<name> kind=compute slots=<n> prov=<p> src=<s>
+resource id=<name> kind=bandwidth cap=<B/s> [lo=<B/s> hi=<B/s>] prov=<p> src=<s>
+resource id=<name> kind=capacity cap=<B> prov=<p> src=<s>
+resource id=<name> kind=launch prov=<p> src=<s>
+op id=<name> kind=<compute|copy|matvec|barrier|storage|persist> [engine=<compute res>] [t_ns=<x> lo=<x> hi=<x> prov=<p> src=<s>] [bytes=<B> bw=<bandwidth res>] [launch_ns=<x> launcher=<launch res>] [M=<n> N=<n> core=<0|1|2> arm=<n>]
+dep <from op> <to op>
+buffer id=<name> bytes=<B> cap=<capacity res> [first=<op>] [last=<op>]
+sync id=<name> ops=<op,op,...>
+energy instrument=<none|name> [boundary=<wall|gpu_module|soc>] [joules=<J> prov=measured src=<receipt>] [power_w=<W> prov=synthetic]
+removed op=<id> reason=<eliminated|reused|unchanged_dep|deferred|moved|shared|lookup> [ref=<op or result identity>] [proof=<src>]
+```
+
+Semantics the evaluator is allowed to rely on:
+
+- `machine`, `build`, `calibration` appear once. Every `measured` or `fitted` value is
+ valid only inside the calibration's validity envelope: the evaluator takes an
+ `asof` date and refuses (`REFUSED_STALE`) when `asof > taken + valid_days`, and refuses
+ (`REFUSED_NO_CALIBRATION`) when a measured or fitted value appears without a
+ `calibration` record. `load1` is the host load during the measurement; it travels with
+ every result so a loaded-box number is never quoted as a quiet-box number.
+- `resource kind=compute slots=n`: n operations may run at once on this engine. A
+ compute resource is a CPU core pool or the GPU; the schema does not model SM-level
+ occupancy.
+- `resource kind=bandwidth cap=B`: a shared fluid pipe. k operations streaming at once
+ each get `cap/k` (processor sharing). This is the only contention rule in v1; it is
+ what makes "sum of concurrent full-bandwidth claims" impossible by construction.
+- `resource kind=capacity`: a byte ledger. CPU and GPU unified memory are ONE capacity
+ resource on the Spark; a file that declares two for the same DRAM is wrong, not refused
+ (the evaluator cannot know), so the convention is one `unified_mem` resource.
+- `resource kind=launch`: a serial queue. Launch cost is paid once per op, one op at a
+ time per launch resource, before the op's own work. It is additive only when serialized;
+ two engines with two launch resources overlap their launches.
+- `op`: `t_ns` is the operation's own busy time on its engine (compute floor, `F/P`).
+ `bytes`/`bw` is its traffic on a bandwidth resource (traffic floor, `Q/B`). The op's
+ ideal floor is `launch + max(t_ns, bytes/cap)`; v1 assumes perfect overlap of its own
+ compute and traffic inside one op (the issue's stated floor). `kind=barrier` has no
+ cost and only orders. `kind=matvec` with `M`,`N`,`core`,`arm` and no `t_ns` gets its
+ `t_ns`, `lo`, `hi` from `rx_costmodel` (`rx_cm_predict`) using the blob named by
+ `calibration model=`; if that cell is not `known`, the op is `unknown` and the DAG is
+ refused. `kind=storage` and `kind=persist` are ops whose `bw` is a storage resource.
+- `dep a b`: b starts after a ends. Cycles are refused.
+- `buffer`: live from the start of `first` to the end of `last`. Missing `first` means
+ live from t=0 (resident state); missing `last` means live until the end. The occupied
+ interval is half-open `[start, end)`: live at time t when `start <= t < end`. `start`
+ is the scheduled start of `first` (or 0); `end` is the scheduled end of `last` (or the
+ makespan). `end == start` is empty (a zero-duration operation or buffer): it contributes
+ no live bytes and cannot offset another buffer. `end` earlier than `start` is inverted:
+ the evaluator refuses `REFUSED_LIFETIME` before any capacity certificate or ranking,
+ naming the buffer, both endpoint operations (`omitted` when the field is absent) and the
+ resolved times. At one timestamp, frees of intervals that started earlier are applied
+ before allocations, so a buffer that ends when another starts does not occupy both
+ (completion/allocation tie). An accepted ledger never goes negative. Peak live bytes
+ per capacity resource must not exceed `cap`, else `REFUSED_CAPACITY` naming the time
+ and the buffers. No frozen field was added; this is the interval convention for the
+ words already in v1.
+- `sync id=X ops=a,b,...`: declares a barrier op `X` (no cost, no engine) that completes
+ when every listed op has completed. Order later work after it with `dep X y`. A barrier
+ with a measured cost is written as `op id=X kind=barrier t_ns=... prov=...` plus `dep` lines.
+- `energy`: `instrument=none` makes every energy figure `UNMEASURED`. A named instrument
+ with `joules` and a receipt is a measured whole-run figure for the named boundary; the
+ evaluator never splits it per op. `power_w` with `prov=synthetic` allows a labelled
+ sensitivity figure `E = P * T` that is never ranked as real energy. `TDP` is not an
+ instrument.
+- `removed`: minimum-work accounting (parent clarification). An op listed here is absent
+ from the transformed DAG; the record keeps why. `reused`/`lookup` need `ref=`; a
+ remaining op that depends on a removed op whose reason is not `reused`/`lookup` is a
+ refusal (`REFUSED_REMOVED_REQUIRED`: required work cannot be removed by assertion).
+
+## What a result must carry
+
+Every evaluator output names: schema version, `machine.id`, `build.sha`,
+`calibration.id` and `load1`, `asof`, the status (`OK`, `REFUSED_*`), the set of
+provenances that fed the result, makespan nominal/lo/hi, the critical-path bound and each
+resource-work bound (both must be <= makespan), peak live bytes, energy status, the
+attribution ledger (compute, bandwidth, contention, launch, serialization, sync,
+residual), and the counterfactual sensitivities. A result whose inputs include
+`synthetic` is marked `synthetic=1`. A result never contains a number for an `unknown`
+input.
+
+## Pinned sources for v1 fixtures
+
+- Spark host `spark-b87b`, GB10, 20 cores, 128 GiB unified memory (specified), DRAM
+ 273 GB/s (specified).
+- M1 hardware passport, omega-mv#578, receipts `~/yardsticks/aien-model/M1/` (measured,
+ load 15 to 29, omega f4a9849f ): block1 realization call path 19.4 to 22.8 us per call;
+ block2 GPU submit lifecycle 36.8 to 41.6 ms per job (fixed, size independent); block4
+ CPU memcpy 1 thread 17.1 to 18.5 GB/s read+write at 1 GB, 8 threads 60.8 to 69.8 GB/s
+ at 1 GB; GPU weight stream 218.6 GB/s from handoff 2026-10-19-qwen38-decode-speed.md
+ (not re-measured in M1).
+- Not available on 2026-10-19 and therefore `unknown` in every fixture: aien-architecture
+ #244 traces, #252 clock calibration, #253 hardware atlas, #274 lifetime maps (all
+ NOT_RUN at the time of freezing). Fixtures that need them refuse.
+
+## Where the evaluator lives
+
+`tools/dagsim` is the OEV1 consumer. It was not on the default branch: the only
+implementation was closed, unmerged PR #590 (`research/cost-sim-583`, commit
+`3bd56731c5517e2a9c8f195955c71e73dc6f9269 `). That branch is gone from origin; the
+pull ref still serves the commit. This tree carries that evaluator plus the
+lifetime refusal above. Held-out measurement receipts, `measure.sh` and the memcpy
+probe from that PR are not part of this tree.
+
+The seeded `.om` replacement of this evaluator is not done. #599 owns that
+replacement. Until it is qualified and this C is removed, `tools/dagsim` is the
+active checker. A host pass is not a chip qualification and is not a performance
+claim.
diff --git a/tests/.crumb b/tests/.crumb
index 75dbe23b9 ..d307aec83 100644
--- a/tests/.crumb
+++ b/tests/.crumb
@@ -110,206 +110,206 @@
"children": [
{
"digest": "2c1deaaa1bae6257789749edde641df61413250fe91ce6aa61a99dfb3b271306 ",
- "last_commit": "28911be7a ",
+ "last_commit": "d863780eb ",
"name": "algebra",
"purpose": "Directory tests/algebra. Purpose not yet described by a human."
},
{
"digest": "63f086b68bb9ffc032cbd74931309ab34df3c8c341b57935e5db43d8bf475800 ",
- "last_commit": "834ee93e4 ",
+ "last_commit": "d863780eb ",
"name": "ans",
"purpose": "Tests 1-10 for ANS (docs/ans/INERTIAL_ALIGNMENT_SPEC_V1.md): freeze/digest, hostile reference mu"
},
{
"digest": "7b69a19958c5a5f55bba4fbc33bc6f26423358efd46311b0eacfe83bb665d4c1 ",
- "last_commit": "1b0e2968c ",
+ "last_commit": "450bbefd4 ",
"name": "brownian",
"purpose": "Directory tests/brownian. Purpose not yet described by a human."
},
{
"digest": "1cd97575b2b10d9313ca0df4997391612056754778bb2851bf052c146144f15e ",
- "last_commit": "30bb116cc ",
+ "last_commit": "d863780eb ",
"name": "canonicalization",
"purpose": "Directory tests/canonicalization. Purpose not yet described by a human."
},
{
"digest": "088f526f8cae115209dd0162f28669812483ce5c926e41e8810dada1eefcb81a ",
- "last_commit": "1edf41a5c ",
+ "last_commit": "450bbefd4 ",
"name": "compiler",
"purpose": "Directory tests/compiler. Purpose not yet described by a human."
},
{
"digest": "9e372cfc9747befacdcf31bc8643356aaff861e81ee6640b4866170be67b5e6c ",
- "last_commit": "28b87934b ",
+ "last_commit": "d863780eb ",
"name": "constraints",
"purpose": "Directory tests/constraints. Purpose not yet described by a human."
},
{
"digest": "87a3efa5cd0aefa7821046f9a31594bfa0a109e95005a1e12f40c99a1bc6cd3d ",
- "last_commit": "49abb0247 ",
+ "last_commit": "d863780eb ",
"name": "crumbline",
"purpose": "Directory tests/crumbline. Purpose not yet described by a human."
},
{
"digest": "10aa3424eded7768fee0bae0eedd062b9deac3279d2e5721439fd024493bc42b ",
- "last_commit": "00f54b6b1 ",
+ "last_commit": "d863780eb ",
"name": "dual_experiment",
"purpose": "Tests for the DUAL applicability experiment: determinism (same seed, byte-identical results dige"
},
{
"digest": "758dde696afa847d9347fad76b0c4935e968f8af4551f0f9810ec2a37ad9847a ",
- "last_commit": "c819b3762 ",
+ "last_commit": "d863780eb ",
"name": "effect",
"purpose": "Directory tests/effect. Purpose not yet described by a human."
},
{
"digest": "23e559d13ff664995baca31dc157a8cf5a860615f3ecb07a9a40fe4626b57ae3 ",
- "last_commit": "1a147e40f ",
+ "last_commit": "d863780eb ",
"name": "estimation",
"purpose": "Directory tests/estimation. Purpose not yet described by a human."
},
{
"digest": "b7b6391caf653c76707a21f9969126abcbc730d1243259219225fdb9bc0084e0 ",
- "last_commit": "3108fc2f5 ",
+ "last_commit": "d863780eb ",
"name": "fabric",
"purpose": "Directory tests/fabric. Purpose not yet described by a human."
},
{
"digest": "defc52a44ea0f65ba5de3468de786148ba58d292ffa217fb95629a28a569a977 ",
- "last_commit": "28b87934b ",
+ "last_commit": "d863780eb ",
"name": "identity",
"purpose": "Directory tests/identity. Purpose not yet described by a human."
},
{
"digest": "6ba43d622b712a4215767cab29425016f29cce4b28eb9e4961fc67fd20e9d765 ",
- "last_commit": "4f55f45ed ",
+ "last_commit": "d863780eb ",
"name": "language",
"purpose": "Directory tests/language. Purpose not yet described by a human."
},
{
"digest": "54f43a3416595ff5d4e64bd12afe013359e706651c39c78e2896a5799638d263 ",
- "last_commit": "30bb116cc ",
+ "last_commit": "d863780eb ",
"name": "malformed",
"purpose": "Directory tests/malformed. Purpose not yet described by a human."
},
{
"digest": "a03a4dd9a72f7b449342e562f6d9df1a3348fb03fb640b662956caf163dcd7e9 ",
- "last_commit": "40d1ea378 ",
+ "last_commit": "d863780eb ",
"name": "numeric_native",
"purpose": "Simulated M16 driver for numeric resource-lifecycle tests. No device execution or numeric parity"
},
{
"digest": "d958af5413726ddc48a47721800d9766939129f480b26492332ba094577837cb ",
- "last_commit": "6d8d92adc ",
+ "last_commit": "d863780eb ",
"name": "osh",
"purpose": "osh lexer host driver, vendored aien-protocols PR#16 draft vectors (5ae5292 )"
},
{
"digest": "65e84051bb8dc00b180c6b06bec58103773785eebd6d6c69c9783de5fd0e2ba9 ",
- "last_commit": "d550b705b ",
+ "last_commit": "450bbefd4 ",
"name": "path",
"purpose": "Directory tests/path. Purpose not yet described by a human."
},
{
"digest": "51f14936b27d3d21379cf05ea1b6b532cf3175a40844dac85f023a61e7a0912c ",
- "last_commit": "5901baa51 ",
+ "last_commit": "d863780eb ",
"name": "physics0",
"purpose": "PD-0 gates: world self-test, oracle calibration, learner L0/L1/NULL, mutations, OSC differential"
},
{
"digest": "c8524317c751fa8f464cabc31b760cef262abba822f1843482a02e239daa81b3 ",
- "last_commit": "61c094113 ",
+ "last_commit": "d863780eb ",
"name": "polyglot",
"purpose": "Directory tests/polyglot. Purpose not yet described by a human."
},
{
"digest": "6569e2cd6dbf6f792edb5d83bf0715df9dece42ca7bd9b3a291535de0492d3aa ",
- "last_commit": "3c82389f7 ",
+ "last_commit": "d863780eb ",
"name": "program",
"purpose": "Directory tests/program. Purpose not yet described by a human."
},
{
"digest": "c549b5b82fd026d664b35e4b1a5d7fd2aaafa13b60b541cfbba87d7522517b1d ",
- "last_commit": "6fdc4c33a ",
+ "last_commit": "d863780eb ",
"name": "r16_inventory",
"purpose": "Directory tests/r16_inventory. Purpose not yet described by a human."
},
{
"digest": "855bd23e4c526fb49eeb430c4ea5967d3f2f9da3a5b3aa3ec9dae5b814b11a21 ",
- "last_commit": "46b9cad0d ",
+ "last_commit": "d863780eb ",
"name": "r16_negative",
"purpose": "Directory tests/r16_negative. Purpose not yet described by a human."
},
{
"digest": "f21be04969cbf51de17118c4f81b103f712db56fd517a1f12dd0d3ac4ff3afe4 ",
- "last_commit": "44d8c06c3 ",
+ "last_commit": "d863780eb ",
"name": "r16_surface",
"purpose": "Directory tests/r16_surface. Purpose not yet described by a human."
},
{
"digest": "b0ba3448394d5f27958c38b7233ae389e5e437e327f0859749a774fb252d6b02 ",
- "last_commit": "40d1ea378 ",
+ "last_commit": "d863780eb ",
"name": "realize",
"purpose": "Directory tests/realize. Purpose not yet described by a human."
},
{
"digest": "157018d66de5bfd149015654cf0bda1346a9cfcefe5fd552c1d54859cd9ece81 ",
- "last_commit": "30bb116cc ",
+ "last_commit": "d863780eb ",
"name": "relations",
"purpose": "Directory tests/relations. Purpose not yet described by a human."
},
{
"digest": "e5f68362c083510e34c41f65de3ba2d553eac8a52fbc3e4cc1f69314eac9cc32 ",
- "last_commit": "dd67f6bd7 ",
+ "last_commit": "d863780eb ",
"name": "reservoir",
"purpose": "Reservoir tests (omega#440): Gate 1 simulator and readout checks against an independent binary64"
},
{
"digest": "10d19641e4bb5b435ec6363d4ea7d3c1596af47d97b86f4de35d6ae57770241e ",
- "last_commit": "501d555cf ",
+ "last_commit": "45f7d7691 ",
"name": "runtime",
"purpose": "Directory tests/runtime. Purpose not yet described by a human."
},
{
"digest": "467652c09505ecbd82d96a5e0e7ea24b19d9216cfd1dad7c60fa8258e47594c0 ",
- "last_commit": "5ae192a43 ",
+ "last_commit": "d863780eb ",
"name": "searchtrace",
"purpose": "Directory tests/searchtrace. Purpose not yet described by a human."
},
{
"digest": "e69616ad471704066a86bf2796776301179eada5c0aa36a7166b9aca788619f4 ",
- "last_commit": "",
+ "last_commit": "ed8de5736 ",
"name": "synapse",
"purpose": "J1 parity driver for syn_codec.osc against the sealed Rust A1 corpus (aien-dev/synapse j1-codec-"
},
{
"digest": "5c97916fbf20310eff2e502c526337cb093e912cb48f18d44b0345ed8a3c3240 ",
- "last_commit": "54826a37f ",
+ "last_commit": "d863780eb ",
"name": "train",
"purpose": "Directory tests/train. Purpose not yet described by a human."
},
{
"digest": "7679bd1c49c7e89d8c26ccf8dfb91478f4e6e2f584745806fa8d26061dbdbb9c ",
- "last_commit": "2564f57a9 ",
+ "last_commit": "d863780eb ",
"name": "turing",
"purpose": "Directory tests/turing. Purpose not yet described by a human."
},
{
"digest": "930fcb9ce348c604424e5380796a77c3586a835b43d42b504325c36b12d166d7 ",
- "last_commit": "fed4f0775 ",
+ "last_commit": "450bbefd4 ",
"name": "visor",
"purpose": "Directory tests/visor. Purpose not yet described by a human."
}
],
"children_root": "sha256:0c57282ff8cf1d34e5685e2729755f2978917e66debb5423961033be9d25c902 ",
- "compiled_at": "2026-10-29T19:08:03Z",
+ "compiled_at": "2026-10-30T11:22:00Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:ea8ae97d49edc85af090218634c9bad13bcc91fa84f96e0d33fefe313704e111 ",
+ "digest": "sha256:b40704fb33f20ab87c728ac9534e2a807c17d649106f5392f0db651e9caf4858 ",
"evidence_files": 16,
"evidence_root": "sha256:96d08097822ad95f4e562c19e0ba5df5a035774c48632f1832912c40a27bd27a ",
- "files": 1375,
- "generated_at_commit": "8975287573f284dd2140b2f2b169619d3e145cf1 ",
- "source_tree": "sha256:9548bc14096907b8a9ba4a0fd5092c442bf89f226c142a117753bb5ce59dc206 "
+ "files": 1391,
+ "generated_at_commit": "efd5146042b83a1fc490f120b914e8922adce540 ",
+ "source_tree": "sha256:cacb3ec7aaf8228f637b64c457b41491fe3c6108f09b1a3427caba29066d1731 "
},
"owner_lane": "",
"provenance": {
diff --git a/tests/dagsim/dagsim_unit.c b/tests/dagsim/dagsim_unit.c
new file mode 100644
index 000000000 ..fcfe46cd2
--- /dev/null
+++ b/tests/dagsim/dagsim_unit.c
@@ -0,0 +1,595 @@
+/*
+ * dagsim_unit -- analytical tests for the offline resource-DAG evaluator
+ * (omega-mv#583 acceptance, first box). Any host, no GPU.
+ *
+ * Every case is a DAG whose answer is known by hand. The evaluator must
+ * produce exactly that number (to 1 ns), the same number twice, and never a
+ * makespan below its own bounds.
+ */
+#include "dagsim.h"
+#include "runtime/rx_costmodel.h"
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static int g_checks, g_fail;
+#define CHECK(cond, ...) do { \
+ g_checks++; \
+ if (!(cond)) { \
+ g_fail++; \
+ fprintf(stderr, " FAIL %s:%d ", __FILE__, __LINE__); \
+ fprintf(stderr, __VA_ARGS__); \
+ fputc('\n', stderr); \
+ } \
+ } while (0)
+#define NEAR(a, b, tol) (fabs((a) - (b)) <= (tol))
+
+static const char *HDR =
+ "oev version=1\n"
+ "machine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test\n"
+ "build repo=omega-mv sha=0000000000000000000000000000000000000000 \n"
+ "calibration id=c1 taken=2026-10-19 valid_days=30 load1=1.0 src=test\n"
+ "resource id=mem kind=capacity cap=1000 prov=specified src=test\n"
+ "energy instrument=none\n";
+
+static int eval_text(const char *body, ds_model *m, ds_result *r, const ds_opts *o) {
+ char text[8192], err[256];
+ snprintf(text, sizeof text, "%s%s", HDR, body);
+ int rc = ds_parse_text(text, m, err, sizeof err);
+ if (rc != DS_OK) { fprintf(stderr, " parse: %s\n", err); r->status = rc; return rc; }
+ ds_opts def; memset(&def, 0, sizeof def);
+ def.asof_day = ds_day_from_date("2026-10-20");
+ def.interval_q = 0.9;
+ rc = ds_eval(m, o ? o : &def, r);
+ /* invariants every OK result must satisfy */
+ if (rc == DS_OK) {
+ CHECK(r->makespan_ns + 1e-6 >= r->bound_ns, "makespan %.1f below bound %.1f", r->makespan_ns, r->bound_ns);
+ CHECK(r->makespan_ns + 1e-6 >= r->bound_critical_path_ns, "below critical path bound");
+ double s = 0; for (int i = 0; i < DS_ATTR_N; i++) s += r->attr_ns[i];
+ CHECK(NEAR(s, r->makespan_ns, 1e-6), "attribution %.3f does not sum to makespan %.3f", s, r->makespan_ns);
+ ds_result r2; ds_eval(m, o ? o : &def, &r2);
+ CHECK(memcmp(&r2, r, sizeof r2) == 0, "not deterministic");
+ }
+ return rc;
+}
+
+static void test_serial_chain(void) {
+ ds_model m; ds_result r;
+ int rc = eval_text(
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=B kind=compute engine=cpu t_ns=20 prov=measured src=t\n"
+ "op id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\n"
+ "dep A B\ndep B C\n", &m, &r, NULL);
+ CHECK(rc == DS_OK, "serial chain status %s: %s", ds_status_name(r.status), r.reason);
+ CHECK(NEAR(r.makespan_ns, 60, 1e-9), "serial makespan %.3f", r.makespan_ns);
+ CHECK(NEAR(r.bound_critical_path_ns, 60, 1e-9), "critical path bound %.3f", r.bound_critical_path_ns);
+ CHECK(r.n_critical == 3, "critical path length %d", r.n_critical);
+ CHECK(NEAR(r.attr_ns[DS_ATTR_COMPUTE], 60, 1e-9), "compute attribution %.3f", r.attr_ns[DS_ATTR_COMPUTE]);
+ CHECK(NEAR(r.attr_ns[DS_ATTR_RESIDUAL], 0, 1e-9), "residual %.3f", r.attr_ns[DS_ATTR_RESIDUAL]);
+ CHECK(NEAR(r.start_ns[2], 30, 1e-9) && NEAR(r.end_ns[2], 60, 1e-9), "C window");
+ CHECK(r.prov_mask == (1u << DS_PROV_MEASURED | 1u << DS_PROV_SPECIFIED), "prov mask %x", r.prov_mask);
+ CHECK(r.n_ops == 3 && NEAR(r.total_busy_ns, 60, 1e-9), "conservation");
+}
+
+static void test_perfect_overlap(void) {
+ ds_model m; ds_result r;
+ int rc = eval_text(
+ "resource id=cpu kind=compute slots=4 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=B kind=compute engine=cpu t_ns=20 prov=measured src=t\n"
+ "op id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\n", &m, &r, NULL);
+ CHECK(rc == DS_OK, "overlap status %s", ds_status_name(r.status));
+ CHECK(NEAR(r.makespan_ns, 30, 1e-9), "independent overlap makespan %.3f", r.makespan_ns);
+ CHECK(NEAR(r.attr_ns[DS_ATTR_SERIALIZATION], 0, 1e-9), "no serialization when slots suffice");
+ /* same DAG, one slot: work bound 60 binds and the wait is serialization */
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=B kind=compute engine=cpu t_ns=20 prov=measured src=t\n"
+ "op id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\n", &m, &r, NULL);
+ CHECK(rc == DS_OK, "one slot status");
+ CHECK(NEAR(r.makespan_ns, 60, 1e-9), "one-slot makespan %.3f", r.makespan_ns);
+ CHECK(NEAR(r.bound_critical_path_ns, 30, 1e-9), "critical path stays 30");
+ CHECK(NEAR(r.bound_ns, 60, 1e-9), "resource bound 60, got %.3f", r.bound_ns);
+ CHECK(NEAR(r.attr_ns[DS_ATTR_SERIALIZATION], 30, 1e-9), "serialization %.3f", r.attr_ns[DS_ATTR_SERIALIZATION]);
+}
+
+static void test_shared_bandwidth(void) {
+ ds_model m; ds_result r;
+ /* two 1 GB copies on a 1 GB/s pipe, both slots free: each gets half, both end at 2 s */
+ int rc = eval_text(
+ "resource id=cpu kind=compute slots=2 prov=specified src=test\n"
+ "resource id=pipe kind=bandwidth cap=1e9 prov=measured src=t\n"
+ "op id=A kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\n"
+ "op id=B kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\n", &m, &r, NULL);
+ CHECK(rc == DS_OK, "bw status %s: %s", ds_status_name(r.status), r.reason);
+ CHECK(NEAR(r.makespan_ns, 2e9, 1e-3), "two concurrent full-bandwidth claims must not sum: %.0f", r.makespan_ns);
+ CHECK(NEAR(r.end_ns[0], 2e9, 1e-3) && NEAR(r.end_ns[1], 2e9, 1e-3), "both end at 2 s");
+ CHECK(NEAR(r.op_contention_ns[0], 1e9, 1e-3), "A contention %.0f", r.op_contention_ns[0]);
+ CHECK(NEAR(r.bound_critical_path_ns, 1e9, 1e-3), "cp bound 1 s");
+ CHECK(NEAR(r.bound_ns, 2e9, 1e-3), "pipe work bound 2 s, got %.0f", r.bound_ns);
+ CHECK(NEAR(r.attr_ns[DS_ATTR_BANDWIDTH] + r.attr_ns[DS_ATTR_CONTENTION], 2e9, 1e-3), "bw+contention = 2 s");
+ CHECK(NEAR(r.attr_ns[DS_ATTR_CONTENTION], 1e9, 1e-3), "contention attributed 1 s, got %.0f", r.attr_ns[DS_ATTR_CONTENTION]);
+ /* unequal: B is half the size; it finishes at 1 s, A at 1.5 s */
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=2 prov=specified src=test\n"
+ "resource id=pipe kind=bandwidth cap=1e9 prov=measured src=t\n"
+ "op id=A kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\n"
+ "op id=B kind=copy engine=cpu bytes=5e8 bw=pipe prov=measured src=t\n", &m, &r, NULL);
+ CHECK(rc == DS_OK, "bw2 status");
+ CHECK(NEAR(r.end_ns[1], 1e9, 1e-3), "B ends at 1 s, got %.0f", r.end_ns[1]);
+ CHECK(NEAR(r.end_ns[0], 1.5e9, 1e-3), "A ends at 1.5 s, got %.0f", r.end_ns[0]);
+ /* compute and traffic inside one op overlap: floor is max(F/P, Q/B) */
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "resource id=pipe kind=bandwidth cap=1e9 prov=measured src=t\n"
+ "op id=A kind=compute engine=cpu t_ns=5e8 bytes=1e9 bw=pipe prov=measured src=t\n", &m, &r, NULL);
+ CHECK(rc == DS_OK && NEAR(r.makespan_ns, 1e9, 1e-3), "max(F/P,Q/B) floor, got %.0f", r.makespan_ns);
+ CHECK(NEAR(r.op_floor_ns[0], 1e9, 1e-3), "op floor");
+ /* a compute-bound op streaming alone has no contention, whatever its busy time */
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "resource id=pipe kind=bandwidth cap=1e9 prov=measured src=t\n"
+ "op id=A kind=compute engine=cpu t_ns=4e9 bytes=1e9 bw=pipe prov=measured src=t\n", &m, &r, NULL);
+ CHECK(rc == DS_OK && NEAR(r.makespan_ns, 4e9, 1e-3) && NEAR(r.op_contention_ns[0], 0, 1e-3),
+ "compute-bound op alone: contention %.0f (want 0)", r.op_contention_ns[0]);
+ CHECK(NEAR(r.attr_ns[DS_ATTR_COMPUTE], 4e9, 1e-3), "attributed as compute");
+ /* serialized sharing: one slot, so no contention and makespan = sum */
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "resource id=pipe kind=bandwidth cap=1e9 prov=measured src=t\n"
+ "op id=A kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\n"
+ "op id=B kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\n", &m, &r, NULL);
+ CHECK(rc == DS_OK && NEAR(r.makespan_ns, 2e9, 1e-3) && NEAR(r.attr_ns[DS_ATTR_CONTENTION], 0, 1e-3),
+ "serialized copies: no contention, makespan %.0f contention %.0f", r.makespan_ns, r.attr_ns[DS_ATTR_CONTENTION]);
+}
+
+static void test_capacity_refusal(void) {
+ ds_model m; ds_result r;
+ int rc = eval_text(
+ "resource id=cpu kind=compute slots=2 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "buffer id=x bytes=600 cap=mem first=A last=A\n"
+ "buffer id=y bytes=600 cap=mem first=A last=A\n", &m, &r, NULL);
+ CHECK(rc == DS_REFUSED_CAPACITY, "1200 live bytes in 1000 must refuse, got %s", ds_status_name(rc));
+ CHECK(strstr(r.reason, "x") && strstr(r.reason, "y"), "reason names the buffers: %s", r.reason);
+ /* same buffers, disjoint lifetimes: fits */
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=2 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=B kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "dep A B\n"
+ "buffer id=x bytes=600 cap=mem first=A last=A\n"
+ "buffer id=y bytes=600 cap=mem first=B last=B\n", &m, &r, NULL);
+ CHECK(rc == DS_OK, "disjoint lifetimes fit, got %s: %s", ds_status_name(rc), r.reason);
+ CHECK(NEAR(r.peak_live_bytes[0], 600, 1e-9), "peak 600, got %.0f", r.peak_live_bytes[0]);
+ /* a single buffer larger than the ledger refuses before any scheduling */
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=2 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "buffer id=big bytes=2000 cap=mem\n", &m, &r, NULL);
+ CHECK(rc == DS_REFUSED_CAPACITY, "oversized resident buffer refuses");
+}
+
+static void test_lifetimes(void) {
+ ds_model m; ds_result r;
+ int rc = eval_text(
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=B kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=C kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "dep A B\ndep B C\n"
+ "buffer id=resident bytes=100 cap=mem\n"
+ "buffer id=x bytes=300 cap=mem first=A last=B\n"
+ "buffer id=y bytes=400 cap=mem first=B last=C\n", &m, &r, NULL);
+ CHECK(rc == DS_OK, "lifetimes status %s: %s", ds_status_name(rc), r.reason);
+ CHECK(NEAR(r.peak_live_bytes[0], 800, 1e-9), "peak = resident + x + y during B, got %.0f", r.peak_live_bytes[0]);
+ CHECK(NEAR(r.peak_live_at_ns[0], 10, 1e-9), "peak reached when B starts, got %.1f", r.peak_live_at_ns[0]);
+}
+
+static void test_sync(void) {
+ ds_model m; ds_result r;
+ int rc = eval_text(
+ "resource id=cpu kind=compute slots=2 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=B kind=compute engine=cpu t_ns=30 prov=measured src=t\n"
+ "op id=C kind=compute engine=cpu t_ns=5 prov=measured src=t\n"
+ "sync id=s ops=A,B\n"
+ "dep s C\n", &m, &r, NULL);
+ CHECK(rc == DS_OK, "sync status %s: %s", ds_status_name(rc), r.reason);
+ int c = ds_find_op(&m, "C");
+ CHECK(c >= 0 && NEAR(r.start_ns[c], 30, 1e-9), "C waits for the slower of A,B: start %.1f", c >= 0 ? r.start_ns[c] : -1);
+ CHECK(NEAR(r.makespan_ns, 35, 1e-9), "sync makespan %.1f", r.makespan_ns);
+ /* a barrier with a declared cost is attributed as sync */
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=2 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=B kind=compute engine=cpu t_ns=30 prov=measured src=t\n"
+ "op id=fence kind=barrier t_ns=7 prov=measured src=t\n"
+ "op id=C kind=compute engine=cpu t_ns=5 prov=measured src=t\n"
+ "dep A fence\ndep B fence\ndep fence C\n", &m, &r, NULL);
+ CHECK(rc == DS_OK && NEAR(r.makespan_ns, 42, 1e-9), "costed barrier makespan %.1f", r.makespan_ns);
+ CHECK(NEAR(r.attr_ns[DS_ATTR_SYNC], 7, 1e-9), "sync attribution %.1f", r.attr_ns[DS_ATTR_SYNC]);
+}
+
+static void test_launch(void) {
+ ds_model m; ds_result r;
+ /* two jobs, one launcher, one slot: launches serialize, 80 ms */
+ int rc = eval_text(
+ "resource id=gpu kind=compute slots=1 prov=specified src=test\n"
+ "resource id=L kind=launch prov=measured src=t\n"
+ "op id=A kind=compute engine=gpu t_ns=0 launch_ns=40e6 launcher=L prov=measured src=t\n"
+ "op id=B kind=compute engine=gpu t_ns=0 launch_ns=40e6 launcher=L prov=measured src=t\n", &m, &r, NULL);
+ CHECK(rc == DS_OK && NEAR(r.makespan_ns, 80e6, 1e-3), "serialized launches add: %.0f", r.makespan_ns);
+ CHECK(NEAR(r.attr_ns[DS_ATTR_LAUNCH] + r.attr_ns[DS_ATTR_SERIALIZATION], 80e6, 1e-3), "launch+serialization");
+ /* two engines, two launchers: launches overlap, 40 ms */
+ rc = eval_text(
+ "resource id=gpu kind=compute slots=1 prov=specified src=test\n"
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "resource id=L1 kind=launch prov=measured src=t\n"
+ "resource id=L2 kind=launch prov=measured src=t\n"
+ "op id=A kind=compute engine=gpu t_ns=0 launch_ns=40e6 launcher=L1 prov=measured src=t\n"
+ "op id=B kind=compute engine=cpu t_ns=0 launch_ns=40e6 launcher=L2 prov=measured src=t\n", &m, &r, NULL);
+ CHECK(rc == DS_OK && NEAR(r.makespan_ns, 40e6, 1e-3), "independent launches overlap: %.0f", r.makespan_ns);
+}
+
+static void test_calibration(void) {
+ ds_model m; ds_result r; char text[4096], err[256];
+ const char *body =
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n";
+ /* stale: asof past taken + valid_days */
+ ds_opts o; memset(&o, 0, sizeof o); o.interval_q = 0.9;
+ o.asof_day = ds_day_from_date("2026-11-19");
+ int rc = eval_text(body, &m, &r, &o);
+ CHECK(rc == DS_REFUSED_STALE, "31 days after a 30-day calibration refuses, got %s", ds_status_name(rc));
+ o.asof_day = ds_day_from_date("2026-11-18");
+ rc = eval_text(body, &m, &r, &o);
+ CHECK(rc == DS_OK, "last valid day is fine, got %s", ds_status_name(rc));
+ /* missing: measured value without a calibration record */
+ snprintf(text, sizeof text,
+ "oev version=1\n"
+ "machine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test\n"
+ "build repo=omega-mv sha=0000000000000000000000000000000000000000 \n"
+ "energy instrument=none\n%s", body);
+ rc = ds_parse_text(text, &m, err, sizeof err);
+ CHECK(rc == DS_OK, "parse without calibration: %s", err);
+ o.asof_day = ds_day_from_date("2026-10-20");
+ rc = ds_eval(&m, &o, &r);
+ CHECK(rc == DS_REFUSED_NO_CALIBRATION, "measured without calibration refuses, got %s", ds_status_name(rc));
+ /* unknown provenance never becomes a number */
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=B kind=compute engine=cpu prov=unknown src=arch-244-not-run\n"
+ "dep A B\n", &m, &r, NULL);
+ CHECK(rc == DS_REFUSED_UNKNOWN, "unknown op refuses, got %s", ds_status_name(rc));
+ CHECK(strstr(r.reason, "B") != NULL, "reason names the op: %s", r.reason);
+ CHECK(r.makespan_ns == 0, "no makespan on refusal");
+ /* synthetic input marks the result */
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=synthetic src=t\n", &m, &r, NULL);
+ CHECK(rc == DS_OK && r.synthetic == 1, "synthetic flag");
+}
+
+static void test_intervals(void) {
+ ds_model m; ds_result r; double lo, hi;
+ char text[8192];
+ snprintf(text, sizeof text, "%s%s", HDR,
+ "resource id=cpu kind=compute slots=2 prov=specified src=test\n"
+ "resource id=pipe kind=bandwidth cap=1e9 lo=0.5e9 hi=2e9 prov=measured src=t\n"
+ "op id=A kind=compute engine=cpu t_ns=100 lo=80 hi=150 prov=measured src=t\n"
+ "op id=B kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\n"
+ "dep A B\n");
+ char err[256];
+ CHECK(ds_parse_text(text, &m, err, sizeof err) == DS_OK, "parse: %s", err);
+ ds_opts o; memset(&o, 0, sizeof o); o.asof_day = ds_day_from_date("2026-10-20"); o.interval_q = 0.9;
+ int rc = ds_eval_interval(&m, &o, &r, &lo, &hi);
+ CHECK(rc == DS_OK, "interval status");
+ CHECK(NEAR(r.makespan_ns, 100 + 1e9, 1e-3), "nominal %.0f", r.makespan_ns);
+ CHECK(NEAR(lo, 80 + 0.5e9, 1e-3), "optimistic %.0f", lo);
+ CHECK(NEAR(hi, 150 + 2e9, 1e-3), "pessimistic %.0f", hi);
+}
+
+static void test_energy(void) {
+ ds_model m; ds_result r; char text[4096], err[256];
+ int rc = eval_text(
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=1e9 prov=measured src=t\n", &m, &r, NULL);
+ CHECK(rc == DS_OK && !r.energy_measured && !r.energy_synthetic, "instrument=none means UNMEASURED");
+ snprintf(text, sizeof text,
+ "oev version=1\n"
+ "machine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test\n"
+ "build repo=omega-mv sha=0000000000000000000000000000000000000000 \n"
+ "calibration id=c1 taken=2026-10-19 valid_days=30 load1=1.0 src=test\n"
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=1e9 prov=measured src=t\n"
+ "energy instrument=tdp-guess boundary=soc power_w=100 prov=synthetic\n");
+ CHECK(ds_parse_text(text, &m, err, sizeof err) == DS_OK, "parse: %s", err);
+ ds_opts o; memset(&o, 0, sizeof o); o.asof_day = ds_day_from_date("2026-10-20"); o.interval_q = 0.9;
+ rc = ds_eval(&m, &o, &r);
+ CHECK(rc == DS_OK && r.energy_synthetic == 1 && !r.energy_measured && NEAR(r.energy_j, 100.0, 1e-9) && r.synthetic,
+ "synthetic power gives a labelled E=P*T (100 J), got %.3f syn=%d", r.energy_j, r.energy_synthetic);
+ snprintf(text, sizeof text,
+ "oev version=1\n"
+ "machine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test\n"
+ "build repo=omega-mv sha=0000000000000000000000000000000000000000 \n"
+ "calibration id=c1 taken=2026-10-19 valid_days=30 load1=1.0 src=test\n"
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=1e9 prov=measured src=t\n"
+ "energy instrument=cyberpower-ups-nut boundary=wall joules=42.5 prov=measured src=receipt.json\n");
+ CHECK(ds_parse_text(text, &m, err, sizeof err) == DS_OK, "parse: %s", err);
+ rc = ds_eval(&m, &o, &r);
+ CHECK(rc == DS_OK && r.energy_measured == 1 && NEAR(r.energy_j, 42.5, 1e-9) && !r.synthetic, "measured joules pass through");
+ /* a measured joules figure with no instrument name is a parse error */
+ snprintf(text, sizeof text,
+ "oev version=1\n"
+ "machine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test\n"
+ "build repo=omega-mv sha=0000000000000000000000000000000000000000 \n"
+ "energy instrument=none joules=42.5 prov=measured src=x\n");
+ CHECK(ds_parse_text(text, &m, err, sizeof err) == DS_PARSE_ERROR, "joules without an instrument is refused at parse");
+}
+
+static void test_parse_and_cycles(void) {
+ ds_model m; ds_result r; char text[4096], err[256];
+ snprintf(text, sizeof text, "%s%s", HDR, "resource id=cpu kind=compute slots=1 prov=specified src=test\nbogus x=1\n");
+ int rc = ds_parse_text(text, &m, err, sizeof err);
+ CHECK(rc == DS_PARSE_ERROR && strstr(err, "line 8"), "unknown keyword is an error with its line: %s", err);
+ snprintf(text, sizeof text, "%s%s", HDR, "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=1 prov=measured src=t typo=3\n");
+ rc = ds_parse_text(text, &m, err, sizeof err);
+ CHECK(rc == DS_PARSE_ERROR, "unknown field is an error: %s", err);
+ snprintf(text, sizeof text, "%s%s", HDR, "resource id=cpu kind=compute slots=1 prov=specified src=test\nop id=A kind=compute engine=cpu t_ns=1 src=t\n");
+ rc = ds_parse_text(text, &m, err, sizeof err);
+ CHECK(rc == DS_PARSE_ERROR, "a number without prov is an error: %s", err);
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=1 prov=measured src=t\n"
+ "op id=B kind=compute engine=cpu t_ns=1 prov=measured src=t\n"
+ "dep A B\ndep B A\n", &m, &r, NULL);
+ CHECK(rc == DS_REFUSED_CYCLE, "cycle refuses, got %s", ds_status_name(rc));
+ /* the pinned fixture parses and evaluates */
+ rc = ds_parse_file("tests/dagsim/fixtures/m1_spark_subset.oev", &m, err, sizeof err);
+ CHECK(rc == DS_OK, "fixture parses: %s", err);
+ if (rc == DS_OK) {
+ ds_opts o; memset(&o, 0, sizeof o); o.asof_day = ds_day_from_date("2026-10-20"); o.interval_q = 0.9;
+ rc = ds_eval(&m, &o, &r);
+ CHECK(rc == DS_OK, "fixture evaluates: %s", r.reason);
+ CHECK(NEAR(r.makespan_ns, 20000 + 40736700 + 111000000 , 1e-3), "fixture serial makespan %.0f", r.makespan_ns);
+ CHECK(!r.energy_measured && !r.energy_synthetic, "fixture energy UNMEASURED");
+ }
+}
+
+/* rx_costmodel integration: a matvec op with a fitted blob gets its time from
+ * rx_cm_predict; an unknown cell refuses. Synthetic observations, so the blob is
+ * labelled fitted on synthetic data and the result is marked synthetic. */
+static void test_costmodel_reuse(void) {
+ RxCostModel cm; rx_cm_init(&cm, 2);
+ uint64_t rng = 0x9E3779B97F4A7C15ull;
+ for (int i = 0; i < 200; i++) {
+ rng ^= rng << 13; rng ^= rng >> 7; rng ^= rng << 17;
+ uint32_t M = 8 + (uint32_t)(rng % 120), N = 4 + (uint32_t)((rng >> 20) % 60);
+ RxCmFeatures f; memset(&f, 0, sizeof f);
+ f.op = RX_CM_OP_MATVEC; f.M = M; f.N = N; f.state_bytes = ((uint64_t)M * N + M + N) * 8u;
+ f.cache_bytes = 1u << 20; f.core = RX_CM_CORE_X925; f.eligible = 3;
+ double l2 = 10.0 + 0.95 * (log2((double)M) + log2((double)N));
+ RxCmObservation o; o.failed = 0; o.ps_per_call = (uint64_t)pow(2.0, l2);
+ rx_cm_observe(&cm, &f, 0, &o);
+ }
+ ds_model m; ds_result r; char text[4096], err[256];
+ snprintf(text, sizeof text, "%s%s", HDR,
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=mv kind=matvec engine=cpu M=64 N=16 core=0 arm=0 prov=fitted src=rx_costmodel\n");
+ CHECK(ds_parse_text(text, &m, err, sizeof err) == DS_OK, "parse: %s", err);
+ ds_opts o; memset(&o, 0, sizeof o); o.asof_day = ds_day_from_date("2026-10-20"); o.interval_q = 0.9;
+ int rc = ds_eval(&m, &o, &r);
+ CHECK(rc == DS_REFUSED_UNKNOWN, "matvec with no model refuses, got %s", ds_status_name(rc));
+ o.costmodel = &cm;
+ rc = ds_eval(&m, &o, &r);
+ CHECK(rc == DS_OK, "matvec with model: %s %s", ds_status_name(rc), r.reason);
+ RxCmFeatures f; memset(&f, 0, sizeof f);
+ f.op = RX_CM_OP_MATVEC; f.M = 64; f.N = 16; f.state_bytes = (64u * 16u + 64u + 16u) * 8u; f.cache_bytes = 1u << 20; f.core = 0;
+ RxCmPrediction p; rx_cm_predict(&cm, &f, 0, &p);
+ CHECK(p.known, "cell known");
+ CHECK(NEAR(r.makespan_ns, pow(2.0, p.mean_log2_ps) / 1000.0, 1e-6), "time comes from rx_cm_predict: %.3f vs %.3f", r.makespan_ns, pow(2.0, p.mean_log2_ps) / 1000.0);
+ CHECK(r.prov_mask & (1u << DS_PROV_FITTED), "fitted provenance recorded");
+ /* arm 1 was never observed: unknown, refuse */
+ snprintf(text, sizeof text, "%s%s", HDR,
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=mv kind=matvec engine=cpu M=64 N=16 core=0 arm=1 prov=fitted src=rx_costmodel\n");
+ CHECK(ds_parse_text(text, &m, err, sizeof err) == DS_OK, "parse: %s", err);
+ rc = ds_eval(&m, &o, &r);
+ CHECK(rc == DS_REFUSED_UNKNOWN, "unobserved arm refuses, got %s", ds_status_name(rc));
+}
+
+static void test_counterfactual(void) {
+ ds_model m; ds_result r;
+ int rc = eval_text(
+ "resource id=cpu kind=compute slots=2 prov=specified src=test\n"
+ "resource id=pipe kind=bandwidth cap=1e9 prov=measured src=t\n"
+ "op id=A kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\n"
+ "op id=B kind=copy engine=cpu bytes=1e9 bw=pipe prov=measured src=t\n", &m, &r, NULL);
+ CHECK(rc == DS_OK, "cf status");
+ ds_opts o; memset(&o, 0, sizeof o); o.asof_day = ds_day_from_date("2026-10-20"); o.interval_q = 0.9;
+ double d = ds_counterfactual(&m, &o, ds_find_res(&m, "pipe"));
+ CHECK(NEAR(d, 1e9, 1e-3), "doubling the pipe halves the bandwidth-bound DAG: %.0f", d);
+ d = ds_counterfactual(&m, &o, ds_find_res(&m, "cpu"));
+ CHECK(NEAR(d, 2e9, 1e-3), "doubling slots changes nothing when the pipe binds: %.0f", d);
+}
+
+static void test_minimum_work_diff(void) {
+ ds_model base, tr; ds_diff d; char text[8192], err[256];
+ const char *base_body =
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=B kind=compute engine=cpu t_ns=20 prov=measured src=t\n"
+ "op id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\n"
+ "dep A B\ndep B C\n";
+ snprintf(text, sizeof text, "%s%s", HDR, base_body);
+ CHECK(ds_parse_text(text, &base, err, sizeof err) == DS_OK, "base: %s", err);
+ ds_opts o; memset(&o, 0, sizeof o); o.asof_day = ds_day_from_date("2026-10-20"); o.interval_q = 0.9;
+ /* no change: identical transformed DAG adds no nodes and removes none */
+ CHECK(ds_parse_text(text, &tr, err, sizeof err) == DS_OK, "tr: %s", err);
+ CHECK(ds_diff_models(&base, &tr, &o, &d) == DS_OK && d.n_removed == 0 && d.n_added == 0 && d.n_kept == 3, "no-change fixture: removed %d added %d kept %d", d.n_removed, d.n_added, d.n_kept);
+ /* B reused from a lookup: valid, 20 ns of work moves to the reused ledger */
+ snprintf(text, sizeof text, "%s%s", HDR,
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=B_lookup kind=compute engine=cpu t_ns=2 prov=measured src=t\n"
+ "op id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\n"
+ "dep A B_lookup\ndep B_lookup C\n"
+ "removed op=B reason=reused ref=B_lookup proof=rx_plan:digest\n");
+ CHECK(ds_parse_text(text, &tr, err, sizeof err) == DS_OK, "tr2: %s", err);
+ int rc = ds_diff_models(&base, &tr, &o, &d);
+ CHECK(rc == DS_OK && NEAR(d.removed_ns[DS_RM_REUSED], 20, 1e-9) && d.n_added == 1, "reuse accounted: %s rc=%s", d.reason, ds_status_name(rc));
+ /* eliminated with no proof while C still consumed it: required work cannot vanish by assertion */
+ snprintf(text, sizeof text, "%s%s", HDR,
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\n"
+ "dep A C\n"
+ "removed op=B reason=eliminated\n");
+ CHECK(ds_parse_text(text, &tr, err, sizeof err) == DS_OK, "tr3: %s", err);
+ rc = ds_diff_models(&base, &tr, &o, &d);
+ CHECK(rc == DS_REFUSED_REMOVED_REQUIRED && d.required_removed, "unproven elimination of consumed work refuses, got %s", ds_status_name(rc));
+ /* unchanged_dep on A, but A changed: the consumer is invalidated */
+ snprintf(text, sizeof text, "%s%s", HDR,
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\n"
+ "dep A C\n"
+ "removed op=B reason=unchanged_dep ref=A\n");
+ CHECK(ds_parse_text(text, &tr, err, sizeof err) == DS_OK, "tr4: %s", err);
+ rc = ds_diff_models(&base, &tr, &o, &d);
+ CHECK(rc == DS_OK && NEAR(d.removed_ns[DS_RM_UNCHANGED_DEP], 20, 1e-9), "unchanged dependency allows skipping B");
+ o.changed = "A";
+ rc = ds_diff_models(&base, &tr, &o, &d);
+ CHECK(rc == DS_REFUSED_REMOVED_REQUIRED, "changed A invalidates the skip of B, got %s", ds_status_name(rc));
+ o.changed = NULL;
+ /* shared work counted twice is detected */
+ snprintf(text, sizeof text, "%s%s", HDR,
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "op id=C kind=compute engine=cpu t_ns=30 prov=measured src=t\n"
+ "dep A C\n"
+ "removed op=B reason=shared ref=A\n"
+ "removed op=B reason=shared ref=C\n");
+ CHECK(ds_parse_text(text, &tr, err, sizeof err) == DS_OK, "tr5: %s", err);
+ rc = ds_diff_models(&base, &tr, &o, &d);
+ CHECK(rc != DS_OK && d.double_counted, "double-counted shared work detected");
+}
+
+static int eval_file(const char *path, ds_model *m, ds_result *r) {
+ char err[256];
+ int rc = ds_parse_file(path, m, err, sizeof err);
+ if (rc != DS_OK) {
+ memset(r, 0, sizeof *r);
+ r->status = rc;
+ snprintf(r->reason, sizeof r->reason, "%s", err);
+ return rc;
+ }
+ ds_opts def; memset(&def, 0, sizeof def);
+ def.asof_day = ds_day_from_date("2026-10-24");
+ def.interval_q = 0.9;
+ return ds_eval(m, &def, r);
+}
+
+static double peak_of(const ds_model *m, const ds_result *r, const char *cap) {
+ int i = ds_find_res(m, cap);
+ return i < 0 ? -1.0 : r->peak_live_bytes[i];
+}
+
+/* Issue #705. An inverted lifetime must not contribute negative live bytes. */
+static void test_inverted_lifetimes(void) {
+ ds_model m; ds_result r, r2;
+ int rc = eval_file("tests/dagsim/fixtures/inverted_masks_overflow.oev", &m, &r);
+ CHECK(rc == DS_REFUSED_LIFETIME
+ && strstr(r.reason, "inverted lifetime for buffer inverted:")
+ && strstr(r.reason, "first=C") && strstr(r.reason, "start_ns=20")
+ && strstr(r.reason, "last=A") && strstr(r.reason, "end_ns=10")
+ && !strstr(r.reason, "went negative"),
+ "inverted_lifetime_masks_overflow: got %s (%s)", ds_status_name(rc), r.reason);
+ CHECK(r.makespan_ns == 0 && r.peak_live_bytes[0] == 0, "refusal carries no capacity certificate");
+ rc = eval_file("tests/dagsim/fixtures/inverted_masks_overflow.oev", &m, &r2);
+ CHECK(rc == r2.status && strcmp(r.reason, r2.reason) == 0, "rejection text is deterministic");
+
+ rc = eval_file("tests/dagsim/fixtures/inverted_lone.oev", &m, &r);
+ CHECK(rc == DS_REFUSED_LIFETIME && strstr(r.reason, "first=C") && strstr(r.reason, "last=A"),
+ "lone inverted lifetime refused, got %s (%s)", ds_status_name(rc), r.reason);
+
+ rc = eval_file("tests/dagsim/fixtures/capacity_two_80.oev", &m, &r);
+ CHECK(rc == DS_REFUSED_CAPACITY && strstr(r.reason, "real1") && strstr(r.reason, "real2"),
+ "two valid 80 B buffers refuse capacity, got %s (%s)", ds_status_name(rc), r.reason);
+
+ rc = eval_file("tests/dagsim/fixtures/valid_disjoint_80.oev", &m, &r);
+ CHECK(rc == DS_OK, "disjoint 80 B pair fits, got %s (%s)", ds_status_name(rc), r.reason);
+ CHECK(NEAR(peak_of(&m, &r, "mem"), 80, 1e-9), "disjoint peak 80, got %.1f", peak_of(&m, &r, "mem"));
+ CHECK(NEAR(r.makespan_ns, 30, 1e-9), "disjoint makespan 30, got %.1f", r.makespan_ns);
+
+ rc = eval_file("tests/dagsim/fixtures/valid_tie_80.oev", &m, &r);
+ CHECK(rc == DS_OK, "completion/allocation tie fits, got %s (%s)", ds_status_name(rc), r.reason);
+ CHECK(NEAR(peak_of(&m, &r, "mem"), 80, 1e-9), "tie peak 80 (not 160), got %.1f", peak_of(&m, &r, "mem"));
+
+ /* zero-duration: empty [start, end), peak 0, and it cannot hide an overlap */
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=Z kind=compute engine=cpu t_ns=0 prov=measured src=t\n"
+ "buffer id=z bytes=80 cap=mem first=Z last=Z\n", &m, &r, NULL);
+ CHECK(rc == DS_OK, "zero-duration buffer status %s (%s)", ds_status_name(rc), r.reason);
+ CHECK(NEAR(r.peak_live_bytes[0], 0, 1e-9), "zero-duration peak 0, got %.1f", r.peak_live_bytes[0]);
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=Z kind=compute engine=cpu t_ns=0 prov=measured src=t\n"
+ "op id=B kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "buffer id=z bytes=400 cap=mem first=Z last=Z\n"
+ "buffer id=real1 bytes=600 cap=mem first=B last=B\n"
+ "buffer id=real2 bytes=600 cap=mem first=B last=B\n", &m, &r, NULL);
+ CHECK(rc == DS_REFUSED_CAPACITY, "zero-duration must not hide 1200 B, got %s (%s)", ds_status_name(rc), r.reason);
+
+ /* omitted endpoints stay valid: resident from 0, open end, and both omitted */
+ rc = eval_text(
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "buffer id=no_first bytes=100 cap=mem last=A\n"
+ "buffer id=no_last bytes=50 cap=mem first=A\n"
+ "buffer id=resident bytes=25 cap=mem\n", &m, &r, NULL);
+ CHECK(rc == DS_OK, "omitted endpoints status %s (%s)", ds_status_name(rc), r.reason);
+ CHECK(NEAR(r.peak_live_bytes[0], 175, 1e-9), "omitted endpoints peak 175, got %.1f", r.peak_live_bytes[0]);
+
+ char text[2048], err[256];
+ snprintf(text, sizeof text, "%s%s", HDR, "buffer id=neg bytes=-5 cap=mem\n");
+ CHECK(ds_parse_text(text, &m, err, sizeof err) == DS_PARSE_ERROR && strstr(err, "finite number >= 0"),
+ "negative bytes refused at parse: %s", err);
+ snprintf(text, sizeof text, "%s%s", HDR, "buffer id=inf bytes=inf cap=mem\n");
+ CHECK(ds_parse_text(text, &m, err, sizeof err) == DS_PARSE_ERROR && strstr(err, "finite number >= 0"),
+ "non-finite bytes refused at parse: %s", err);
+ snprintf(text, sizeof text, "%s%s", HDR,
+ "resource id=cpu kind=compute slots=1 prov=specified src=test\n"
+ "op id=A kind=compute engine=cpu t_ns=10 prov=measured src=t\n"
+ "buffer id=ghost bytes=10 cap=mem first=nope last=A\n");
+ CHECK(ds_parse_text(text, &m, err, sizeof err) == DS_PARSE_ERROR && strstr(err, "not an op"),
+ "unknown endpoint refused at parse: %s", err);
+}
+
+int main(void) {
+ test_serial_chain();
+ test_perfect_overlap();
+ test_shared_bandwidth();
+ test_capacity_refusal();
+ test_lifetimes();
+ test_sync();
+ test_launch();
+ test_calibration();
+ test_intervals();
+ test_energy();
+ test_parse_and_cycles();
+ test_costmodel_reuse();
+ test_counterfactual();
+ test_minimum_work_diff();
+ test_inverted_lifetimes();
+ printf("dagsim_unit: %d checks, %d failed\n", g_checks, g_fail);
+ return g_fail ? 1 : 0;
+}
diff --git a/tests/dagsim/fixtures/capacity_two_80.oev b/tests/dagsim/fixtures/capacity_two_80.oev
new file mode 100644
index 000000000 ..c4c18c4a6
--- /dev/null
+++ b/tests/dagsim/fixtures/capacity_two_80.oev
@@ -0,0 +1,11 @@
+oev version=1
+machine id=toy soc=toy cores=1 mem_bytes=100 prov=synthetic src=analytical-fixture
+build repo=omega-mv sha=3bd56731c5517e2a9c8f195955c71e73dc6f9269
+resource id=cpu kind=compute slots=1 prov=synthetic src=analytical-fixture
+resource id=mem kind=capacity cap=100 prov=synthetic src=analytical-fixture
+op id=A kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+op id=B kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+op id=C kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+buffer id=real1 bytes=80 cap=mem first=B last=B
+buffer id=real2 bytes=80 cap=mem first=B last=B
+energy instrument=none
diff --git a/tests/dagsim/fixtures/inverted_lone.oev b/tests/dagsim/fixtures/inverted_lone.oev
new file mode 100644
index 000000000 ..f85cc1f97
--- /dev/null
+++ b/tests/dagsim/fixtures/inverted_lone.oev
@@ -0,0 +1,10 @@
+oev version=1
+machine id=toy soc=toy cores=1 mem_bytes=100 prov=synthetic src=analytical-fixture
+build repo=omega-mv sha=3bd56731c5517e2a9c8f195955c71e73dc6f9269
+resource id=cpu kind=compute slots=1 prov=synthetic src=analytical-fixture
+resource id=mem kind=capacity cap=100 prov=synthetic src=analytical-fixture
+op id=A kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+op id=B kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+op id=C kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+buffer id=inverted bytes=80 cap=mem first=C last=A
+energy instrument=none
diff --git a/tests/dagsim/fixtures/inverted_masks_overflow.oev b/tests/dagsim/fixtures/inverted_masks_overflow.oev
new file mode 100644
index 000000000 ..724b447cd
--- /dev/null
+++ b/tests/dagsim/fixtures/inverted_masks_overflow.oev
@@ -0,0 +1,12 @@
+oev version=1
+machine id=toy soc=toy cores=1 mem_bytes=100 prov=synthetic src=analytical-fixture
+build repo=omega-mv sha=3bd56731c5517e2a9c8f195955c71e73dc6f9269
+resource id=cpu kind=compute slots=1 prov=synthetic src=analytical-fixture
+resource id=mem kind=capacity cap=100 prov=synthetic src=analytical-fixture
+op id=A kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+op id=B kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+op id=C kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+buffer id=inverted bytes=80 cap=mem first=C last=A
+buffer id=real1 bytes=80 cap=mem first=B last=B
+buffer id=real2 bytes=80 cap=mem first=B last=B
+energy instrument=none
diff --git a/tests/dagsim/fixtures/m1_spark_overlap.oev b/tests/dagsim/fixtures/m1_spark_overlap.oev
new file mode 100644
index 000000000 ..249980f17
--- /dev/null
+++ b/tests/dagsim/fixtures/m1_spark_overlap.oev
@@ -0,0 +1,34 @@
+# OEV1 fixture: Spark M1 hardware passport subset (omega-mv#578), pinned 2026-10-19.
+# Every number below is a loaded-machine measurement (load1 15 to 29) or a datasheet
+# ceiling, and says which. Nothing here was produced by running a GPU in this harness.
+oev version=1
+machine id=spark-b87b soc=GB10 cores=20 mem_bytes=137438953472 prov=specified src=nvidia-dgx-spark-datasheet
+build repo=omega-mv sha=f4a9849f00000000000000000000000000000000 physics=6d7cf0d4
+calibration id=M1-20261019 taken=2026-10-19 valid_days=30 load1=24.2 src=~/yardsticks/aien-model/M1/
+
+# Resources. One capacity ledger for CPU and GPU (unified memory).
+resource id=cpu kind=compute slots=20 prov=specified src=nproc
+resource id=gpu kind=compute slots=1 prov=specified src=one-job-at-a-time-engine
+resource id=dram_spec kind=bandwidth cap=273e9 prov=specified src=nvidia-dgx-spark-datasheet
+resource id=dram_gpu kind=bandwidth cap=218.6e9 lo=218.6e9 hi=219e9 prov=measured src=handoff-2026-10-19-qwen38-decode-speed.md:calc:e726ff77
+resource id=dram_cpu kind=bandwidth cap=65.4e9 lo=60.8e9 hi=69.8e9 prov=measured src=M1/block4.csv:gb=1,threads=8
+resource id=unified_mem kind=capacity cap=137438953472 prov=specified src=nvidia-dgx-spark-datasheet
+resource id=gpu_launch kind=launch prov=measured src=M1/block2.csv
+
+# Ops. Same work as m1_spark_subset.oev, but the 1 GB copy is split into two
+# concurrent halves on two CPU slots. They share dram_cpu (processor sharing).
+# At two threads the per-thread busy time (55.5 ms) still binds and the shared
+# pipe does not (2 GB of traffic at 65.4 GB/s is 30.6 ms), which is what block4
+# shows at 4 threads (50 to 61 GB/s). More halves would hit the pipe.
+op id=realize kind=compute engine=cpu t_ns=20000 lo=19400 hi=22800 prov=measured src=M1/block1.csv:path_ns_per_call
+op id=gpu_job kind=compute engine=gpu t_ns=0 prov=measured src=M1/block2.csv:vecadd_65 launch_ns=40736700 launcher=gpu_launch
+op id=copyA kind=copy engine=cpu t_ns=55500000 lo=53950000 hi=58300000 prov=measured src=M1/block4.csv:gb=1,threads=1,half bytes=1000000000 bw=dram_cpu
+op id=copyB kind=copy engine=cpu t_ns=55500000 lo=53950000 hi=58300000 prov=measured src=M1/block4.csv:gb=1,threads=1,half bytes=1000000000 bw=dram_cpu
+dep realize gpu_job
+dep gpu_job copyA
+dep gpu_job copyB
+
+buffer id=src1g bytes=1000000000 cap=unified_mem first=copyA last=copyB
+buffer id=dst1g bytes=1000000000 cap=unified_mem first=copyA last=copyB
+
+energy instrument=none
diff --git a/tests/dagsim/fixtures/m1_spark_subset.oev b/tests/dagsim/fixtures/m1_spark_subset.oev
new file mode 100644
index 000000000 ..34fdf7364
--- /dev/null
+++ b/tests/dagsim/fixtures/m1_spark_subset.oev
@@ -0,0 +1,32 @@
+# OEV1 fixture: Spark M1 hardware passport subset (omega-mv#578), pinned 2026-10-19.
+# Every number below is a loaded-machine measurement (load1 15 to 29) or a datasheet
+# ceiling, and says which. Nothing here was produced by running a GPU in this harness.
+oev version=1
+machine id=spark-b87b soc=GB10 cores=20 mem_bytes=137438953472 prov=specified src=nvidia-dgx-spark-datasheet
+build repo=omega-mv sha=f4a9849f00000000000000000000000000000000 physics=6d7cf0d4
+calibration id=M1-20261019 taken=2026-10-19 valid_days=30 load1=24.2 src=~/yardsticks/aien-model/M1/
+
+# Resources. One capacity ledger for CPU and GPU (unified memory).
+resource id=cpu kind=compute slots=20 prov=specified src=nproc
+resource id=gpu kind=compute slots=1 prov=specified src=one-job-at-a-time-engine
+resource id=dram_spec kind=bandwidth cap=273e9 prov=specified src=nvidia-dgx-spark-datasheet
+resource id=dram_gpu kind=bandwidth cap=218.6e9 lo=218.6e9 hi=219e9 prov=measured src=handoff-2026-10-19-qwen38-decode-speed.md:calc:e726ff77
+resource id=dram_cpu kind=bandwidth cap=65.4e9 lo=60.8e9 hi=69.8e9 prov=measured src=M1/block4.csv:gb=1,threads=8
+resource id=unified_mem kind=capacity cap=137438953472 prov=specified src=nvidia-dgx-spark-datasheet
+resource id=gpu_launch kind=launch prov=measured src=M1/block2.csv
+
+# Ops. A CPU realization call (block1 path) feeding one GPU job (block2) whose
+# fixed submit lifecycle dominates, then a CPU memcpy of 1 GB (block4, 1 thread).
+op id=realize kind=compute engine=cpu t_ns=20000 lo=19400 hi=22800 prov=measured src=M1/block1.csv:path_ns_per_call
+op id=gpu_job kind=compute engine=gpu t_ns=0 prov=measured src=M1/block2.csv:vecadd_65 launch_ns=40736700 launcher=gpu_launch
+op id=copy1g kind=copy engine=cpu t_ns=111000000 lo=107900000 hi=116600000 prov=measured src=M1/block4.csv:gb=1,threads=1 bytes=2000000000 bw=dram_cpu
+dep realize gpu_job
+dep gpu_job copy1g
+
+# Buffers.
+buffer id=src1g bytes=1000000000 cap=unified_mem first=copy1g last=copy1g
+buffer id=dst1g bytes=1000000000 cap=unified_mem first=copy1g last=copy1g
+
+# Energy: no wall instrument on this box; nvidia-smi is GPU module only and was not
+# integrated over this DAG. UNMEASURED.
+energy instrument=none
diff --git a/tests/dagsim/fixtures/m1_synthetic_power.oev b/tests/dagsim/fixtures/m1_synthetic_power.oev
new file mode 100644
index 000000000 ..3087178ea
--- /dev/null
+++ b/tests/dagsim/fixtures/m1_synthetic_power.oev
@@ -0,0 +1,31 @@
+# OEV1 fixture: Spark M1 hardware passport subset (omega-mv#578), pinned 2026-10-19.
+# Every number below is a loaded-machine measurement (load1 15 to 29) or a datasheet
+# ceiling, and says which. Nothing here was produced by running a GPU in this harness.
+oev version=1
+machine id=spark-b87b soc=GB10 cores=20 mem_bytes=137438953472 prov=specified src=nvidia-dgx-spark-datasheet
+build repo=omega-mv sha=f4a9849f00000000000000000000000000000000 physics=6d7cf0d4
+calibration id=M1-20261019 taken=2026-10-19 valid_days=30 load1=24.2 src=~/yardsticks/aien-model/M1/
+
+# Resources. One capacity ledger for CPU and GPU (unified memory).
+resource id=cpu kind=compute slots=20 prov=specified src=nproc
+resource id=gpu kind=compute slots=1 prov=specified src=one-job-at-a-time-engine
+resource id=dram_spec kind=bandwidth cap=273e9 prov=specified src=nvidia-dgx-spark-datasheet
+resource id=dram_gpu kind=bandwidth cap=218.6e9 lo=218.6e9 hi=219e9 prov=measured src=handoff-2026-10-19-qwen38-decode-speed.md:calc:e726ff77
+resource id=dram_cpu kind=bandwidth cap=65.4e9 lo=60.8e9 hi=69.8e9 prov=measured src=M1/block4.csv:gb=1,threads=8
+resource id=unified_mem kind=capacity cap=137438953472 prov=specified src=nvidia-dgx-spark-datasheet
+resource id=gpu_launch kind=launch prov=measured src=M1/block2.csv
+
+# Ops. A CPU realization call (block1 path) feeding one GPU job (block2) whose
+# fixed submit lifecycle dominates, then a CPU memcpy of 1 GB (block4, 1 thread).
+op id=realize kind=compute engine=cpu t_ns=20000 lo=19400 hi=22800 prov=measured src=M1/block1.csv:path_ns_per_call
+op id=gpu_job kind=compute engine=gpu t_ns=0 prov=measured src=M1/block2.csv:vecadd_65 launch_ns=40736700 launcher=gpu_launch
+op id=copy1g kind=copy engine=cpu t_ns=111000000 lo=107900000 hi=116600000 prov=measured src=M1/block4.csv:gb=1,threads=1 bytes=2000000000 bw=dram_cpu
+dep realize gpu_job
+dep gpu_job copy1g
+
+# Buffers.
+buffer id=src1g bytes=1000000000 cap=unified_mem first=copy1g last=copy1g
+buffer id=dst1g bytes=1000000000 cap=unified_mem first=copy1g last=copy1g
+
+# Labelled sensitivity only: 100 W is a made-up figure, not an instrument.
+energy instrument=what-if-100W boundary=wall power_w=100 prov=synthetic
diff --git a/tests/dagsim/fixtures/mw_bad_elimination.oev b/tests/dagsim/fixtures/mw_bad_elimination.oev
new file mode 100644
index 000000000 ..cc9e2a480
--- /dev/null
+++ b/tests/dagsim/fixtures/mw_bad_elimination.oev
@@ -0,0 +1,14 @@
+# Minimum-work accounting fixtures (parent #276 clarification). Synthetic
+# numbers, labelled so; the point is the ledger, not the magnitudes.
+oev version=1
+machine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test
+build repo=omega-mv sha=0000000000000000000000000000000000000000
+calibration id=mw taken=2026-10-19 valid_days=3650 load1=0 src=synthetic
+resource id=cpu kind=compute slots=1 prov=specified src=test
+resource id=mem kind=capacity cap=1000 prov=specified src=test
+energy instrument=none
+op id=parse kind=compute engine=cpu t_ns=10 prov=synthetic src=t
+op id=execute kind=compute engine=cpu t_ns=50 prov=synthetic src=t
+dep parse execute
+removed op=search reason=eliminated
+removed op=check reason=eliminated
diff --git a/tests/dagsim/fixtures/mw_baseline.oev b/tests/dagsim/fixtures/mw_baseline.oev
new file mode 100644
index 000000000 ..e2eaf36f8
--- /dev/null
+++ b/tests/dagsim/fixtures/mw_baseline.oev
@@ -0,0 +1,16 @@
+# Minimum-work accounting fixtures (parent #276 clarification). Synthetic
+# numbers, labelled so; the point is the ledger, not the magnitudes.
+oev version=1
+machine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test
+build repo=omega-mv sha=0000000000000000000000000000000000000000
+calibration id=mw taken=2026-10-19 valid_days=3650 load1=0 src=synthetic
+resource id=cpu kind=compute slots=1 prov=specified src=test
+resource id=mem kind=capacity cap=1000 prov=specified src=test
+energy instrument=none
+op id=parse kind=compute engine=cpu t_ns=10 prov=synthetic src=t
+op id=search kind=compute engine=cpu t_ns=200 prov=synthetic src=t
+op id=check kind=compute engine=cpu t_ns=20 prov=synthetic src=t
+op id=execute kind=compute engine=cpu t_ns=50 prov=synthetic src=t
+dep parse search
+dep search check
+dep check execute
diff --git a/tests/dagsim/fixtures/mw_reuse.oev b/tests/dagsim/fixtures/mw_reuse.oev
new file mode 100644
index 000000000 ..9e24750f3
--- /dev/null
+++ b/tests/dagsim/fixtures/mw_reuse.oev
@@ -0,0 +1,17 @@
+# Minimum-work accounting fixtures (parent #276 clarification). Synthetic
+# numbers, labelled so; the point is the ledger, not the magnitudes.
+oev version=1
+machine id=t soc=t cores=4 mem_bytes=1000 prov=specified src=test
+build repo=omega-mv sha=0000000000000000000000000000000000000000
+calibration id=mw taken=2026-10-19 valid_days=3650 load1=0 src=synthetic
+resource id=cpu kind=compute slots=1 prov=specified src=test
+resource id=mem kind=capacity cap=1000 prov=specified src=test
+energy instrument=none
+op id=parse kind=compute engine=cpu t_ns=10 prov=synthetic src=t
+op id=lookup kind=compute engine=cpu t_ns=5 prov=synthetic src=t
+op id=check kind=compute engine=cpu t_ns=20 prov=synthetic src=t
+op id=execute kind=compute engine=cpu t_ns=50 prov=synthetic src=t
+dep parse lookup
+dep lookup check
+dep check execute
+removed op=search reason=reused ref=lookup proof=rx_plan:verified-plan-digest
diff --git a/tests/dagsim/fixtures/needs_arch244_trace.oev b/tests/dagsim/fixtures/needs_arch244_trace.oev
new file mode 100644
index 000000000 ..671165072
--- /dev/null
+++ b/tests/dagsim/fixtures/needs_arch244_trace.oev
@@ -0,0 +1,24 @@
+# OEV1 fixture: Spark M1 hardware passport subset (omega-mv#578), pinned 2026-10-19.
+# Every number below is a loaded-machine measurement (load1 15 to 29) or a datasheet
+# ceiling, and says which. Nothing here was produced by running a GPU in this harness.
+oev version=1
+machine id=spark-b87b soc=GB10 cores=20 mem_bytes=137438953472 prov=specified src=nvidia-dgx-spark-datasheet
+build repo=omega-mv sha=f4a9849f00000000000000000000000000000000 physics=6d7cf0d4
+calibration id=M1-20261019 taken=2026-10-19 valid_days=30 load1=24.2 src=~/yardsticks/aien-model/M1/
+
+# Resources. One capacity ledger for CPU and GPU (unified memory).
+resource id=cpu kind=compute slots=20 prov=specified src=nproc
+resource id=gpu kind=compute slots=1 prov=specified src=one-job-at-a-time-engine
+resource id=dram_spec kind=bandwidth cap=273e9 prov=specified src=nvidia-dgx-spark-datasheet
+resource id=dram_gpu kind=bandwidth cap=218.6e9 lo=218.6e9 hi=219e9 prov=measured src=handoff-2026-10-19-qwen38-decode-speed.md:calc:e726ff77
+resource id=dram_cpu kind=bandwidth cap=65.4e9 lo=60.8e9 hi=69.8e9 prov=measured src=M1/block4.csv:gb=1,threads=8
+resource id=unified_mem kind=capacity cap=137438953472 prov=specified src=nvidia-dgx-spark-datasheet
+resource id=gpu_launch kind=launch prov=measured src=M1/block2.csv
+
+# Ops. The second op needs the aien-architecture#244 objective trace, which was
+# NOT_RUN on 2026-10-19. Unknown stays unknown: this fixture must be refused.
+op id=realize kind=compute engine=cpu t_ns=20000 lo=19400 hi=22800 prov=measured src=M1/block1.csv:path_ns_per_call
+op id=objective_replay kind=compute engine=cpu prov=unknown src=aien-architecture#244:NOT_RUN
+dep realize objective_replay
+
+energy instrument=none
diff --git a/tests/dagsim/fixtures/valid_disjoint_80.oev b/tests/dagsim/fixtures/valid_disjoint_80.oev
new file mode 100644
index 000000000 ..1bf831d40
--- /dev/null
+++ b/tests/dagsim/fixtures/valid_disjoint_80.oev
@@ -0,0 +1,11 @@
+oev version=1
+machine id=toy soc=toy cores=1 mem_bytes=100 prov=synthetic src=analytical-fixture
+build repo=omega-mv sha=3bd56731c5517e2a9c8f195955c71e73dc6f9269
+resource id=cpu kind=compute slots=1 prov=synthetic src=analytical-fixture
+resource id=mem kind=capacity cap=100 prov=synthetic src=analytical-fixture
+op id=A kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+op id=B kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+op id=C kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+buffer id=real1 bytes=80 cap=mem first=A last=A
+buffer id=real2 bytes=80 cap=mem first=C last=C
+energy instrument=none
diff --git a/tests/dagsim/fixtures/valid_tie_80.oev b/tests/dagsim/fixtures/valid_tie_80.oev
new file mode 100644
index 000000000 ..a39a0a784
--- /dev/null
+++ b/tests/dagsim/fixtures/valid_tie_80.oev
@@ -0,0 +1,11 @@
+oev version=1
+machine id=toy soc=toy cores=1 mem_bytes=100 prov=synthetic src=analytical-fixture
+build repo=omega-mv sha=3bd56731c5517e2a9c8f195955c71e73dc6f9269
+resource id=cpu kind=compute slots=1 prov=synthetic src=analytical-fixture
+resource id=mem kind=capacity cap=100 prov=synthetic src=analytical-fixture
+op id=A kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+op id=B kind=compute engine=cpu t_ns=10 prov=synthetic src=analytical-fixture
+dep A B
+buffer id=x bytes=80 cap=mem first=A last=A
+buffer id=y bytes=80 cap=mem first=B last=B
+energy instrument=none
diff --git a/tests/dagsim/mutant_lifetime.sh b/tests/dagsim/mutant_lifetime.sh
new file mode 100755
index 000000000 ..c458eb314
--- /dev/null
+++ b/tests/dagsim/mutant_lifetime.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+# Drop the inverted-lifetime check and require the named assertion to fail.
+# A mutant that still prints a passing inverted_lifetime_masks_overflow is a miss.
+set -eu
+ROOT=$(CDPATH= cd -- "$(dirname "$0")/../.." && pwd)
+cd "$ROOT"
+src=tools/dagsim/dagsim.c
+grep -q 'LIFETIME_ORDER_CHECK' "$src"
+tmp=$(mktemp -d)
+trap 'rm -rf "$tmp"' EXIT
+sed '/LIFETIME_ORDER_CHECK/d' "$src" > "$tmp/dagsim.c"
+grep -q 'LIFETIME_ORDER_CHECK' "$tmp/dagsim.c" && { echo "mutant: check still present"; exit 1; }
+grep -q 'reject_inverted_lifetimes' "$tmp/dagsim.c" || { echo "mutant: deleted more than the call"; exit 1; }
+
+CC=${CC:-cc}
+# -Wno-unused-function: deleting the call leaves reject_inverted_lifetimes unreferenced.
+# The mutant has to run. The kill is the named assertion, not a compile error.
+cflags="-std=gnu11 -Wall -Wextra -Werror -Wno-unused-function -D_GNU_SOURCE -O2 -Isrc -Itools/dagsim"
+$CC $cflags -c -o "$tmp/dagsim.o" "$tmp/dagsim.c"
+$CC $cflags -c -o "$tmp/rx_costmodel.o" src/runtime/rx_costmodel.c
+if [ "$(uname -m)" = aarch64 ]; then
+ sha=src/omega_om_units.c
+else
+ sha=tests/dagsim/sha256_host.c
+fi
+$CC $cflags -o "$tmp/unit" tests/dagsim/dagsim_unit.c "$tmp/dagsim.o" "$tmp/rx_costmodel.o" "$sha" -lm
+set +e
+"$tmp/unit" > "$tmp/out" 2>&1
+rc=$?
+set -e
+if [ "$rc" -eq 0 ]; then
+ echo "mutant survived: unit suite passed after dropping LIFETIME_ORDER_CHECK"
+ exit 1
+fi
+if ! grep -q 'inverted_lifetime_masks_overflow' "$tmp/out"; then
+ echo "mutant did not fail named assertion inverted_lifetime_masks_overflow"
+ cat "$tmp/out"
+ exit 1
+fi
+echo "mutant killed: inverted_lifetime_masks_overflow"
diff --git a/tests/dagsim/run_cli.sh b/tests/dagsim/run_cli.sh
new file mode 100755
index 000000000 ..0c5d7b364
--- /dev/null
+++ b/tests/dagsim/run_cli.sh
@@ -0,0 +1,87 @@
+#!/bin/sh
+# run_cli.sh DAGSIM_BIN [OUT_DIR]
+# Reproducible CLI example for omega-mv#583: pinned fixtures in, JSON and a
+# Pareto table out, byte-identical on a second run, no GPU touched.
+set -u
+BIN=${1:?dagsim binary}
+OUT=${2:-/tmp/dagsim-cli-$$}
+F=tests/dagsim/fixtures
+ASOF=2026-10-20
+mkdir -p "$OUT"
+fail=0
+say() { echo "run_cli: $*"; }
+check() { if [ "$1" -ne 0 ]; then say "FAIL $2"; fail=1; else say "ok $2"; fi; }
+
+"$BIN" eval $F/m1_spark_subset.oev --asof $ASOF > "$OUT/subset.json"; rc=$?
+check $rc "eval exits 0 on the pinned M1 subset"
+grep -q '"status": "OK"' "$OUT/subset.json"; check $? "status OK"
+grep -q '"makespan_ns": {"nominal": 151756700 ,' "$OUT/subset.json"; check $? "serial makespan 20000 + 40736700 + 111000000 ns"
+grep -q '"makespan_ge_bounds": true' "$OUT/subset.json"; check $? "makespan is above its bounds"
+grep -q '"status": "UNMEASURED"' "$OUT/subset.json"; check $? "energy UNMEASURED without an instrument"
+grep -q '"gpu_executed": false' "$OUT/subset.json"; check $? "offline: no GPU execution"
+grep -q '"provenance": \["measured", "specified"\]' "$OUT/subset.json"; check $? "provenance list names measured and specified only"
+"$BIN" eval $F/m1_spark_subset.oev --asof $ASOF > "$OUT/subset2.json"
+cmp -s "$OUT/subset.json" "$OUT/subset2.json"; check $? "second run byte-identical"
+
+"$BIN" eval $F/needs_arch244_trace.oev --asof $ASOF > "$OUT/unknown.json"; rc=$?
+[ $rc -eq 1 ] ; check $? "unknown-trace fixture exits 1"
+grep -q '"status": "REFUSED_UNKNOWN"' "$OUT/unknown.json"; check $? "unknown stays unknown (REFUSED_UNKNOWN)"
+grep -q 'makespan' "$OUT/unknown.json"; [ $? -ne 0 ]; check $? "no makespan printed on refusal"
+
+"$BIN" eval $F/m1_spark_subset.oev --asof 2026-12-01 > "$OUT/stale.json"
+grep -q '"status": "REFUSED_STALE"' "$OUT/stale.json"; check $? "30-day calibration refused at 43 days"
+
+"$BIN" eval $F/m1_synthetic_power.oev --asof $ASOF > "$OUT/syn.json"
+grep -q '"status": "SYNTHETIC_SENSITIVITY_ONLY"' "$OUT/syn.json"; check $? "synthetic power is labelled, not ranked"
+grep -q '"ranking_valid": false' "$OUT/syn.json"; check $? "energy ranking invalid on synthetic power"
+
+"$BIN" eval $F/m1_spark_overlap.oev --asof $ASOF > "$OUT/overlap.json"
+grep -q '"status": "OK"' "$OUT/overlap.json"; check $? "overlap fixture evaluates"
+# two halves sharing a 65.4 GB/s pipe: 2 GB of traffic is 30.58 ms, each half's own busy
+# time is 55.5 ms, so busy time binds and both halves end together at 40.7567 + 55.5 ms.
+grep -q '"makespan_ns": {"nominal": 96256700 ,' "$OUT/overlap.json"; check $? "split copy: busy time binds, 40756700 + 55500000 ns"
+
+"$BIN" pareto $F/m1_spark_subset.oev $F/m1_spark_overlap.oev $F/m1_synthetic_power.oev $F/needs_arch244_trace.oev --asof $ASOF > "$OUT/pareto.txt"; rc=$?
+check $rc "pareto exits 0"
+grep -q 'needs_arch244_trace.oev *REFUSED_UNKNOWN' "$OUT/pareto.txt"; check $? "refused candidate shown as refused in the table"
+grep -q 'm1_spark_overlap.oev *OK .* yes$' "$OUT/pareto.txt"; check $? "faster candidate is on the front"
+grep -q 'm1_spark_subset.oev *OK .* no$' "$OUT/pareto.txt"; check $? "dominated candidate is off the front"
+grep -q 'Energy not measured on every row' "$OUT/pareto.txt"; check $? "pareto says energy is not ranked"
+
+"$BIN" diff $F/mw_baseline.oev $F/mw_reuse.oev --asof $ASOF > "$OUT/diff_reuse.json"; rc=$?
+check $rc "reuse diff OK"
+grep -q '"reused": 200' "$OUT/diff_reuse.json"; check $? "200 ns of search moved to the reused ledger"
+"$BIN" diff $F/mw_baseline.oev $F/mw_bad_elimination.oev --asof $ASOF > "$OUT/diff_bad.json"; rc=$?
+[ $rc -eq 1 ]; check $? "unproven elimination exits 1"
+grep -q '"status": "REFUSED_REMOVED_REQUIRED"' "$OUT/diff_bad.json"; check $? "unproven elimination refused"
+"$BIN" diff $F/mw_baseline.oev $F/mw_baseline.oev --asof $ASOF > "$OUT/diff_same.json"
+grep -q '"kept": 4, "added": 0, "removed": 0' "$OUT/diff_same.json"; check $? "no-change fixture adds no nodes"
+
+# omega-mv#705: inverted lifetime must not come back as an OK capacity certificate.
+"$BIN" eval $F/inverted_masks_overflow.oev --asof 2026-10-24 > "$OUT/inverted.json"; rc=$?
+[ $rc -eq 1 ]; check $? "inverted lifetime exits 1"
+grep -q '"status": "REFUSED_LIFETIME"' "$OUT/inverted.json"; check $? "inverted lifetime status"
+grep -q 'first=C' "$OUT/inverted.json"; check $? "inverted reason names first=C"
+grep -q 'last=A' "$OUT/inverted.json"; check $? "inverted reason names last=A"
+grep -q 'makespan' "$OUT/inverted.json"; [ $? -ne 0 ]; check $? "no makespan on inverted refusal"
+"$BIN" eval $F/inverted_lone.oev --asof 2026-10-24 > "$OUT/inverted_lone.json"; rc=$?
+[ $rc -eq 1 ]; check $? "lone inverted lifetime exits 1"
+grep -q '"status": "REFUSED_LIFETIME"' "$OUT/inverted_lone.json"; check $? "lone inverted is not peak 0"
+"$BIN" eval $F/capacity_two_80.oev --asof 2026-10-24 > "$OUT/cap80.json"; rc=$?
+[ $rc -eq 1 ]; check $? "two overlapping 80 B buffers exit 1"
+grep -q '"status": "REFUSED_CAPACITY"' "$OUT/cap80.json"; check $? "overlap is REFUSED_CAPACITY"
+"$BIN" eval $F/valid_disjoint_80.oev --asof 2026-10-24 > "$OUT/disjoint80.json"; rc=$?
+check $rc "disjoint 80 B pair exits 0"
+grep -q '"status": "OK"' "$OUT/disjoint80.json"; check $? "disjoint pair OK"
+grep -q '"bytes": 80' "$OUT/disjoint80.json"; check $? "disjoint peak 80"
+"$BIN" eval $F/valid_tie_80.oev --asof 2026-10-24 > "$OUT/tie80.json"; rc=$?
+check $rc "completion/allocation tie exits 0"
+grep -q '"status": "OK"' "$OUT/tie80.json"; check $? "tie OK"
+grep -q '"bytes": 80' "$OUT/tie80.json"; check $? "tie peak 80"
+"$BIN" pareto $F/inverted_masks_overflow.oev $F/valid_disjoint_80.oev --asof 2026-10-24 > "$OUT/pareto_life.txt"; rc=$?
+check $rc "pareto with a refused lifetime exits 0"
+grep -q 'inverted_masks_overflow.oev *REFUSED_LIFETIME' "$OUT/pareto_life.txt"; check $? "inverted row is refused, not ranked OK"
+grep -q 'valid_disjoint_80.oev *OK' "$OUT/pareto_life.txt"; check $? "valid row still ranked"
+
+say "outputs in $OUT"
+exit $fail
diff --git a/tests/dagsim/sha256_host.c b/tests/dagsim/sha256_host.c
new file mode 100644
index 000000000 ..4a853e52c
--- /dev/null
+++ b/tests/dagsim/sha256_host.c
@@ -0,0 +1,17 @@
+/* Host link for dagsim when the seeded SHA-256 unit cannot be compiled.
+ * src/omega_om_units.c is AArch64 machine code. rx_costmodel.o references
+ * sha256_hash from serialize/digest only; the analytical dagsim tests do not
+ * call it. On AArch64 the Makefile links src/omega_om_units.c instead and
+ * this file is not built. */
+#if !defined(__aarch64__)
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <stdint.h>
+
+void sha256_hash(const uint8_t *d, size_t n, uint8_t out[32]) {
+ (void)d; (void)n; (void)out;
+ fprintf(stderr, "sha256_hash: not linked (seeded unit is AArch64); dagsim --model is NOT_RUN on this host\n");
+ abort();
+}
+#endif
diff --git a/tools/.crumb b/tools/.crumb
index 5f1a7214f ..79906ebbe 100644
--- a/tools/.crumb
+++ b/tools/.crumb
@@ -62,14 +62,14 @@
}
],
"children_root": "sha256:8d3d3b952374b3b72e667521f07bf028c4c02bcefff772ad1a71cfff3e5266f2 ",
- "compiled_at": "2026-10-28T02:06:07Z",
+ "compiled_at": "2026-10-30T11:20:30Z",
"compiler": "crumb-compile/1",
- "digest": "sha256:4e83dea21da137c30076c2dc0ca4f3a488f576f30a94e334558ad5ea523f3a6b ",
+ "digest": "sha256:c8e85176667df172aad0d9d1c6d0de9dcc71674f0f04e3c8d127024fa291b2c3 ",
"evidence_files": 0,
"evidence_root": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855 ",
- "files": 295,
- "generated_at_commit": "82509c4f949504dc63f13371607b211c14cdee74 ",
- "source_tree": "sha256:319916f06e7ad69219b50ea9df5420b8baec42170d0ba675632059208dda0949 "
+ "files": 298,
+ "generated_at_commit": "dd39bf71fb8eb14c45bf0abd20c74d5da69c807c ",
+ "source_tree": "sha256:312283d3cb16b6d19b25c2dea27987afe692888adff60057bed22ad302981e78 "
},
"owner_lane": "",
"provenance": {
diff --git a/tools/dagsim/dagsim.c b/tools/dagsim/dagsim.c
new file mode 100644
index 000000000 ..5aac119f8
--- /dev/null
+++ b/tools/dagsim/dagsim.c
@@ -0,0 +1,805 @@
+/*
+ * dagsim.c -- offline resource-DAG cost evaluator (omega-mv#583).
+ *
+ * See dagsim.h and spec/offline-evidence-v1.md. The scheduler is a
+ * deterministic fluid simulation: compute engines have slots, bandwidth
+ * resources are shared equally among the ops streaming on them at any
+ * instant, launches are serialized per launch resource, and an op finishes
+ * when both its own busy time and its traffic are done (perfect overlap
+ * inside one op, which is the issue's stated floor max(F/P, Q/B)). Ops are
+ * dispatched in file order, so the same file always gives the same bytes.
+ */
+#include "dagsim.h"
+#include "runtime/rx_costmodel.h"
+
+#include <ctype.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+/* ---------------------------------------------------------------- names */
+
+const char *ds_status_name(int s) {
+ switch (s) {
+ case DS_OK: return "OK";
+ case DS_REFUSED_UNKNOWN: return "REFUSED_UNKNOWN";
+ case DS_REFUSED_STALE: return "REFUSED_STALE";
+ case DS_REFUSED_NO_CALIBRATION: return "REFUSED_NO_CALIBRATION";
+ case DS_REFUSED_CAPACITY: return "REFUSED_CAPACITY";
+ case DS_REFUSED_CYCLE: return "REFUSED_CYCLE";
+ case DS_REFUSED_UNSUPPORTED: return "REFUSED_UNSUPPORTED";
+ case DS_REFUSED_REMOVED_REQUIRED: return "REFUSED_REMOVED_REQUIRED";
+ case DS_REFUSED_LIFETIME: return "REFUSED_LIFETIME";
+ case DS_PARSE_ERROR: return "PARSE_ERROR";
+ default: return "?";
+ }
+}
+
+const char *ds_prov_name(int p) {
+ switch (p) {
+ case DS_PROV_UNKNOWN: return "unknown";
+ case DS_PROV_SYNTHETIC: return "synthetic";
+ case DS_PROV_FITTED: return "fitted";
+ case DS_PROV_MEASURED: return "measured";
+ case DS_PROV_SPECIFIED: return "specified";
+ default: return "?";
+ }
+}
+
+static int prov_from_name(const char *s) {
+ if (!strcmp(s, "unknown")) return DS_PROV_UNKNOWN;
+ if (!strcmp(s, "synthetic")) return DS_PROV_SYNTHETIC;
+ if (!strcmp(s, "fitted")) return DS_PROV_FITTED;
+ if (!strcmp(s, "measured")) return DS_PROV_MEASURED;
+ if (!strcmp(s, "specified")) return DS_PROV_SPECIFIED;
+ return -1;
+}
+
+/* days since 1970-01-01 for a civil date (Howard Hinnant's days_from_civil) */
+int ds_day_from_date(const char *s) {
+ int y, m, d;
+ if (!s || sscanf(s, "%d-%d-%d", &y, &m, &d) != 3) return -1;
+ y -= m <= 2;
+ int era = (y >= 0 ? y : y - 399) / 400;
+ unsigned yoe = (unsigned)(y - era * 400);
+ unsigned doy = (153u * (unsigned)(m + (m > 2 ? -3 : 9)) + 2u) / 5u + (unsigned)d - 1u;
+ unsigned doe = yoe * 365u + yoe / 4u - yoe / 100u + doy;
+ return era * 146097 + (int)doe - 719468;
+}
+
+int ds_find_op(const ds_model *m, const char *id) {
+ for (int i = 0; i < m->n_ops; i++) if (!strcmp(m->ops[i].id, id)) return i;
+ return -1;
+}
+int ds_find_res(const ds_model *m, const char *id) {
+ for (int i = 0; i < m->n_res; i++) if (!strcmp(m->res[i].id, id)) return i;
+ return -1;
+}
+
+/* ---------------------------------------------------------------- parse */
+/* bounded string copy; ids and sources are truncated, never overflowed */
+static void sset(char *dst, size_t cap, const char *src) {
+ size_t n = strlen(src);
+ if (n >= cap) n = cap - 1;
+ memcpy(dst, src, n); dst[n] = 0;
+}
+
+
+typedef struct { char key[32]; char val[DS_SRC]; int used; } kv;
+
+static int split_kv(char *line, char *keyword, size_t kwcap, kv *kvs, int maxkv, char *positional[], int *npos) {
+ int n = 0; *npos = 0; keyword[0] = 0;
+ char *p = strchr(line, '#'); if (p) *p = 0;
+ char *save = NULL;
+ char *tok = strtok_r(line, " \t\r\n", &save);
+ if (!tok) return -1; /* empty */
+ snprintf(keyword, kwcap, "%s", tok);
+ while ((tok = strtok_r(NULL, " \t\r\n", &save))) {
+ char *eq = strchr(tok, '=');
+ if (!eq) { if (*npos < 8) positional[(*npos)++] = tok; continue; }
+ if (n >= maxkv) return -2;
+ *eq = 0;
+ sset(kvs[n].key, sizeof kvs[n].key, tok);
+ sset(kvs[n].val, sizeof kvs[n].val, eq + 1);
+ kvs[n].used = 0;
+ n++;
+ }
+ return n;
+}
+
+static const char *get(kv *kvs, int n, const char *key) {
+ for (int i = 0; i < n; i++) if (!strcmp(kvs[i].key, key)) { kvs[i].used = 1; return kvs[i].val; }
+ return NULL;
+}
+
+static int unused_key(kv *kvs, int n, char *out, size_t cap) {
+ for (int i = 0; i < n; i++) if (!kvs[i].used) { snprintf(out, cap, "%s", kvs[i].key); return 1; }
+ return 0;
+}
+
+static int parse_real(const char *s, double *out) {
+ if (!s) return 0;
+ char *end; double v = strtod(s, &end);
+ if (end == s || *end) return 0;
+ if (!(v == v) || v < 0) return 0;
+ *out = v; return 1;
+}
+
+#define PERR(...) do { snprintf(err, errcap, "line %d: ", lineno); size_t _l = strlen(err); snprintf(err + _l, errcap - _l, __VA_ARGS__); return DS_PARSE_ERROR; } while (0)
+
+static int parse_prov_src(kv *kvs, int n, int *prov, char *src, size_t srccap, int required, char *err, size_t errcap, int lineno) {
+ const char *p = get(kvs, n, "prov");
+ const char *s = get(kvs, n, "src");
+ if (!p) { if (required) PERR("prov= is required wherever a number appears"); *prov = -1; return DS_OK; }
+ int v = prov_from_name(p);
+ if (v < 0) PERR("prov=%s is not one of specified|measured|fitted|synthetic|unknown", p);
+ *prov = v;
+ if ((v == DS_PROV_MEASURED || v == DS_PROV_FITTED) && !s) PERR("prov=%s needs src=", p);
+ snprintf(src, srccap, "%s", s ? s : "");
+ return DS_OK;
+}
+
+int ds_parse_text(const char *text, ds_model *m, char *err, size_t errcap) {
+ memset(m, 0, sizeof *m);
+ err[0] = 0;
+ int lineno = 0;
+ const char *cur = text;
+ int seen_oev = 0, seen_machine = 0, seen_build = 0;
+ /* two-pass is not needed: ops before deps/buffers is the convention; we
+ * resolve references at use and require definition before use. */
+ while (*cur) {
+ const char *nl = strchr(cur, '\n');
+ size_t len = nl ? (size_t)(nl - cur) : strlen(cur);
+ char line[1024];
+ lineno++;
+ if (len >= sizeof line) PERR("line too long");
+ memcpy(line, cur, len); line[len] = 0;
+ cur = nl ? nl + 1 : cur + len;
+ char keyword[32]; kv kvs[24]; char *pos[8]; int npos;
+ int n = split_kv(line, keyword, sizeof keyword, kvs, 24, pos, &npos);
+ if (n == -1) continue;
+ if (n == -2) PERR("too many fields");
+ if (!strcmp(keyword, "oev")) {
+ const char *v = get(kvs, n, "version");
+ if (!v || strcmp(v, "1")) PERR("oev version=1 required");
+ m->version = 1; seen_oev = 1;
+ } else if (!strcmp(keyword, "machine")) {
+ const char *v;
+ if (!(v = get(kvs, n, "id"))) PERR("machine needs id=");
+ sset(m->machine_id, sizeof m->machine_id, v);
+ if ((v = get(kvs, n, "soc"))) sset(m->soc, sizeof m->soc, v);
+ if ((v = get(kvs, n, "cores"))) m->cores = atoi(v);
+ if ((v = get(kvs, n, "mem_bytes")) && !parse_real(v, &m->mem_bytes)) PERR("bad mem_bytes");
+ int prov; char src[DS_SRC];
+ int rc = parse_prov_src(kvs, n, &prov, src, sizeof src, 1, err, errcap, lineno); if (rc) return rc;
+ seen_machine = 1;
+ } else if (!strcmp(keyword, "build")) {
+ const char *v;
+ if ((v = get(kvs, n, "repo"))) sset(m->repo, sizeof m->repo, v);
+ if (!(v = get(kvs, n, "sha")) || strlen(v) != 40) PERR("build needs sha=<40 hex>");
+ sset(m->build_sha, sizeof m->build_sha, v);
+ if ((v = get(kvs, n, "physics"))) sset(m->physics, sizeof m->physics, v);
+ seen_build = 1;
+ } else if (!strcmp(keyword, "calibration")) {
+ const char *v;
+ if (m->has_calibration) PERR("one calibration record only");
+ if (!(v = get(kvs, n, "id"))) PERR("calibration needs id=");
+ sset(m->cal_id, sizeof m->cal_id, v);
+ if (!(v = get(kvs, n, "taken")) || (m->cal_taken_day = ds_day_from_date(v)) < 0) PERR("calibration needs taken=YYYY-MM-DD");
+ if (!(v = get(kvs, n, "valid_days"))) PERR("calibration needs valid_days=");
+ m->cal_valid_days = atoi(v);
+ if (!(v = get(kvs, n, "load1")) || !parse_real(v, &m->cal_load1)) PERR("calibration needs load1=");
+ if (!(v = get(kvs, n, "src"))) PERR("calibration needs src=");
+ sset(m->cal_src, sizeof m->cal_src, v);
+ if ((v = get(kvs, n, "model"))) sset(m->cal_model, sizeof m->cal_model, v);
+ m->has_calibration = 1;
+ } else if (!strcmp(keyword, "resource")) {
+ if (m->n_res >= DS_MAX_RES) PERR("too many resources (max %d)", DS_MAX_RES);
+ ds_resource *r = &m->res[m->n_res];
+ memset(r, 0, sizeof *r);
+ const char *v;
+ if (!(v = get(kvs, n, "id"))) PERR("resource needs id=");
+ if (ds_find_res(m, v) >= 0) PERR("duplicate resource %s", v);
+ sset(r->id, sizeof r->id, v);
+ if (!(v = get(kvs, n, "kind"))) PERR("resource needs kind=");
+ if (!strcmp(v, "compute")) {
+ r->kind = DS_RES_COMPUTE;
+ if (!(v = get(kvs, n, "slots")) || (r->slots = atoi(v)) < 1) PERR("compute resource needs slots>=1");
+ } else if (!strcmp(v, "bandwidth")) {
+ r->kind = DS_RES_BANDWIDTH;
+ if (!parse_real(get(kvs, n, "cap"), &r->cap) || r->cap <= 0) PERR("bandwidth resource needs cap>0");
+ r->lo = r->hi = r->cap;
+ if ((v = get(kvs, n, "lo")) && !parse_real(v, &r->lo)) PERR("bad lo");
+ if ((v = get(kvs, n, "hi")) && !parse_real(v, &r->hi)) PERR("bad hi");
+ if (r->lo > r->cap || r->hi < r->cap) PERR("need lo <= cap <= hi");
+ } else if (!strcmp(v, "capacity")) {
+ r->kind = DS_RES_CAPACITY;
+ if (!parse_real(get(kvs, n, "cap"), &r->cap) || r->cap <= 0) PERR("capacity resource needs cap>0");
+ } else if (!strcmp(v, "launch")) {
+ r->kind = DS_RES_LAUNCH;
+ } else PERR("resource kind=%s unknown", v);
+ int rc = parse_prov_src(kvs, n, &r->prov, r->src, sizeof r->src, 1, err, errcap, lineno); if (rc) return rc;
+ m->n_res++;
+ } else if (!strcmp(keyword, "op")) {
+ if (m->n_ops >= DS_MAX_OPS) PERR("too many ops (max %d)", DS_MAX_OPS);
+ ds_op *o = &m->ops[m->n_ops];
+ memset(o, 0, sizeof *o);
+ o->engine = o->bw = o->launcher = -1;
+ const char *v;
+ if (!(v = get(kvs, n, "id"))) PERR("op needs id=");
+ if (ds_find_op(m, v) >= 0) PERR("duplicate op %s", v);
+ sset(o->id, sizeof o->id, v);
+ if (!(v = get(kvs, n, "kind"))) PERR("op needs kind=");
+ if (!strcmp(v, "compute")) o->kind = DS_OP_COMPUTE;
+ else if (!strcmp(v, "copy")) o->kind = DS_OP_COPY;
+ else if (!strcmp(v, "matvec")) o->kind = DS_OP_MATVEC;
+ else if (!strcmp(v, "barrier")) o->kind = DS_OP_BARRIER;
+ else if (!strcmp(v, "storage")) o->kind = DS_OP_STORAGE;
+ else if (!strcmp(v, "persist")) o->kind = DS_OP_PERSIST;
+ else PERR("op kind=%s unknown", v);
+ if ((v = get(kvs, n, "engine"))) {
+ o->engine = ds_find_res(m, v);
+ if (o->engine < 0 || m->res[o->engine].kind != DS_RES_COMPUTE) PERR("engine=%s is not a compute resource defined above", v);
+ }
+ if ((v = get(kvs, n, "t_ns"))) { if (!parse_real(v, &o->t_ns)) PERR("bad t_ns"); o->has_t = 1; o->lo = o->hi = o->t_ns; }
+ if ((v = get(kvs, n, "lo"))) { if (!o->has_t || !parse_real(v, &o->lo) || o->lo > o->t_ns) PERR("lo needs t_ns and lo <= t_ns"); }
+ if ((v = get(kvs, n, "hi"))) { if (!o->has_t || !parse_real(v, &o->hi) || o->hi < o->t_ns) PERR("hi needs t_ns and hi >= t_ns"); }
+ if ((v = get(kvs, n, "bytes"))) {
+ if (!parse_real(v, &o->bytes)) PERR("bad bytes");
+ const char *b = get(kvs, n, "bw");
+ if (!b || (o->bw = ds_find_res(m, b)) < 0 || m->res[o->bw].kind != DS_RES_BANDWIDTH) PERR("bytes= needs bw=<bandwidth resource defined above>");
+ }
+ if ((v = get(kvs, n, "launch_ns"))) {
+ if (!parse_real(v, &o->launch_ns)) PERR("bad launch_ns");
+ const char *l = get(kvs, n, "launcher");
+ if (!l || (o->launcher = ds_find_res(m, l)) < 0 || m->res[o->launcher].kind != DS_RES_LAUNCH) PERR("launch_ns= needs launcher=<launch resource defined above>");
+ }
+ if ((v = get(kvs, n, "M"))) o->M = (uint32_t)strtoul(v, NULL, 10);
+ if ((v = get(kvs, n, "N"))) o->N = (uint32_t)strtoul(v, NULL, 10);
+ if ((v = get(kvs, n, "core"))) o->core = (uint32_t)strtoul(v, NULL, 10);
+ if ((v = get(kvs, n, "arm"))) o->arm = (uint32_t)strtoul(v, NULL, 10);
+ if (o->kind == DS_OP_MATVEC && !o->has_t && (o->M == 0 || o->N == 0)) PERR("matvec needs M= and N= (or t_ns=)");
+ if (o->kind != DS_OP_BARRIER && o->engine < 0) PERR("op %s needs engine=", o->id);
+ int required = o->has_t || o->bytes > 0 || o->launch_ns > 0 || o->kind == DS_OP_MATVEC;
+ int rc = parse_prov_src(kvs, n, &o->t_prov, o->src, sizeof o->src, required, err, errcap, lineno); if (rc) return rc;
+ if (o->t_prov < 0) o->t_prov = DS_PROV_SPECIFIED; /* a costless barrier: ordering only */
+ if (!o->has_t && o->kind != DS_OP_MATVEC && o->t_prov == DS_PROV_UNKNOWN) { /* fine: explicitly unknown */ }
+ m->n_ops++;
+ } else if (!strcmp(keyword, "dep")) {
+ if (npos != 2 || n != 0) PERR("dep <from> <to>");
+ if (m->n_deps >= DS_MAX_DEPS) PERR("too many deps");
+ int a = ds_find_op(m, pos[0]), b = ds_find_op(m, pos[1]);
+ if (a < 0 || b < 0) PERR("dep names an op not defined above: %s %s", pos[0], pos[1]);
+ m->deps[m->n_deps].from = a; m->deps[m->n_deps].to = b; m->n_deps++;
+ } else if (!strcmp(keyword, "buffer")) {
+ if (m->n_buf >= DS_MAX_BUF) PERR("too many buffers");
+ ds_buffer *b = &m->buf[m->n_buf];
+ memset(b, 0, sizeof *b); b->first = b->last = -1;
+ const char *v;
+ if (!(v = get(kvs, n, "id"))) PERR("buffer needs id=");
+ sset(b->id, sizeof b->id, v);
+ if (!parse_real(get(kvs, n, "bytes"), &b->bytes) || !isfinite(b->bytes))
+ PERR("buffer bytes must be a finite number >= 0");
+ if (!(v = get(kvs, n, "cap")) || (b->cap = ds_find_res(m, v)) < 0 || m->res[b->cap].kind != DS_RES_CAPACITY) PERR("buffer needs cap=<capacity resource>");
+ if ((v = get(kvs, n, "first")) && (b->first = ds_find_op(m, v)) < 0) PERR("first=%s not an op", v);
+ if ((v = get(kvs, n, "last")) && (b->last = ds_find_op(m, v)) < 0) PERR("last=%s not an op", v);
+ m->n_buf++;
+ } else if (!strcmp(keyword, "sync")) {
+ /* a barrier op that depends on every listed op */
+ if (m->n_ops >= DS_MAX_OPS) PERR("too many ops");
+ const char *v, *list;
+ if (!(v = get(kvs, n, "id"))) PERR("sync needs id=");
+ if (ds_find_op(m, v) >= 0) PERR("duplicate op %s", v);
+ if (!(list = get(kvs, n, "ops"))) PERR("sync needs ops=a,b,...");
+ ds_op *o = &m->ops[m->n_ops];
+ memset(o, 0, sizeof *o);
+ o->engine = o->bw = o->launcher = -1; o->kind = DS_OP_BARRIER; o->t_prov = DS_PROV_SPECIFIED;
+ sset(o->id, sizeof o->id, v);
+ int self = m->n_ops++;
+ char tmp[DS_SRC]; sset(tmp, sizeof tmp, list);
+ char *save = NULL;
+ for (char *t = strtok_r(tmp, ",", &save); t; t = strtok_r(NULL, ",", &save)) {
+ int a = ds_find_op(m, t);
+ if (a < 0 || a == self) PERR("sync lists unknown op %s", t);
+ if (m->n_deps >= DS_MAX_DEPS) PERR("too many deps");
+ m->deps[m->n_deps].from = a; m->deps[m->n_deps].to = self; m->n_deps++;
+ }
+ } else if (!strcmp(keyword, "energy")) {
+ const char *v;
+ if (m->has_energy) PERR("one energy record only");
+ if (!(v = get(kvs, n, "instrument"))) PERR("energy needs instrument=");
+ sset(m->instrument, sizeof m->instrument, v);
+ if ((v = get(kvs, n, "boundary"))) sset(m->boundary, sizeof m->boundary, v);
+ const char *j = get(kvs, n, "joules"), *pw = get(kvs, n, "power_w");
+ int prov = -1; char src[DS_SRC];
+ int rc = parse_prov_src(kvs, n, &prov, src, sizeof src, j || pw ? 1 : 0, err, errcap, lineno); if (rc) return rc;
+ m->energy_prov = prov;
+ if (j) {
+ if (!strcmp(m->instrument, "none") || !m->boundary[0]) PERR("joules= needs a named instrument and boundary=");
+ if (prov != DS_PROV_MEASURED) PERR("joules= must be prov=measured with src=");
+ if (!parse_real(j, &m->joules)) PERR("bad joules");
+ }
+ if (pw) {
+ if (prov != DS_PROV_SYNTHETIC) PERR("power_w= is allowed only as prov=synthetic (a sensitivity figure); measured power must be integrated into joules= by the instrument");
+ if (!parse_real(pw, &m->power_w)) PERR("bad power_w");
+ }
+ m->has_energy = 1;
+ } else if (!strcmp(keyword, "removed")) {
+ if (m->n_removed >= DS_MAX_REMOVED) PERR("too many removed records");
+ ds_removed *r = &m->removed[m->n_removed];
+ memset(r, 0, sizeof *r);
+ const char *v;
+ if (!(v = get(kvs, n, "op"))) PERR("removed needs op=");
+ sset(r->op, sizeof r->op, v);
+ if (ds_find_op(m, v) >= 0) PERR("removed op %s is still present in this DAG", v);
+ if (!(v = get(kvs, n, "reason"))) PERR("removed needs reason=");
+ if (!strcmp(v, "eliminated")) r->reason = DS_RM_ELIMINATED;
+ else if (!strcmp(v, "reused")) r->reason = DS_RM_REUSED;
+ else if (!strcmp(v, "unchanged_dep")) r->reason = DS_RM_UNCHANGED_DEP;
+ else if (!strcmp(v, "deferred")) r->reason = DS_RM_DEFERRED;
+ else if (!strcmp(v, "moved")) r->reason = DS_RM_MOVED;
+ else if (!strcmp(v, "shared")) r->reason = DS_RM_SHARED;
+ else if (!strcmp(v, "lookup")) r->reason = DS_RM_LOOKUP;
+ else PERR("removed reason=%s unknown", v);
+ if ((v = get(kvs, n, "ref"))) sset(r->ref, sizeof r->ref, v);
+ if ((v = get(kvs, n, "proof"))) sset(r->proof, sizeof r->proof, v);
+ m->n_removed++;
+ } else PERR("unknown record '%s'", keyword);
+ char bad[32];
+ if (unused_key(kvs, n, bad, sizeof bad)) PERR("unknown field %s= on '%s'", bad, keyword);
+ }
+ lineno = 0;
+ if (!seen_oev) PERR("missing 'oev version=1'");
+ if (!seen_machine) PERR("missing machine record");
+ if (!seen_build) PERR("missing build record");
+ if (!m->has_energy) PERR("missing energy record (use instrument=none for UNMEASURED)");
+ return DS_OK;
+}
+
+int ds_parse_file(const char *path, ds_model *m, char *err, size_t errcap) {
+ FILE *fp = fopen(path, "r");
+ if (!fp) { snprintf(err, errcap, "cannot open %s", path); return DS_PARSE_ERROR; }
+ fseek(fp, 0, SEEK_END); long n = ftell(fp); fseek(fp, 0, SEEK_SET);
+ if (n < 0 || n > (1 << 20)) { fclose(fp); snprintf(err, errcap, "file size out of range"); return DS_PARSE_ERROR; }
+ char *buf = malloc((size_t)n + 1);
+ if (!buf) { fclose(fp); snprintf(err, errcap, "out of memory"); return DS_PARSE_ERROR; }
+ size_t got = fread(buf, 1, (size_t)n, fp); buf[got] = 0; fclose(fp);
+ int rc = ds_parse_text(buf, m, err, errcap);
+ free(buf);
+ return rc;
+}
+
+/* ---------------------------------------------------------------- evaluate */
+
+/* resolved per-op numbers for one evaluation mode */
+typedef struct { double t, launch, bytes, cap; int prov; } ds_num; /* cap in B/ns */
+
+static double res_cap(const ds_resource *r, int mode) {
+ if (mode < 0) return r->lo;
+ if (mode > 0) return r->hi;
+ return r->cap;
+}
+
+static int refuse(ds_result *r, int status, const char *fmt, const char *a, const char *b) {
+ memset(r, 0, sizeof *r);
+ r->status = status;
+ snprintf(r->reason, sizeof r->reason, fmt, a ? a : "", b ? b : "");
+ return status;
+}
+
+static int refuse_msg(ds_result *r, int status, const char *msg) {
+ memset(r, 0, sizeof *r);
+ r->status = status;
+ snprintf(r->reason, sizeof r->reason, "%s", msg ? msg : "");
+ return status;
+}
+
+static int resolve(const ds_model *m, const ds_opts *o, ds_num *num, ds_result *r) {
+ int any_cal = 0;
+ for (int i = 0; i < m->n_res; i++) {
+ if (m->res[i].prov == DS_PROV_UNKNOWN) return refuse(r, DS_REFUSED_UNKNOWN, "resource %s has prov=unknown; unknown stays unknown%s", m->res[i].id, "");
+ if (m->res[i].prov == DS_PROV_MEASURED || m->res[i].prov == DS_PROV_FITTED) any_cal = 1;
+ }
+ for (int i = 0; i < m->n_ops; i++) {
+ const ds_op *op = &m->ops[i];
+ ds_num *x = &num[i];
+ memset(x, 0, sizeof *x);
+ x->prov = op->t_prov;
+ x->launch = op->launch_ns;
+ x->bytes = op->bytes;
+ x->cap = op->bw >= 0 ? res_cap(&m->res[op->bw], o->mode) * 1e-9 : 0; /* B/s -> B/ns */
+ if (op->kind == DS_OP_MATVEC && !op->has_t) {
+ const RxCostModel *cm = (const RxCostModel *)o->costmodel;
+ if (!cm) return refuse(r, DS_REFUSED_UNKNOWN, "op %s is a matvec with no rx_costmodel blob supplied (calibration model=)%s", op->id, "");
+ RxCmFeatures f; memset(&f, 0, sizeof f);
+ f.op = RX_CM_OP_MATVEC; f.M = op->M; f.N = op->N;
+ f.state_bytes = ((uint64_t)op->M * op->N + op->M + op->N) * 8u;
+ f.cache_bytes = 1u << 20; f.core = op->core; f.eligible = 1u << op->arm; f.current_arm = op->arm;
+ RxCmPrediction p; rx_cm_predict(cm, &f, op->arm, &p);
+ if (!p.known || p.n == 0) return refuse(r, DS_REFUSED_UNKNOWN, "op %s: rx_costmodel has no known cell for this (op, core, pressure) and arm; measure it first%s", op->id, "");
+ double q = o->interval_q > 0 && o->interval_q < 1 ? o->interval_q : 0.9;
+ double k = rx_cm_t_quantile(q, p.dof);
+ double l2 = p.mean_log2_ps + (o->mode < 0 ? k * p.sd_log2 : o->mode > 0 ? -k * p.sd_log2 : 0);
+ x->t = pow(2.0, l2) / 1000.0; /* ps -> ns */
+ x->prov = DS_PROV_FITTED;
+ any_cal = 1;
+ } else {
+ if (op->t_prov == DS_PROV_UNKNOWN) return refuse(r, DS_REFUSED_UNKNOWN, "op %s has prov=unknown (%s); unknown stays unknown", op->id, op->src[0] ? op->src : "no source");
+ x->t = o->mode < 0 ? op->hi : o->mode > 0 ? op->lo : op->t_ns;
+ if (op->t_prov == DS_PROV_MEASURED || op->t_prov == DS_PROV_FITTED) any_cal = 1;
+ }
+ if (op->engine < 0 && op->kind != DS_OP_BARRIER) return refuse(r, DS_REFUSED_UNSUPPORTED, "op %s has no engine%s", op->id, "");
+ if (op->launcher >= 0 && op->engine < 0) return refuse(r, DS_REFUSED_UNSUPPORTED, "op %s: launch without an engine%s", op->id, "");
+ }
+ if (any_cal) {
+ if (!m->has_calibration) return refuse(r, DS_REFUSED_NO_CALIBRATION, "measured or fitted values need a calibration record naming when and under what load they were taken%s%s", "", "");
+ int asof = o->asof_day;
+ if (asof <= 0) asof = (int)(time(NULL) / 86400);
+ if (asof > m->cal_taken_day + m->cal_valid_days) {
+ char d[64]; snprintf(d, sizeof d, "asof is %d day(s) past the validity envelope", asof - m->cal_taken_day - m->cal_valid_days);
+ return refuse(r, DS_REFUSED_STALE, "calibration %s is stale: %s", m->cal_id, d);
+ }
+ }
+ return DS_OK;
+}
+
+/* Kahn topological order; returns 0 on a cycle */
+static int topo(const ds_model *m, int *order) {
+ int indeg[DS_MAX_OPS] = {0};
+ for (int i = 0; i < m->n_deps; i++) indeg[m->deps[i].to]++;
+ int n = 0, head = 0;
+ for (int i = 0; i < m->n_ops; i++) if (indeg[i] == 0) order[n++] = i;
+ while (head < n) {
+ int u = order[head++];
+ for (int i = 0; i < m->n_deps; i++) if (m->deps[i].from == u && --indeg[m->deps[i].to] == 0) order[n++] = m->deps[i].to;
+ }
+ return n == m->n_ops;
+}
+
+enum { ST_WAIT = 0, ST_READY, ST_LAUNCH, ST_RUN, ST_DONE };
+enum { BLK_NONE = 0, BLK_SLOT, BLK_LAUNCHER };
+
+/* Half-open [start, end). Missing first -> 0; missing last -> makespan. */
+static void buffer_window(const ds_model *m, const ds_result *r, int b, double *s, double *e) {
+ *s = m->buf[b].first >= 0 ? r->start_ns[m->buf[b].first] : 0.0;
+ *e = m->buf[b].last >= 0 ? r->end_ns[m->buf[b].last] : r->makespan_ns;
+}
+
+static const char *endpoint_name(const ds_model *m, int op) {
+ return op >= 0 ? m->ops[op].id : "omitted";
+}
+
+/* Resolved end earlier than start is not an interval. Refuse before the ledger. */
+static int reject_inverted_lifetimes(const ds_model *m, ds_result *r) {
+ for (int b = 0; b < m->n_buf; b++) {
+ double s, e;
+ buffer_window(m, r, b, &s, &e);
+ if (e + 1e-9 < s) {
+ char msg[256];
+ snprintf(msg, sizeof msg,
+ "inverted lifetime for buffer %s: first=%s start_ns=%.9g last=%s end_ns=%.9g",
+ m->buf[b].id, endpoint_name(m, m->buf[b].first), s,
+ endpoint_name(m, m->buf[b].last), e);
+ return refuse_msg(r, DS_REFUSED_LIFETIME, msg);
+ }
+ }
+ return DS_OK;
+}
+
+int ds_eval(const ds_model *m, const ds_opts *o, ds_result *r) {
+ memset(r, 0, sizeof *r);
+ if (m->n_ops == 0) return refuse(r, DS_REFUSED_UNSUPPORTED, "empty DAG%s%s", "", "");
+ ds_num num[DS_MAX_OPS];
+ int rc = resolve(m, o, num, r);
+ if (rc) return rc;
+ int order[DS_MAX_OPS];
+ if (!topo(m, order)) return refuse(r, DS_REFUSED_CYCLE, "dependency cycle%s%s", "", "");
+ /* a buffer that never fits */
+ for (int i = 0; i < m->n_buf; i++)
+ if (m->buf[i].bytes > m->res[m->buf[i].cap].cap)
+ return refuse(r, DS_REFUSED_CAPACITY, "buffer %s alone exceeds capacity %s", m->buf[i].id, m->res[m->buf[i].cap].id);
+
+ /* provenance mask */
+ for (int i = 0; i < m->n_ops; i++) r->prov_mask |= 1u << num[i].prov;
+ for (int i = 0; i < m->n_res; i++) {
+ int used = 0;
+ for (int j = 0; j < m->n_ops; j++) if (m->ops[j].engine == i || m->ops[j].bw == i || m->ops[j].launcher == i) used = 1;
+ for (int j = 0; j < m->n_buf; j++) if (m->buf[j].cap == i) used = 1;
+ if (used) r->prov_mask |= 1u << m->res[i].prov;
+ }
+
+ /* ---- fluid simulation ---- */
+ int state[DS_MAX_OPS] = {0}, blocked[DS_MAX_OPS] = {0}, npred[DS_MAX_OPS] = {0}, done_pred[DS_MAX_OPS] = {0};
+ double rem_t[DS_MAX_OPS], rem_b[DS_MAX_OPS], rem_l[DS_MAX_OPS], run_start[DS_MAX_OPS], bytes_end[DS_MAX_OPS];
+ int free_slots[DS_MAX_RES], launcher_busy[DS_MAX_RES] = {0};
+ for (int i = 0; i < m->n_res; i++) free_slots[i] = m->res[i].slots;
+ for (int i = 0; i < m->n_deps; i++) npred[m->deps[i].to]++;
+ for (int i = 0; i < m->n_ops; i++) {
+ rem_t[i] = num[i].t; rem_b[i] = num[i].bytes; rem_l[i] = num[i].launch;
+ run_start[i] = bytes_end[i] = -1;
+ r->n_ops++;
+ r->total_bytes += num[i].bytes; r->total_busy_ns += num[i].t; r->total_launch_ns += num[i].launch;
+ }
+ double t = 0;
+ int remaining = m->n_ops, guard = 0;
+ while (remaining > 0) {
+ if (++guard > 8 * DS_MAX_OPS + 16) return refuse(r, DS_REFUSED_UNSUPPORTED, "scheduler did not converge%s%s", "", "");
+ /* deps satisfied -> ready */
+ for (int i = 0; i < m->n_ops; i++) if (state[i] == ST_WAIT && done_pred[i] == npred[i]) { state[i] = ST_READY; r->ready_ns[i] = t; }
+ /* dispatch in file order */
+ for (int i = 0; i < m->n_ops; i++) {
+ if (state[i] != ST_READY) continue;
+ const ds_op *op = &m->ops[i];
+ if (op->engine >= 0 && free_slots[op->engine] <= 0) { blocked[i] = BLK_SLOT; continue; }
+ if (op->launcher >= 0 && rem_l[i] > 0 && launcher_busy[op->launcher]) { blocked[i] = BLK_LAUNCHER; continue; }
+ if (op->engine >= 0) free_slots[op->engine]--;
+ r->start_ns[i] = t;
+ if (op->launcher >= 0 && rem_l[i] > 0) { launcher_busy[op->launcher] = 1; state[i] = ST_LAUNCH; }
+ else { state[i] = ST_RUN; run_start[i] = t; }
+ }
+ /* next event */
+ int active[DS_MAX_RES] = {0};
+ for (int i = 0; i < m->n_ops; i++) if (state[i] == ST_RUN && rem_b[i] > 0) active[m->ops[i].bw]++;
+ double dt = -1; int any = 0;
+ for (int i = 0; i < m->n_ops; i++) {
+ if (state[i] == ST_LAUNCH) { any = 1; if (dt < 0 || rem_l[i] < dt) dt = rem_l[i]; }
+ else if (state[i] == ST_RUN) {
+ any = 1;
+ /* next event for this op: the earlier of its two progress bars */
+ double d = -1;
+ if (rem_t[i] > 0) d = rem_t[i];
+ if (rem_b[i] > 0) {
+ double share = num[i].cap / active[m->ops[i].bw];
+ double db = rem_b[i] / share;
+ if (d < 0 || db < d) d = db;
+ }
+ if (d < 0) d = 0;
+ if (dt < 0 || d < dt) dt = d;
+ }
+ }
+ if (!any) return refuse(r, DS_REFUSED_UNSUPPORTED, "no op can make progress (slots=0 or all blocked)%s%s", "", "");
+ if (dt < 0) dt = 0;
+ t += dt;
+ const double eps = 1e-9;
+ for (int i = 0; i < m->n_ops; i++) {
+ if (state[i] == ST_LAUNCH) {
+ rem_l[i] -= dt;
+ if (rem_l[i] <= eps) { rem_l[i] = 0; launcher_busy[m->ops[i].launcher] = 0; state[i] = ST_RUN; run_start[i] = t; }
+ } else if (state[i] == ST_RUN) {
+ if (rem_t[i] > 0) { rem_t[i] -= dt; if (rem_t[i] <= eps) rem_t[i] = 0; }
+ if (rem_b[i] > 0) {
+ double share = num[i].cap / active[m->ops[i].bw];
+ rem_b[i] -= share * dt;
+ if (rem_b[i] <= eps * (num[i].bytes > 1 ? num[i].bytes : 1)) { rem_b[i] = 0; bytes_end[i] = t; }
+ }
+ if (rem_t[i] <= 0 && rem_b[i] <= 0) {
+ state[i] = ST_DONE; r->end_ns[i] = t; remaining--;
+ if (m->ops[i].engine >= 0) free_slots[m->ops[i].engine]++;
+ for (int d = 0; d < m->n_deps; d++) if (m->deps[d].from == i) done_pred[m->deps[d].to]++;
+ if (num[i].bytes > 0) {
+ double ideal = num[i].bytes / num[i].cap;
+ double actual = (bytes_end[i] >= 0 ? bytes_end[i] : t) - run_start[i];
+ r->op_contention_ns[i] = actual - ideal > 0 ? actual - ideal : 0;
+ }
+ }
+ }
+ }
+ if (t > r->makespan_ns) r->makespan_ns = t;
+ }
+
+ /* ---- bounds ---- */
+ double cp[DS_MAX_OPS];
+ for (int k = 0; k < m->n_ops; k++) {
+ int i = order[k];
+ double floor_ = num[i].t;
+ if (num[i].bytes > 0 && num[i].bytes / num[i].cap > floor_) floor_ = num[i].bytes / num[i].cap;
+ floor_ += num[i].launch;
+ r->op_floor_ns[i] = floor_;
+ double best = 0;
+ for (int d = 0; d < m->n_deps; d++) if (m->deps[d].to == i && cp[m->deps[d].from] > best) best = cp[m->deps[d].from];
+ cp[i] = best + floor_;
+ if (cp[i] > r->bound_critical_path_ns) r->bound_critical_path_ns = cp[i];
+ }
+ r->bound_ns = r->bound_critical_path_ns;
+ for (int i = 0; i < m->n_res; i++) {
+ double w = 0;
+ for (int j = 0; j < m->n_ops; j++) {
+ if (m->res[i].kind == DS_RES_BANDWIDTH && m->ops[j].bw == i) w += num[j].bytes / num[j].cap;
+ if (m->res[i].kind == DS_RES_COMPUTE && m->ops[j].engine == i) w += (num[j].t + num[j].launch) / m->res[i].slots;
+ if (m->res[i].kind == DS_RES_LAUNCH && m->ops[j].launcher == i) w += num[j].launch;
+ }
+ r->bound_resource_ns[i] = w;
+ if (w > r->bound_ns) r->bound_ns = w;
+ }
+
+ /* Inverted lifetimes never enter the ledger (and never rank). */
+ if ((rc = reject_inverted_lifetimes(m, r)) != DS_OK) return rc; /* LIFETIME_ORDER_CHECK */
+
+ /* ---- capacity ledger: frees before allocations at the same instant ----
+ * Positive intervals only. A zero-duration [s, e) is empty and emits no
+ * event, so a same-time free cannot pull the ledger negative or offset
+ * another buffer. Frees of earlier intervals still precede allocs, which
+ * is the completion/allocation tie. */
+ for (int c = 0; c < m->n_res; c++) {
+ if (m->res[c].kind != DS_RES_CAPACITY) continue;
+ double live = 0, peak = 0, peak_at = 0;
+ /* event list */
+ double et[2 * DS_MAX_BUF]; double ev[2 * DS_MAX_BUF]; int en = 0;
+ for (int b = 0; b < m->n_buf; b++) {
+ if (m->buf[b].cap != c) continue;
+ double s, e;
+ buffer_window(m, r, b, &s, &e);
+ if (!(s + 1e-9 < e)) continue;
+ et[en] = s; ev[en] = m->buf[b].bytes; en++;
+ et[en] = e; ev[en] = -m->buf[b].bytes; en++;
+ }
+ /* insertion sort by time, frees (negative) first on ties; stable */
+ for (int i = 1; i < en; i++) {
+ double kt = et[i], kv_ = ev[i]; int j = i - 1;
+ while (j >= 0 && (et[j] > kt || (et[j] == kt && ev[j] > 0 && kv_ < 0))) { et[j + 1] = et[j]; ev[j + 1] = ev[j]; j--; }
+ et[j + 1] = kt; ev[j + 1] = kv_;
+ }
+ for (int i = 0; i < en; i++) {
+ live += ev[i];
+ if (live < -1e-6) {
+ char msg[256];
+ snprintf(msg, sizeof msg,
+ "capacity %s live bytes went negative (%.9g at t=%.9g); refusing the certificate",
+ m->res[c].id, live, et[i]);
+ return refuse_msg(r, DS_REFUSED_LIFETIME, msg);
+ }
+ if (live > peak) { peak = live; peak_at = et[i]; }
+ }
+ r->peak_live_bytes[c] = peak; r->peak_live_at_ns[c] = peak_at;
+ if (peak > m->res[c].cap + 1e-9) {
+ char names[160] = ""; size_t L = 0;
+ for (int b = 0; b < m->n_buf && L < sizeof names - 8; b++) {
+ if (m->buf[b].cap != c) continue;
+ double s, e;
+ buffer_window(m, r, b, &s, &e);
+ if (s <= peak_at && e > peak_at) { snprintf(names + L, sizeof names - L, "%s%s", L ? "," : "", m->buf[b].id); L = strlen(names); }
+ }
+ char what[200]; snprintf(what, sizeof what, "%.0f B live at t=%.0f ns (%s) exceeds", peak, peak_at, names);
+ int st = refuse(r, DS_REFUSED_CAPACITY, "%s %s", what, m->res[c].id);
+ return st;
+ }
+ }
+
+ /* ---- attribution along the schedule's critical chain ---- */
+ int cur = 0;
+ for (int i = 1; i < m->n_ops; i++) if (r->end_ns[i] > r->end_ns[cur]) cur = i;
+ double accounted = 0;
+ int chain[DS_MAX_OPS]; int nc = 0;
+ while (cur >= 0 && nc < DS_MAX_OPS) {
+ chain[nc++] = cur;
+ const ds_op *op = &m->ops[cur];
+ double runtime = r->end_ns[cur] - (run_start[cur] >= 0 ? run_start[cur] : r->start_ns[cur]);
+ r->attr_ns[DS_ATTR_LAUNCH] += num[cur].launch;
+ accounted += num[cur].launch;
+ if (op->kind == DS_OP_BARRIER) r->attr_ns[DS_ATTR_SYNC] += runtime;
+ else if (num[cur].bytes > 0) {
+ double ideal = num[cur].bytes / num[cur].cap;
+ double actual = ideal + r->op_contention_ns[cur];
+ if (num[cur].t >= actual) r->attr_ns[DS_ATTR_COMPUTE] += runtime;
+ else { r->attr_ns[DS_ATTR_BANDWIDTH] += ideal; r->attr_ns[DS_ATTR_CONTENTION] += r->op_contention_ns[cur]; if (runtime > actual) r->attr_ns[DS_ATTR_RESIDUAL] += runtime - actual; }
+ } else r->attr_ns[DS_ATTR_COMPUTE] += runtime;
+ accounted += runtime;
+ /* predecessor: the dep that finished last */
+ int pred = -1;
+ for (int d = 0; d < m->n_deps; d++) if (m->deps[d].to == cur && (pred < 0 || r->end_ns[m->deps[d].from] > r->end_ns[pred])) pred = m->deps[d].from;
+ double gap = r->start_ns[cur] - (pred >= 0 ? r->end_ns[pred] : 0);
+ if (gap > 0) {
+ if (blocked[cur] == BLK_SLOT) r->attr_ns[DS_ATTR_SERIALIZATION] += gap;
+ else if (blocked[cur] == BLK_LAUNCHER) r->attr_ns[DS_ATTR_LAUNCH] += gap;
+ else r->attr_ns[DS_ATTR_RESIDUAL] += gap;
+ accounted += gap;
+ }
+ cur = pred;
+ }
+ for (int i = 0; i < nc; i++) r->critical_path[i] = chain[nc - 1 - i];
+ r->n_critical = nc;
+ double leftover = r->makespan_ns - accounted;
+ if (fabs(leftover) > 1e-6) r->attr_ns[DS_ATTR_RESIDUAL] += leftover;
+
+ /* ---- energy ---- */
+ if (m->has_energy && m->joules > 0 && strcmp(m->instrument, "none")) { r->energy_measured = 1; r->energy_j = m->joules; }
+ else if (m->has_energy && m->power_w > 0 && m->energy_prov == DS_PROV_SYNTHETIC) { r->energy_synthetic = 1; r->energy_j = m->power_w * r->makespan_ns * 1e-9; r->prov_mask |= 1u << DS_PROV_SYNTHETIC; }
+ r->synthetic = (r->prov_mask & (1u << DS_PROV_SYNTHETIC)) ? 1 : 0;
+ r->status = DS_OK;
+ return DS_OK;
+}
+
+int ds_eval_interval(const ds_model *m, const ds_opts *o, ds_result *nominal, double *lo_ns, double *hi_ns) {
+ ds_opts x = *o; x.mode = 0;
+ int rc = ds_eval(m, &x, nominal);
+ *lo_ns = *hi_ns = 0;
+ if (rc) return rc;
+ ds_result tmp;
+ x.mode = +1; if (ds_eval(m, &x, &tmp) == DS_OK) *lo_ns = tmp.makespan_ns;
+ x.mode = -1; if (ds_eval(m, &x, &tmp) == DS_OK) *hi_ns = tmp.makespan_ns;
+ return rc;
+}
+
+double ds_counterfactual(const ds_model *m, const ds_opts *o, int res_index) {
+ if (res_index < 0 || res_index >= m->n_res) return -DS_REFUSED_UNSUPPORTED;
+ ds_model *c = malloc(sizeof *c);
+ if (!c) return -DS_REFUSED_UNSUPPORTED;
+ *c = *m;
+ ds_resource *r = &c->res[res_index];
+ switch (r->kind) {
+ case DS_RES_BANDWIDTH: r->cap *= 2; r->lo *= 2; r->hi *= 2; break;
+ case DS_RES_COMPUTE: r->slots *= 2; break;
+ case DS_RES_LAUNCH: for (int i = 0; i < c->n_ops; i++) if (c->ops[i].launcher == res_index) c->ops[i].launch_ns = 0; break;
+ case DS_RES_CAPACITY: r->cap *= 2; break;
+ }
+ ds_result res; ds_opts x = *o; x.mode = 0;
+ int rc = ds_eval(c, &x, &res);
+ free(c);
+ return rc == DS_OK ? res.makespan_ns : -(double)rc;
+}
+
+/* ---------------------------------------------------------------- diff */
+
+static int in_changed(const char *list, const char *id) {
+ if (!list) return 0;
+ const char *p = list; size_t L = strlen(id);
+ while (*p) {
+ const char *q = strchr(p, ','); size_t n = q ? (size_t)(q - p) : strlen(p);
+ if (n == L && !strncmp(p, id, L)) return 1;
+ if (!q) break;
+ p = q + 1;
+ }
+ return 0;
+}
+
+int ds_diff_models(const ds_model *b, const ds_model *t, const ds_opts *o, ds_diff *d) {
+ memset(d, 0, sizeof *d);
+ for (int i = 0; i < t->n_ops; i++) if (ds_find_op(b, t->ops[i].id) < 0) d->n_added++;
+ for (int i = 0; i < b->n_ops; i++) {
+ int j = ds_find_op(t, b->ops[i].id);
+ if (j >= 0) {
+ d->n_kept++;
+ if (b->ops[i].t_ns != t->ops[j].t_ns || b->ops[i].bytes != t->ops[j].bytes)
+ snprintf(d->reason, sizeof d->reason, "op %s kept but its demand changed; trace conservation broken", b->ops[i].id);
+ continue;
+ }
+ d->n_removed++;
+ /* find its removed record(s) */
+ int found = 0; const ds_removed *rec = NULL;
+ for (int k = 0; k < t->n_removed; k++) if (!strcmp(t->removed[k].op, b->ops[i].id)) { found++; rec = &t->removed[k]; }
+ if (found == 0) { d->required_removed = 1; snprintf(d->reason, sizeof d->reason, "op %s vanished without a removed record", b->ops[i].id); return DS_REFUSED_REMOVED_REQUIRED; }
+ if (found > 1) { d->double_counted = 1; snprintf(d->reason, sizeof d->reason, "op %s removed %d times (double counted)", b->ops[i].id, found); return DS_REFUSED_REMOVED_REQUIRED; }
+ /* consumers of the removed op in the baseline that still exist */
+ int has_consumer = 0;
+ for (int k = 0; k < b->n_deps; k++) if (b->deps[k].from == i && ds_find_op(t, b->ops[b->deps[k].to].id) >= 0) has_consumer = 1;
+ int ok = 1;
+ switch (rec->reason) {
+ case DS_RM_ELIMINATED: if (has_consumer && !rec->proof[0]) ok = 0; break;
+ case DS_RM_REUSED: case DS_RM_LOOKUP: case DS_RM_MOVED: if (!rec->ref[0] || ds_find_op(t, rec->ref) < 0) ok = 0; break;
+ case DS_RM_UNCHANGED_DEP: if (!rec->ref[0] || ds_find_op(b, rec->ref) < 0 || in_changed(o ? o->changed : NULL, rec->ref)) ok = 0; break;
+ case DS_RM_DEFERRED: if (has_consumer) ok = 0; break;
+ case DS_RM_SHARED:
+ if (!rec->ref[0] || ds_find_op(t, rec->ref) < 0) ok = 0;
+ for (int k = 0; k < t->n_removed; k++) if (!strcmp(t->removed[k].op, rec->ref)) { d->double_counted = 1; ok = 0; }
+ break;
+ }
+ if (!ok) {
+ d->required_removed = 1;
+ snprintf(d->reason, sizeof d->reason, "op %s: removal reason %d not supported by its evidence (ref=%s proof=%s changed=%s)",
+ b->ops[i].id, rec->reason, rec->ref, rec->proof, o && o->changed ? o->changed : "");
+ return DS_REFUSED_REMOVED_REQUIRED;
+ }
+ double w = b->ops[i].t_ns + b->ops[i].launch_ns;
+ if (b->ops[i].bytes > 0 && b->ops[i].bw >= 0) { double tb = b->ops[i].bytes / (b->res[b->ops[i].bw].cap * 1e-9); if (tb > b->ops[i].t_ns) w = tb + b->ops[i].launch_ns; }
+ d->removed_ns[rec->reason] += w;
+ }
+ /* removed records that name ops never in the baseline are fabricated savings */
+ for (int k = 0; k < t->n_removed; k++) if (ds_find_op(b, t->removed[k].op) < 0) {
+ d->double_counted = 1;
+ snprintf(d->reason, sizeof d->reason, "removed record for %s, which was never in the baseline", t->removed[k].op);
+ return DS_REFUSED_REMOVED_REQUIRED;
+ }
+ return DS_OK;
+}
diff --git a/tools/dagsim/dagsim.h b/tools/dagsim/dagsim.h
new file mode 100644
index 000000000 ..8ab62e55d
--- /dev/null
+++ b/tools/dagsim/dagsim.h
@@ -0,0 +1,168 @@
+/*
+ * dagsim.h -- offline resource-DAG cost evaluator (omega-mv#583).
+ *
+ * Reads an OEV1 file (spec/offline-evidence-v1.md) and composes the per-op
+ * costs it carries, or that rx_costmodel predicts for matvec ops, into a
+ * whole-DAG schedule under finite resources: compute slots, shared
+ * bandwidth (processor sharing), serialized launches, one capacity ledger,
+ * dependencies and barriers. It never executes anything. It refuses rather
+ * than guess: unknown provenance, stale calibration, capacity overflow,
+ * an inverted buffer lifetime (resolved end before start), unsupported
+ * constructs and cycles are all refusals with a reason.
+ *
+ * Host only. No GPU, no authority, no generation store.
+ */
+#ifndef DAGSIM_H
+#define DAGSIM_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#define DS_MAX_OPS 256
+#define DS_MAX_RES 32
+#define DS_MAX_BUF 256
+#define DS_MAX_DEPS 1024
+#define DS_MAX_REMOVED 256
+#define DS_ID 40
+#define DS_SRC 128
+
+enum ds_prov { DS_PROV_UNKNOWN = 0, DS_PROV_SYNTHETIC, DS_PROV_FITTED, DS_PROV_MEASURED, DS_PROV_SPECIFIED };
+enum ds_res_kind { DS_RES_COMPUTE = 1, DS_RES_BANDWIDTH, DS_RES_CAPACITY, DS_RES_LAUNCH };
+enum ds_op_kind { DS_OP_COMPUTE = 1, DS_OP_COPY, DS_OP_MATVEC, DS_OP_BARRIER, DS_OP_STORAGE, DS_OP_PERSIST };
+enum ds_removed_reason { DS_RM_ELIMINATED = 1, DS_RM_REUSED, DS_RM_UNCHANGED_DEP, DS_RM_DEFERRED, DS_RM_MOVED, DS_RM_SHARED, DS_RM_LOOKUP };
+
+enum ds_status {
+ DS_OK = 0,
+ DS_REFUSED_UNKNOWN, /* an op or resource with prov=unknown feeds the result */
+ DS_REFUSED_STALE, /* asof is past calibration taken + valid_days */
+ DS_REFUSED_NO_CALIBRATION, /* measured/fitted values but no calibration record */
+ DS_REFUSED_CAPACITY, /* peak live bytes exceed a capacity resource */
+ DS_REFUSED_CYCLE,
+ DS_REFUSED_UNSUPPORTED, /* construct the evaluator does not model */
+ DS_REFUSED_REMOVED_REQUIRED, /* a remaining op depends on removed work without a valid derivation */
+ DS_REFUSED_LIFETIME, /* resolved buffer end is earlier than its start */
+ DS_PARSE_ERROR
+};
+
+typedef struct {
+ char id[DS_ID];
+ int kind;
+ int slots; /* compute */
+ double cap, lo, hi; /* bandwidth (B/s) or capacity (B) */
+ int prov;
+ char src[DS_SRC];
+} ds_resource;
+
+typedef struct {
+ char id[DS_ID];
+ int kind;
+ int engine; /* resource index or -1 */
+ double t_ns, lo, hi; /* own busy time */
+ int t_prov;
+ int has_t;
+ double bytes;
+ int bw; /* bandwidth resource index or -1 */
+ double launch_ns;
+ int launcher; /* launch resource index or -1 */
+ uint32_t M, N, core, arm; /* matvec */
+ char src[DS_SRC];
+} ds_op;
+
+typedef struct { char id[DS_ID]; double bytes; int cap; int first, last; } ds_buffer;
+typedef struct { int from, to; } ds_dep;
+typedef struct { char op[DS_ID]; int reason; char ref[DS_ID]; char proof[DS_SRC]; } ds_removed;
+
+typedef struct {
+ int version;
+ char machine_id[DS_ID], soc[DS_ID];
+ int cores;
+ double mem_bytes;
+ char build_sha[48], physics[48], repo[DS_ID];
+ int has_calibration;
+ char cal_id[DS_ID];
+ int cal_taken_day; /* days since 1970-01-01 */
+ int cal_valid_days;
+ double cal_load1;
+ char cal_src[DS_SRC], cal_model[DS_SRC];
+ int n_res, n_ops, n_buf, n_deps, n_removed;
+ ds_resource res[DS_MAX_RES];
+ ds_op ops[DS_MAX_OPS];
+ ds_buffer buf[DS_MAX_BUF];
+ ds_dep deps[DS_MAX_DEPS];
+ ds_removed removed[DS_MAX_REMOVED];
+ /* energy */
+ char instrument[DS_ID], boundary[DS_ID];
+ int energy_prov;
+ double joules, power_w;
+ int has_energy;
+} ds_model;
+
+typedef struct {
+ int asof_day; /* days since epoch; 0 = today */
+ int mode; /* 0 nominal, -1 pessimistic (lo bandwidth, hi time), +1 optimistic */
+ const void *costmodel; /* const RxCostModel* or NULL */
+ double interval_q; /* for rx_costmodel intervals, e.g. 0.9 */
+ const char *changed; /* diff only: comma list of baseline ops whose inputs changed */
+} ds_opts;
+
+enum { DS_ATTR_COMPUTE = 0, DS_ATTR_BANDWIDTH, DS_ATTR_CONTENTION, DS_ATTR_LAUNCH, DS_ATTR_SERIALIZATION, DS_ATTR_SYNC, DS_ATTR_RESIDUAL, DS_ATTR_N };
+
+typedef struct {
+ int status;
+ char reason[256];
+ double makespan_ns;
+ double start_ns[DS_MAX_OPS], end_ns[DS_MAX_OPS], ready_ns[DS_MAX_OPS];
+ double op_contention_ns[DS_MAX_OPS]; /* extra traffic time due to sharing */
+ double op_floor_ns[DS_MAX_OPS]; /* launch + max(t, bytes/cap) */
+ double bound_critical_path_ns;
+ double bound_resource_ns[DS_MAX_RES]; /* per resource work bound */
+ double bound_ns; /* max of all bounds */
+ double peak_live_bytes[DS_MAX_RES]; /* per capacity resource */
+ double peak_live_at_ns[DS_MAX_RES];
+ double attr_ns[DS_ATTR_N];
+ int critical_path[DS_MAX_OPS], n_critical;
+ uint32_t prov_mask; /* bit per ds_prov that fed the result */
+ int synthetic;
+ /* conservation: what went in is what was scheduled */
+ int n_ops;
+ double total_bytes, total_busy_ns, total_launch_ns;
+ /* energy */
+ int energy_measured; /* 1: joules from a named instrument */
+ int energy_synthetic; /* 1: E = P*T from a synthetic power figure */
+ double energy_j;
+} ds_result;
+
+/* Parse. Returns DS_OK or DS_PARSE_ERROR with the line and reason in `err`. */
+int ds_parse_file(const char *path, ds_model *m, char *err, size_t errcap);
+int ds_parse_text(const char *text, ds_model *m, char *err, size_t errcap);
+
+/* Evaluate deterministically. Fills every field of `r` or sets a refusal. */
+int ds_eval(const ds_model *m, const ds_opts *o, ds_result *r);
+
+/* Three-point interval: nominal, lo (optimistic) and hi (pessimistic) makespan.
+ * Returns the nominal status; lo/hi are 0 when any point refused. */
+int ds_eval_interval(const ds_model *m, const ds_opts *o, ds_result *nominal, double *lo_ns, double *hi_ns);
+
+/* Counterfactual sensitivity: makespan with one resource doubled (bandwidth cap x2,
+ * compute slots x2, launch cost 0). Returns the new makespan or a negative status. */
+double ds_counterfactual(const ds_model *m, const ds_opts *o, int res_index);
+
+/* Minimum-work accounting: compare a baseline and a transformed model by stable op
+ * ids. Sums removed work by reason and detects double-counted shared work and removal
+ * of required work. */
+typedef struct {
+ double removed_ns[8]; /* by ds_removed_reason */
+ int n_removed, n_added, n_kept;
+ int double_counted; /* an op removed with reason=shared appears twice or refs a missing op */
+ int required_removed; /* a removed op without a valid derivation still has consumers */
+ char reason[256];
+} ds_diff;
+int ds_diff_models(const ds_model *baseline, const ds_model *transformed, const ds_opts *o, ds_diff *d);
+
+const char *ds_status_name(int s);
+const char *ds_prov_name(int p);
+int ds_day_from_date(const char *yyyy_mm_dd);
+int ds_find_op(const ds_model *m, const char *id);
+int ds_find_res(const ds_model *m, const char *id);
+
+#endif /* DAGSIM_H */
diff --git a/tools/dagsim/dagsim_cli.c b/tools/dagsim/dagsim_cli.c
new file mode 100644
index 000000000 ..fb279f904
--- /dev/null
+++ b/tools/dagsim/dagsim_cli.c
@@ -0,0 +1,222 @@
+/*
+ * dagsim_cli -- reproducible command line for the offline resource-DAG
+ * evaluator (omega-mv#583). No GPU, no execution: it reads OEV1 files and
+ * prints JSON. Every number it prints names the provenance it came from.
+ *
+ * dagsim eval FILE [--asof YYYY-MM-DD] [--model BLOB]
+ * dagsim pareto FILE... [--asof YYYY-MM-DD] [--model BLOB]
+ * dagsim diff BASELINE TRANSFORMED [--changed a,b,...]
+ */
+#include "dagsim.h"
+#include "runtime/rx_costmodel.h"
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+static void jstr(const char *s) {
+ putchar('"');
+ for (; *s; s++) {
+ if (*s == '"' || *s == '\\') { putchar('\\'); putchar(*s); }
+ else if ((unsigned char)*s < 0x20) printf("\\u%04x", *s);
+ else putchar(*s);
+ }
+ putchar('"');
+}
+static void jnum(double v) { if (v == floor(v) && fabs(v) < 1e15) printf("%.0f", v); else printf("%.6g", v); }
+
+static int load_model(const char *path, RxCostModel *cm) {
+ FILE *fp = fopen(path, "rb");
+ if (!fp) return 0;
+ size_t cap = rx_cm_blob_size();
+ uint8_t *buf = malloc(cap);
+ if (!buf) { fclose(fp); return 0; }
+ size_t got = fread(buf, 1, cap, fp);
+ fclose(fp);
+ int ok = rx_cm_deserialize(cm, buf, got) == RX_CM_OK;
+ free(buf);
+ return ok;
+}
+
+static const char *attr_name[DS_ATTR_N] = { "compute", "bandwidth", "contention", "launch", "serialization", "sync", "residual" };
+static const char *res_kind_name(int k) {
+ switch (k) { case DS_RES_COMPUTE: return "compute"; case DS_RES_BANDWIDTH: return "bandwidth"; case DS_RES_CAPACITY: return "capacity"; case DS_RES_LAUNCH: return "launch"; default: return "?"; }
+}
+
+static void emit_result_json(const char *path, const ds_model *m, const ds_opts *o, const ds_result *r, double lo, double hi) {
+ printf("{\n \"schema\": \"oev1\", \"tool\": \"dagsim\", \"file\": "); jstr(path);
+ printf(",\n \"machine\": "); jstr(m->machine_id);
+ printf(", \"build_sha\": "); jstr(m->build_sha);
+ printf(",\n \"calibration\": {\"id\": "); jstr(m->has_calibration ? m->cal_id : "");
+ printf(", \"taken_day\": %d, \"valid_days\": %d, \"load1\": ", m->cal_taken_day, m->cal_valid_days); jnum(m->cal_load1);
+ printf(", \"src\": "); jstr(m->cal_src); printf("},\n \"asof_day\": %d,\n", o->asof_day);
+ printf(" \"status\": "); jstr(ds_status_name(r->status)); printf(", \"reason\": "); jstr(r->reason);
+ printf(",\n \"provenance\": ["); int first = 1;
+ for (int p = 0; p <= DS_PROV_SPECIFIED; p++) if (r->prov_mask & (1u << p)) { if (!first) printf(", "); jstr(ds_prov_name(p)); first = 0; }
+ printf("], \"synthetic\": %d, \"offline\": true, \"gpu_executed\": false", r->synthetic);
+ if (r->status != DS_OK) { printf("\n}\n"); return; }
+ printf(",\n \"makespan_ns\": {\"nominal\": "); jnum(r->makespan_ns); printf(", \"lo\": "); jnum(lo); printf(", \"hi\": "); jnum(hi);
+ printf(", \"interval_known\": %s}", (lo > 0 && hi > 0) ? "true" : "false");
+ printf(",\n \"bounds_ns\": {\"critical_path\": "); jnum(r->bound_critical_path_ns); printf(", \"max\": "); jnum(r->bound_ns); printf(", \"resources\": {");
+ for (int i = 0; i < m->n_res; i++) { if (i) printf(", "); jstr(m->res[i].id); printf(": "); jnum(r->bound_resource_ns[i]); }
+ printf("}, \"makespan_ge_bounds\": %s}", r->makespan_ns + 1e-6 >= r->bound_ns ? "true" : "false");
+ printf(",\n \"ops\": [");
+ for (int i = 0; i < m->n_ops; i++) {
+ printf("%s\n {\"id\": ", i ? "," : ""); jstr(m->ops[i].id);
+ printf(", \"start_ns\": "); jnum(r->start_ns[i]); printf(", \"end_ns\": "); jnum(r->end_ns[i]);
+ printf(", \"floor_ns\": "); jnum(r->op_floor_ns[i]); printf(", \"contention_ns\": "); jnum(r->op_contention_ns[i]);
+ printf(", \"prov\": "); jstr(ds_prov_name(m->ops[i].kind == DS_OP_MATVEC && !m->ops[i].has_t ? DS_PROV_FITTED : m->ops[i].t_prov));
+ printf(", \"src\": "); jstr(m->ops[i].src); printf("}");
+ }
+ printf("\n ],\n \"critical_path\": [");
+ for (int i = 0; i < r->n_critical; i++) { if (i) printf(", "); jstr(m->ops[r->critical_path[i]].id); }
+ printf("],\n \"peak_live_bytes\": {");
+ first = 1;
+ for (int i = 0; i < m->n_res; i++) if (m->res[i].kind == DS_RES_CAPACITY) {
+ if (!first) printf(", ");
+ first = 0;
+ jstr(m->res[i].id); printf(": {\"bytes\": "); jnum(r->peak_live_bytes[i]); printf(", \"at_ns\": "); jnum(r->peak_live_at_ns[i]); printf(", \"cap\": "); jnum(m->res[i].cap); printf("}");
+ }
+ printf("},\n \"attribution_ns\": {");
+ for (int i = 0; i < DS_ATTR_N; i++) { if (i) printf(", "); jstr(attr_name[i]); printf(": "); jnum(r->attr_ns[i]); }
+ printf("},\n \"energy\": {\"status\": ");
+ jstr(r->energy_measured ? "MEASURED" : r->energy_synthetic ? "SYNTHETIC_SENSITIVITY_ONLY" : "UNMEASURED");
+ printf(", \"joules\": "); if (r->energy_measured || r->energy_synthetic) jnum(r->energy_j); else printf("null");
+ printf(", \"instrument\": "); jstr(m->instrument); printf(", \"boundary\": "); jstr(m->boundary);
+ printf(", \"ranking_valid\": %s}", r->energy_measured ? "true" : "false");
+ printf(",\n \"conservation\": {\"n_ops\": %d, \"total_bytes\": ", r->n_ops); jnum(r->total_bytes);
+ printf(", \"total_busy_ns\": "); jnum(r->total_busy_ns); printf(", \"total_launch_ns\": "); jnum(r->total_launch_ns);
+ printf(", \"instrument_overhead_ns\": null}");
+ /* counterfactual sensitivities, ranked by how much they could move the makespan,
+ * weighted by how uncertain the resource's own figure is */
+ printf(",\n \"sensitivities\": [");
+ double score[DS_MAX_RES]; int idx[DS_MAX_RES]; double cf[DS_MAX_RES]; double width[DS_MAX_RES];
+ for (int i = 0; i < m->n_res; i++) {
+ cf[i] = ds_counterfactual(m, o, i);
+ width[i] = m->res[i].kind == DS_RES_BANDWIDTH && m->res[i].cap > 0 ? (m->res[i].hi - m->res[i].lo) / m->res[i].cap : 0;
+ if (m->res[i].prov == DS_PROV_SPECIFIED) width[i] = 1.0; /* a datasheet number is not a measurement */
+ score[i] = cf[i] >= 0 ? fabs(r->makespan_ns - cf[i]) * (width[i] > 0 ? width[i] : 0.05) : 0;
+ idx[i] = i;
+ }
+ for (int a = 1; a < m->n_res; a++) {
+ int k = idx[a]; int b = a - 1;
+ while (b >= 0 && score[idx[b]] < score[k]) { idx[b + 1] = idx[b]; b--; }
+ idx[b + 1] = k;
+ }
+ for (int a = 0; a < m->n_res; a++) {
+ int i = idx[a];
+ printf("%s\n {\"resource\": ", a ? "," : ""); jstr(m->res[i].id);
+ printf(", \"kind\": "); jstr(res_kind_name(m->res[i].kind));
+ printf(", \"makespan_if_doubled_ns\": "); if (cf[i] >= 0) jnum(cf[i]); else printf("null");
+ printf(", \"delta_ns\": "); if (cf[i] >= 0) jnum(r->makespan_ns - cf[i]); else printf("null");
+ printf(", \"interval_width_frac\": "); jnum(width[i]);
+ printf(", \"decision_score\": "); jnum(score[i]);
+ printf(", \"next_experiment\": ");
+ if (m->res[i].kind == DS_RES_BANDWIDTH) jstr(m->res[i].prov == DS_PROV_SPECIFIED ? "measure this bandwidth on this DAG's shapes (datasheet figure, never attained)" : "repeat the bandwidth receipt on a quiet box to tighten lo/hi");
+ else if (m->res[i].kind == DS_RES_LAUNCH) jstr("measure launch with the device context held open (M1 block2 follow-up)");
+ else if (m->res[i].kind == DS_RES_COMPUTE) jstr("measure the critical op at the next larger shape");
+ else jstr("none: capacity is a ledger, not a rate");
+ printf("}");
+ }
+ printf("\n ],\n \"unresolved_residual_ns\": "); jnum(r->attr_ns[DS_ATTR_RESIDUAL]);
+ printf(",\n \"note\": \"loaded-box calibration (load1 above); bounds are floors, not predictions; no performance claim from this simulation alone\"\n}\n");
+}
+
+static int cmd_eval(const char *path, const ds_opts *o) {
+ ds_model *m = malloc(sizeof *m); char err[256];
+ if (!m) return 2;
+ if (ds_parse_file(path, m, err, sizeof err) != DS_OK) {
+ printf("{\"schema\": \"oev1\", \"tool\": \"dagsim\", \"file\": "); jstr(path); printf(", \"status\": \"PARSE_ERROR\", \"reason\": "); jstr(err); printf("}\n");
+ free(m); return 1;
+ }
+ ds_result *r = malloc(sizeof *r); double lo, hi;
+ if (!r) { free(m); return 2; }
+ int rc = ds_eval_interval(m, o, r, &lo, &hi);
+ emit_result_json(path, m, o, r, lo, hi);
+ free(r); free(m);
+ return rc == DS_OK ? 0 : 1;
+}
+
+typedef struct { const char *path; int status; double t, lo, hi, peak, e; int e_meas, e_syn, front; char reason[256]; } prow;
+
+static int cmd_pareto(int n, const char **paths, const ds_opts *o) {
+ prow rows[64]; if (n > 64) n = 64;
+ int all_energy = 1;
+ for (int k = 0; k < n; k++) {
+ prow *p = &rows[k]; memset(p, 0, sizeof *p); p->path = paths[k];
+ ds_model *m = malloc(sizeof *m); ds_result *r = malloc(sizeof *r); char err[256];
+ if (!m || !r) return 2;
+ if (ds_parse_file(paths[k], m, err, sizeof err) != DS_OK) { p->status = DS_PARSE_ERROR; snprintf(p->reason, sizeof p->reason, "%s", err); free(m); free(r); all_energy = 0; continue; }
+ p->status = ds_eval_interval(m, o, r, &p->lo, &p->hi);
+ snprintf(p->reason, sizeof p->reason, "%s", r->reason);
+ if (p->status == DS_OK) {
+ p->t = r->makespan_ns;
+ for (int i = 0; i < m->n_res; i++) if (m->res[i].kind == DS_RES_CAPACITY && r->peak_live_bytes[i] > p->peak) p->peak = r->peak_live_bytes[i];
+ p->e = r->energy_j; p->e_meas = r->energy_measured; p->e_syn = r->energy_synthetic;
+ if (!p->e_meas) all_energy = 0;
+ } else all_energy = 0;
+ free(m); free(r);
+ }
+ /* non-dominated on (time, peak bytes[, measured joules]) among OK rows */
+ for (int a = 0; a < n; a++) {
+ if (rows[a].status != DS_OK) continue;
+ rows[a].front = 1;
+ for (int b = 0; b < n; b++) {
+ if (a == b || rows[b].status != DS_OK) continue;
+ int le = rows[b].t <= rows[a].t && rows[b].peak <= rows[a].peak && (!all_energy || rows[b].e <= rows[a].e);
+ int lt = rows[b].t < rows[a].t || rows[b].peak < rows[a].peak || (all_energy && rows[b].e < rows[a].e);
+ if (le && lt) { rows[a].front = 0; break; }
+ }
+ }
+ printf("# dagsim pareto: objectives = seconds, peak bytes%s. Energy %s.\n", all_energy ? ", joules" : "",
+ all_energy ? "measured on every row and part of the dominance test" : "not measured on every row: shown, never ranked");
+ printf("# %-36s %-24s %14s %14s %14s %12s %-14s %s\n", "file", "status", "seconds", "lo_s", "hi_s", "peak_bytes", "energy", "front");
+ for (int k = 0; k < n; k++) {
+ prow *p = &rows[k];
+ char e[32];
+ if (p->e_meas) snprintf(e, sizeof e, "%.3f J", p->e); else if (p->e_syn) snprintf(e, sizeof e, "syn %.3f J", p->e); else snprintf(e, sizeof e, "UNMEASURED");
+ if (p->status == DS_OK)
+ printf(" %-36s %-24s %14.6f %14.6f %14.6f %12.0f %-14s %s\n", p->path, "OK", p->t * 1e-9, p->lo * 1e-9, p->hi * 1e-9, p->peak, e, p->front ? "yes" : "no");
+ else
+ printf(" %-36s %-24s %14s %14s %14s %12s %-14s %s # %s\n", p->path, ds_status_name(p->status), "-", "-", "-", "-", "-", "refused", p->reason);
+ }
+ return 0;
+}
+
+static int cmd_diff(const char *a, const char *b, const ds_opts *o) {
+ ds_model *ma = malloc(sizeof *ma), *mb = malloc(sizeof *mb); char err[256]; ds_diff d;
+ if (!ma || !mb) return 2;
+ if (ds_parse_file(a, ma, err, sizeof err) != DS_OK) { fprintf(stderr, "%s: %s\n", a, err); return 1; }
+ if (ds_parse_file(b, mb, err, sizeof err) != DS_OK) { fprintf(stderr, "%s: %s\n", b, err); return 1; }
+ int rc = ds_diff_models(ma, mb, o, &d);
+ static const char *rn[8] = { "", "eliminated", "reused", "unchanged_dep", "deferred", "moved", "shared", "lookup" };
+ printf("{\"tool\": \"dagsim diff\", \"baseline\": "); jstr(a); printf(", \"transformed\": "); jstr(b);
+ printf(", \"status\": "); jstr(ds_status_name(rc)); printf(", \"reason\": "); jstr(d.reason);
+ printf(", \"kept\": %d, \"added\": %d, \"removed\": %d, \"double_counted\": %d, \"required_removed\": %d, \"removed_ns\": {", d.n_kept, d.n_added, d.n_removed, d.double_counted, d.required_removed);
+ for (int i = 1; i < 8; i++) { if (i > 1) printf(", "); jstr(rn[i]); printf(": "); jnum(d.removed_ns[i]); }
+ printf("}, \"changed\": "); jstr(o->changed ? o->changed : ""); printf("}\n");
+ free(ma); free(mb);
+ return rc == DS_OK ? 0 : 1;
+}
+
+int main(int argc, char **argv) {
+ if (argc < 3) { fprintf(stderr, "usage: dagsim eval FILE | pareto FILE... | diff BASE TRANSFORMED [--asof YYYY-MM-DD] [--model BLOB] [--changed a,b]\n"); return 2; }
+ ds_opts o; memset(&o, 0, sizeof o); o.interval_q = 0.9;
+ RxCostModel *cm = NULL;
+ const char *files[64]; int nf = 0;
+ for (int i = 2; i < argc; i++) {
+ if (!strcmp(argv[i], "--asof") && i + 1 < argc) { o.asof_day = ds_day_from_date(argv[++i]); if (o.asof_day < 0) { fprintf(stderr, "bad --asof\n"); return 2; } }
+ else if (!strcmp(argv[i], "--model") && i + 1 < argc) { cm = malloc(sizeof *cm); if (!cm || !load_model(argv[++i], cm)) { fprintf(stderr, "cannot load rx_costmodel blob %s\n", argv[i]); return 2; } o.costmodel = cm; }
+ else if (!strcmp(argv[i], "--changed") && i + 1 < argc) o.changed = argv[++i];
+ else if (nf < 64) files[nf++] = argv[i];
+ }
+ if (o.asof_day == 0) { fprintf(stderr, "dagsim: --asof YYYY-MM-DD is required so the run is reproducible (calibration validity is checked against it)\n"); return 2; }
+ int rc;
+ if (!strcmp(argv[1], "eval") && nf == 1) rc = cmd_eval(files[0], &o);
+ else if (!strcmp(argv[1], "pareto") && nf >= 1) rc = cmd_pareto(nf, files, &o);
+ else if (!strcmp(argv[1], "diff") && nf == 2) rc = cmd_diff(files[0], files[1], &o);
+ else { fprintf(stderr, "usage: dagsim eval FILE | pareto FILE... | diff BASE TRANSFORMED\n"); rc = 2; }
+ free(cm);
+ return rc;
+}