harness and matrix: record the whole process's instructions per run and gate the frame and burst rows on them
The harness now counts each timed run's user-space instructions across the whole process. The counts repeat run to run where the times do not: rt's p50 spread across processes was 0.16 to 0.27%. The matrix gates the frame and burst rows (WALL_ROWS) on those counts, beside the host-time judgement and floors they keep under the GPU-p50 rule. devtools: ProcessInstructions opens one user-space instructions counter per core type with inherit set, so every thread started after it opens counts: the runtimes' and the drivers' threads too. The harness opens it first thing in main, before any device starts a thread, and each timed run records the counted delta. A node that refuses perf_event_open, and every non-Linux host, records none. harness: each row whose runs were not sized prints `M2V-MATRIX instructions harness-<runtime>/<row>/per_run <p50>`. matrix: a frame or burst row with a count on both runtimes passes the instructions gate as well as its time's limit: - it fails when rt's count is over old's; - it fails when rt's count is past 1.03 times the stored count in scripts/matrix/instructions.tsv (one column per driver family, `all` where the legs agree within 3%); - it is named when its count is more than 1% under the stored count, which then ratchets down; - it is named when no count is stored, and is then gated against old alone. The single-kernel rows stay judged on their GPU p50 as before, and every row's count is shown beside its times. The old runtime's harness counts are parked from the per-record instructions-versus-base check, like its times. instructions.tsv starts empty: a matrix run's counts seed it. VALIDATION.md describes the time rules and the gate in one paragraph. Verified: scripts/matrix tests (python3 -m unittest discover, 45 OK) on this Mac, over this rule and the GPU-p50 rule together. Before the rebase, check m3-max-45591 on msi (at c597bb3603) passed clippy x4, nextest for devtools, harness and rt (118 passed, with the process counter's test), and the release harness build. Count job m3-max-45641 on the 2080's node recorded the per_run count of every row on both runtimes except long_4cb, which is sized.
This commit is contained in:
1 parent
b2e33dba6d
commit
d2e5edbd60
8 files changed
+314
-26
No files matched your search
@@ -13,9 +13,13 @@
|
||||
//! 0 of one that stayed on its efficiency cores). So where the kernel lists such units, the
|
||||
//! counter opens the event on each and sums them.
|
||||
//!
|
||||
//! [`ProcessInstructions`] counts the whole process in user space: the thread that opens it and
|
||||
//! every thread started after, through one inherited counter per core type. That is what the
|
||||
//! harness records per timed run, so work a runtime moves onto its own threads still counts.
|
||||
//!
|
||||
//! Only Linux offers the counters (read here on its little-endian targets): elsewhere
|
||||
//! [`InstructionCounter::new`] answers [`io::ErrorKind::Unsupported`], and a test records no
|
||||
//! `instructions` line there.
|
||||
//! [`InstructionCounter::new`] and [`ProcessInstructions::new`] answer
|
||||
//! [`io::ErrorKind::Unsupported`], and nothing records an `instructions` line there.
|
||||
|
||||
use std::io;
|
||||
use std::marker::PhantomData;
|
||||
@@ -87,6 +91,59 @@ impl InstructionCounter {
|
||||
}
|
||||
}
|
||||
|
||||
/// User-space instructions retired by the whole process since [`ProcessInstructions::new`]: the
|
||||
/// thread that opened it and every thread started after it, summed over every core type.
|
||||
///
|
||||
/// A thread started before the open does not count, so a program opens it before it starts its
|
||||
/// threads (a device's, its driver's). Two [`ProcessInstructions::read`]s bracket a span of work
|
||||
/// in the whole process, whichever thread did it.
|
||||
pub struct ProcessInstructions {
|
||||
#[cfg(all(target_os = "linux", target_endian = "little"))]
|
||||
events: Vec<std::fs::File>,
|
||||
#[cfg(not(all(target_os = "linux", target_endian = "little")))]
|
||||
never: std::convert::Infallible,
|
||||
}
|
||||
|
||||
impl ProcessInstructions {
|
||||
/// Opens the counters, counting from now. An error is the kernel's refusal (for one,
|
||||
/// `perf_event_paranoid` above 2, or no hardware counters in a virtual machine), or
|
||||
/// [`io::ErrorKind::Unsupported`] off Linux.
|
||||
pub fn new() -> io::Result<Self> {
|
||||
#[cfg(all(target_os = "linux", target_endian = "little"))]
|
||||
{
|
||||
let events = linux::core_events()?
|
||||
.into_iter()
|
||||
.map(linux::open_inherited)
|
||||
.collect::<io::Result<Vec<_>>>()?;
|
||||
Ok(Self { events })
|
||||
}
|
||||
#[cfg(not(all(target_os = "linux", target_endian = "little")))]
|
||||
{
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Unsupported,
|
||||
"user-space instruction counters are read through Linux's perf_event_open alone",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
/// The user-space instructions the process retired since the open: its threads still running
|
||||
/// and those that ended.
|
||||
pub fn read(&self) -> io::Result<u64> {
|
||||
#[cfg(all(target_os = "linux", target_endian = "little"))]
|
||||
{
|
||||
let mut retired = 0;
|
||||
for event in &self.events {
|
||||
retired += linux::read(event)?;
|
||||
}
|
||||
Ok(retired)
|
||||
}
|
||||
#[cfg(not(all(target_os = "linux", target_endian = "little")))]
|
||||
{
|
||||
match self.never {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(all(target_os = "linux", target_endian = "little"))]
|
||||
mod linux {
|
||||
use std::fs::{self, File};
|
||||
@@ -96,9 +153,10 @@ mod linux {
|
||||
/// `PERF_TYPE_HARDWARE` and its `PERF_COUNT_HW_INSTRUCTIONS`.
|
||||
const TYPE_HARDWARE: u32 = 0;
|
||||
const HW_INSTRUCTIONS: u64 = 1;
|
||||
/// `perf_event_attr`'s bit fields `disabled`, `exclude_kernel` and `exclude_hv`, in a
|
||||
/// little-endian target's bit order.
|
||||
/// `perf_event_attr`'s bit fields `disabled`, `inherit`, `exclude_kernel` and `exclude_hv`, in
|
||||
/// a little-endian target's bit order.
|
||||
const DISABLED: u64 = 1 << 0;
|
||||
const INHERIT: u64 = 1 << 1;
|
||||
const EXCLUDE_KERNEL: u64 = 1 << 5;
|
||||
const EXCLUDE_HV: u64 = 1 << 6;
|
||||
/// `PERF_FLAG_FD_CLOEXEC`: the descriptor does not pass to a child the test starts.
|
||||
@@ -147,13 +205,23 @@ mod linux {
|
||||
|
||||
/// The calling thread's user-space instructions event of `config`, disabled until enabled.
|
||||
pub(super) fn open(config: u64) -> io::Result<File> {
|
||||
open_with(config, DISABLED | EXCLUDE_KERNEL | EXCLUDE_HV)
|
||||
}
|
||||
|
||||
/// The user-space instructions event of `config` of the calling thread and every thread it
|
||||
/// starts after, counting from now.
|
||||
pub(super) fn open_inherited(config: u64) -> io::Result<File> {
|
||||
open_with(config, INHERIT | EXCLUDE_KERNEL | EXCLUDE_HV)
|
||||
}
|
||||
|
||||
/// The calling thread's user-space instructions event of `config` with the bit fields `flags`.
|
||||
fn open_with(config: u64, flags: u64) -> io::Result<File> {
|
||||
let mut attr = [0u8; ATTR_SIZE];
|
||||
attr[ATTR_TYPE..ATTR_TYPE + 4].copy_from_slice(&TYPE_HARDWARE.to_ne_bytes());
|
||||
attr[ATTR_SIZE_FIELD..ATTR_SIZE_FIELD + 4]
|
||||
.copy_from_slice(&(ATTR_SIZE as u32).to_ne_bytes());
|
||||
attr[ATTR_CONFIG..ATTR_CONFIG + 8].copy_from_slice(&config.to_ne_bytes());
|
||||
attr[ATTR_FLAGS..ATTR_FLAGS + 8]
|
||||
.copy_from_slice(&(DISABLED | EXCLUDE_KERNEL | EXCLUDE_HV).to_ne_bytes());
|
||||
attr[ATTR_FLAGS..ATTR_FLAGS + 8].copy_from_slice(&flags.to_ne_bytes());
|
||||
let (thread, any_cpu, no_group): (libc::pid_t, libc::c_int, libc::c_int) = (0, -1, -1);
|
||||
// SAFETY: `attr` is a valid `perf_event_attr` of the size it states and outlives the
|
||||
// call; pid 0 and cpu -1 name the calling thread on any CPU, with no group.
|
||||
@@ -195,7 +263,7 @@ mod linux {
|
||||
|
||||
#[cfg(all(test, target_os = "linux", target_arch = "x86_64"))]
|
||||
mod tests {
|
||||
use super::InstructionCounter;
|
||||
use super::{InstructionCounter, ProcessInstructions};
|
||||
use std::path::Path;
|
||||
|
||||
/// Iterations of the fixed loop on each CPU.
|
||||
@@ -313,4 +381,34 @@ mod tests {
|
||||
counts[0] * 1000 / (ITERATIONS * cpus.len() as u64)
|
||||
);
|
||||
}
|
||||
|
||||
/// The process counter counts a thread started after it opened: the fixed loop on every CPU
|
||||
/// that thread may use, on a thread of its own, is in the count once the thread ended.
|
||||
#[test]
|
||||
fn the_process_counter_counts_a_thread_started_after_it_opened() {
|
||||
if !counters_offered() {
|
||||
assert!(
|
||||
ProcessInstructions::new().is_err(),
|
||||
"the host offers no counters, yet a counter opened"
|
||||
);
|
||||
return;
|
||||
}
|
||||
let process = ProcessInstructions::new().expect("the host offers counters");
|
||||
let cpus = allowed_cpus();
|
||||
let expected = 2 * ITERATIONS * cpus.len() as u64;
|
||||
let before = process.read().expect("reading the counters");
|
||||
let worker = std::thread::spawn(move || {
|
||||
for &cpu in &cpus {
|
||||
pin(&[cpu]);
|
||||
fixed_loop(ITERATIONS);
|
||||
}
|
||||
});
|
||||
worker.join().expect("the loop's thread");
|
||||
let counted = process.read().expect("reading the counters") - before;
|
||||
// Starting and ending the thread and the pinning add their own instructions.
|
||||
assert!(
|
||||
(expected..expected + expected / 20).contains(&counted),
|
||||
"{counted} user-space instructions counted for {expected}"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -60,6 +60,8 @@ const USAGE: &str = "usage: harness --runtime old|new[,old|new...] [--runs N] [-
|
||||
[--store DIRECTORY] [--workloads DIRECTORY --description FILE]";
|
||||
|
||||
fn main() -> ExitCode {
|
||||
// Before any device starts its threads, so that theirs count too.
|
||||
run::count_instructions();
|
||||
match parse(std::env::args().skip(1)).and_then(|args| run_all(&args)) {
|
||||
Ok(true) => ExitCode::SUCCESS,
|
||||
Ok(false) => ExitCode::FAILURE,
|
||||
@@ -632,6 +634,13 @@ fn print(runtime: &str, name: &str, report: &Report) {
|
||||
for (count, value) in &report.counts {
|
||||
println!("M2V-MATRIX metric harness-{runtime}/{name}/{count}_per_run {value}");
|
||||
}
|
||||
// The whole process's user-space instructions per timed run at the 50th percentile, where the
|
||||
// kernel offered the counter; none for a row the device sizes, whose work follows the size.
|
||||
let mut instructions = report.instructions.clone();
|
||||
instructions.sort_unstable();
|
||||
if let (Some(&p50), None) = (instructions.get(instructions.len() / 2), report.scaled_to) {
|
||||
println!("M2V-MATRIX instructions harness-{runtime}/{name}/per_run {p50}");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -10,12 +10,29 @@ use crate::{
|
||||
ComputeDevice, Device, Failed, Library, Refused, RenderCommandEncoder, Result, Storage,
|
||||
Texture, Waits,
|
||||
};
|
||||
use metal2vulkan_devtools::instructions::ProcessInstructions;
|
||||
use std::collections::HashMap;
|
||||
use std::ops::Range;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::{Arc, Condvar, Mutex, PoisonError};
|
||||
use std::sync::{Arc, Condvar, Mutex, OnceLock, PoisonError};
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
/// The whole process's user-space instruction counter, once [`count_instructions`] opened it;
|
||||
/// None where the kernel refused it (`perf_event_paranoid` above 2, no hardware counters, or not
|
||||
/// Linux), and then the harness records no instructions.
|
||||
static INSTRUCTIONS: OnceLock<Option<ProcessInstructions>> = OnceLock::new();
|
||||
|
||||
/// Opens the process's instruction counter. The harness calls it before it makes any device, so
|
||||
/// that the threads a runtime and its driver start count on it.
|
||||
pub fn count_instructions() {
|
||||
INSTRUCTIONS.get_or_init(|| ProcessInstructions::new().ok());
|
||||
}
|
||||
|
||||
/// The process's user-space instructions so far, where its counter is open.
|
||||
fn instructions() -> Option<u64> {
|
||||
INSTRUCTIONS.get()?.as_ref()?.read().ok()
|
||||
}
|
||||
|
||||
/// The kernel of the authored library that moves bytes for the harness, 16 a thread.
|
||||
const COPY_FUNCTION: &str = "copy_words";
|
||||
|
||||
@@ -170,6 +187,10 @@ pub struct Report {
|
||||
/// Each run's process CPU time from before its command buffer's creation through the return
|
||||
/// of the wait for the run before it, in nanoseconds; empty where the host has no such clock.
|
||||
pub cpu_ns: Vec<f64>,
|
||||
/// Each run's user-space instructions in the whole process over the same span, every thread
|
||||
/// of the runtime and its driver included ([`count_instructions`]); empty where the kernel
|
||||
/// refused the counter.
|
||||
pub instructions: Vec<u64>,
|
||||
/// Each timed command buffer's time from just before its `commit` until its completed
|
||||
/// handler ran, in microseconds, by its place in its run: one list per place, the first
|
||||
/// committed first, each in the order the handlers ran. Empty unless the plan asks for it
|
||||
@@ -994,10 +1015,14 @@ impl<D: ComputeDevice> Session for Harness<D> {
|
||||
for run in 1..=runs.timed {
|
||||
let wall = Instant::now();
|
||||
let cpu = clocks::process_cpu_nanos();
|
||||
let retired = instructions();
|
||||
let (gpu_us, encoded) = self.next(plan, &made, &mut in_flight, completions.as_ref())?;
|
||||
if let (Some(before), Some(after)) = (cpu, clocks::process_cpu_nanos()) {
|
||||
report.cpu_ns.push(after.saturating_sub(before) as f64);
|
||||
}
|
||||
if let (Some(before), Some(after)) = (retired, instructions()) {
|
||||
report.instructions.push(after.saturating_sub(before));
|
||||
}
|
||||
report.wall_us.push(wall.elapsed().as_secs_f64() * 1e6);
|
||||
report.encode_ns.push(encoded.as_nanos() as f64);
|
||||
report.gpu_us.push(gpu_us);
|
||||
|
||||
+18
-5
@@ -303,7 +303,7 @@ changes the harness sets the base for the next.
|
||||
| Kind | What it counts | Fails when |
|
||||
|---|---|---|
|
||||
| `metric` | A deterministic count per frame or per command buffer: submissions, passes, barriers, bytes copied, pipelines created | It is larger than the base's |
|
||||
| `instructions` | User-space CPU instructions per draw or per dispatch | It is more than 1% over the base's |
|
||||
| `instructions` | User-space CPU instructions per draw or per dispatch, and per harness run (`harness-<runtime>/<row>/per_run`: the whole process's, every runtime and driver thread counted, the p50 over the row's timed runs) | It is more than 1% over the base's (the old runtime's are parked) |
|
||||
| `gauge` | Live objects of one resource kind, the key ending in the point it was read at: `@100` and `@200` (loop iterations), `@drop` (after the device dropped) | `@drop` is not 0, or `@200` differs from `@100`; for the memory pool's `blocks`, which frees allocations an earlier workload left idle once the most bytes in use over its window falls and the device is quiet for 20 ms, only `@200` over `@100` |
|
||||
| `time` | A duration in microseconds: what a program waits on in a harness workload's run, timed on the host: its last command buffer's commit-to-complete time where the workload times it (the others' lateness is a column of the harness's table and no record), else the host wall time a run adds (a run's GPU time is a record of its own, `harness-gpu-<runtime>/<row>`, parked here and judged by the harness budget) | Only as a cross-GPU outlier: its ratio to the base's is more than 1.25 times the median of that ratio over at least 3 GPUs |
|
||||
| `size` | The size a harness row whose size follows the device ran at (`long_4cb`) | The leg's two runtimes ran the row at different sizes: its times are then not compared (the harness budget) |
|
||||
@@ -349,7 +349,16 @@ instead, against the floor of the old runtime's GPU time from the same runs
|
||||
a few percent where its host time spreads up to 1.3 (the XTX's `simd_reduce`: GPU p50 36.96-37.12
|
||||
µs over 8 runs, host time 44.9-55.8 µs). The frame and burst rows (`WALL_ROWS` in
|
||||
`scripts/matrix/results.py`), whose GPU time spans the gaps between their command buffers and
|
||||
spreads as widely, stay on their times and the instructions gate. A row whose GPU time varies on
|
||||
spreads as widely, stay on their times and floors, and where both runtimes counted them (Linux,
|
||||
a node that grants the counter), each must also pass the instructions gate: its instructions per
|
||||
timed run on the new runtime (the whole process's, `instructions harness-<runtime>/<row>/per_run`)
|
||||
at most the old runtime's, and at most 1.03 times its stored count
|
||||
(`scripts/matrix/instructions.tsv`: one count per row where the legs agree within 3%, else one
|
||||
per driver family). A stored count only ratchets down: a leg more than 1% under it is named, and
|
||||
nothing raises it without a ruling; a row with none stored is named and gated against the old
|
||||
runtime alone. The count repeats to well under 1% between runs where the time does not, so a
|
||||
time that moves while its count holds names waits. Every row records its count; only these are
|
||||
gated on it. A row whose GPU time varies on
|
||||
one card itself (`CARD_VARIANCE`: the XTX's `sampling` and `constant_managed`) is named on the
|
||||
leg's line as the card's variance and fails nothing. A row over it fails its leg unless a ruling, made after the work on that
|
||||
row, gave it a ceiling on that GPU (`HARNESS_CEILINGS` in `scripts/matrix/results.py`); a ceiling
|
||||
@@ -374,7 +383,8 @@ Each row's GPU time on each runtime, the p50 over its timed runs of a run's firs
|
||||
last GPU end, is recorded as `time harness-gpu-<runtime>/<row>` where the row has one. The budget
|
||||
judges a row on it as above, and shows it beside the times of a row it does not judge on it; it is
|
||||
parked for the `time` rule. `run` and `show` print, under each leg's line, every harness row's time and GPU time
|
||||
on both runtimes and the ratio of the times.
|
||||
on both runtimes and the ratio of the times, and where the leg counted them, its instructions per
|
||||
run and their ratio.
|
||||
The budget goes with the old runtime.
|
||||
|
||||
The old runtime's translations do not move either. The golden hash table compiles through
|
||||
@@ -386,8 +396,11 @@ exception is a range where a commit since the table's last bless has a subject t
|
||||
`metal2vulkan_devtools::instructions::InstructionCounter` measures `instructions`: the calling
|
||||
thread's user-space instructions from Linux's `perf_event_open`, the form an unprivileged process
|
||||
may open at `perf_event_paranoid` 2. On a hybrid x86 CPU it sums the event over each core type's
|
||||
unit, since the generic event counts on one of them only. Off Linux it opens nothing, so the
|
||||
Windows leg records no `instructions`.
|
||||
unit, since the generic event counts on one of them only.
|
||||
`metal2vulkan_devtools::instructions::ProcessInstructions` measures the harness's: one counter per
|
||||
core type opened with `inherit` before the harness makes a device, so it counts every thread the
|
||||
runtimes and their drivers start. Off Linux neither opens, so the Windows leg records no
|
||||
`instructions`; a node that refuses them records none either.
|
||||
|
||||
The rules and the sizing of the matrix's jobs have their own tests, which need no cluster:
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# The new runtime's user-space instructions per timed run that each frame and burst row
|
||||
# (results.WALL_ROWS) is held to by the instructions gate (results.STORED_INSTRUCTIONS): the whole process's count, the p50 over a
|
||||
# row's timed runs. One count per row in the `all` column where every leg's count lies within 3%
|
||||
# of the others', else one per driver family (a GPU leg id's vendor). A count only ratchets down:
|
||||
# a landing that lowers it by more than 1% stores the lower one, and nothing raises it without a
|
||||
# ruling. A row with no count here is gated against the old runtime's count alone, and its line
|
||||
# names it, until the counts of a matrix run are stored.
|
||||
row all
|
||||
|
@@ -839,7 +839,7 @@ def run_cmd(sha, only, dry):
|
||||
def print_leg(leg_id, leg):
|
||||
"""A leg's verdict line, then each of its harness rows' times and GPU times."""
|
||||
print(results.verdict_line(leg_id, leg))
|
||||
for line in results.harness_rows(leg["records"]["time"]):
|
||||
for line in results.harness_rows(leg["records"]):
|
||||
print(f" {line}")
|
||||
|
||||
|
||||
|
||||
@@ -253,7 +253,7 @@ def leg_problems(leg, records, base):
|
||||
problems.append(f"metric {key}: {was} -> {value}")
|
||||
for key, value in sorted(records["instructions"].items()):
|
||||
was = base["instructions"].get(key)
|
||||
if was is not None and value > was * (1 + INSTRUCTIONS_BAND):
|
||||
if was is not None and not key.startswith(PARKED_RECORDS) and value > was * (1 + INSTRUCTIONS_BAND):
|
||||
problems.append(f"instructions {key}: {was} -> {value} (+{(value / was - 1) * 100:.1f}%)")
|
||||
return problems
|
||||
|
||||
@@ -349,6 +349,73 @@ def gpu_beside(times, runtime, row):
|
||||
return "" if gpu is None else f" (GPU p50 {gpu:.1f} us)"
|
||||
|
||||
|
||||
#: The instructions gate of the frame and burst rows (WALL_ROWS), beside the judgement of their
|
||||
#: time: on Linux, the whole process's user-space instructions per timed run (`instructions
|
||||
#: harness-<runtime>/<row>/per_run`, the p50 over its timed runs, every runtime and driver thread
|
||||
#: counted). The new runtime's count is at most the old's, and at most HARNESS_BUDGET times its
|
||||
#: stored count (STORED_INSTRUCTIONS), with no floor and no ceiling: the count repeats to well
|
||||
#: under 1% (0.16 to 0.27% across processes on the 2080's node). A time that moves while the
|
||||
#: count does not names waits. A leg that records no instructions (the kernel refused the
|
||||
#: counter, or Windows) has no gate. Every row records its count; only these are gated on it.
|
||||
INSTRUCTIONS_PER_RUN = "/per_run"
|
||||
|
||||
|
||||
def read_counts(text):
|
||||
"""The stored instruction counts' TEXT: `#` comments, a header of `row` and driver families
|
||||
(a GPU leg id's vendor, `10de`, or `all` for every leg), then per line a row and its count in
|
||||
each, `-` for none. Returns {family: {row: count}}."""
|
||||
counts, families = {}, None
|
||||
for line in text.splitlines():
|
||||
if not line.strip() or line.startswith("#"):
|
||||
continue
|
||||
cells = line.split()
|
||||
if families is None:
|
||||
families = cells[1:]
|
||||
continue
|
||||
for family, cell in zip(families, cells[1:]):
|
||||
if cell != "-":
|
||||
counts.setdefault(family, {})[cells[0]] = int(cell)
|
||||
return counts
|
||||
|
||||
|
||||
#: The new runtime's instructions per timed run that each WALL_ROWS row is held to
|
||||
#: (`instructions.tsv`, beside this file): one count per row where the legs' counts lie within 3%
|
||||
#: of each other, else one per driver family. A count only ratchets down: a landing that lowers a
|
||||
#: row's count by more than 1% stores the lower one, and nothing raises it without a ruling.
|
||||
STORED_INSTRUCTIONS = read_counts((Path(__file__).resolve().parent / "instructions.tsv").read_text())
|
||||
|
||||
|
||||
def stored_count(leg_id, row):
|
||||
"""ROW's stored count on LEG_ID: its driver family's, else every leg's, else None."""
|
||||
family = leg_id.split(":")[0]
|
||||
for column in (family, "all"):
|
||||
if row in STORED_INSTRUCTIONS.get(column, {}):
|
||||
return STORED_INSTRUCTIONS[column][row]
|
||||
return None
|
||||
|
||||
|
||||
def instruction_gate(leg_id, row, records):
|
||||
"""ROW's instructions gate on LEG_ID from the leg's RECORDS: (problems, parked), both empty
|
||||
where ROW is not a WALL_ROWS row or a runtime recorded no count. A count over the old
|
||||
runtime's, or past HARNESS_BUDGET times the stored count, is a problem; one more than
|
||||
INSTRUCTIONS_BAND under the stored count, or a row with none stored, is named."""
|
||||
counted = [records["instructions"].get(f"harness-{runtime}/{row}{INSTRUCTIONS_PER_RUN}")
|
||||
for runtime in ("new", "old")]
|
||||
if not row.startswith(WALL_ROWS) or not all(counted):
|
||||
return [], []
|
||||
(new, old), stored = counted, stored_count(leg_id, row)
|
||||
line = (f"harness budget {row}: instructions new {new} per run over old {old} is {new / old:.3f}, "
|
||||
+ (f"stored {stored}" if stored else "none stored"))
|
||||
if new > old:
|
||||
return [f"{line}: new over old"], []
|
||||
if stored and new > HARNESS_BUDGET * stored:
|
||||
return [f"{line}: past {HARNESS_BUDGET} times the stored count"], []
|
||||
if stored and new < (1 - INSTRUCTIONS_BAND) * stored:
|
||||
return [], [f"{line}: more than {INSTRUCTIONS_BAND:.0%} under the stored count, which ratchets "
|
||||
"down to it"]
|
||||
return [], [] if stored else [line]
|
||||
|
||||
|
||||
#: The harness rows over HARNESS_BUDGET that a ruling gave a ceiling, per GPU leg, each a ratio of
|
||||
#: the times its row is judged on (gpu_judged): a row past its ceiling fails its leg, so an open
|
||||
#: row can neither hide nor grow. A
|
||||
@@ -567,6 +634,9 @@ def harness_budget(leg_id, leg):
|
||||
"times measure different work")
|
||||
continue
|
||||
limit = row_limit(leg_id, row)
|
||||
gated, named = instruction_gate(leg_id, row, records)
|
||||
problems += gated
|
||||
parked += named
|
||||
if first_row(row):
|
||||
samples = first_samples(times, row)
|
||||
if samples is None:
|
||||
@@ -620,21 +690,30 @@ def harness_budget(leg_id, leg):
|
||||
return problems, parked
|
||||
|
||||
|
||||
def harness_rows(times):
|
||||
"""Every harness row timed on either runtime in a leg's TIMES, one line each: its time and its
|
||||
GPU time (HARNESS_GPU) on the new runtime and on the old, `-` where it has none, and new over
|
||||
old where both have a time."""
|
||||
def harness_rows(records):
|
||||
"""Every harness row timed on either runtime in a leg's RECORDS, one line each: its time, its
|
||||
GPU time (HARNESS_GPU) and, where recorded, its instructions per run, on the new runtime and on
|
||||
the old, `-` where it has none, and new over old of the times and of the instructions."""
|
||||
times, counted = records["time"], records["instructions"]
|
||||
rows = sorted({key.split("/", 1)[1] for key in times if key.startswith((HARNESS_NEW, HARNESS_OLD))})
|
||||
lines = []
|
||||
for row in rows:
|
||||
cells = []
|
||||
for runtime in ("new", "old"):
|
||||
wall, gpu = times.get(f"harness-{runtime}/{row}"), times.get(f"{HARNESS_GPU}{runtime}/{row}")
|
||||
cells.append(f"{runtime} {'-' if wall is None else f'{wall:.1f}':>10} us, "
|
||||
f"GPU p50 {'-' if gpu is None else f'{gpu:.1f}':>10} us")
|
||||
cell = (f"{runtime} {'-' if wall is None else f'{wall:.1f}':>10} us, "
|
||||
f"GPU p50 {'-' if gpu is None else f'{gpu:.1f}':>10} us")
|
||||
instructions = counted.get(f"harness-{runtime}/{row}{INSTRUCTIONS_PER_RUN}")
|
||||
if instructions is not None:
|
||||
cell += f", {instructions} instructions"
|
||||
cells.append(cell)
|
||||
new, old = times.get(HARNESS_NEW + row), times.get(HARNESS_OLD + row)
|
||||
ratio = f"{new / old:.3f}" if new is not None and old else "-"
|
||||
lines.append(f"{row:<36} {cells[0]} | {cells[1]} | {ratio}")
|
||||
line = f"{row:<36} {cells[0]} | {cells[1]} | {ratio}"
|
||||
new_i, old_i = (counted.get(f"harness-{runtime}/{row}{INSTRUCTIONS_PER_RUN}") for runtime in ("new", "old"))
|
||||
if new_i is not None and old_i:
|
||||
line += f", instructions {new_i / old_i:.3f}"
|
||||
lines.append(line)
|
||||
return lines
|
||||
|
||||
|
||||
|
||||
@@ -113,6 +113,12 @@ class RuleTests(unittest.TestCase):
|
||||
self.assertEqual(self.problems(recs(metric={"a/barriers": 5, "a/passes": 2}), base),
|
||||
["metric a/barriers: 4 -> 5"])
|
||||
|
||||
def test_the_old_runtime_s_instructions_are_not_compared_to_its_base(self):
|
||||
base = recs(instructions={"harness-old/frame/per_run": 100000, "harness-new/frame/per_run": 50000})
|
||||
now = recs(instructions={"harness-old/frame/per_run": 105000, "harness-new/frame/per_run": 51000})
|
||||
self.assertEqual(self.problems(now, base),
|
||||
["instructions harness-new/frame/per_run: 50000 -> 51000 (+2.0%)"])
|
||||
|
||||
def test_instructions_fail_past_one_percent(self):
|
||||
base = recs(instructions={"a/per_draw": 10000})
|
||||
self.assertEqual(self.problems(recs(instructions={"a/per_draw": 10100}), base), [])
|
||||
@@ -583,20 +589,70 @@ class HarnessBudgetTests(unittest.TestCase):
|
||||
"M2V-MATRIX time harness-retime/sampling/2/new 36.000",
|
||||
"M2V-MATRIX time harness-retime-gpu/sampling/2/new 17.600"])
|
||||
|
||||
def test_every_row_shows_its_times_and_gpu_times_on_both_runtimes(self):
|
||||
def test_every_row_shows_its_times_gpu_times_and_instructions_on_both_runtimes(self):
|
||||
times = {"harness-old/frame": 100.0, "harness-new/frame": 120.0,
|
||||
"harness-gpu-old/frame": 80.25, "harness-gpu-new/frame": 81.0,
|
||||
"harness-new/create_64MiB/first_take": 50.0, "harness-old/create_64MiB/first_take": 40.0,
|
||||
"harness-old/sampling": 50.0, "harness-first/create_64MiB/first_take/2/new": 51.0,
|
||||
"loop/gpu": 1000.0}
|
||||
self.assertEqual(results.harness_rows(times), [
|
||||
counted = {"harness-new/frame/per_run": 61253, "harness-old/frame/per_run": 149185}
|
||||
self.assertEqual(results.harness_rows(recs(time=times, instructions=counted)), [
|
||||
"create_64MiB/first_take new 50.0 us, GPU p50 - us | old 40.0 us, "
|
||||
"GPU p50 - us | 1.250",
|
||||
"frame new 120.0 us, GPU p50 81.0 us | old 100.0 us, "
|
||||
"GPU p50 80.2 us | 1.200",
|
||||
"frame new 120.0 us, GPU p50 81.0 us, 61253 instructions | "
|
||||
"old 100.0 us, GPU p50 80.2 us, 149185 instructions | 1.200, instructions 0.411",
|
||||
"sampling new - us, GPU p50 - us | old 50.0 us, "
|
||||
"GPU p50 - us | -"])
|
||||
|
||||
def test_the_frame_and_burst_rows_keep_their_time_s_limit_and_pass_the_instructions_gate_too(self):
|
||||
times = {"harness-old/frame": 100.0, "harness-new/frame": 101.0,
|
||||
"harness-old/alu": 100.0, "harness-new/alu": 101.0}
|
||||
counted = {"harness-new/frame/per_run": 61000, "harness-old/frame/per_run": 149000,
|
||||
"harness-new/alu/per_run": 9000, "harness-old/alu/per_run": 5000}
|
||||
|
||||
def budget(leg_id, counts, these=times):
|
||||
return results.harness_budget(leg_id, leg_of(recs(time=these, instructions=counts)))
|
||||
|
||||
line = "harness budget frame: instructions new {} per run over old 149000 is {}, {}"
|
||||
with mock.patch.object(results, "HARNESS_CEILINGS", {}), \
|
||||
mock.patch.object(results, "HARNESS_FLOORS", {}):
|
||||
# Both within the time's budget. alu, not a frame or burst row, has no gate, its count
|
||||
# over old's though it is.
|
||||
with mock.patch.object(results, "STORED_INSTRUCTIONS", {}):
|
||||
self.assertEqual(budget("10de:1e87", counted), ([], [line.format(61000, "0.409", "none stored")]))
|
||||
stored = {"all": {"frame": 60000}}
|
||||
with mock.patch.object(results, "STORED_INSTRUCTIONS", stored):
|
||||
# Within 1.03 times the stored count: nothing to say.
|
||||
self.assertEqual(budget("10de:1e87", counted), ([], []))
|
||||
over = dict(counted, **{"harness-new/frame/per_run": 61900})
|
||||
self.assertEqual(budget("10de:1e87", over)[0], [
|
||||
line.format(61900, "0.415", "stored 60000") + ": past 1.03 times the stored count"])
|
||||
under = dict(counted, **{"harness-new/frame/per_run": 59000})
|
||||
self.assertEqual(budget("10de:1e87", under), ([], [
|
||||
line.format(59000, "0.396", "stored 60000") + ": more than 1% under the stored count, "
|
||||
"which ratchets down to it"]))
|
||||
past_old = dict(counted, **{"harness-new/frame/per_run": 150000})
|
||||
self.assertEqual(budget("10de:1e87", past_old)[0], [
|
||||
line.format(150000, "1.007", "stored 60000") + ": new over old"])
|
||||
# A time past its limit still fails, its count within the gate though it is.
|
||||
slow = dict(times, **{"harness-new/frame": 120.0})
|
||||
self.assertEqual(budget("10de:1e87", counted, slow)[0], [
|
||||
"harness budget frame: new 120.0 us over old 100.0 us is 1.200, past 1.03"])
|
||||
# A driver family's count before every leg's.
|
||||
with mock.patch.object(results, "STORED_INSTRUCTIONS", {"all": {"frame": 60000},
|
||||
"1002": {"frame": 70000}}):
|
||||
self.assertEqual(results.stored_count("1002:744c", "frame"), 70000)
|
||||
self.assertEqual(results.stored_count("10de:2204", "frame"), 60000)
|
||||
# A leg with no counts (Windows, or a refused counter) has no gate.
|
||||
self.assertEqual(budget("8086:3e9b", {}), ([], []))
|
||||
|
||||
def test_the_stored_counts_table_reads_per_family_and_row(self):
|
||||
text = "# a comment\nrow all 1002\nframe 61253 -\nburst_160 - 90000\n"
|
||||
self.assertEqual(results.read_counts(text), {"all": {"frame": 61253}, "1002": {"burst_160": 90000}})
|
||||
for family, rows in results.STORED_INSTRUCTIONS.items():
|
||||
self.assertRegex(family, r"^(all|[0-9a-f]{4})$")
|
||||
self.assertTrue(all(row.startswith(results.WALL_ROWS) for row in rows), family)
|
||||
|
||||
def test_every_ceiling_is_over_the_budget(self):
|
||||
for leg, rows in results.HARNESS_CEILINGS.items():
|
||||
for row, ceiling in rows.items():
|
||||
|
||||
Reference in new issue
Block a user