forge
Explore
Log in

Don't you dare go Hollow

Coefficient and mode-info range-ladder rungs for the oracle

Browse files at this commit

3e41e6263988d9642cb5001118448d54f933631eAhmet Kaan GümüşParent: a447d85
  • feat
    • coefficient and mode-info range-ladder rungs for the oracle
Show full message
feat(av1): coefficient and mode-info range-ladder rungs for the oracle

Two lanes stalled on the same missing instrument: the oracle's aomdec traced
only read_partition, so a desync inside a coefficient block or inside the
mv-stack/DRL/mv reads had no ladder to walk. Partition granularity is far too
coarse for either.

EC_TRACE_COEFF=1 wraps av1_read_coeffs_txb and prints the msac range before and
after every coefficient block, keyed by plane/row/col/tx_size. EC_TRACE_MODE=1
wraps read_inter_block_mode_info and prints the range either side of a block's
mode info, with the resulting mode, both refs and mv0.

Same wrapper-around-impl shape as the existing partition rung, same idempotence
guard, and both are env-gated: an uninstrumented run emits nothing, verified.

Building the instrument is the first subtask, not the excuse.
scripts/instrument-aom-oracle.shmodified+109 -0
@@ -15,6 +15,13 @@
15 # before every partition symbol, "EC_PART_VAL .. value=.." after. The15 # before every partition symbol, "EC_PART_VAL .. value=.." after. The
16 # range ladder: compare rng element-by-element against our own16 # range ladder: compare rng element-by-element against our own
17 # `TRACE part32_pre` (class compare-range-not-tell -- ranges, never tell).17 # `TRACE part32_pre` (class compare-range-not-tell -- ranges, never tell).
18+# EC_TRACE_COEFF=1 -> "EC_COEFF plane=.. row=.. col=.. tx_size=.. rng=.."
19+# before every coefficient block, "EC_COEFF_VAL .. rng=.." after.
20+# Partition granularity is too coarse to localize a coefficient desync;
21+# two lanes stalled on 2026-08-30 because this rung did not exist.
22+# EC_TRACE_MODE=1 -> "EC_MODE mi_row=.. mi_col=.. rng=.." before every inter
23+# block's mode info, "EC_MODE_VAL .. mode=.. ref0/1=.. mv0=.. rng=.."
24+# after -- the mv-stack/DRL/mv reads EC_PART cannot see.
18 #25 #
19 # Idempotent: re-running is a no-op. Rebuild afterwards with26 # Idempotent: re-running is a no-op. Rebuild afterwards with
20 # ninja -C ~/.cache/aom-oracle/build aomdec27 # ninja -C ~/.cache/aom-oracle/build aomdec
@@ -103,3 +110,105 @@ open(path, "w").write(s)
103 print("instrumented")110 print("instrumented")
104 PY111 PY
105 echo "now: ninja -C ${AOM_ORACLE_BUILD:-$HOME/.cache/aom-oracle/build} aomdec"112 echo "now: ninja -C ${AOM_ORACLE_BUILD:-$HOME/.cache/aom-oracle/build} aomdec"
113+
114+# --- rung 3: coefficient range ladder (decodetxb.c) ---------------------
115+G="$SRC/av1/decoder/decodetxb.c"
116+[ -f "$G" ] || { echo "no oracle source at $G" >&2; exit 1; }
117+
118+python3 - "$G" <<'PYC'
119+import sys
120+path = sys.argv[1]
121+s = open(path).read()
122+if "EC_INSTRUMENTED" in s:
123+ print("decodetxb already instrumented (no-op)")
124+ sys.exit(0)
125+
126+old = """void av1_read_coeffs_txb(const AV1_COMMON *const cm, DecoderCodingBlock *dcb,
127+ aom_reader *const r, const int plane, const int row,
128+ const int col, const TX_SIZE tx_size) {"""
129+new = """/* EC_INSTRUMENTED */
130+static void ec_read_coeffs_txb_impl(const AV1_COMMON *const cm,
131+ DecoderCodingBlock *dcb,
132+ aom_reader *const r, const int plane,
133+ const int row, const int col,
134+ const TX_SIZE tx_size);
135+
136+void av1_read_coeffs_txb(const AV1_COMMON *const cm, DecoderCodingBlock *dcb,
137+ aom_reader *const r, const int plane, const int row,
138+ const int col, const TX_SIZE tx_size) {
139+ const int ec_trace = getenv("EC_TRACE_COEFF") != NULL;
140+ if (ec_trace) {
141+ fprintf(stderr, "EC_COEFF plane=%d row=%d col=%d tx_size=%d rng=%u\\n",
142+ plane, row, col, (int)tx_size, (unsigned)r->ec.rng);
143+ }
144+ ec_read_coeffs_txb_impl(cm, dcb, r, plane, row, col, tx_size);
145+ if (ec_trace) {
146+ fprintf(stderr, "EC_COEFF_VAL plane=%d row=%d col=%d rng=%u\\n", plane, row,
147+ col, (unsigned)r->ec.rng);
148+ }
149+}
150+
151+static void ec_read_coeffs_txb_impl(const AV1_COMMON *const cm,
152+ DecoderCodingBlock *dcb,
153+ aom_reader *const r, const int plane,
154+ const int row, const int col,
155+ const TX_SIZE tx_size) {"""
156+assert old in s, "av1_read_coeffs_txb signature moved"
157+s = s.replace(old, new, 1)
158+open(path, "w").write(s)
159+print("decodetxb instrumented")
160+PYC
161+
162+# --- rung 4: mode-info range ladder (decodemv.c) ------------------------
163+H="$SRC/av1/decoder/decodemv.c"
164+[ -f "$H" ] || { echo "no oracle source at $H" >&2; exit 1; }
165+
166+python3 - "$H" <<'PYM'
167+import sys
168+path = sys.argv[1]
169+s = open(path).read()
170+if "EC_INSTRUMENTED" in s:
171+ print("decodemv already instrumented (no-op)")
172+ sys.exit(0)
173+
174+old = """static void read_inter_block_mode_info(AV1Decoder *const pbi,
175+ DecoderCodingBlock *dcb,
176+ MB_MODE_INFO *const mbmi,
177+ aom_reader *r) {"""
178+new = """/* EC_INSTRUMENTED */
179+static void ec_read_inter_block_mode_info_impl(AV1Decoder *const pbi,
180+ DecoderCodingBlock *dcb,
181+ MB_MODE_INFO *const mbmi,
182+ aom_reader *r);
183+
184+static void read_inter_block_mode_info(AV1Decoder *const pbi,
185+ DecoderCodingBlock *dcb,
186+ MB_MODE_INFO *const mbmi,
187+ aom_reader *r) {
188+ const int ec_trace = getenv("EC_TRACE_MODE") != NULL;
189+ const MACROBLOCKD *const ec_xd = &dcb->xd;
190+ if (ec_trace) {
191+ fprintf(stderr, "EC_MODE mi_row=%d mi_col=%d rng=%u\\n", ec_xd->mi_row,
192+ ec_xd->mi_col, (unsigned)r->ec.rng);
193+ }
194+ ec_read_inter_block_mode_info_impl(pbi, dcb, mbmi, r);
195+ if (ec_trace) {
196+ fprintf(stderr,
197+ "EC_MODE_VAL mi_row=%d mi_col=%d mode=%d ref0=%d ref1=%d "
198+ "mv0=(%d,%d) rng=%u\\n",
199+ ec_xd->mi_row, ec_xd->mi_col, (int)mbmi->mode,
200+ (int)mbmi->ref_frame[0], (int)mbmi->ref_frame[1],
201+ mbmi->mv[0].as_mv.row, mbmi->mv[0].as_mv.col,
202+ (unsigned)r->ec.rng);
203+ }
204+}
205+
206+static void ec_read_inter_block_mode_info_impl(AV1Decoder *const pbi,
207+ DecoderCodingBlock *dcb,
208+ MB_MODE_INFO *const mbmi,
209+ aom_reader *r) {"""
210+assert old in s, "read_inter_block_mode_info signature moved"
211+s = s.replace(old, new, 1)
212+open(path, "w").write(s)
213+print("decodemv instrumented")
214+PYM