replay: --snapshots no plays every m2v.privateBytes dispatch as it is on either runtime, so old's and rt's plays do the same work
Old's play of gb on the 3090 with snapshots read 0.54 of 1.9 GB of stream in about 5 minutes (m3-max-44322, cancelled before its 15-minute limit): the player's own splits and readbacks around 12,000 dispatches dominate it, and rt declines them, so their frame times and memory would not compare. Player::without_snapshots takes none on any backend. Verified: cargo fmt only; clippy, replay tests and the release build next.
This commit is contained in:
1 parent
6dab612810
commit
fd0f8fcaef
4 files changed
+86
-40
No files matched your search
@@ -2,8 +2,10 @@
|
||||
//! or the new one, or print its records.
|
||||
//!
|
||||
//! `command-replay play --stream FILE --out DIR --device-type cpu|gpu --shader-cache DIR
|
||||
//! [--blobs DIR] [--runtime old|rt]` plays the stream whose first segment is `FILE` through the
|
||||
//! old runtime (the default) or the new one (`rt`) and writes `DIR/report.txt`: `device NAME`,
|
||||
//! [--blobs DIR] [--runtime old|rt] [--snapshots yes|no]` plays the stream whose first segment is
|
||||
//! `FILE` through the old runtime (the default) or the new one (`rt`), with `--snapshots no`
|
||||
//! taking no `m2v.privateBytes` snapshot on either (so two runtimes' plays do the same work), and
|
||||
//! writes `DIR/report.txt`: `device NAME`,
|
||||
//! the player's report lines, the backend's own lines, `cut SEGMENT OFFSET` where the last
|
||||
//! segment ends in a record cut
|
||||
//! short, `skipped ...` where the backend skipped what its runtime does not build (such a play is
|
||||
@@ -31,7 +33,7 @@ use std::io::Write as _;
|
||||
use std::path::PathBuf;
|
||||
|
||||
const USAGE: &str = "usage: command-replay play --stream FILE --out DIR --device-type cpu|gpu \
|
||||
--shader-cache DIR [--blobs DIR] [--runtime old|rt]\n command-replay dump --stream FILE\n \
|
||||
--shader-cache DIR [--blobs DIR] [--runtime old|rt] [--snapshots yes|no]\n command-replay dump --stream FILE\n \
|
||||
command-replay shapes --stream FILE";
|
||||
|
||||
fn main() {
|
||||
@@ -202,6 +204,14 @@ fn play(options: &BTreeMap<String, String>) -> i32 {
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
let snapshots = match options.get("snapshots").map(String::as_str) {
|
||||
None | Some("yes") => true,
|
||||
Some("no") => false,
|
||||
Some(other) => {
|
||||
report.line(&format!("error snapshots: {other} is neither yes nor no"));
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
let cache = PathBuf::from(&options["shader-cache"]);
|
||||
match options.get("runtime").map(String::as_str) {
|
||||
None | Some("old") => {
|
||||
@@ -217,7 +227,7 @@ fn play(options: &BTreeMap<String, String>) -> i32 {
|
||||
};
|
||||
report.line(&format!("device {}", device.name()));
|
||||
let mut backend = OldRuntime::new(device, device_type);
|
||||
run(&mut backend, &mut reader, &mut report)
|
||||
run(&mut backend, &mut reader, &mut report, snapshots)
|
||||
}
|
||||
Some("rt") => {
|
||||
let mut backend = match open_rt(device_type, cache) {
|
||||
@@ -230,7 +240,7 @@ fn play(options: &BTreeMap<String, String>) -> i32 {
|
||||
return 2;
|
||||
}
|
||||
};
|
||||
run(&mut backend, &mut reader, &mut report)
|
||||
run(&mut backend, &mut reader, &mut report, snapshots)
|
||||
}
|
||||
Some(other) => {
|
||||
report.line(&format!("error runtime: {other} is neither old nor rt"));
|
||||
@@ -285,8 +295,18 @@ fn open_rt(device_type: DeviceType, cache: PathBuf) -> Result<(NewRuntime, Strin
|
||||
}
|
||||
|
||||
/// Play `reader` through `backend` into `report`: the exit status.
|
||||
fn run<B: Backend>(backend: &mut B, reader: &mut StreamReader, report: &mut ReportFile) -> i32 {
|
||||
let (played, ended) = Player::new(backend).play(reader);
|
||||
fn run<B: Backend>(
|
||||
backend: &mut B,
|
||||
reader: &mut StreamReader,
|
||||
report: &mut ReportFile,
|
||||
snapshots: bool,
|
||||
) -> i32 {
|
||||
let player = Player::new(backend);
|
||||
let player = match snapshots {
|
||||
true => player,
|
||||
false => player.without_snapshots(),
|
||||
};
|
||||
let (played, ended) = player.play(reader);
|
||||
for line in played.lines() {
|
||||
report.line(&line);
|
||||
}
|
||||
|
||||
@@ -512,6 +512,9 @@ pub struct Player<'b, B: Backend> {
|
||||
frame: Counts,
|
||||
/// When the frame being played began: the first call played, or the frame before's end.
|
||||
frame_began: Option<std::time::Instant>,
|
||||
/// Whether the player takes the `m2v.privateBytes` snapshots where the backend does
|
||||
/// (`Player::without_snapshots`).
|
||||
snapshots: bool,
|
||||
report: Report,
|
||||
}
|
||||
|
||||
@@ -704,10 +707,19 @@ impl<'b, B: Backend> Player<'b, B> {
|
||||
fixed,
|
||||
frame: Counts::default(),
|
||||
frame_began: None,
|
||||
snapshots: true,
|
||||
report: Report::default(),
|
||||
}
|
||||
}
|
||||
|
||||
/// The player that takes no `m2v.privateBytes` snapshots on any backend: every dispatch plays as
|
||||
/// the program made it, counted (`Report::unsnapshotted`), so that two runtimes' plays do the
|
||||
/// same work and their times and memory compare.
|
||||
pub fn without_snapshots(mut self) -> Self {
|
||||
self.snapshots = false;
|
||||
self
|
||||
}
|
||||
|
||||
/// Play every call of `stream`; the report holds what ran, whether or not it all did.
|
||||
pub fn play(mut self, stream: &mut StreamReader) -> (Report, Result<(), PlayError>) {
|
||||
let start = self.baseline.clone();
|
||||
@@ -736,7 +748,7 @@ impl<'b, B: Backend> Player<'b, B> {
|
||||
self.frame_began.get_or_insert_with(std::time::Instant::now);
|
||||
let issued = self.issued(&call);
|
||||
match self.ahead.remove(&self.position) {
|
||||
Some(ranges) if self.backend.snapshots() => {
|
||||
Some(ranges) if self.snapshots && self.backend.snapshots() => {
|
||||
self.split(stream, call, ranges, left_out)?
|
||||
}
|
||||
Some(_) => {
|
||||
|
||||
@@ -1175,38 +1175,49 @@ fn a_frame_end_reports_the_gauges_as_they_stand() {
|
||||
assert!(ends[1].ends_with(" live calls=3"), "{lines:?}");
|
||||
}
|
||||
|
||||
/// On a backend that takes no snapshots, a dispatch an `m2v.privateBytes` record names plays as it
|
||||
/// is, with none of the player's own calls, and the report counts it.
|
||||
/// On a backend that takes no snapshots, or with a player that takes none, a dispatch an
|
||||
/// `m2v.privateBytes` record names plays as it is, with none of the player's own calls, and the
|
||||
/// report counts it.
|
||||
#[test]
|
||||
fn a_backend_without_snapshots_plays_the_dispatch_as_it_is() {
|
||||
let bytes: Vec<u8> = (0..4).collect();
|
||||
let mut kept = Kept {
|
||||
declines_snapshots: true,
|
||||
..Kept::default()
|
||||
};
|
||||
let (report, ended) = played(&mut kept, |w| {
|
||||
let word = w.blob(&bytes)?;
|
||||
w.call("MTLCreateSystemDefaultDevice", 0, 1, &[], &[])?;
|
||||
w.call("newCommandQueue", 1, 2, &[], &[])?;
|
||||
let private = [Value::Uint(4), Value::Uint(0x20)];
|
||||
w.call("newBufferWithLength:options:", 1, 3, &private, &[])?;
|
||||
w.call("commandBuffer", 2, 4, &[], &[])?;
|
||||
w.call("computeCommandEncoder", 4, 5, &[], &[])?;
|
||||
let threads = map(&[("width", Value::Uint(1)), ("height", Value::Uint(1))]);
|
||||
let dispatch = "dispatchThreadgroups:threadsPerThreadgroup:";
|
||||
w.call(dispatch, 5, 0, &[threads.clone(), threads], &[])?;
|
||||
w.call("endEncoding", 5, 0, &[], &[])?;
|
||||
w.call("commit", 4, 0, &[], &[])?;
|
||||
let range = map(&[("location", Value::Uint(0)), ("length", Value::Uint(4))]);
|
||||
let args = [Value::Uint(5), range, Value::Blob(word), Value::Blob(word)];
|
||||
w.call("m2v.privateBytes", 3, 0, &args, &[])?;
|
||||
Ok(())
|
||||
});
|
||||
ended.unwrap();
|
||||
assert!(kept.calls.iter().all(|c| !c.contains(&format!("#{OWN}"))));
|
||||
assert_eq!((report.unsnapshotted, report.splits), (1, 0));
|
||||
assert!(report.private.is_empty());
|
||||
assert!(report.lines().contains(&"unsnapshotted 1".to_string()));
|
||||
for player_declines in [false, true] {
|
||||
let bytes: Vec<u8> = (0..4).collect();
|
||||
let mut kept = Kept {
|
||||
declines_snapshots: !player_declines,
|
||||
..Kept::default()
|
||||
};
|
||||
let dir = ScratchDir::new("replay-player").unwrap();
|
||||
let path = written(&dir, "s.m2vr", |w| {
|
||||
let word = w.blob(&bytes)?;
|
||||
w.call("MTLCreateSystemDefaultDevice", 0, 1, &[], &[])?;
|
||||
w.call("newCommandQueue", 1, 2, &[], &[])?;
|
||||
let private = [Value::Uint(4), Value::Uint(0x20)];
|
||||
w.call("newBufferWithLength:options:", 1, 3, &private, &[])?;
|
||||
w.call("commandBuffer", 2, 4, &[], &[])?;
|
||||
w.call("computeCommandEncoder", 4, 5, &[], &[])?;
|
||||
let threads = map(&[("width", Value::Uint(1)), ("height", Value::Uint(1))]);
|
||||
let dispatch = "dispatchThreadgroups:threadsPerThreadgroup:";
|
||||
w.call(dispatch, 5, 0, &[threads.clone(), threads], &[])?;
|
||||
w.call("endEncoding", 5, 0, &[], &[])?;
|
||||
w.call("commit", 4, 0, &[], &[])?;
|
||||
let range = map(&[("location", Value::Uint(0)), ("length", Value::Uint(4))]);
|
||||
let args = [Value::Uint(5), range, Value::Blob(word), Value::Blob(word)];
|
||||
w.call("m2v.privateBytes", 3, 0, &args, &[])?;
|
||||
Ok(())
|
||||
});
|
||||
let mut reader = StreamReader::open(&[path], None).unwrap();
|
||||
let player = Player::new(&mut kept);
|
||||
let player = match player_declines {
|
||||
true => player.without_snapshots(),
|
||||
false => player,
|
||||
};
|
||||
let (report, ended) = player.play(&mut reader);
|
||||
ended.unwrap();
|
||||
assert!(kept.calls.iter().all(|c| !c.contains(&format!("#{OWN}"))));
|
||||
assert_eq!((report.unsnapshotted, report.splits), (1, 0));
|
||||
assert!(report.private.is_empty());
|
||||
assert!(report.lines().contains(&"unsnapshotted 1".to_string()));
|
||||
}
|
||||
}
|
||||
|
||||
/// A record must name an earlier call, and that call a compute encoder's dispatch; a blob must hold
|
||||
|
||||
@@ -339,8 +339,11 @@ and the (name id, value) answer pairs.
|
||||
## 10. The player
|
||||
|
||||
`command-replay play --stream FILE --out DIR --device-type cpu|gpu --shader-cache DIR
|
||||
[--blobs DIR] [--runtime old|rt]` plays a stream (its first segment) on one device through the
|
||||
old runtime (the default) or the new one (`rt`), and writes `DIR/report.txt`. `command-replay dump --stream FILE` prints the call records as text, and
|
||||
[--blobs DIR] [--runtime old|rt] [--snapshots yes|no]` plays a stream (its first segment) on one
|
||||
device through the old runtime (the default) or the new one (`rt`), and writes `DIR/report.txt`.
|
||||
With `--snapshots no` it takes no `m2v.privateBytes` snapshot on either runtime: each such dispatch
|
||||
plays as it is, counted on the `unsnapshotted` line, so two runtimes' plays do the same work and
|
||||
their times and memory compare. `command-replay dump --stream FILE` prints the call records as text, and
|
||||
`command-replay shapes --stream FILE` each selector's argument shapes, with no data.
|
||||
|
||||
- It relocates (section 5) and plays the host's plumbing as the plain calls it stands for
|
||||
|
||||
Reference in new issue
Block a user