diff --git a/crates/ec-av1/src/tile/blocks.rs b/crates/ec-av1/src/tile/blocks.rs index 85360230..49db2629 100644 --- a/crates/ec-av1/src/tile/blocks.rs +++ b/crates/ec-av1/src/tile/blocks.rs @@ -292,10 +292,6 @@ pub(super) fn write_block_planes( } else { usize::from(around[plane].above_coded) + usize::from(around[plane].left_coded) }; - #[cfg(test)] - let before = enc.tell(); - #[cfg(test)] - let q_ctx = cdfs.q_ctx; let mut coding = cdfs.txb(planes[plane], mode); let tx_type = if plane == 0 { luma_tx_type @@ -319,15 +315,6 @@ pub(super) fn write_block_planes( Some(plane), tx_type, ); - #[cfg(test)] - census_record( - planes[plane], - q_ctx, - grid, - f64::from(enc.tell() - before), - skip_ctx, - dc_sign_ctx(around[plane].dc_vote), - ); ec_rng_trace(|| { format!( "EC_PLANE plane={plane} nz={} skip_ctx={skip_ctx} tell={}", @@ -433,10 +420,6 @@ pub(super) fn write_luma_tus( neighbours.luma_skip_ctx(tu_mi, tx / MI) }; let around = neighbours.around_mi(tu_mi, tx)[0]; - #[cfg(test)] - let before = enc.tell(); - #[cfg(test)] - let q_ctx = cdfs.q_ctx; write_coeffs( enc, &mut cdfs.txb(set, mode), @@ -450,15 +433,6 @@ pub(super) fn write_luma_tus( .copied() .unwrap_or(TxType::DctDct), ); - #[cfg(test)] - census_record( - set, - q_ctx, - &unit, - f64::from(enc.tell() - before), - skip_ctx, - dc_sign_ctx(around.dc_vote), - ); if n > 1 { neighbours.record_mi_luma(tu_mi, tx, &unit); } @@ -1321,7 +1295,6 @@ pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) { 1 => true, _ => !screen, }; - PRICING_HITS[usize::from(on && base.is_some())].fetch_add(1, Ordering::Relaxed); PRICING_BASE.with_borrow_mut(|slot| { *slot = base .filter(|_| on) @@ -1329,90 +1302,6 @@ pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) { }); } -/// How many times a frame's search was armed with the DEFAULT tables and how -/// many with the frame's REAL starting tables ([`arm_pricing_cdfs`]), so a -/// gate can print which side of the screen gate every frame landed on. Counts -/// arming calls, not frames: a multi-tile frame arms one worker per tile. -pub(crate) static PRICING_HITS: [AtomicUsize; 2] = [AtomicUsize::new(0), AtomicUsize::new(0)]; - -/// The pricer census (`pricer_census_on`): for every transform block the tile -/// writer really codes, the bits it spent against the bits [`coeff_bits`] -/// prices those very levels at -- the search's rate term measured against the -/// rate it is meant to predict. Keyed by (table set, non-zero bucket) so a -/// class that is systematically mispriced (all-zero blocks' `txb_skip`, the -/// eob of a one-coefficient block, a whole size) shows up on its own row -/// rather than inside one average. -/// Thread-local, so a census cannot pick up the blocks of another test's -/// encode running beside it; a multi-tile, multi-threaded encode would -/// therefore only census the tiles this thread wrote, which is every tile of -/// the one-tile-one-thread encodes the gates print it from. -#[cfg(test)] -pub(super) type CensusRows = BTreeMap<(String, usize), (u64, f64, f64)>; -#[cfg(test)] -thread_local! { - pub(super) static CENSUS: RefCell> = const { RefCell::new(None) }; -} - -/// Starts a census on this thread, discarding anything a previous one left. -#[cfg(test)] -pub(crate) fn pricer_census_on() { - CENSUS.with_borrow_mut(|c| *c = Some(BTreeMap::new())); -} - -/// Stops the census and hands back its rows: (set, non-zero bucket) -> -/// (blocks, priced bits, written bits). -#[cfg(test)] -pub(crate) fn take_pricer_census() -> CensusRows { - CENSUS.with_borrow_mut(|c| c.take()).unwrap_or_default() -} - -/// The label of a non-zero bucket, for the tables the gates print. -#[cfg(test)] -pub(crate) fn census_bucket_label(bucket: usize) -> &'static str { - ["0", "1", "2", "3-4", "5-8", "9-16", "17+"][bucket] -} - -#[cfg(test)] -pub(super) fn census_record( - set: TxbSet, - q_ctx: usize, - grid: &[i32], - written: f64, - // The writer's own neighbour contexts for this very transform block: the - // census prices the search's estimate the way the search now takes it - // (lane-av1skipctx), so a row's error is the table/adaptation drift that - // is left once the context is right. - skip_ctx: usize, - sign_ctx: usize, -) { - if CENSUS.with_borrow(|c| c.is_none()) { - return; - } - let nz = grid.iter().filter(|&&l| l != 0).count(); - let bucket = match nz { - 0 => 0, - 1 => 1, - 2 => 2, - 3..=4 => 3, - 5..=8 => 4, - 9..=16 => 5, - _ => 6, - }; - let priced = coeff_bits(grid, set, q_ctx, skip_ctx, sign_ctx); - CENSUS.with_borrow_mut(|rows| { - let rows = rows.as_mut().expect("the census is on"); - let row = rows.entry((format!("{set:?}"), bucket)).or_default(); - row.0 += 1; - row.1 += priced; - row.2 += written; - }); -} - -/// What the partition symbol of a block of `side` samples costs, in bits, when -/// it says the block is split (or that it is not). -/// -/// The price is taken at context zero — a block whose neighbours are no finer -/// than it is — because the search that reads it runs before the tile knows /// what its neighbours will be. pub(crate) fn partition_bits(side: usize, split: bool) -> f64 { // Read-only, and the same tables every call: built once (see diff --git a/crates/ec-av1/src/tile/mod.rs b/crates/ec-av1/src/tile/mod.rs index 7e1f64b6..0233c250 100644 --- a/crates/ec-av1/src/tile/mod.rs +++ b/crates/ec-av1/src/tile/mod.rs @@ -10,10 +10,8 @@ //! off as they arrive. use std::cell::RefCell; -#[cfg(test)] -use std::collections::BTreeMap; use std::sync::LazyLock; -use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; +use std::sync::atomic::{AtomicU64, Ordering}; use ec_core::{Error, Result};