Wall tables for the per-tile search at 1080p and 4K, with a librav1e reference
Browse files at this commitc69113cccdb01fc46789530b97622a2afd980f30Parent: 8421ce2- test
- wall tables for the per-tile search at 1080p and 4K, with a librav1e reference
1 changed file +165 -0
- crates/ec-av1/src/encoder.rs +165 -0
crates/ec-av1/src/encoder.rsmodified+165 -0
| @@ -1839,6 +1839,171 @@ mod tests { | |||
| 1839 | crate::par::set_tile_threads(1); | 1839 | crate::par::set_tile_threads(1); |
| 1840 | } | 1840 | } |
| 1841 | 1841 | ||
| 1842 | + /// What the per-tile search (lane-av1tsearch) is worth in wall and in | ||
| 1843 | + /// frames per second at the editor's own export sizes: every tile layout | ||
| 1844 | + /// crossed with every tile-thread count, plus librav1e at the matching | ||
| 1845 | + /// `tile_cols`/`tile_rows`/`threads` as the reference point. Two passes | ||
| 1846 | + /// over the whole table (A,B,A,B... rather than AA,BB) with the best of | ||
| 1847 | + /// the two kept, so a thermal drift cannot order the rows. | ||
| 1848 | + /// | ||
| 1849 | + /// Measurement, not a pass/fail gate: it asserts only that every cell | ||
| 1850 | + /// produced a stream. | ||
| 1851 | + #[test] | ||
| 1852 | + #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"] | ||
| 1853 | + fn tile_search_wall_1080p() { | ||
| 1854 | + tile_search_wall(1920, 1080, 12, &[(0, 0), (1, 0), (1, 1), (2, 1)], &[1, 2, 4, 8]); | ||
| 1855 | + } | ||
| 1856 | + | ||
| 1857 | + /// The same table at the 4K frame size the editor exports (3840x1608), | ||
| 1858 | + /// at the two layouts with enough tiles to fill this box. | ||
| 1859 | + #[test] | ||
| 1860 | + #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"] | ||
| 1861 | + fn tile_search_wall_4k() { | ||
| 1862 | + tile_search_wall(3840, 1608, 6, &[(2, 1), (3, 2)], &[1, 8, 12]); | ||
| 1863 | + } | ||
| 1864 | + | ||
| 1865 | + fn tile_search_wall( | ||
| 1866 | + width: usize, | ||
| 1867 | + height: usize, | ||
| 1868 | + frames: usize, | ||
| 1869 | + layouts: &[(u32, u32)], | ||
| 1870 | + threads: &[usize], | ||
| 1871 | + ) { | ||
| 1872 | + let _gate_lock = crate::stream::tests::lock_gate_counters(); | ||
| 1873 | + let Some(sources) = h264_clip_frames(width, height, frames) else { | ||
| 1874 | + eprintln!("SKIP the tile-search wall table: no fixture or no ffmpeg"); | ||
| 1875 | + return; | ||
| 1876 | + }; | ||
| 1877 | + let run = |cols_log2: u32, rows_log2: u32, t: usize| -> (std::time::Duration, usize) { | ||
| 1878 | + crate::par::set_tile_threads(t); | ||
| 1879 | + let config = EncoderConfig { | ||
| 1880 | + width, | ||
| 1881 | + height, | ||
| 1882 | + base_q_idx: 120, | ||
| 1883 | + gop: frames, | ||
| 1884 | + colour: Colour::Bt709Limited, | ||
| 1885 | + tile_cols_log2: cols_log2, | ||
| 1886 | + tile_rows_log2: rows_log2, | ||
| 1887 | + }; | ||
| 1888 | + let mut enc = Av1Encoder::new(config).unwrap(); | ||
| 1889 | + let start = std::time::Instant::now(); | ||
| 1890 | + let mut bytes = 0usize; | ||
| 1891 | + for picture in &sources { | ||
| 1892 | + bytes += enc.encode(picture).unwrap().data.len(); | ||
| 1893 | + } | ||
| 1894 | + (start.elapsed(), bytes) | ||
| 1895 | + }; | ||
| 1896 | + let cells: Vec<((u32, u32), usize)> = layouts | ||
| 1897 | + .iter() | ||
| 1898 | + .flat_map(|&l| threads.iter().map(move |&t| (l, t))) | ||
| 1899 | + .collect(); | ||
| 1900 | + let mut best: Vec<Option<(std::time::Duration, usize)>> = vec![None; cells.len()]; | ||
| 1901 | + for _pass in 0..2 { | ||
| 1902 | + for (i, &((c, r), t)) in cells.iter().enumerate() { | ||
| 1903 | + let got = run(c, r, t); | ||
| 1904 | + assert!(got.1 > 0, "{}x{} tiles at {t} threads: empty stream", 1 << c, 1 << r); | ||
| 1905 | + if best[i].is_none_or(|(w, _)| got.0 < w) { | ||
| 1906 | + best[i] = Some(got); | ||
| 1907 | + } | ||
| 1908 | + } | ||
| 1909 | + } | ||
| 1910 | + crate::par::set_tile_threads(1); | ||
| 1911 | + eprintln!("\n{width}x{height}, {frames} frames, base_q_idx 120 -- best of two passes"); | ||
| 1912 | + eprintln!("| layout | tiles | threads | wall | fps | speedup vs 1 tile 1 thread | bytes |"); | ||
| 1913 | + let base = best[0].expect("the first cell ran").0.as_secs_f64(); | ||
| 1914 | + for (i, &((c, r), t)) in cells.iter().enumerate() { | ||
| 1915 | + let (wall, bytes) = best[i].expect("every cell ran"); | ||
| 1916 | + let secs = wall.as_secs_f64(); | ||
| 1917 | + eprintln!( | ||
| 1918 | + "| {}x{} | {} | {t} | {secs:.2}s | {:.2} | {:.2}x | {bytes} |", | ||
| 1919 | + 1 << c, | ||
| 1920 | + 1 << r, | ||
| 1921 | + 1 << (c + r), | ||
| 1922 | + frames as f64 / secs, | ||
| 1923 | + base / secs, | ||
| 1924 | + ); | ||
| 1925 | + } | ||
| 1926 | + // Parallel efficiency per layout: what the extra threads actually | ||
| 1927 | + // took off that layout's own single-threaded wall, and so what share | ||
| 1928 | + // of the added cores sat idle. | ||
| 1929 | + for &(c, r) in layouts { | ||
| 1930 | + let one = cells | ||
| 1931 | + .iter() | ||
| 1932 | + .position(|&(l, t)| l == (c, r) && t == threads[0]) | ||
| 1933 | + .map(|i| best[i].expect("cell").0.as_secs_f64()); | ||
| 1934 | + let Some(one) = one else { continue }; | ||
| 1935 | + for &t in &threads[1..] { | ||
| 1936 | + let i = cells.iter().position(|&(l, tt)| l == (c, r) && tt == t).expect("cell"); | ||
| 1937 | + let secs = best[i].expect("cell").0.as_secs_f64(); | ||
| 1938 | + let workers = (t.min(1 << (c + r))) as f64 / threads[0] as f64; | ||
| 1939 | + let speedup = one / secs; | ||
| 1940 | + eprintln!( | ||
| 1941 | + "{}x{} tiles, {} -> {t} threads: {speedup:.2}x of a possible {workers:.2}x, \ | ||
| 1942 | + idle share {:.0}%", | ||
| 1943 | + 1 << c, | ||
| 1944 | + 1 << r, | ||
| 1945 | + threads[0], | ||
| 1946 | + 100.0 * (1.0 - speedup / workers).max(0.0), | ||
| 1947 | + ); | ||
| 1948 | + } | ||
| 1949 | + } | ||
| 1950 | + rav1e_wall_reference(width, height, frames, layouts, threads); | ||
| 1951 | + } | ||
| 1952 | + | ||
| 1953 | + /// librav1e at the same sizes, layouts and thread counts, through ffmpeg | ||
| 1954 | + /// -- the reference the wall table is read against. | ||
| 1955 | + fn rav1e_wall_reference( | ||
| 1956 | + width: usize, | ||
| 1957 | + height: usize, | ||
| 1958 | + frames: usize, | ||
| 1959 | + layouts: &[(u32, u32)], | ||
| 1960 | + threads: &[usize], | ||
| 1961 | + ) { | ||
| 1962 | + let clip = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 1963 | + .join("../../fixtures/video/h264-1080p-23.976-8bit.mp4"); | ||
| 1964 | + let listed = Command::new("ffmpeg").args(["-hide_banner", "-encoders"]).output(); | ||
| 1965 | + let has_rav1e = listed | ||
| 1966 | + .map(|o| String::from_utf8_lossy(&o.stdout).contains("librav1e")) | ||
| 1967 | + .unwrap_or(false); | ||
| 1968 | + if !has_rav1e || !clip.exists() { | ||
| 1969 | + eprintln!("SKIP the rav1e reference: no librav1e or no fixture"); | ||
| 1970 | + return; | ||
| 1971 | + } | ||
| 1972 | + eprintln!("| rav1e layout | threads | wall | fps | bytes |"); | ||
| 1973 | + for &(c, r) in layouts { | ||
| 1974 | + for &t in threads { | ||
| 1975 | + let out = std::env::temp_dir().join(format!("ec-av1-rav1e-{}.ivf", std::process::id())); | ||
| 1976 | + let params = format!( | ||
| 1977 | + "speed=6:quantizer=100:tile_cols={}:tile_rows={}:threads={t}", | ||
| 1978 | + 1 << c, | ||
| 1979 | + 1 << r | ||
| 1980 | + ); | ||
| 1981 | + let start = std::time::Instant::now(); | ||
| 1982 | + let status = Command::new("ffmpeg") | ||
| 1983 | + .args(["-v", "error", "-y", "-i", clip.to_str().unwrap()]) | ||
| 1984 | + .args(["-frames:v", &frames.to_string()]) | ||
| 1985 | + .args(["-vf", &format!("scale={width}:{height}")]) | ||
| 1986 | + .args(["-c:v", "librav1e", "-rav1e-params", ¶ms]) | ||
| 1987 | + .arg(out.to_str().unwrap()) | ||
| 1988 | + .output() | ||
| 1989 | + .expect("ffmpeg failed to run"); | ||
| 1990 | + let secs = start.elapsed().as_secs_f64(); | ||
| 1991 | + if !status.status.success() { | ||
| 1992 | + eprintln!("| {}x{} | {t} | FAILED: {} |", 1 << c, 1 << r, String::from_utf8_lossy(&status.stderr).lines().last().unwrap_or("")); | ||
| 1993 | + continue; | ||
| 1994 | + } | ||
| 1995 | + let bytes = std::fs::metadata(&out).map(|m| m.len()).unwrap_or(0); | ||
| 1996 | + let _ = std::fs::remove_file(&out); | ||
| 1997 | + eprintln!( | ||
| 1998 | + "| {}x{} | {t} | {secs:.2}s | {:.2} | {bytes} |", | ||
| 1999 | + 1 << c, | ||
| 2000 | + 1 << r, | ||
| 2001 | + frames as f64 / secs | ||
| 2002 | + ); | ||
| 2003 | + } | ||
| 2004 | + } | ||
| 2005 | + } | ||
| 2006 | + | ||
| 1842 | /// The same round trip at a real 1920x1080 crop of the gate's own clip | 2007 | /// The same round trip at a real 1920x1080 crop of the gate's own clip |
| 1843 | /// -- the size the editor's export actually runs at, where a tile grid | 2008 | /// -- the size the editor's export actually runs at, where a tile grid |
| 1844 | /// is worth having. Ignored by default only for its wall (a 1080p | 2009 | /// is worth having. Ignored by default only for its wall (a 1080p |