cmpff: prune infeasible subtrees in the assignment search (three cells went from >30 min to byte-exact in a second), count pairs at C speed, and pin PROBE to a provenance-verified build
Browse files at this commitf91abd5137a1542db3bbcafdd034d145bb65474eParent: 05c44512 changed files +74 -3
- scripts/cmp422-ffmpeg.py +73 -2
- scripts/run422-ffmpeg.py +1 -1
scripts/cmp422-ffmpeg.pymodified+73 -2
| @@ -77,16 +77,32 @@ def split(raw, sizes, fsz, cell): | |||
| 77 | return [raw[i * fsz:(i + 1) * fsz] for i in range(len(raw) // fsz)] | 77 | return [raw[i * fsz:(i + 1) * fsz] for i in range(len(raw) // fsz)] |
| 78 | 78 | ||
| 79 | 79 | ||
| 80 | -def _matchings(cands, disp_n, cap=64): | 80 | +def _matchings(cands, disp_n, cap=64, node_cap=4_000_000): |
| 81 | """Every way to assign each decode frame either a distinct display partner | 81 | """Every way to assign each decode frame either a distinct display partner |
| 82 | or the hidden role, covering the display side exactly. Enumerated, not | 82 | or the hidden role, covering the display side exactly. Enumerated, not |
| 83 | guessed: a duplicated picture can make the assignment genuinely ambiguous, | 83 | guessed: a duplicated picture can make the assignment genuinely ambiguous, |
| 84 | - and the caller then has to show the ambiguity does not change the answer.""" | 84 | + and the caller then has to show the ambiguity does not change the answer. |
| 85 | + | ||
| 86 | + Two bounds, both learned the hard way: without the feasibility prune, an | ||
| 87 | + instance whose candidate lists cannot cover the display side explores the | ||
| 88 | + whole 2**frames tree before returning empty (that is what made three | ||
| 89 | + 43-frame cells burn a 300 s cap with 15 minutes of user CPU and never | ||
| 90 | + finish), and without a node cap a pathological instance would hang the | ||
| 91 | + comparator instead of reporting.""" | ||
| 85 | sols = [] | 92 | sols = [] |
| 93 | + nodes = 0 | ||
| 86 | 94 | ||
| 87 | def dfs(i, used, acc, hid): | 95 | def dfs(i, used, acc, hid): |
| 96 | + nonlocal nodes | ||
| 97 | + nodes += 1 | ||
| 98 | + if nodes > node_cap: | ||
| 99 | + raise SystemExit(f"the decode->display assignment search exceeded {node_cap} nodes " | ||
| 100 | + f"at frame {i} of {len(cands)} ({disp_n} display frames) -- this " | ||
| 101 | + f"instance is not enumerable; report it rather than hang") | ||
| 88 | if len(sols) >= cap: | 102 | if len(sols) >= cap: |
| 89 | return | 103 | return |
| 104 | + if disp_n - len(used) > len(cands) - i: | ||
| 105 | + return # not enough decode frames left to cover the display side | ||
| 90 | if i == len(cands): | 106 | if i == len(cands): |
| 91 | if len(used) == disp_n: | 107 | if len(used) == disp_n: |
| 92 | sols.append((dict(acc), list(hid))) | 108 | sols.append((dict(acc), list(hid))) |
| @@ -181,6 +197,61 @@ def compare(cell, ours_prefix, disp, w, h, ss_x, ss_y, depth, want_hidden=None): | |||
| 181 | per_dec.append(fcount) | 197 | per_dec.append(fcount) |
| 182 | return tot, per_disp, per_dec, first, bb_all | 198 | return tot, per_disp, per_dec, first, bb_all |
| 183 | 199 | ||
| 200 | + def xor_plane_counts(a, b): | ||
| 201 | + """Per-plane differing-SAMPLE counts at 8-bit, at C speed: XOR the two | ||
| 202 | + planes as big ints, then count non-zero bytes per plane. Equivalent to | ||
| 203 | + the per-sample loop above, and the only reason a 43-frame cell with 64 | ||
| 204 | + candidate assignments used to cost half an hour.""" | ||
| 205 | + z = int.from_bytes(a, "big") ^ int.from_bytes(b, "big") | ||
| 206 | + zb = z.to_bytes(len(a), "big") | ||
| 207 | + out, off = [], 0 | ||
| 208 | + for sz in sizes: | ||
| 209 | + seg = zb[off:off + sz] | ||
| 210 | + off += sz | ||
| 211 | + out.append(len(seg) - seg.count(0)) | ||
| 212 | + return out | ||
| 213 | + | ||
| 214 | + if bps == 1: | ||
| 215 | + pair_cache = {} | ||
| 216 | + | ||
| 217 | + def pair_total(oi, di): | ||
| 218 | + v = pair_cache.get((oi, di)) | ||
| 219 | + if v is None: | ||
| 220 | + v = xor_plane_counts(ours[oi], disp[di]) | ||
| 221 | + pair_cache[(oi, di)] = v | ||
| 222 | + return v | ||
| 223 | + | ||
| 224 | + sol_totals = [] | ||
| 225 | + for m, _h in sols: | ||
| 226 | + t = [0, 0, 0] | ||
| 227 | + for oi, di in m.items(): | ||
| 228 | + p = pair_total(oi, di) | ||
| 229 | + t[0] += p[0] | ||
| 230 | + t[1] += p[1] | ||
| 231 | + t[2] += p[2] | ||
| 232 | + sol_totals.append(tuple(t)) | ||
| 233 | + if len(set(sol_totals)) > 1: | ||
| 234 | + raise SystemExit(f"{cell}: the decode->display assignment is AMBIGUOUS " | ||
| 235 | + f"({len(sols)} solutions) and they DISAGREE on the counts " | ||
| 236 | + f"{sorted(set(sol_totals))} -- pick the identity source explicitly, " | ||
| 237 | + f"this instrument will not choose for you") | ||
| 238 | + tot = list(sol_totals[0]) | ||
| 239 | + mapping, hidden = sols[0] | ||
| 240 | + if tot == [0, 0, 0]: | ||
| 241 | + per_disp = [[0, 0, 0] for _ in disp] | ||
| 242 | + per_dec = [None if oi in hidden else [0, 0, 0] for oi in range(len(ours))] | ||
| 243 | + first, bbox = None, [[None, None, None, None] for _ in range(3)] | ||
| 244 | + else: | ||
| 245 | + tot, per_disp, per_dec, first, bbox = measure(mapping, hidden) | ||
| 246 | + else: | ||
| 247 | + # 16-bit planes: the sample loop below is the only path today. | ||
| 248 | + if all(all(ours[oi] == disp[di] for oi, di in m.items()) for m, h in sols): | ||
| 249 | + hidden0 = sols[0][1] | ||
| 250 | + measured = [([0, 0, 0], [[0, 0, 0] for _ in disp], | ||
| 251 | + [None if oi in hidden0 else [0, 0, 0] for oi in range(len(ours))], | ||
| 252 | + None, [[None, None, None, None] for _ in range(3)])] | ||
| 253 | + measured *= len(sols) | ||
| 254 | + else: | ||
| 184 | measured = [measure(m, h) for m, h in sols] | 255 | measured = [measure(m, h) for m, h in sols] |
| 185 | totals = {tuple(t[0]) for t in measured} | 256 | totals = {tuple(t[0]) for t in measured} |
| 186 | if len(totals) > 1: | 257 | if len(totals) > 1: |
scripts/run422-ffmpeg.pymodified+1 -1
| @@ -9,7 +9,7 @@ import sys | |||
| 9 | sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | 9 | sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| 10 | import cmpff # noqa: E402 | 10 | import cmpff # noqa: E402 |
| 11 | 11 | ||
| 12 | -PROBE = "/home/user/.cache/tgt/av1422seed/debug/examples/decode_probe" | 12 | +PROBE = "/home/user/.cache/probes/decode_probe-main-8d6998d7" |
| 13 | WORK = "/home/user/.cache/seed422" | 13 | WORK = "/home/user/.cache/seed422" |
| 14 | 14 | ||
| 15 | 15 | ||