harness: a compute state row's first dispatches 64x1x1, the streams' commonest size; one thread beside it

The create_state row's first dispatched one thread (1x1x1), a size of few dispatches: 3.9% of the
compute dispatches in the discrete replay recordings (from 3 to 5 kernels) and at most 0.5% in the
unified ones, by identity's census of every stream's threadsPerThreadgroup. A runtime that
compiles its pipeline for the dispatch's size (the old runtime) compiled the first at 1x1x1, where
a program's first dispatch runs at its own size. The first now dispatches one threadgroup of
FIRST_THREADGROUP, 64x1x1: the commonest size over the five streams of record, 24.1% of their
compute dispatches (41.7% of the unified recordings', 7.1% of the discrete ones', where 128x1x1
leads with 39.3%; 128x1x1 is 23.3% overall). Each thread's 16 bytes are checked.

Today's form stays beside it, shown and never judged: another content's first (the kernel with
other constants) dispatched as one thread, create_state/first_one_thread
(CreateReport::one_thread_first_us; results.SHOWN_FIRST). The name has no digits so the matrix's
FIRST_KEEP keeps it from every creation process, which a results test holds. The warm-up stays at
one thread. docs/VALIDATION.md and the crate doc say it; the authored device test asserts the
compute row has the one-thread first.
This commit is contained in:
Anees Iqbal committed 2026-11-18 16:27:00 -08:00
1 parent c1bd2d46d6
commit ca92b2aa9e
8 files changed
+152 -62

No files matched your search

