From e33c385375a351563c5df0f586eb3f062e6e8e3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 16:57:52 +0300 Subject: [PATCH] docs(av1): lane-lr r7 charter; commit r6's SGR pin harness out of the reapable scratchpad --- lanes/lr-r7.charter.md | 55 ++++++++++++++++++++++++++++++++++++ scripts/lr-sgr-pin-harness.c | 48 +++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) create mode 100644 lanes/lr-r7.charter.md create mode 100644 scripts/lr-sgr-pin-harness.c diff --git a/lanes/lr-r7.charter.md b/lanes/lr-r7.charter.md new file mode 100644 index 00000000..1b551ffe --- /dev/null +++ b/lanes/lr-r7.charter.md @@ -0,0 +1,55 @@ +# lane-lr r7 — one tap + +At e5ad671 (+ this charter). Read the r6 section of `lanes/lr.report.md`. + +## Where you stand — the search is down to one number +r6 linked libaom's real `av1_apply_selfguided_restoration_c` out of +`~/.cache/aom-oracle/build/libaom.a` and called it directly on OUR OWN +`lr_sample`-substituted bytes. It reproduced 194. That decisively rules out +`lr_sample` and the stripe boundary — r5's suspicion — and it rules out the +fast (`r0`) arm, whose `flt0` is bit-exact against real libaom. + +What is left: the dense (`r1`) arm. Eight of its nine A/B taps at the failing +pixel match a from-scratch box-sum of the real bytes; the combined `flt1` is +**3110 where libaom gets 3109**. One tap, or a rounding mode. + +r6's harness is now committed at `scripts/lr-sgr-pin-harness.c` — it lived in +the scratchpad, which this box reaps (class `oracle-in-reaped-dir`). Use and +extend it. + +## Do not +- Re-suspect `lr_sample` or the stripe boundary. Proven correct. +- Re-suspect the fast arm. Proven bit-exact. +- Hand-trace further. Three rounds have now shown our arithmetic is + self-consistent with our own output; only libaom's own intermediate values + can break the tie. + +## Do +r6 named the two ways to get per-tap ground truth, and preferred the first: +1. `calculate_intermediate_result` and `boxsum1` are `static` in libaom's + `restoration.c`, so they cannot be called from the harness as-is. Patch them + non-static in the oracle copy and rebuild (~5 min) — the same pattern + `scripts/instrument-aom-oracle.sh` already uses for the trace rungs, so add + it there as an env-gated rung rather than an ad-hoc edit, and it stays + reusable. +2. Or bisect single input pixels through the existing harness until the tap + that diverges identifies itself. + +Then fix it, get the gate green, COMMIT immediately. + +## Then +Wiener and self-guided are otherwise feature-complete with the refusal already +dropped, so once green this lane is ready to merge. Before it does: confirm +`gate_coverage.rs`'s `NEVER_EXERCISED` no longer needs `enable-restoration` +(main's copy — down to `enable-intrabc` alone as of this batch), and consider +`git merge main` here first and resolving it yourself; main is at 93d9510 and +has landed multi-tile decode, CDEF index reads, chroma modes, a `bit_depth != 8` +refusal and three reworded partition refusals since this branch forked. Report +every refusal string you add, rename or remove, verbatim. + +Hard rules: `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-lr`; foreground +`nice -n 19 cargo ... -j4`; every `cargo test` a timeout >= 600000 ms. Sibling +worktrees have live agents — never build in or edit them. Never push, never +merge into `main`. 75-turn cap, does not reset: COMMIT AT EVERY GREEN STEP, and +commit any harness or instrument you build — a scratchpad is not storage. +Update `lanes/lr.report.md` with an r7 section, VERDICT first. diff --git a/scripts/lr-sgr-pin-harness.c b/scripts/lr-sgr-pin-harness.c new file mode 100644 index 00000000..44ff393f --- /dev/null +++ b/scripts/lr-sgr-pin-harness.c @@ -0,0 +1,48 @@ +#include +#include +#include + +extern int av1_apply_selfguided_restoration_c( + const uint8_t *dat8, int width, int height, int stride, int eps, + const int *xqd, uint8_t *dst8, int dst_stride, int32_t *tmpbuf, + int bit_depth, int highbd); +extern int av1_selfguided_restoration_c(const uint8_t *dgd8, int width, + int height, int dgd_stride, + int32_t *flt0, int32_t *flt1, + int flt_stride, int sgr_params_idx, + int bit_depth, int highbd); + +int main(void) { + const int bw = 102, bh = 10; + // real libaom splits stripe_width into RESTORATION_PROC_UNIT_SIZE=64 + // chunks (sgrproj_filter_stripe's `for j += procunit_width` loop) -- + // av1_apply_selfguided_restoration_c's internal fixed-size arrays are + // sized for that max, so replicate the chunking (target col=6 is in + // the first 64-wide chunk). + const int w = 64, h = 4; + uint8_t *buf = malloc(bw * bh); + FILE *f = fopen("/tmp/lr_full.bin", "rb"); + if (!f) { perror("open"); return 1; } + if (fread(buf, 1, bw * bh, f) != (size_t)(bw * bh)) { fprintf(stderr, "short read\n"); return 1; } + fclose(f); + + const uint8_t *dgd8 = buf + 3 * bw + 3; // logical (0,0) + int xqd[2] = { -16, -32 }; + uint8_t dst[w * h]; + // flt1 = tmpbuf + RESTORATION_UNITPELS_MAX (~152100); undersizing this + // segfaults inside av1_apply_selfguided_restoration_c. + static int32_t tmpbuf[2 * 400 * 400]; + + int ret = av1_apply_selfguided_restoration_c(dgd8, w, h, bw, /*eps=*/6, xqd, + dst, w, tmpbuf, 8, 0); + printf("ret=%d\n", ret); + // target pixel: row i=1, col j=6 + printf("out[1][6] = %d\n", dst[1 * w + 6]); + printf("dgd[1][6] = %d\n", dgd8[1 * bw + 6]); + + static int32_t flt0[400 * 400], flt1[400 * 400]; + int r2 = av1_selfguided_restoration_c(dgd8, w, h, bw, flt0, flt1, w, 6, 8, 0); + printf("selfguided ret=%d flt0[1][6]=%d flt1[1][6]=%d\n", r2, flt0[1 * w + 6], + flt1[1 * w + 6]); + return 0; +}