diff --git a/crates/metal2vulkan-conformance/README.md b/crates/metal2vulkan-conformance/README.md index c2cd91172..bd4c45f00 100644 --- a/crates/metal2vulkan-conformance/README.md +++ b/crates/metal2vulkan-conformance/README.md @@ -522,10 +522,21 @@ with the one-minute load average holding at 6.1 and every load rule judging both Nearly all the movement the ledger's band pays for is that one pass. The paired rows common to the degraded pass and a good one move a median 2.62x, 14.96x at the 90th percentile and 63.9x at worst; **the two undegraded passes move a median 1.12x, 1.51x at the 90th percentile and 2.00x at worst -over all 100 rows.** So the ratio is not inherently unstable, and the gate did not refuse the pass -that makes it look so: 0.275 against 0.236 us is 1.17x, inside the 1.5x the calibration check -allows. `known-slow-calls.tsv`'s header carries the rest, including the four live per-call costs -that went unwritten because that header had said they changed sides when they had not. +over all 100 rows.** So the ratio is not inherently unstable, and for a while the gate did not +refuse the pass that makes it look so: 0.275 against 0.236 us is 1.17x, inside the 1.5x the +calibration check allows. **It refuses it now, on the floor under the measurement rather than on +the instrument's reading of itself.** The suite makes hundreds of calls that do almost nothing, so a +leg that is measuring at all resolves some of them under one instrument cost: both undegraded +passes read a cheapest figure of 41 ns on each leg — one tick of this chip's 24 MHz timebase, 0.17 +instrument costs — while the degraded pass has none of Metal's 2,979 figures under even the resolve +line and a floor of 5.15 instrument costs. `constant_data_offset`, a getter that does nothing, cost +41 ns on Metal's leg in both good passes and 3.000 us in that one. Every other quantity the gate +reads ranks the degraded pass as the best of the three — it ran at the lowest load, its two legs' +instrument readings agree the most tightly, its eight rounds are the most repeatable, and it sat +closer to its recorded reference than the good pass beside it, because a pass overwrites that +reference and so inherits its predecessor's degradation. `known-slow-calls.tsv`'s header carries the +rest, including the four live per-call costs that went unwritten because that header had said they +changed sides when they had not. **And a per-call row now has to carry its per-case figure**, because the two-tables warning above is not advisory. Metal compiles the AIR at `library` and we translate it at pipeline creation and @@ -538,9 +549,10 @@ those five is that its cost is work Metal never does, not work Metal already did case. The ledger's header asks that question of every new row. So the gate judges a per-call row only when the measurement can say something about it. It withholds -when the **instrument's own cost** disagrees with itself across a leg, across the two legs, or with -what this chip's recordings carry — bracketed per leg, because a single reading at a leg's start is -from a freshly-spawned thread and a leg is minutes long. And it withholds a row whose cheaper leg's +when the **instrument's own cost** disagrees with itself across a leg, across the two legs, with +what this chip's recordings carry, or with the cheapest figure that leg actually produced — +bracketed per leg, because a single reading at a leg's start is from a freshly-spawned thread and a +leg is minutes long. And it withholds a row whose cheaper leg's typical call costs under four instrument costs: of the 41 such rows, the ratio moved a median 4.23x between the two passes against 1.87x above the line. A withheld row neither adds a ledger row nor retires one, which is what protects `replace_region`'s row — a pooled ratio that moved 7.4x to 31.3x diff --git a/crates/metal2vulkan-conformance/src/bin/conformance.rs b/crates/metal2vulkan-conformance/src/bin/conformance.rs index 7f6bc0110..0e310047a 100644 --- a/crates/metal2vulkan-conformance/src/bin/conformance.rs +++ b/crates/metal2vulkan-conformance/src/bin/conformance.rs @@ -725,17 +725,20 @@ fn times( ours: ours.as_ref().map(|one| one.calibration).unwrap_or_default(), reference: recorded_instrument(cases), }; + // The paired table is built before the gate rather than inside it, because the gate reads it + // too: a leg whose own cheapest figure sits above its instrument cost did not take those + // figures on the CPU the instrument measured itself on (`slow_calls::FLOOR_MAY_REACH`). + let rows = match (&metal, &ours) { + (Some(metal), Some(ours)) => metal2vulkan_conformance::times::paired(metal, ours), + _ => Vec::new(), + }; if let Err(why) = - metal2vulkan_conformance::slow_calls::judges(shaders, metal_load, our_load, cpu) + metal2vulkan_conformance::slow_calls::judges(shaders, metal_load, our_load, cpu, &rows) { println!("\n{why}"); - } else if let (Some(metal), Some(ours)) = (&metal, &ours) { + } else if let (Some(_), Some(ours)) = (&metal, &ours) { let ledger = metal2vulkan_conformance::slow_calls::ledger()?; - let held = metal2vulkan_conformance::slow_calls::held( - &metal2vulkan_conformance::times::paired(metal, ours), - &ledger, - ours.instrument, - ); + let held = metal2vulkan_conformance::slow_calls::held(&rows, &ledger, ours.instrument); println!(); for one in &held { println!("{one}"); diff --git a/crates/metal2vulkan-conformance/src/slow_calls.rs b/crates/metal2vulkan-conformance/src/slow_calls.rs index 13747da99..59d559470 100644 --- a/crates/metal2vulkan-conformance/src/slow_calls.rs +++ b/crates/metal2vulkan-conformance/src/slow_calls.rs @@ -88,13 +88,31 @@ const LEDGER: &str = include_str!("../known-slow-calls.tsv"); /// 90th percentile and 2.00x at worst over all 100 rows they share — under even the 2.43x the /// 2.5 divisor was set from. So this divisor is paying for a pass [`judges`] should have refused /// and did not: that pass's instrument readings are 1.17x apart, inside what -/// [`CALIBRATION_MAY_MOVE`] allows, while its ratios move 64x. Tightening that check rather than -/// this divisor is the fix, and it is the owner's call; `known-slow-calls.tsv`'s header carries -/// the three passes and their figures. +/// [`CALIBRATION_MAY_MOVE`] allows, while its ratios move 64x. /// -/// The cost of the wider divisor is that a row genuinely fixed stays listed until it reads under -/// 1.43x, and the `NoLongerSlow` direction therefore says less than it did. That is the honest -/// trade: the measurement cannot tell 11x from 1.6x across two passes, so neither can the gate. +/// **That check is now tightened** ([`FLOOR_MAY_REACH`]), and the pass this divisor pays for is +/// refused by its own figures — verified both ways over all three stored passes +/// (`tests::the_floor_rule_refuses_the_degraded_pass_and_keeps_the_undegraded_ones`). **So the +/// divisor is the owner's to lower, and here is what the evidence supports.** What the +/// `NoLongerSlow` direction fires on is a *resolved* row's ratio, and between the two undegraded +/// passes those moved a median 1.10x, 1.51x at the 90th percentile and **1.97x at worst** over the +/// 56 rows they share. A row genuinely over a 10x margin can therefore read as low as 10 / 1.97 = +/// 5.08x on another undegraded pass, so any divisor at or above **1.97** keeps the direction sound +/// on the measured worst case; **2.5 — the number this constant replaced — puts the band at 4.0x +/// with 27% of headroom over that worst case**, and is now justified on the right quantity rather +/// than on Metal's own totals. +/// +/// Lowering it to 2.5 would move a fixed row's retirement from **1.43x to 4.0x**. Over the 19:57 +/// pass and today's ledger it changes no row's verdict — the six `Known` rows read 19.8x to 48.4x +/// and the two in the band read 4.42x and 5.30x — so what it buys is forward: `tile_pipeline` at +/// 4.42x and `render_pipeline_with_reflection` at 5.30x would announce themselves fixed on +/// reaching 4.0x instead of having to reach 1.43x, which is a ratio a real fix produces and 1.43x +/// is not. Whoever lowers it also moves +/// `tests::a_listed_row_in_the_band_is_neither_a_pass_nor_a_failure`, whose assertion is written +/// against the degraded pair's 6.92x and would want the undegraded 1.97x. +/// +/// Until then the cost of the wider divisor stands: a row genuinely fixed stays listed until it +/// reads under 1.43x, and the `NoLongerSlow` direction therefore says less than it did. pub const BAND_DIVISOR: f64 = 7.0; /// The ratio a listed row must fall under before the run reads it as fixed. @@ -191,6 +209,35 @@ pub const CALIBRATION_MAY_MOVE: f64 = 1.5; /// unstable must neither add a row nor retire one. pub const RESOLVES_AT: u64 = 4; +/// **How far the floor of one leg's own per-call figures may reach, in that leg's instrument +/// costs**, before the instrument's reading is not the cost of the figures that leg took. +/// +/// **This is the check the instrument's own readings cannot do, and the one the degraded whole-set +/// pass needed.** [`RESOLVES_AT`] says a call must cost four instrument costs before its row is +/// judged. This is its dual and it holds the whole measurement: the suite makes hundreds of calls +/// that do almost nothing — a property getter, a setter — so a leg that can measure at all +/// resolves some of them **under** its own instrument cost, and the cheapest figure it produced is +/// therefore a statement about the CPU it ran on that needs no reference and no second pass. +/// +/// Measured over the three whole-set passes this tree's recordings carry, re-read from them rather +/// than supposed. In both undegraded passes the cheapest paired row costs **41 ns on each leg**, +/// one tick of this chip's 24 MHz timebase, which is 0.168 and 0.171 instrument costs at 16:06 and +/// 0.174 and 0.176 at 19:57 — four readings spanning 1.05x — and 228 of 3,287 and 255 of 3,340 of +/// Metal's per-call figures sit under one instrument cost. In the degraded 07:44 pass **not one of +/// Metal's 2,979 figures is under even the resolve line**, and its cheapest row costs 1.416 us, or +/// **5.15 instrument costs**. The same trivial getters say it without a statistic: +/// `constant_data_offset` cost 41 ns on Metal's leg in both undegraded passes and 3.000 us at +/// 07:44, `sparse_tile_size` 41 ns against 3.125 us — 73x and 76x on calls that do nothing, while +/// that pass's instrument reading moved 1.17x and every rule above this one judged it. +/// +/// So the bound sits between a measured 0.176 and a measured 5.15, and at one instrument cost it +/// is nearly the middle of that range in both directions: 5.7x of headroom over every undegraded +/// reading, and the pass it was written for 5.1x the wrong side of it. It is also the one value in +/// that range with a meaning rather than a position — **the cheapest call a leg measured must cost +/// less than the instrument costs to look at it**, which is true of every call the suite makes +/// for free and false of a leg that has lost its resolution. +pub const FLOOR_MAY_REACH: f64 = 1.0; + /// What the instrument itself cost on the CPU one leg ran on: one reading before that leg and one /// after it. /// @@ -240,10 +287,22 @@ impl Calibration { /// /// The reference is the median of the readings the selection's recordings carry for this chip and /// this macOS build, and it is the only part of the gate that reaches outside the run. It is there -/// because a run degraded from its first instruction to its last has nothing inside it to compare -/// against: all four of its readings agree, and only a figure from another day says they are all -/// wrong together. A recording holds that figure already ([`crate::times::TimeRecord::instrument`]) -/// and holds the chip and the build it was taken on, so the reference needs no constant per host. +/// because a run degraded from its first instruction to its last has nothing inside its own +/// readings to compare against: all four of them agree, so only a figure from another day says +/// they are all wrong together. A recording holds that figure already +/// ([`crate::times::TimeRecord::instrument`]) and holds the chip and the build it was taken on, so +/// the reference needs no constant per host. +/// +/// **It is not the catch it was written to be, and the recordings say so.** A pass overwrites this +/// chip's readings with its own, so the reference a pass faces is in practice its predecessor's — +/// and when the predecessor was degraded too, the reference drifts along with the degradation +/// instead of standing still. Re-read from the recordings as each pass found them: the degraded +/// 07:44 pass read 0.275 and 0.269 us against a reference of 0.295 us, **1.10x off at worst**, +/// while the undegraded 16:06 pass read 0.244 and 0.240 us against the 0.269 us 07:44 had just +/// written, **1.12x off**. The quantity ranks the degraded pass as the more credible of the two, so +/// no threshold on it can refuse one and keep the other. What catches such a pass from inside +/// itself is [`FLOOR_MAY_REACH`], which compares the instrument's reading against the figures that +/// instrument took rather than against another day's reading of itself. #[derive(Clone, Copy, Debug, Default)] pub struct Calibrations { pub metal: Calibration, @@ -306,27 +365,41 @@ impl LegLoad { /// whole run could never see it, because the run's endpoints average over exactly the interval /// where the damage happens. These brackets measure it directly. /// -/// Refused seven ways, each with its reason for the caller to print: a cold reading, which does +/// Refused eight ways, each with its reason for the caller to print: a cold reading, which does /// not separate our compile cost from first use on a new device; any reading over /// [`QUIET_ENOUGH`]; a single leg whose own load moved by more than [`LOAD_MAY_MOVE`], so that /// leg is not one measurement; the two legs' loads differing by more than [`LOAD_MAY_MOVE`], /// so the ratio is of two machines; a leg whose **instrument cost** moved by more than /// [`CALIBRATION_MAY_MOVE`] while it ran; the two legs' instrument costs differing by that much, -/// so the ratio divides one CPU's figure by another's; and every reading of the instrument sitting -/// that far off what this chip's own recordings say it costs, which is the only way a run degraded -/// from start to finish can be caught from inside itself. +/// so the ratio divides one CPU's figure by another's; every reading of the instrument sitting that +/// far off what this chip's own recordings say it costs; and a leg whose own cheapest figure sits +/// more than [`FLOOR_MAY_REACH`] instrument costs up, which says the instrument's reading is not +/// the cost of the figures that leg took. +/// +/// **The last rule is the one the measurement itself supplies, and the first seven needed it.** The +/// degraded 07:44 whole-set pass moved its per-call ratios 64x and **every one of the seven judged +/// it**: it ran at the lowest load of the three passes recorded (2.74 and 3.46 against 4.95 and +/// 4.36), its two instrument readings agree to 1.02x, its eight rounds are the most repeatable of +/// the three, and it sat 1.10x off a reference its own degraded predecessor had written while the +/// undegraded pass beside it sat 1.12x off. Each of those is a measurement of the *host* or of the +/// *instrument*, and a uniformly slow CPU is a quiet, steady, agreeable host. [`FLOOR_MAY_REACH`] +/// asks the one question none of them does — whether the instrument's reading is consistent with +/// the figures it took — and answers it 5.15 against 0.176. /// /// The load readings and the calibration readings are both kept because they see different things: /// measured on this host, a background scheduling class doubled a per-call ratio while the load /// average held at 6.06 and 6.26, and the calibration moved 2.67x over the same pair of runs. /// /// A host that answers no load average is judged on what it does answer, and judged outright if -/// it answers nothing: a missing reading is not evidence of a busy machine. +/// it answers nothing: a missing reading is not evidence of a busy machine. `rows` is held to the +/// same rule — a measurement with no paired row has no floor to read, which is a selection without +/// a comparison rather than a degraded CPU. pub fn judges( shaders: crate::run::Shaders, metal: LegLoad, ours: LegLoad, cpu: Calibrations, + rows: &[crate::times::Paired], ) -> Result<(), String> { if matches!(shaders, crate::run::Shaders::Cold) { return Err(WHY_COLD_IS_NOT_JUDGED.to_owned()); @@ -453,8 +526,53 @@ pub fn judges( } } } + // The floor under the instrument, which is the measurement judging itself on its own figures + // rather than on another reading of itself. Every rule above compares the instrument with a + // load average, with its other end, with the other leg or with another day; this one compares + // it with the calls it measured, and it is the only one the degraded pass could not satisfy. + for (whose, floor, instrument) in [ + ( + "Metal's leg", + floor(rows.iter().map(|row| row.metal.typical)), + cpu.metal.typical(), + ), + ( + "our leg", + floor(rows.iter().map(|row| row.ours.typical)), + cpu.ours.typical(), + ), + ] { + let (Some(floor), Some(instrument)) = (floor, instrument.filter(|cost| *cost > 0)) else { + continue; + }; + let reached = floor as f64 / instrument as f64; + if reached > FLOOR_MAY_REACH { + return Err(format!( + "the margin is reported and not judged: the cheapest call {whose} measured cost \ + {:.3} us,\nand the instrument says it cost {:.3} us a call to measure one -- a \ + floor {reached:.2} instrument costs up,\nwhere the gate allows \ + {FLOOR_MAY_REACH:.1}. The suite makes hundreds of calls that do almost nothing, \ + so a leg\nthat is measuring at all resolves some of them under its own \ + instrument: measured on this host,\nboth undegraded whole-set passes read a floor \ + of 0.17 instrument costs -- one tick of the clock --\nwhile the pass this rule \ + was written for read 5.15 and moved its ratios 64x with its instrument\nreading \ + 1.17x. These figures and that instrument are not of one CPU. Re-run it where the \ + measuring\nthread keeps what it started with.", + floor as f64 / 1_000.0, + instrument as f64 / 1_000.0 + )); + } + } Ok(()) } + +/// The floor under one leg's measurement: the cheapest figure it produced for any paired row. +/// +/// A row the leg made no call for reads zero and is not a cheap call, so it is left out rather +/// than taken as a floor of nothing. +fn floor(of: impl Iterator) -> Option { + of.filter(|typical| *typical > 0).min() +} /// One call we have written down as costing an order of magnitude more than Metal's. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] pub struct KnownSlowCall { @@ -756,10 +874,14 @@ mod tests { metal, ours, Calibrations::unmeasured(), + &[], ) } /// The gate over a warm measurement on a quiet host, judged by its instrument alone. + /// + /// No rows, so the floor rule has nothing to read and the instrument rules are what the test + /// exercises. fn instrument( metal: Calibration, ours: Calibration, @@ -774,6 +896,7 @@ mod tests { ours, reference, }, + &[], ) } @@ -788,6 +911,7 @@ mod tests { steady(1.0), steady(1.0), Calibrations::unmeasured(), + &[], ) .expect_err( "a cold measurement was judged, and its readings do not separate the two causes", @@ -1077,6 +1201,371 @@ mod tests { ); } + /// One whole-set pass as its recordings carry it: what the instrument read on each leg, the + /// cheapest figure each leg produced, and the one-minute load each leg ran at. + struct Pass { + what: &'static str, + metal_instrument: u64, + ours_instrument: u64, + metal_floor: u64, + ours_floor: u64, + metal_load: f64, + ours_load: f64, + /// What this chip's recordings said the instrument cost when the pass was judged, which is + /// in practice its predecessor's reading ([`Calibrations`]). + reference: u64, + } + + /// The three whole-set passes this tree's recordings carry, re-read from them rather than + /// restated: the figures are each pass's own stored per-leg `instrument`, the minimum + /// `typical` over its paired rows, and the loads its `measured` words name. + /// + /// The per-leg calibration **brackets** are not stored — a recording keeps only their mean — + /// so each leg's two ends are given that mean, which is the reading most favourable to the + /// pass and makes the refusal below a conservative one. + const PASSES: [Pass; 3] = [ + Pass { + what: "the degraded 07:44 pass, whose ratios move 64x", + metal_instrument: 275, + ours_instrument: 269, + metal_floor: 1416, + ours_floor: 41, + metal_load: 2.74, + ours_load: 3.46, + reference: 295, + }, + Pass { + what: "the undegraded 16:06 pass", + metal_instrument: 244, + ours_instrument: 240, + metal_floor: 41, + ours_floor: 41, + metal_load: 4.95, + ours_load: 4.36, + reference: 269, + }, + Pass { + what: "the undegraded 19:57 pass", + metal_instrument: 236, + ours_instrument: 233, + metal_floor: 41, + ours_floor: 41, + metal_load: 3.18, + ours_load: 2.63, + reference: 240, + }, + ]; + + impl Pass { + /// The gate's verdict on this pass, by every rule. + fn judged(&self) -> Result<(), String> { + judges( + crate::run::Shaders::Warm, + steady(self.metal_load), + steady(self.ours_load), + Calibrations { + metal: calibrated(self.metal_instrument), + ours: calibrated(self.ours_instrument), + reference: Some(self.reference), + }, + &self.rows(), + ) + } + + /// The gate's verdict on this pass with the floor rule's input withheld, which is what the + /// gate read before this rule existed. + fn judged_without_its_floor(&self) -> Result<(), String> { + judges( + crate::run::Shaders::Warm, + steady(self.metal_load), + steady(self.ours_load), + Calibrations { + metal: calibrated(self.metal_instrument), + ours: calibrated(self.ours_instrument), + reference: Some(self.reference), + }, + &[], + ) + } + + /// One paired row per leg floor: the gate reads the minimum, so the pass's cheapest figure + /// on each leg is the whole of what it needs. + fn rows(&self) -> Vec { + let mut row = resolved_at("cheapest", 1, self.metal_floor); + row.metal.typical = self.metal_floor; + row.ours.typical = self.ours_floor; + vec![row] + } + } + + /// **The two-way proof over all three stored whole-set passes.** The floor rule refuses the + /// degraded one and judges both undegraded ones, and the test fails if either direction + /// breaks. + /// + /// It also pins *why* the rule was needed: with the floor withheld, **every other rule judges + /// all three passes**, the degraded one included. That pass ran at the lowest load of the + /// three and sat closer to its reference than the undegraded pass beside it, so no threshold + /// on what the gate read before could have separated them. + #[test] + fn the_floor_rule_refuses_the_degraded_pass_and_keeps_the_undegraded_ones() { + let [degraded, ref undegraded @ ..] = PASSES; + + // The direction that must fire. + let why = degraded + .judged() + .expect_err("the degraded whole-set pass was judged, and its ratios move 64x"); + assert!( + why.contains("cheapest call Metal's leg measured") && why.contains("1.416"), + "the reason does not name the leg and the floor it read: {why}" + ); + assert!( + degraded.metal_floor as f64 / degraded.metal_instrument as f64 > FLOOR_MAY_REACH, + "this test no longer pins a pass over the bound" + ); + + // The direction that must not. + for pass in undegraded { + assert!( + pass.judged().is_ok(), + "{} was refused, and a gate that refuses a good measurement is a gate nobody \ + runs: {}", + pass.what, + pass.judged().unwrap_err() + ); + } + + // **The negative control.** Every rule but this one judges every one of the three. + for pass in &PASSES { + assert!( + pass.judged_without_its_floor().is_ok(), + "{} is refused by a rule other than the floor, so this test does not prove the \ + floor is what separates them: {}", + pass.what, + pass.judged_without_its_floor().unwrap_err() + ); + } + + // And the margin either side is stated, so a reader sees how much room there is rather + // than taking a pass or a failure on trust. + let reached = |pass: &Pass| { + (pass.metal_floor as f64 / pass.metal_instrument as f64) + .max(pass.ours_floor as f64 / pass.ours_instrument as f64) + }; + let worst_good = undegraded.iter().map(reached).fold(0.0f64, f64::max); + assert!( + worst_good < FLOOR_MAY_REACH, + "the undegraded passes reach {worst_good:.3} instrument costs, at or over the bound" + ); + println!( + "the degraded pass reaches {:.2} instrument costs and the two undegraded ones {:.3} at \ + worst, against a bound of {FLOOR_MAY_REACH:.1}: {:.1}x over it and {:.1}x under it", + reached(°raded), + worst_good, + reached(°raded) / FLOOR_MAY_REACH, + FLOOR_MAY_REACH / worst_good + ); + } + + /// **The rule holds each leg on its own**, the way the load and instrument rules do: a ratio + /// is corrupt when either of its halves lost its resolution, and at 07:44 only Metal's leg + /// had. + #[test] + fn either_leg_losing_its_floor_refuses_the_measurement() { + let instrument = 240; + let under = |floor: u64| { + let mut row = resolved_at("row", 1, INSTRUMENT * RESOLVES_AT * 10); + row.metal.typical = floor; + row.ours.typical = floor; + row + }; + let at_the_bound = (instrument as f64 * FLOOR_MAY_REACH) as u64; + let judge = |metal_floor: u64, ours_floor: u64| { + let mut row = under(metal_floor); + row.ours.typical = ours_floor; + judges( + crate::run::Shaders::Warm, + steady(1.0), + steady(1.0), + Calibrations { + metal: calibrated(instrument), + ours: calibrated(instrument), + reference: Some(instrument), + }, + std::slice::from_ref(&row), + ) + }; + let why = judge(at_the_bound + 1, at_the_bound) + .expect_err("a Metal leg whose floor sits over its instrument was judged"); + assert!( + why.contains("Metal's leg"), + "the reason does not name the leg that lost its floor: {why}" + ); + let why = judge(at_the_bound, at_the_bound + 1) + .expect_err("our leg's floor sitting over its instrument was judged"); + assert!( + why.contains("our leg"), + "the reason does not name our leg: {why}" + ); + assert!( + judge(at_the_bound, at_the_bound).is_ok(), + "the allowance itself is refused, so no measurement can ever meet it" + ); + // A measurement with no row has no floor, and a selection without a comparison is not a + // degraded CPU. + assert!( + judges( + crate::run::Shaders::Warm, + steady(1.0), + steady(1.0), + Calibrations { + metal: calibrated(instrument), + ours: calibrated(instrument), + reference: Some(instrument), + }, + &[], + ) + .is_ok(), + "a measurement was refused for having no paired row to read a floor from" + ); + // Neither does a row for a call a leg never made: a zero is not a cheap call. + let mut absent = under(0); + absent.ours.typical = 0; + assert!( + judges( + crate::run::Shaders::Warm, + steady(1.0), + steady(1.0), + Calibrations { + metal: calibrated(instrument), + ours: calibrated(instrument), + reference: Some(instrument), + }, + std::slice::from_ref(&absent), + ) + .is_ok(), + "a row whose legs made no call was read as a floor of nothing" + ); + // And a run that took no calibration has nothing to normalise a floor by. + assert!( + judges( + crate::run::Shaders::Warm, + steady(1.0), + steady(1.0), + Calibrations::unmeasured(), + std::slice::from_ref(&under(at_the_bound * 100)), + ) + .is_ok(), + "a run was refused for the instrument having said nothing to compare its floor with" + ); + } + + /// **The same rule over the committed recordings, re-derived rather than restated.** The pass + /// the tree carries is rebuilt from the cases' own time records through the real + /// [`crate::times::paired`], and the gate judges it. + /// + /// It is the half of the two-way proof that cannot drift from the tree: the constants above + /// are a reading of three passes, and this is a reading of the pass that is actually here. It + /// also holds the rule's premise — that the suite makes calls it can resolve under one + /// instrument cost — so a tree whose cheap calls all left would fail here and say so, rather + /// than leaving the gate refusing every honest measurement. + #[test] + fn the_committed_pass_floor_sits_under_its_own_instrument() { + use crate::times::{CaseTimes, Leg, Measurement}; + + let mut legs: Vec<(Leg, Vec, Vec)> = vec![ + (Leg::Metal, Vec::new(), Vec::new()), + (Leg::Ours, Vec::new(), Vec::new()), + ]; + for case in crate::cases::all() { + let Ok(recording) = crate::recording::read(case.name()) else { + continue; + }; + for held in &recording.times { + if held.chip != crate::recording::ORACLE_CHIP + || held.os_build != crate::recording::ORACLE_OS_BUILD + { + continue; + } + for (leg, cases, instruments) in legs.iter_mut() { + if held.leg == *leg { + cases.push(held.times.clone()); + if held.instrument > 0 { + instruments.push(held.instrument); + } + } + } + } + } + let built = |leg: Leg, cases: Vec, instrument: u64| Measurement { + leg, + venue: leg.label().to_owned(), + rounds: 0, + instrument, + calibration: calibrated(instrument), + cpu_clock: true, + cases, + calls: Vec::new(), + noticed_calls: Vec::new(), + }; + let mut held = legs.into_iter(); + let (metal_leg, metal_cases, mut metal_instruments) = held.next().unwrap(); + let (our_leg, our_cases, mut our_instruments) = held.next().unwrap(); + metal_instruments.sort_unstable(); + our_instruments.sort_unstable(); + let (Some(&metal_instrument), Some(&our_instrument)) = ( + metal_instruments.get((metal_instruments.len().max(1) - 1) / 2), + our_instruments.get((our_instruments.len().max(1) - 1) / 2), + ) else { + panic!( + "the recordings carry no instrument reading for {} on {}, so the gate's premise \ + cannot be read back", + crate::recording::ORACLE_CHIP, + crate::recording::ORACLE_OS_BUILD + ); + }; + let metal = built(metal_leg, metal_cases, metal_instrument); + let ours = built(our_leg, our_cases, our_instrument); + let rows = crate::times::paired(&metal, &ours); + assert!( + !rows.is_empty(), + "the committed recordings pair no call at all, so there is no floor to read" + ); + + let metal_floor = floor(rows.iter().map(|row| row.metal.typical)) + .expect("no Metal leg figure in the committed pass"); + let our_floor = floor(rows.iter().map(|row| row.ours.typical)).expect("no figure of ours"); + let reached = (metal_floor as f64 / metal_instrument as f64) + .max(our_floor as f64 / our_instrument as f64); + println!( + "the committed pass pairs {} row(s); its floor is {:.3} us on Metal's leg against a \ + {:.3} us instrument and {:.3} us on ours against {:.3} us, reaching {reached:.3} \ + instrument costs", + rows.len(), + metal_floor as f64 / 1_000.0, + metal_instrument as f64 / 1_000.0, + our_floor as f64 / 1_000.0, + our_instrument as f64 / 1_000.0, + ); + assert!( + judges( + crate::run::Shaders::Warm, + steady(1.0), + steady(1.0), + Calibrations { + metal: calibrated(metal_instrument), + ours: calibrated(our_instrument), + reference: Some(our_instrument), + }, + &rows, + ) + .is_ok(), + "the gate refuses the pass this tree carries, whose floor reaches {reached:.3} \ + instrument costs against a bound of {FLOOR_MAY_REACH:.1}. Either the measurement it \ + was recorded on was degraded, or the suite no longer makes a call it can resolve \ + under one instrument cost and the bound is measuring the wrong thing" + ); + } + /// A call that is *faster* than Metal's never fires the gate: it is an upper bound on our own /// cost, and an unexplained win is not something a gate should bless. #[test]