+13 -1
View File
@@ -198,10 +198,15 @@ pub enum Makes {
/// Compute pipeline states of one content: `function` of the authored library with the
/// `float` function constants `constants` (index, value), values no other workload gives it,
/// so the first creation is of a content the device has not seen and each later one of a
/// content it has. [`STATE_CREATIONS`] are timed, whatever `--runs` says.
/// content it has. The first's dispatch is one threadgroup of [`FIRST_THREADGROUP`]. Beside
/// it, shown and never judged, the first of another content, `function` with `one_thread`'s
/// constants, dispatched as one thread
/// ([`CreateReport::one_thread_first_us`](crate::run::CreateReport::one_thread_first_us)).
/// [`STATE_CREATIONS`] are timed, whatever `--runs` says.
States {
function: &'static str,
constants: &'static [(u32, f32)],
one_thread: &'static [(u32, f32)],
},
/// Render pipeline states of one content: the vertex function `vertex` and the fragment
/// function `fragment` of the render library ([`render_library_air`]), drawing into one colour
@@ -227,6 +232,12 @@ pub const WARM_KERNEL: &str = "lcg_step";
/// vertex function and attachment: another of the render library's.
pub const WARM_FRAGMENT: &str = "sampled_fragment";
/// The threadgroup of a compute pipeline state row's first dispatch: 64 by 1 by 1, the commonest
/// threadgroup size of the replay streams' compute dispatches (24% of them: 42% of those recorded
/// on a unified-memory device, 7% of those on a discrete one, where 128 by 1 by 1 leads with 39%).
/// A runtime that compiles its pipeline for the dispatch's size compiles it at this one.
pub const FIRST_THREADGROUP: [u32; 3] = [64, 1, 1];
/// The timed creations of a pipeline-state workload.
pub const STATE_CREATIONS: u32 = 1000;
@@ -253,6 +264,7 @@ pub const CREATES: [Create; 6] = [
makes: Makes::States {
function: "signed_zero_products",
constants: &[(0, 2.0), (1, -2.0)],
one_thread: &[(0, 3.0), (1, -3.0)],
},
},
Create {
+18 -3
View File
@@ -31,7 +31,7 @@
//! themselves. The command exits 0 when every workload matched or was refused, 1 when one did
//! not match or failed, and 2 when it could not start.
use metal2vulkan_harness::authored::{Create, Makes};
use metal2vulkan_harness::authored::{Create, Makes, FIRST_THREADGROUP};
use metal2vulkan_harness::plan::Plan;
use metal2vulkan_harness::run::{
commit_to_complete, count_instructions, matrix_time, percentile, run_each, steady,
@@ -464,11 +464,16 @@ fn gauges(gauges: &[(u32, Vec<(&'static str, u64)>)]) -> String {
}
}
/// A threadgroup size as `64x1x1`.
fn size([width, height, depth]: [u32; 3]) -> String {
format!("{width}x{height}x{depth}")
}
/// `report`'s row, and its matrix lines.
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(),
@@ -490,7 +495,8 @@ fn print_create(runtime: &str, create: &Create, report: &CreateReport, store: &s
format!("; first {us:.1} us, its creation alone; store {store}")
}
(Some(us), Some(create), _, _) => format!(
"; first {us:.1} us with one dispatch, its creation {create:.1} us; store {store}"
"; first {us:.1} us with one dispatch of {}, its creation {create:.1} us; store {store}",
size(FIRST_THREADGROUP)
),
(None, Some(first), Some(again), _) => {
format!("; first take {first:.1} us, the next {again:.1} us")
@@ -500,6 +506,9 @@ fn print_create(runtime: &str, create: &Create, report: &CreateReport, store: &s
report
.device_first_us
.map_or(String::new(), |us| format!("; its warm-up {us:.1} us")),
report.one_thread_first_us.map_or(String::new(), |us| format!(
"; another content's first with one dispatch of 1x1x1 {us:.1} us"
)),
);
if let Some(waits) = report.first_allocations {
println!(
@@ -546,6 +555,12 @@ fn print_create(runtime: &str, create: &Create, report: &CreateReport, store: &s
create.name
);
}
if let Some(us) = report.one_thread_first_us {
println!(
"M2V-MATRIX time harness-{runtime}/{}/first_one_thread {us:.3}",
create.name
);
}
if let (None, Some(first), Some(again)) =
(report.first_us, report.first_create_us, report.again_us)
{
+5 -3
View File
@@ -39,9 +39,11 @@
//! (`create_private_16MiB`: the runtime's zeroing of the buffer lands in that time, wherever it
//! does it); and compute pipeline states of
//! one content (`create_state`), the first of a content the device has not seen timed apart
//! with one dispatch of it through to completion (`first`: a runtime may compile its pipeline in
//! the creation or at the first dispatch, and the sum holds both; the row also shows the creation
//! alone), then 1,000 of a content it has, each made and released in turn; and render pipeline
//! with one dispatch of it through to completion, one threadgroup of
//! [`authored::FIRST_THREADGROUP`] (`first`: a runtime may compile its pipeline in the creation
//! or at the first dispatch, and the sum holds both; the row also shows the creation alone, and
//! another content's first dispatched as one thread), 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). Each row's first is a fresh object's on a device that has gone that
+86 -48
View File
@@ -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, WARM_FRAGMENT, WARM_KERNEL};
use crate::authored::{Makes, FIRST_THREADGROUP, STATE_CREATIONS, WARM_FRAGMENT, WARM_KERNEL};
use crate::plan::{
Binding, Blit, BufferPlan, Constant, Grid, Plan, SamplerPlan, Scaled, Source, TexturePlan,
TextureSource,
@@ -520,10 +520,10 @@ pub struct CreateReport {
pub create_us: Vec<f64>,
/// The first creation's wall time, in microseconds, where it is timed apart: a pipeline
/// state's of a content the device had not seen. A compute pipeline state's holds one
/// dispatch of it through to completion, since a runtime may pay its pipeline's compile in the
/// creation or at the first dispatch and the sum holds both, and the creation of the 16-byte
/// buffer the dispatch writes, the guest's take of memory beside it; a render pipeline state's
/// is its creation alone.
/// dispatch of it through to completion, one threadgroup of [`FIRST_THREADGROUP`], since a
/// runtime may pay its pipeline's compile in the creation or at the first dispatch and the sum
/// holds both, and the creation of the buffer the dispatch writes (16 bytes a thread), the
/// guest's take of memory beside it; a render pipeline state's is its creation alone.
pub first_us: Option<f64>,
/// 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
@@ -536,6 +536,11 @@ pub struct CreateReport {
/// [`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<f64>,
/// For a compute pipeline state, the first of another content the device has not seen,
/// timed as [`first_us`](Self::first_us) is but with its dispatch one thread, after the
/// first, in microseconds: shown beside the first, whose dispatch is a threadgroup of
/// [`FIRST_THREADGROUP`].
pub one_thread_first_us: Option<f64>,
/// 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<f64>,
@@ -1224,7 +1229,8 @@ impl<D: ComputeDevice> Session for Harness<D> {
Makes::States {
function,
constants,
} => self.create_states(function, constants, runs),
one_thread,
} => self.create_states(function, constants, one_thread, runs),
Makes::RenderStates {
vertex,
fragment,
@@ -1345,48 +1351,50 @@ impl<D: ComputeDevice> Harness<D> {
/// [`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; 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`]).
/// seen, is timed with one dispatch of it through to completion, one threadgroup of
/// [`FIRST_THREADGROUP`], its output checked; the warm-up ahead of it is a state of
/// [`WARM_KERNEL`] made and dispatched as one thread, kept until the first is done
/// ([`CreateReport::device_first_us`]). After it, the first of another content, `function`
/// with the constants `one_thread`, dispatched as one thread
/// ([`CreateReport::one_thread_first_us`]).
fn create_states(
&self,
function: &str,
constants: &[(u32, f32)],
one_thread: &[(u32, f32)],
runs: Runs,
) -> Result<CreateReport> {
let values: Vec<Constant> = (constants.iter())
.map(|&(index, value)| Constant {
index,
// `MTLDataTypeFloat`.
data_type: 3,
value: value.to_le_bytes().to_vec(),
})
.collect();
let function = self.authored.new_function(function, &values)?;
let of = |constants: &[(u32, f32)]| {
let values: Vec<Constant> = (constants.iter())
.map(|&(index, value)| Constant {
index,
// `MTLDataTypeFloat`.
data_type: 3,
value: value.to_le_bytes().to_vec(),
})
.collect();
self.authored.new_function(function, &values)
};
let (main, other) = (of(constants)?, of(one_thread)?);
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 (_, device_first, warm) = self.first_state(&warm, [1, 1, 1], |_| [1, 0, 0, 0])?;
let before = self.device.allocations();
let (first_create, first, _) = self.first_state(&function, want)?;
let (first_create, first, _) = self.first_state(&main, FIRST_THREADGROUP, |thread| {
products(constants, thread)
})?;
let allocations = since(before, self.device.allocations());
drop(warm);
let (_, one_thread_first, _) =
self.first_state(&other, [1, 1, 1], |thread| products(one_thread, thread))?;
let mut report = self.time_states(
|| self.device.new_compute_pipeline_state(&function, &[]),
|| self.device.new_compute_pipeline_state(&main, &[]),
first,
runs,
)?;
report.device_first_us = Some(device_first);
report.first_create_us = Some(first_create);
report.one_thread_first_us = Some(one_thread_first);
report.first_allocations = allocations;
Ok(report)
}
@@ -1421,17 +1429,23 @@ impl<D: ComputeDevice> Harness<D> {
Ok(report)
}
/// 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.
/// A first state of `function`, a kernel whose thread at grid position `i` writes up to 16
/// bytes at byte `16 * i` of buffer 0 and reads a `uint` at buffer 1, made, then dispatched
/// once, one threadgroup of `size` (one row: `size[1]` and `size[2]` are 1) with 1 at buffer
/// 1, through to completion: the creation's wall time and the whole's, in microseconds, and
/// the state. Each thread's 16 bytes are checked against `want` of its index, four
/// little-endian words.
fn first_state(
&self,
function: &D::Function,
want: [u32; 4],
size: [u32; 3],
want: impl Fn(u32) -> [u32; 4],
) -> Result<(f64, f64, D::ComputePipelineState)> {
let threads = size[0];
let started = Instant::now();
let destination = self.device.new_buffer(16, Storage::Shared)?;
let destination = self
.device
.new_buffer(16 * u64::from(threads), Storage::Shared)?;
let creating = Instant::now();
let state = self.device.new_compute_pipeline_state(function, &[])?;
let made = creating.elapsed();
@@ -1440,7 +1454,7 @@ impl<D: ComputeDevice> Harness<D> {
encoder.set_compute_pipeline_state(&state)?;
encoder.set_buffer(&destination, 0, 0)?;
encoder.set_bytes(&1u32.to_le_bytes(), 1)?;
encoder.dispatch_threadgroups([1, 1, 1], [1, 1, 1])?;
encoder.dispatch_threadgroups([1, 1, 1], size)?;
encoder.end_encoding()?;
command_buffer.commit()?;
command_buffer.wait_until_completed()?;
@@ -1448,21 +1462,45 @@ impl<D: ComputeDevice> Harness<D> {
let contents = destination
.contents()
.ok_or("the first state's destination has no contents")?;
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 = u32::from_le_bytes(bytes);
}
if got != want {
return Err(
format!("the first state's dispatch wrote {got:#x?}, not {want:#x?}").into(),
);
for thread in 0..threads {
let mut got = [0u32; 4];
for (at, value) in got.iter_mut().enumerate() {
let byte = 16 * thread as usize + 4 * at;
// SAFETY: the buffer holds 16 bytes a thread and its command buffer has completed.
let bytes = unsafe { contents.as_ptr().add(byte).cast::<[u8; 4]>().read() };
*value = u32::from_le_bytes(bytes);
}
let want = want(thread);
if got != want {
return Err(format!(
"the first state's dispatch wrote {got:#x?} at thread {thread}, not {want:#x?}"
)
.into());
}
}
Ok((made.as_secs_f64() * 1e6, whole.as_secs_f64() * 1e6, state))
}
}
/// What `signed_zero_products` with the `float` constants `constants` writes for thread
/// `thread`, one round: its start (`thread & 63`, `-((thread >> 6) & 63)`, 0.5, -0.25) after the
/// FMA step, plus the products' difference of the start, `a * positive - a * negative`, as four
/// little-endian words.
fn products(constants: &[(u32, f32)], thread: u32) -> [u32; 4] {
let factor = |index| {
(constants.iter())
.find(|&&(at, _)| at == index)
.map_or(0.0, |&(_, value)| value)
};
let start = [
(thread & 63) as f32,
-(((thread >> 6) & 63) as f32),
0.5,
-0.25,
];
start.map(|a| (a.mul_add(0.96875, 0.03125) + (0.0 + a * factor(0) - a * factor(1))).to_bits())
}
/// The allocations between two reads of [`Device::allocations`]: their count and time, and
/// the longest since the device was made.
fn since(before: Option<Waits>, after: Option<Waits>) -> Option<Waits> {
@@ -52,6 +52,8 @@ fn every_workload(session: &mut dyn Session) {
let timed = authored::STATE_CREATIONS as usize;
assert_eq!(report.create_us.len(), timed, "{name}");
assert!(report.first_us.is_some(), "{name}");
let compute = matches!(create.makes, authored::Makes::States { .. });
assert_eq!(report.one_thread_first_us.is_some(), compute, "{name}");
// The first state's timed work holds its VkPipeline's compile on either runtime:
// in the creation, or at its one dispatch. (The warm-up's kernel is one the
// authored workloads made already here.)
+8 -5
View File
@@ -390,8 +390,8 @@ Both runs skip the creation rows (the harness's `--skip 'create_*'`): those run
on a fresh empty cache directory and store, so no row before them moves their times: a
creation's first sample on the new runtime is cold, and the old runtime's follows it on the same
cache. The first process's records are kept whole, its devices' gauges at drop as `harness-<runtime>/creates/device/...`; of each later process, only the
creation rows' first samples (`<row>/first`, `/first_call`, `/first_take`, `/next_take`,
`/first_allocation_total`, `/device_first`, one sample per process), as
creation rows' first samples (`<row>/first`, `/first_call`, `/first_one_thread`, `/first_take`,
`/next_take`, `/first_allocation_total`, `/device_first`, one sample per process), as
`harness-first/<row>/<n>/<runtime>`,
parked for the `time` rule.
@@ -440,9 +440,12 @@ within that is named on the leg's line. A fix lowers its row's ceiling to the ra
and a row within 1.03 leaves the list. A creation row's first sample is judged by the ratio of
the medians of its five processes, the new runtime's over the old's; a first sample alone is
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. Each creation row's first sample
through to completion, one threadgroup of 64 by 1 by 1, the replay streams' commonest compute
dispatch size (24% of their dispatches), since Metal compiles at the creation and a runtime may
compile at the first dispatch instead, for the dispatch's size, 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, and so is `/first_one_thread`, another content's first dispatched as one thread,
a size of few dispatches (under 4% of them). 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
+5 -2
View File
@@ -611,11 +611,14 @@ HARNESS_FIRST = "harness-first/"
#: 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.
#: creation call alone (`/first_call`), the warm-up (`/device_first`), which holds what the
#: device pays once, which a guest that keeps its device pays once in its life, and a compute
#: state's first dispatched as one thread (`/first_one_thread`), beside the judged first, whose
#: dispatch is a threadgroup of the replay streams' commonest size.
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",
"/first_one_thread": "a first dispatched as one thread, a size of few dispatches",
}
#: The sed program the first creation process's output goes through: its devices' gauges at drop
#: become `harness-<runtime>/creates/device/...`, apart from the other rows' process's, so each
+15
View File
@@ -495,6 +495,21 @@ class HarnessBudgetTests(unittest.TestCase):
"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_a_first_at_one_thread_is_kept_from_every_process_shown_and_never_judged(self):
row = "create_state/first_one_thread"
keep = results.FIRST_KEEP.replace("$runtime", "new").replace("$n", "2")
run = subprocess.run(["sed", "-n", keep], input=f"M2V-MATRIX time harness-new/{row} 3000.000\n",
capture_output=True, text=True, check=True)
self.assertEqual(run.stdout.splitlines(), [f"M2V-MATRIX time {results.HARNESS_FIRST}{row}/2/new 3000.000"])
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: a first dispatched as one thread, a size of few dispatches"]))
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",