From 99ec109264710fd5cc5ed4c8c5ffecaefeeb9ea8 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 18 Nov 2026 12:58:16 -0800 Subject: [PATCH] harness: each creation row's first is a fresh object's on a device that has made one of its kind A creation row's first sample was the first of its kind in a fresh process, so it held the device's own first use (its first recorder, submission, upload, staging region, stamp pool) together with the object's. A guest keeps one device for the machine's life, so what a device pays once never reaches it. The planner ruled that every first row is judged on a new object's first use on a warm device. Each creation row now makes a warm-up of its kind first, made and used as the first is and kept until the first is done, then the timed first on a fresh object: - Shared and Private buffers: a buffer of the same length, kept, so the first takes memory the warm-up did not give back (a new 16 MiB Private block on rt's harness placement); the next take still follows the first's release. - compute states: a state of another authored kernel (lcg_step, bound as signed_zero_products is), created and dispatched once, its word checked; - render states: a state of another fragment function (sampled_fragment) with the row's vertex function and attachment. The warm-up's time is its own record, `/device_first`. The matrix shows it with the ratio of its medians and never judges it (results.SHOWN_FIRST now names each shown sample with its reason). time_states takes the first as its caller timed it; its other form had no caller left. Tests: a host-buffer device shows the buffer row's order (the warm-up alone, the first and the next beside it, the timed ones alone); the matrix shows a warm-up and judges the first it comes before; the device test checks every row records its warm-up. --- crates/metal2vulkan-harness/src/authored.rs | 12 ++ .../metal2vulkan-harness/src/bin/harness.rs | 11 +- crates/metal2vulkan-harness/src/lib.rs | 5 +- crates/metal2vulkan-harness/src/run.rs | 136 +++++++++++------- crates/metal2vulkan-harness/src/tests.rs | 108 +++++++++++++- crates/metal2vulkan-harness/tests/authored.rs | 4 +- docs/VALIDATION.md | 10 +- scripts/matrix/results.py | 25 ++-- scripts/matrix/test_results.py | 16 +++ 9 files changed, 258 insertions(+), 69 deletions(-) diff --git a/crates/metal2vulkan-harness/src/authored.rs b/crates/metal2vulkan-harness/src/authored.rs index 8940494e6..591556aa0 100644 --- a/crates/metal2vulkan-harness/src/authored.rs +++ b/crates/metal2vulkan-harness/src/authored.rs @@ -211,6 +211,18 @@ pub enum Makes { }, } +/// The kernel of a compute pipeline state row's warm-up +/// ([`CreateReport::device_first_us`](crate::run::CreateReport::device_first_us)): another of the +/// authored library's, bound as the row's own is (16 bytes it writes at buffer 0, a `uint` at +/// buffer 1). Some authored workloads make it too, so its state is the device's first only where +/// the creation rows run alone, as the matrix runs them. +pub const WARM_KERNEL: &str = "lcg_step"; + +/// The fragment function of a render pipeline state row's warm-up +/// ([`CreateReport::device_first_us`](crate::run::CreateReport::device_first_us)), with the row's +/// vertex function and attachment: another of the render library's. +pub const WARM_FRAGMENT: &str = "sampled_fragment"; + /// The timed creations of a pipeline-state workload. pub const STATE_CREATIONS: u32 = 1000; diff --git a/crates/metal2vulkan-harness/src/bin/harness.rs b/crates/metal2vulkan-harness/src/bin/harness.rs index 14758bf10..42e7e82cd 100644 --- a/crates/metal2vulkan-harness/src/bin/harness.rs +++ b/crates/metal2vulkan-harness/src/bin/harness.rs @@ -468,7 +468,7 @@ fn gauges(gauges: &[(u32, Vec<(&'static str, u64)>)]) -> String { fn print_create(runtime: &str, create: &Create, report: &CreateReport, store: &str) { let us = |p| percentile(&report.create_us, p).map_or("-".to_owned(), |us| format!("{us:.1}")); println!( - "{:<17} {runtime:<8} {:>10} {:>11} {:>11} {:>11} {:>11} {:>11} {}{}", + "{:<17} {runtime:<8} {:>10} {:>11} {:>11} {:>11} {:>11} {:>11} {}{}{}", create.name, match create.makes { Makes::Buffers { length } | Makes::PrivateBuffers { length } => length.to_string(), @@ -497,6 +497,9 @@ fn print_create(runtime: &str, create: &Create, report: &CreateReport, store: &s } _ => String::new(), }, + report + .device_first_us + .map_or(String::new(), |us| format!("; its warm-up {us:.1} us")), ); if let Some(waits) = report.first_allocations { println!( @@ -522,6 +525,12 @@ fn print_create(runtime: &str, create: &Create, report: &CreateReport, store: &s steady(&report.create_us), &report.gauges, ); + if let Some(us) = report.device_first_us { + println!( + "M2V-MATRIX time harness-{runtime}/{}/device_first {us:.3}", + create.name + ); + } if let Some(us) = report.first_us { println!( "M2V-MATRIX time harness-{runtime}/{}/first {us:.3}", diff --git a/crates/metal2vulkan-harness/src/lib.rs b/crates/metal2vulkan-harness/src/lib.rs index 982c4570e..33863da06 100644 --- a/crates/metal2vulkan-harness/src/lib.rs +++ b/crates/metal2vulkan-harness/src/lib.rs @@ -41,7 +41,10 @@ //! alone), then 1,000 of a content it has, each made and released in turn; and render pipeline //! states of one content the same way, the first's creation alone (`create_render_state`: a //! vertex and a fragment function of the public fixture `examples/runtime_examples.ll`, into one -//! `BGRA8Unorm` attachment). +//! `BGRA8Unorm` attachment). Each row's first is a fresh object's on a device that has gone that +//! way once: a warm-up of the row's kind comes first, made and used as the first is and kept +//! until the first is done (a buffer of the same length, a state of another kernel or fragment +//! function), timed as the row's `device_first` ([`run::CreateReport::device_first_us`]). //! //! ```sh //! cargo run --release -p metal2vulkan-harness -- --runtime old|new[,old|new...] [--runs 200] \ diff --git a/crates/metal2vulkan-harness/src/run.rs b/crates/metal2vulkan-harness/src/run.rs index a188fb3ea..dd269fc1c 100644 --- a/crates/metal2vulkan-harness/src/run.rs +++ b/crates/metal2vulkan-harness/src/run.rs @@ -1,6 +1,6 @@ //! A plan on a device: its objects made, its first run checked, the runs after it timed. -use crate::authored::{Makes, STATE_CREATIONS}; +use crate::authored::{Makes, STATE_CREATIONS, WARM_FRAGMENT, WARM_KERNEL}; use crate::plan::{ Binding, Blit, BufferPlan, Constant, Grid, Plan, SamplerPlan, Scaled, Source, TexturePlan, TextureSource, @@ -290,7 +290,8 @@ pub trait Session { /// takes the range the last one left: one checked whole, then `runs`, each checked to start /// zero (every 4 KiB), then written all over before its release. Compute pipeline states of /// one content: the first, of a content the device has not seen, timed apart, then `runs`' - /// warm-up and [`crate::authored::STATE_CREATIONS`] timed ones. + /// warm-up and [`crate::authored::STATE_CREATIONS`] timed ones. Each kind's first sample + /// follows a warm-up of its kind ([`CreateReport::device_first_us`]). fn create(&mut self, makes: Makes, runs: Runs) -> Result; /// Drops the session, its device last; the device's gauges after that, where the runtime's @@ -417,12 +418,19 @@ pub struct CreateReport { /// buffer the dispatch writes, the guest's take of memory beside it; a render pipeline state's /// is its creation alone. pub first_us: Option, + /// The warm-up ahead of the first creation, in microseconds: an object of the row's kind made + /// and used as the first is, and kept until the first is done, so that the first is a fresh + /// object's on a device that has gone that way once. A buffer of the same length; a compute + /// pipeline state of another kernel ([`WARM_KERNEL`]), with its dispatch; a render pipeline + /// state of another fragment function ([`WARM_FRAGMENT`]). Where the row is the first of its + /// kind on the device, it holds what the device pays once, beside the object's own costs. + pub device_first_us: Option, /// The first creation's wall time alone, in microseconds: for a pipeline state, the part of /// [`first_us`](Self::first_us) the creation call paid, all of it for a render pipeline /// state; for a buffer, the device's first take of memory for a buffer of its length. pub first_create_us: Option, - /// For a buffer, the second creation's wall time, in microseconds: the first after the first - /// buffer was released, which a runtime may serve from the memory that buffer gave back. + /// For a buffer, the wall time of the creation after the first's release, in microseconds, + /// which a runtime may serve from the memory that buffer gave back. pub again_us: Option, /// The runtime's memory allocations on the caller's thread during the first creation (with /// its dispatch and its buffer, for a compute pipeline state): their count and time, and the @@ -1100,11 +1108,19 @@ impl Session for Harness { .new_library(Code::Air(&crate::authored::render_library_air()?))?; let vertex = library.new_function(vertex, &[])?; let fragment = library.new_function(fragment, &[])?; - self.time_states( - || (self.device).new_render_pipeline_state(&vertex, &fragment, color), - None, - runs, - ) + let warm = library.new_function(WARM_FRAGMENT, &[])?; + let started = Instant::now(); + let warm = (self.device).new_render_pipeline_state(&vertex, &warm, color)?; + let device_first = started.elapsed().as_secs_f64() * 1e6; + let make = || (self.device).new_render_pipeline_state(&vertex, &fragment, color); + let started = Instant::now(); + let state = make()?; + let first = started.elapsed().as_secs_f64() * 1e6; + drop((state, warm)); + let mut report = self.time_states(make, first, runs)?; + report.device_first_us = Some(device_first); + report.first_create_us = Some(first); + Ok(report) } } } @@ -1154,10 +1170,11 @@ impl Harness { /// [`Session::create`] of `Private` buffers of `length` bytes (at least 32): each made, then /// used once by the copy kernel, which moves its first and last 16 bytes into a `Shared` /// buffer, through to completion, the copy checked zero; timed from the creation to the - /// completion. + /// completion. The first is made while the warm-up's buffer is kept + /// ([`CreateReport::device_first_us`]), so it takes memory the warm-up did not give back. fn create_private(&self, length: u64, runs: Runs) -> Result { let out = self.device.new_buffer(32, Storage::Shared)?; - let once = || -> Result { + let take = || -> Result<(f64, D::Buffer)> { scribble(&out, 32)?; let started = Instant::now(); let buffer = self.device.new_buffer(length, Storage::Private)?; @@ -1174,13 +1191,17 @@ impl Harness { command_buffer.wait_until_completed()?; let used = started.elapsed(); zeroed(&out, 32, 4)?; - Ok(used.as_secs_f64() * 1e6) + Ok((used.as_secs_f64() * 1e6, buffer)) }; + let once = || take().map(|(us, _)| us); + let (device_first, warm) = take()?; let before = self.device.allocations(); let first = once()?; let first_allocations = since(before, self.device.allocations()); let again = once()?; + drop(warm); let mut report = CreateReport { + device_first_us: Some(device_first), first_create_us: Some(first), again_us: Some(again), first_allocations, @@ -1198,7 +1219,9 @@ impl Harness { /// [`Session::create`] of pipeline states of `function` with the `float` constants /// `constants`: each made, timed, and released. The first, of a content the device has not - /// seen, is timed with one dispatch of it through to completion, its output checked. + /// seen, is timed with one dispatch of it through to completion, its output checked; the + /// warm-up ahead of it is a state of [`WARM_KERNEL`] made and dispatched the same way, kept + /// until the first is done ([`CreateReport::device_first_us`]). fn create_states( &self, function: &str, @@ -1214,27 +1237,41 @@ impl Harness { }) .collect(); let function = self.authored.new_function(function, &values)?; + let warm = self.authored.new_function(WARM_KERNEL, &[])?; + // Word 0 stepped once from zero with an increment of 1. + let (_, device_first, warm) = self.first_state(&warm, [1, 0, 0, 0])?; + // Thread 0's start (0, -0, 0.5, -0.25), one round: the FMA step plus the products' + // difference, a * positive - a * negative, of the start. + let factor = |index| { + (constants.iter()) + .find(|&&(at, _)| at == index) + .map_or(0.0, |&(_, value)| value) + }; + let want = [0.0f32, -0.0, 0.5, -0.25].map(|a| { + (a.mul_add(0.96875, 0.03125) + (0.0 + a * factor(0) - a * factor(1))).to_bits() + }); let before = self.device.allocations(); - let (first_create, first) = self.first_state(&function, constants)?; + let (first_create, first, _) = self.first_state(&function, want)?; let allocations = since(before, self.device.allocations()); + drop(warm); let mut report = self.time_states( || self.device.new_compute_pipeline_state(&function, &[]), - Some(first), + first, runs, )?; + report.device_first_us = Some(device_first); report.first_create_us = Some(first_create); report.first_allocations = allocations; Ok(report) } - /// [`Session::create`] of the states `make` makes: the first timed apart (`first`, where the - /// caller timed it with more than its creation; else its creation here, which is then its - /// [`first_create_us`](CreateReport::first_create_us) too), then `runs`' warm-up and - /// [`STATE_CREATIONS`] timed ones, each released before the next. + /// [`Session::create`] of the states `make` makes, after the first, which the caller timed + /// (`first`): `runs`' warm-up and [`STATE_CREATIONS`] timed ones, each released before the + /// next. fn time_states( &self, make: impl Fn() -> Result, - first: Option, + first: f64, runs: Runs, ) -> Result { let once = || -> Result { @@ -1244,16 +1281,8 @@ impl Harness { drop(state); Ok(made.as_secs_f64() * 1e6) }; - let (first, first_create_us) = match first { - Some(first) => (first, None), - None => { - let first = once()?; - (first, Some(first)) - } - }; let mut report = CreateReport { first_us: Some(first), - first_create_us, warmup: warm_up(runs, &once)?, ..CreateReport::default() }; @@ -1266,11 +1295,15 @@ impl Harness { Ok(report) } - /// The first state of `function` (`signed_zero_products`, with the `float` constants - /// `constants` as its two products' factors) made, then dispatched once, one thread of one - /// round, through to completion: the creation's wall time and the whole's, in microseconds. - /// The thread's `float4` is checked against the kernel's arithmetic. - fn first_state(&self, function: &D::Function, constants: &[(u32, f32)]) -> Result<(f64, f64)> { + /// A first state of `function`, a kernel that writes up to 16 bytes at buffer 0 and reads a + /// `uint` at buffer 1, made, then dispatched once, one thread with 1 at buffer 1, through to + /// completion: the creation's wall time and the whole's, in microseconds, and the state. The + /// 16 bytes are checked against `want`, four little-endian words. + fn first_state( + &self, + function: &D::Function, + want: [u32; 4], + ) -> Result<(f64, f64, D::ComputePipelineState)> { let started = Instant::now(); let destination = self.device.new_buffer(16, Storage::Shared)?; let creating = Instant::now(); @@ -1286,28 +1319,21 @@ impl Harness { command_buffer.commit()?; command_buffer.wait_until_completed()?; let whole = started.elapsed(); - // Thread 0's start (0, -0, 0.5, -0.25), one round: the FMA step plus the products' - // difference, a * positive - a * negative, of the start. - let factor = |index| { - (constants.iter()) - .find(|&&(at, _)| at == index) - .map_or(0.0, |&(_, value)| value) - }; - let want = [0.0f32, -0.0, 0.5, -0.25] - .map(|a| a.mul_add(0.96875, 0.03125) + (0.0 + a * factor(0) - a * factor(1))); let contents = destination .contents() .ok_or("the first state's destination has no contents")?; - let mut got = [0f32; 4]; + let mut got = [0u32; 4]; for (at, value) in got.iter_mut().enumerate() { // SAFETY: the buffer holds 16 bytes and its command buffer has completed. let bytes = unsafe { contents.as_ptr().add(4 * at).cast::<[u8; 4]>().read() }; - *value = f32::from_le_bytes(bytes); + *value = u32::from_le_bytes(bytes); } if got != want { - return Err(format!("the first state's dispatch wrote {got:?}, not {want:?}").into()); + return Err( + format!("the first state's dispatch wrote {got:#x?}, not {want:#x?}").into(), + ); } - Ok((made.as_secs_f64() * 1e6, whole.as_secs_f64() * 1e6)) + Ok((made.as_secs_f64() * 1e6, whole.as_secs_f64() * 1e6, state)) } } @@ -1323,23 +1349,29 @@ fn since(before: Option, after: Option) -> Option { } /// [`Session::create`] of buffers on `device`. -fn create(device: &D, length: u64, runs: Runs) -> Result { - // A creation's time, its buffer checked zero at every `stride`th byte, then written all over - // and released. - let once = |stride| -> Result { +pub(crate) fn create(device: &D, length: u64, runs: Runs) -> Result { + // A creation's time and its buffer, checked zero at every `stride`th byte, then written all + // over. + let take = |stride| -> Result<(f64, D::Buffer)> { let started = Instant::now(); let buffer = device.new_buffer(length, Storage::Shared)?; let created = started.elapsed(); zeroed(&buffer, length, stride)?; scribble(&buffer, length)?; - Ok(created.as_secs_f64() * 1e6) + Ok((created.as_secs_f64() * 1e6, buffer)) }; - // The first take of memory for a buffer of the length, then the first after its release. + // A creation, its buffer then released. + let once = |stride| take(stride).map(|(us, _)| us); + // The warm-up's buffer, kept; the first take of memory for a buffer of the length beside it, + // then the first after its release. + let (device_first, warm) = take(4)?; let before = device.allocations(); let first = once(4)?; let first_allocations = since(before, device.allocations()); let again = once(4)?; + drop(warm); let mut report = CreateReport { + device_first_us: Some(device_first), first_create_us: Some(first), again_us: Some(again), first_allocations, diff --git a/crates/metal2vulkan-harness/src/tests.rs b/crates/metal2vulkan-harness/src/tests.rs index f980b20c7..223be8978 100644 --- a/crates/metal2vulkan-harness/src/tests.rs +++ b/crates/metal2vulkan-harness/src/tests.rs @@ -8,14 +8,16 @@ use crate::plan::{ }; use crate::rt::{self, Ranges}; use crate::run::{ - compare_outputs, copy_dispatches, matrix_time, parts, percentile, run_each, settled, steady, - warm_up, zeroed, CreateReport, Report, Runs, Session, + compare_outputs, copy_dispatches, create, matrix_time, parts, percentile, run_each, settled, + steady, warm_up, zeroed, CreateReport, Report, Runs, Session, }; -use crate::{Buffer, Failed, Refused, Result, Storage, Waits}; +use crate::{Buffer, Device, Failed, GaugeReader, Refused, Result, Storage, Waits}; use metal2vulkan::metal::TextureUsage; use metal2vulkan_rt::{Error as RtError, Gap, Limit}; +use std::cell::{Cell, RefCell}; use std::path::Path; use std::ptr::NonNull; +use std::rc::Rc; #[test] fn percentiles_take_the_nearest_rank() { @@ -850,6 +852,106 @@ fn a_new_buffer_is_zero_only_where_every_word_read_is() { assert!(zeroed(&HostBuffer(vec![9; 4]), 16, 4).is_err()); } +/// A host buffer that counts the live ones of its device. +struct Counted { + words: Vec, + live: Rc>, +} + +impl Buffer for Counted { + fn contents(&self) -> Option> { + NonNull::new(self.words.as_ptr().cast_mut().cast()) + } + + fn did_modify_range(&self, _: u64, _: u64) -> Result<()> { + Ok(()) + } +} + +impl Drop for Counted { + fn drop(&mut self) { + self.live.set(self.live.get() - 1); + } +} + +/// A device of host buffers that keeps, at each creation, how many of its buffers lived. +#[derive(Default)] +struct HostDevice { + live: Rc>, + beside: RefCell>, +} + +impl Device for HostDevice { + type Buffer = Counted; + + fn name(&self) -> String { + "host".to_owned() + } + + fn new_buffer(&self, length: u64, _: Storage) -> Result { + self.beside.borrow_mut().push(self.live.get()); + self.live.set(self.live.get() + 1); + Ok(Counted { + words: vec![0; length.div_ceil(4) as usize], + live: Rc::clone(&self.live), + }) + } + + fn gauges(&self) -> Vec<(&'static str, u64)> { + Vec::new() + } + + fn gauges_after_drop(&self) -> Option { + None + } + + fn threads(&self) -> Vec { + Vec::new() + } + + fn pipelines_created(&self) -> u64 { + 0 + } + + fn counts(&self) -> Vec<(&'static str, u64)> { + Vec::new() + } + + fn submissions(&self) -> u64 { + 0 + } + + fn submit_infos(&self) -> Option { + None + } + + fn first_use_waits(&self) -> Option { + None + } + + fn allocations(&self) -> Option { + None + } +} + +#[test] +fn a_buffer_row_s_first_is_made_beside_its_kept_warm_up() { + let device = HostDevice::default(); + let runs = Runs { + warmup: 0, + settle: false, + timed: 2, + }; + let report = create(&device, 4096, runs).unwrap(); + // The warm-up alone; the first, then the next after its release, each beside the warm-up; + // the timed ones alone once the warm-up is released. + assert_eq!(*device.beside.borrow(), [0, 1, 1, 0, 0]); + assert_eq!(device.live.get(), 0); + assert!(report.device_first_us.is_some()); + assert!(report.first_create_us.is_some() && report.again_us.is_some()); + assert_eq!(report.create_us.len(), 2); +} + #[test] fn ranges_place_at_the_lowest_free_range_and_merge_what_is_given_back() { let mut free = Ranges::new(1024); diff --git a/crates/metal2vulkan-harness/tests/authored.rs b/crates/metal2vulkan-harness/tests/authored.rs index dd393a108..a01a6d3e2 100644 --- a/crates/metal2vulkan-harness/tests/authored.rs +++ b/crates/metal2vulkan-harness/tests/authored.rs @@ -43,6 +43,7 @@ fn every_workload(session: &mut dyn Session) { let made = session.pipelines_created(); let report = (session.create(create.makes, runs)).unwrap_or_else(|why| panic!("{name}: {why}")); + assert!(report.device_first_us.is_some(), "{name}: no warm-up"); match create.makes { authored::Makes::Buffers { .. } | authored::Makes::PrivateBuffers { .. } => { assert_eq!(report.create_us.len(), 1, "{name}"); @@ -52,7 +53,8 @@ fn every_workload(session: &mut dyn Session) { assert_eq!(report.create_us.len(), timed, "{name}"); assert!(report.first_us.is_some(), "{name}"); // The first state's timed work holds its VkPipeline's compile on either runtime: - // in the creation, or at its one dispatch. + // in the creation, or at its one dispatch. (The warm-up's kernel is one the + // authored workloads made already here.) assert!( session.pipelines_created() > made, "{name}: the first state made no VkPipeline" diff --git a/docs/VALIDATION.md b/docs/VALIDATION.md index 467026d33..e09e20403 100644 --- a/docs/VALIDATION.md +++ b/docs/VALIDATION.md @@ -371,7 +371,8 @@ Both runs skip the creation rows (the harness's `--skip 'create_*'`): those run store, so no row before them moves their times. The first process's records are kept whole, its device's gauges at drop as `harness-/creates/device/...`; of each later process, only the creation rows' first samples (`/first`, `/first_call`, `/first_take`, `/next_take`, -`/first_allocation_total`, one sample per process), as `harness-first///`, +`/first_allocation_total`, `/device_first`, one sample per process), as +`harness-first///`, parked for the `time` rule. The harness budget compares the two runtimes rather than two commits, apart from the `time` rule @@ -411,7 +412,12 @@ the medians of its five processes, the new runtime's over the old's; a first sam never past its limit. A compute pipeline state row's `/first` is its creation and one dispatch through to completion, since Metal compiles at the creation and a runtime may compile at the first dispatch instead, as the old runtime does; its `/first_call`, the creation call alone, is -shown beside it with the ratio of its medians and never judged. A row whose time +shown beside it with the ratio of its medians and never judged. Each creation row's first sample +is a fresh object's on a device that has gone that way once: the harness makes a warm-up of the +row's kind first (a buffer of the same length, kept; a compute state of another kernel, with its +dispatch; a render state of another fragment function), so what a device pays once, which a guest +that keeps its device pays once in its life, stays out of the judged sample. The warm-up's own +time, `/device_first`, is shown the same way and never judged. A row whose time either runtime recorded more than once fails, uncompared. A row whose size follows the device (`long_4cb`) is sized by the first runtime's run, and the later runs, warm and re-timed ones included, are given that size (the harness's `--size`); each run records it as diff --git a/scripts/matrix/results.py b/scripts/matrix/results.py index 06ac4f159..131a48205 100644 --- a/scripts/matrix/results.py +++ b/scripts/matrix/results.py @@ -644,16 +644,23 @@ def past_limit(leg_id, row, gpu=False): #: store, so no row before them moves their times. HARNESS_CREATES = "create_" #: A creation row's first samples (`/first`, `/first_take`, `/next_take`, -#: `/first_allocation_total`) are one sample per process, so harness_budget judges each by the -#: median of FIRST_RUNS processes per runtime: the first process's own record and the later -#: processes' `harness-first///`. A first sample alone is never past its limit. +#: `/first_allocation_total`, `/device_first`) are one sample per process, so harness_budget judges +#: each by the median of FIRST_RUNS processes per runtime: the first process's own record and the +#: later processes' `harness-first///`. A first sample alone is never past its +#: limit. FIRST_RUNS = 5 HARNESS_FIRST = "harness-first/" #: A compute creation row's `/first` sample is its creation and one dispatch through to completion, #: as Metal compiles at the creation and a runtime may compile at the dispatch instead (the old -#: runtime does); its `/first_call` sample, the creation call alone, is shown beside it with the -#: ratio of its medians, and never judged. -SHOWN_FIRST = "/first_call" +#: runtime does). A creation row's first sample is a fresh object's on a device that has made one of +#: its kind: the harness makes a warm-up of the row's kind first. The first samples SHOWN_FIRST +#: names are shown with the ratio of their medians, and never judged, each for its reason: the +#: creation call alone (`/first_call`), and the warm-up (`/device_first`), which holds what the +#: device pays once, which a guest that keeps its device pays once in its life. +SHOWN_FIRST = { + "/first_call": "the creation call alone, which old returns from before it makes its pipeline", + "/device_first": "the warm-up, the first object of its kind on the device", +} #: The sed program the first creation process's output goes through: its device's gauges at drop #: become `harness-/creates/device/...`, apart from the other rows' process's, so each #: key is recorded once. @@ -796,13 +803,13 @@ def harness_budget(leg_id, leg): gated, named = instruction_gate(leg_id, row, records) problems += gated parked += named - if first_row(row) and row.endswith(SHOWN_FIRST): + shown = next((why for end, why in SHOWN_FIRST.items() if row.endswith(end)), None) + if first_row(row) and shown: samples = first_samples(times, row) if samples is not None: old, new = (statistics.median(values) for values in samples) parked.append(f"harness budget {row}: median of {FIRST_RUNS} processes, new {new:.1f} us " - f"over old {old:.1f} us is {new / old:.3f}: shown, not judged: the creation " - "call alone, which old returns from before it makes its pipeline") + f"over old {old:.1f} us is {new / old:.3f}: shown, not judged: {shown}") continue if first_row(row): samples = first_samples(times, row) diff --git a/scripts/matrix/test_results.py b/scripts/matrix/test_results.py index 07652c35d..1cdfad887 100644 --- a/scripts/matrix/test_results.py +++ b/scripts/matrix/test_results.py @@ -523,6 +523,22 @@ class HarnessBudgetTests(unittest.TestCase): one = {f"harness-old/{row}": 1000.0, f"harness-new/{row}": 5000.0} self.assertEqual(self.budget("a", one), ([], [])) + def test_a_warm_up_is_shown_beside_the_first_it_comes_before_and_never_judged(self): + row = "create_private_16MiB/device_first" + times = {f"harness-old/{row}": 1000.0, f"harness-new/{row}": 3000.0} + for n in range(2, results.FIRST_RUNS + 1): + times[f"{results.HARNESS_FIRST}{row}/{n}/old"] = 1000.0 + n + times[f"{results.HARNESS_FIRST}{row}/{n}/new"] = 3000.0 + n + with mock.patch.object(results, "HARNESS_CEILINGS", {}): + self.assertEqual(self.budget("a", times), ([], [ + f"harness budget {row}: median of 5 processes, new 3003.0 us over old 1003.0 us is 2.994: " + "shown, not judged: the warm-up, the first object of its kind on the device"])) + # The first it comes before is judged. + first = {key.replace("/device_first", "/first_take"): us for key, us in times.items()} + self.assertEqual(self.budget("a", first), ([ + "harness budget create_private_16MiB/first_take: median of 5 processes, new 3003.0 us over " + "old 1003.0 us is 2.994, past 1.03"], [])) + def test_the_creation_processes_record_each_key_once_beside_the_other_rows(self): others = ["M2V-MATRIX time harness-new/alu 10.000", "M2V-MATRIX gauge harness-new/device/blocks@drop 0"] creates = ["M2V-MATRIX time harness-new/create_64MiB 700.000",