forge
Explore
Log in

Don't you dare go Hollow

Commit the oracle localization instrumentation (was lost with /tmp)

Browse files at this commit

663273740bc443351bb86d9b449e06d409b5bb70Ahmet Kaan GümüşParent: 1fc2eb0
  • feat
    • commit the oracle localization instrumentation (was lost with /tmp)
Show full message
feat(av1): commit the oracle localization instrumentation (was lost with /tmp)

scripts/instrument-aom-oracle.sh idempotently adds the two ladder rungs to the
oracle's aomdec, both env-gated so an uninstrumented run is unchanged:
  EC_AV1_PREFILT_DUMP -> per-frame Y/U/V recon written after tile decode and
    BEFORE loop filter/CDEF/LR (separates recon from filtering mismatches)
  EC_TRACE=1 -> EC_PART/EC_PART_VAL with ctx, tell and msac RANGE per
    partition symbol (the range ladder; compare ranges, never tell)

These existed only as hand edits in the reaped /tmp tree. Re-derived against
the pinned v3.13.3 source and verified byte-compatible with the pre-loss
instrument: EC_PART emits the identical rng values (frame 0 mi(0,0) bsize=9
rng=51744) and the dump is the same 4096+1024+1024 layout.

EVIDENCE: rect-flake-2.obu, oracle dump vs our EC_AV1_PREFILT_DUMP --
24/24 frames byte-identical.
scripts/instrument-aom-oracle.shadded+105 -0
@@ -0,0 +1,105 @@
1+#!/usr/bin/env bash
2+# Add the decode-localization instrumentation to the libaom oracle's aomdec.
3+#
4+# These patches used to live only in the hand-built /tmp tree; the 2026-08-30
5+# tmpfs reclaim destroyed them along with the tree (see memory
6+# oracle-in-reaped-dir). They are re-derived here so `build-aom-oracle.sh` +
7+# this script reproduce the full ladder from scratch.
8+#
9+# Rungs provided (both env-gated, so an uninstrumented run is unchanged):
10+# EC_AV1_PREFILT_DUMP=<prefix> -> <prefix>.f<N> per frame, Y then U then V,
11+# crop-sized rows, written after tile decode and BEFORE any loop filter,
12+# CDEF or LR. Diff against our own EC_AV1_PREFILT_DUMP to separate a
13+# reconstruction mismatch from a filtering one.
14+# EC_TRACE=1 -> "EC_PART mi_row=.. mi_col=.. bsize=.. ctx=.. tell=.. rng=.."
15+# before every partition symbol, "EC_PART_VAL .. value=.." after. The
16+# range ladder: compare rng element-by-element against our own
17+# `TRACE part32_pre` (class compare-range-not-tell -- ranges, never tell).
18+#
19+# Idempotent: re-running is a no-op. Rebuild afterwards with
20+# ninja -C ~/.cache/aom-oracle/build aomdec
21+set -euo pipefail
22+SRC="${AOM_ORACLE_SRC:-$HOME/.cache/aom-oracle/src}"
23+F="$SRC/av1/decoder/decodeframe.c"
24+[ -f "$F" ] || { echo "no oracle source at $F -- run scripts/build-aom-oracle.sh first" >&2; exit 1; }
25+
26+python3 - "$F" <<'PY'
27+import sys, re
28+path = sys.argv[1]
29+s = open(path).read()
30+if "EC_INSTRUMENTED" in s:
31+ print("already instrumented (no-op)")
32+ sys.exit(0)
33+
34+# --- rung 2: partition range ladder -------------------------------------
35+old_sig = """static PARTITION_TYPE read_partition(MACROBLOCKD *xd, int mi_row, int mi_col,
36+ aom_reader *r, int has_rows, int has_cols,
37+ BLOCK_SIZE bsize) {"""
38+new_sig = """/* EC_INSTRUMENTED */
39+static PARTITION_TYPE ec_read_partition_impl(MACROBLOCKD *xd, int mi_row,
40+ int mi_col, aom_reader *r,
41+ int has_rows, int has_cols,
42+ BLOCK_SIZE bsize);
43+
44+static PARTITION_TYPE read_partition(MACROBLOCKD *xd, int mi_row, int mi_col,
45+ aom_reader *r, int has_rows, int has_cols,
46+ BLOCK_SIZE bsize) {
47+ const int ec_trace = getenv("EC_TRACE") != NULL;
48+ if (ec_trace) {
49+ fprintf(stderr,
50+ "EC_PART mi_row=%d mi_col=%d bsize=%d ctx=%d tell=%d rng=%u\\n",
51+ mi_row, mi_col, (int)bsize,
52+ partition_plane_context(xd, mi_row, mi_col, bsize),
53+ (int)aom_reader_tell(r), (unsigned)r->ec.rng);
54+ }
55+ PARTITION_TYPE ec_p =
56+ ec_read_partition_impl(xd, mi_row, mi_col, r, has_rows, has_cols, bsize);
57+ if (ec_trace) {
58+ fprintf(stderr, "EC_PART_VAL mi_row=%d mi_col=%d bsize=%d value=%d\\n",
59+ mi_row, mi_col, (int)bsize, (int)ec_p);
60+ }
61+ return ec_p;
62+}
63+
64+static PARTITION_TYPE ec_read_partition_impl(MACROBLOCKD *xd, int mi_row,
65+ int mi_col, aom_reader *r,
66+ int has_rows, int has_cols,
67+ BLOCK_SIZE bsize) {"""
68+assert old_sig in s, "read_partition signature moved"
69+s = s.replace(old_sig, new_sig, 1)
70+
71+# --- rung 1: pre-filter recon dump --------------------------------------
72+anchor = """ av1_alloc_cdef_buffers(cm, &pbi->cdef_worker, &pbi->cdef_sync,
73+ pbi->num_workers, 1);"""
74+dump = """ {
75+ const char *ec_dump = getenv("EC_AV1_PREFILT_DUMP");
76+ if (ec_dump) {
77+ static int ec_prefilt_idx = 0;
78+ char ec_path[1024];
79+ snprintf(ec_path, sizeof(ec_path), "%s.f%d", ec_dump, ec_prefilt_idx++);
80+ FILE *ec_f = fopen(ec_path, "wb");
81+ if (ec_f) {
82+ const YV12_BUFFER_CONFIG *ec_b = &cm->cur_frame->buf;
83+ for (int ec_r = 0; ec_r < ec_b->y_crop_height; ++ec_r)
84+ fwrite(ec_b->y_buffer + ec_r * ec_b->y_stride, 1, ec_b->y_crop_width,
85+ ec_f);
86+ if (num_planes > 1) {
87+ for (int ec_r = 0; ec_r < ec_b->uv_crop_height; ++ec_r)
88+ fwrite(ec_b->u_buffer + ec_r * ec_b->uv_stride, 1,
89+ ec_b->uv_crop_width, ec_f);
90+ for (int ec_r = 0; ec_r < ec_b->uv_crop_height; ++ec_r)
91+ fwrite(ec_b->v_buffer + ec_r * ec_b->uv_stride, 1,
92+ ec_b->uv_crop_width, ec_f);
93+ }
94+ fclose(ec_f);
95+ }
96+ }
97+ }
98+
99+"""
100+assert anchor in s, "cdef alloc anchor moved"
101+s = s.replace(anchor, dump + anchor, 1)
102+open(path, "w").write(s)
103+print("instrumented")
104+PY
105+echo "now: ninja -C ${AOM_ORACLE_BUILD:-$HOME/.cache/aom-oracle/build} aomdec"