U3: delete the pricer census (CENSUS, census_record and its two call sites, pricer_census_on, take_pricer_census, census_bucket_label) and the PRICING_HITS counter nothing read; the tile writer's before/q_ctx locals that only fed it. Test-only or write-only, no output change. cargo check -p ec-av1 --all-targets clean
Browse files at this commit30f025ca581453018d552741386ea67f3e0ca54fParent: ea929a72 changed files +1 -114
crates/ec-av1/src/tile/blocks.rsmodified+0 -111
| @@ -292,10 +292,6 @@ pub(super) fn write_block_planes( | |||
| 292 | } else { | 292 | } else { |
| 293 | usize::from(around[plane].above_coded) + usize::from(around[plane].left_coded) | 293 | usize::from(around[plane].above_coded) + usize::from(around[plane].left_coded) |
| 294 | }; | 294 | }; |
| 295 | - #[cfg(test)] | ||
| 296 | - let before = enc.tell(); | ||
| 297 | - #[cfg(test)] | ||
| 298 | - let q_ctx = cdfs.q_ctx; | ||
| 299 | let mut coding = cdfs.txb(planes[plane], mode); | 295 | let mut coding = cdfs.txb(planes[plane], mode); |
| 300 | let tx_type = if plane == 0 { | 296 | let tx_type = if plane == 0 { |
| 301 | luma_tx_type | 297 | luma_tx_type |
| @@ -319,15 +315,6 @@ pub(super) fn write_block_planes( | |||
| 319 | Some(plane), | 315 | Some(plane), |
| 320 | tx_type, | 316 | tx_type, |
| 321 | ); | 317 | ); |
| 322 | - #[cfg(test)] | ||
| 323 | - census_record( | ||
| 324 | - planes[plane], | ||
| 325 | - q_ctx, | ||
| 326 | - grid, | ||
| 327 | - f64::from(enc.tell() - before), | ||
| 328 | - skip_ctx, | ||
| 329 | - dc_sign_ctx(around[plane].dc_vote), | ||
| 330 | - ); | ||
| 331 | ec_rng_trace(|| { | 318 | ec_rng_trace(|| { |
| 332 | format!( | 319 | format!( |
| 333 | "EC_PLANE plane={plane} nz={} skip_ctx={skip_ctx} tell={}", | 320 | "EC_PLANE plane={plane} nz={} skip_ctx={skip_ctx} tell={}", |
| @@ -433,10 +420,6 @@ pub(super) fn write_luma_tus( | |||
| 433 | neighbours.luma_skip_ctx(tu_mi, tx / MI) | 420 | neighbours.luma_skip_ctx(tu_mi, tx / MI) |
| 434 | }; | 421 | }; |
| 435 | let around = neighbours.around_mi(tu_mi, tx)[0]; | 422 | let around = neighbours.around_mi(tu_mi, tx)[0]; |
| 436 | - #[cfg(test)] | ||
| 437 | - let before = enc.tell(); | ||
| 438 | - #[cfg(test)] | ||
| 439 | - let q_ctx = cdfs.q_ctx; | ||
| 440 | write_coeffs( | 423 | write_coeffs( |
| 441 | enc, | 424 | enc, |
| 442 | &mut cdfs.txb(set, mode), | 425 | &mut cdfs.txb(set, mode), |
| @@ -450,15 +433,6 @@ pub(super) fn write_luma_tus( | |||
| 450 | .copied() | 433 | .copied() |
| 451 | .unwrap_or(TxType::DctDct), | 434 | .unwrap_or(TxType::DctDct), |
| 452 | ); | 435 | ); |
| 453 | - #[cfg(test)] | ||
| 454 | - census_record( | ||
| 455 | - set, | ||
| 456 | - q_ctx, | ||
| 457 | - &unit, | ||
| 458 | - f64::from(enc.tell() - before), | ||
| 459 | - skip_ctx, | ||
| 460 | - dc_sign_ctx(around.dc_vote), | ||
| 461 | - ); | ||
| 462 | if n > 1 { | 436 | if n > 1 { |
| 463 | neighbours.record_mi_luma(tu_mi, tx, &unit); | 437 | neighbours.record_mi_luma(tu_mi, tx, &unit); |
| 464 | } | 438 | } |
| @@ -1321,7 +1295,6 @@ pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) { | |||
| 1321 | 1 => true, | 1295 | 1 => true, |
| 1322 | _ => !screen, | 1296 | _ => !screen, |
| 1323 | }; | 1297 | }; |
| 1324 | - PRICING_HITS[usize::from(on && base.is_some())].fetch_add(1, Ordering::Relaxed); | ||
| 1325 | PRICING_BASE.with_borrow_mut(|slot| { | 1298 | PRICING_BASE.with_borrow_mut(|slot| { |
| 1326 | *slot = base | 1299 | *slot = base |
| 1327 | .filter(|_| on) | 1300 | .filter(|_| on) |
| @@ -1329,90 +1302,6 @@ pub(crate) fn arm_pricing_cdfs(base: Option<&Cdfs>, screen: bool) { | |||
| 1329 | }); | 1302 | }); |
| 1330 | } | 1303 | } |
| 1331 | 1304 | ||
| 1332 | -/// How many times a frame's search was armed with the DEFAULT tables and how | ||
| 1333 | -/// many with the frame's REAL starting tables ([`arm_pricing_cdfs`]), so a | ||
| 1334 | -/// gate can print which side of the screen gate every frame landed on. Counts | ||
| 1335 | -/// arming calls, not frames: a multi-tile frame arms one worker per tile. | ||
| 1336 | -pub(crate) static PRICING_HITS: [AtomicUsize; 2] = [AtomicUsize::new(0), AtomicUsize::new(0)]; | ||
| 1337 | - | ||
| 1338 | -/// The pricer census (`pricer_census_on`): for every transform block the tile | ||
| 1339 | -/// writer really codes, the bits it spent against the bits [`coeff_bits`] | ||
| 1340 | -/// prices those very levels at -- the search's rate term measured against the | ||
| 1341 | -/// rate it is meant to predict. Keyed by (table set, non-zero bucket) so a | ||
| 1342 | -/// class that is systematically mispriced (all-zero blocks' `txb_skip`, the | ||
| 1343 | -/// eob of a one-coefficient block, a whole size) shows up on its own row | ||
| 1344 | -/// rather than inside one average. | ||
| 1345 | -/// Thread-local, so a census cannot pick up the blocks of another test's | ||
| 1346 | -/// encode running beside it; a multi-tile, multi-threaded encode would | ||
| 1347 | -/// therefore only census the tiles this thread wrote, which is every tile of | ||
| 1348 | -/// the one-tile-one-thread encodes the gates print it from. | ||
| 1349 | -#[cfg(test)] | ||
| 1350 | -pub(super) type CensusRows = BTreeMap<(String, usize), (u64, f64, f64)>; | ||
| 1351 | -#[cfg(test)] | ||
| 1352 | -thread_local! { | ||
| 1353 | - pub(super) static CENSUS: RefCell<Option<CensusRows>> = const { RefCell::new(None) }; | ||
| 1354 | -} | ||
| 1355 | - | ||
| 1356 | -/// Starts a census on this thread, discarding anything a previous one left. | ||
| 1357 | -#[cfg(test)] | ||
| 1358 | -pub(crate) fn pricer_census_on() { | ||
| 1359 | - CENSUS.with_borrow_mut(|c| *c = Some(BTreeMap::new())); | ||
| 1360 | -} | ||
| 1361 | - | ||
| 1362 | -/// Stops the census and hands back its rows: (set, non-zero bucket) -> | ||
| 1363 | -/// (blocks, priced bits, written bits). | ||
| 1364 | -#[cfg(test)] | ||
| 1365 | -pub(crate) fn take_pricer_census() -> CensusRows { | ||
| 1366 | - CENSUS.with_borrow_mut(|c| c.take()).unwrap_or_default() | ||
| 1367 | -} | ||
| 1368 | - | ||
| 1369 | -/// The label of a non-zero bucket, for the tables the gates print. | ||
| 1370 | -#[cfg(test)] | ||
| 1371 | -pub(crate) fn census_bucket_label(bucket: usize) -> &'static str { | ||
| 1372 | - ["0", "1", "2", "3-4", "5-8", "9-16", "17+"][bucket] | ||
| 1373 | -} | ||
| 1374 | - | ||
| 1375 | -#[cfg(test)] | ||
| 1376 | -pub(super) fn census_record( | ||
| 1377 | - set: TxbSet, | ||
| 1378 | - q_ctx: usize, | ||
| 1379 | - grid: &[i32], | ||
| 1380 | - written: f64, | ||
| 1381 | - // The writer's own neighbour contexts for this very transform block: the | ||
| 1382 | - // census prices the search's estimate the way the search now takes it | ||
| 1383 | - // (lane-av1skipctx), so a row's error is the table/adaptation drift that | ||
| 1384 | - // is left once the context is right. | ||
| 1385 | - skip_ctx: usize, | ||
| 1386 | - sign_ctx: usize, | ||
| 1387 | -) { | ||
| 1388 | - if CENSUS.with_borrow(|c| c.is_none()) { | ||
| 1389 | - return; | ||
| 1390 | - } | ||
| 1391 | - let nz = grid.iter().filter(|&&l| l != 0).count(); | ||
| 1392 | - let bucket = match nz { | ||
| 1393 | - 0 => 0, | ||
| 1394 | - 1 => 1, | ||
| 1395 | - 2 => 2, | ||
| 1396 | - 3..=4 => 3, | ||
| 1397 | - 5..=8 => 4, | ||
| 1398 | - 9..=16 => 5, | ||
| 1399 | - _ => 6, | ||
| 1400 | - }; | ||
| 1401 | - let priced = coeff_bits(grid, set, q_ctx, skip_ctx, sign_ctx); | ||
| 1402 | - CENSUS.with_borrow_mut(|rows| { | ||
| 1403 | - let rows = rows.as_mut().expect("the census is on"); | ||
| 1404 | - let row = rows.entry((format!("{set:?}"), bucket)).or_default(); | ||
| 1405 | - row.0 += 1; | ||
| 1406 | - row.1 += priced; | ||
| 1407 | - row.2 += written; | ||
| 1408 | - }); | ||
| 1409 | -} | ||
| 1410 | - | ||
| 1411 | -/// What the partition symbol of a block of `side` samples costs, in bits, when | ||
| 1412 | -/// it says the block is split (or that it is not). | ||
| 1413 | -/// | ||
| 1414 | -/// The price is taken at context zero — a block whose neighbours are no finer | ||
| 1415 | -/// than it is — because the search that reads it runs before the tile knows | ||
| 1416 | /// what its neighbours will be. | 1305 | /// what its neighbours will be. |
| 1417 | pub(crate) fn partition_bits(side: usize, split: bool) -> f64 { | 1306 | pub(crate) fn partition_bits(side: usize, split: bool) -> f64 { |
| 1418 | // Read-only, and the same tables every call: built once (see | 1307 | // Read-only, and the same tables every call: built once (see |
crates/ec-av1/src/tile/mod.rsmodified+1 -3
| @@ -10,10 +10,8 @@ | |||
| 10 | //! off as they arrive. | 10 | //! off as they arrive. |
| 11 | 11 | ||
| 12 | use std::cell::RefCell; | 12 | use std::cell::RefCell; |
| 13 | -#[cfg(test)] | ||
| 14 | -use std::collections::BTreeMap; | ||
| 15 | use std::sync::LazyLock; | 13 | use std::sync::LazyLock; |
| 16 | -use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering}; | 14 | +use std::sync::atomic::{AtomicU64, Ordering}; |
| 17 | 15 | ||
| 18 | use ec_core::{Error, Result}; | 16 | use ec_core::{Error, Result}; |
| 19 | 17 | ||