replay: a group that held a Private-range split reports its executed counts apart

Leaving out what the runtime counted while the player's own calls ran
did not keep the split out of the executed counts: the old runtime
records the barriers a split needs at the program's next command and at
the commit. Device legs at 0b882f337c (jobs m3-max-41605, m3-max-41608)
counted 8 barriers on the RX 7900 XTX, RX 550, 780M and lavapipe and 10
on the RTX 2080 for the test stream, against 5 for the same stream
without the records. A background pipeline that landed inside an
uncounted window also left pipelines_made out (RX 550, 780M,
lavapipe).

The runtime's work for a split cannot be told apart from the program's,
so a group whose command buffers held a split now reports no executed
counts. Those counts are added up apart, in Report::split_executed and
on the `split N executed COUNTS` line, and the total leaves them out
with the readbacks. The player's own calls around the dispatch are no
longer measured on their own.
This commit is contained in:
Anees Iqbal committed 2026-11-17 10:12:59 -08:00
1 parent 15e29501fb
commit 9cb90de8cc
4 files changed
+72 -55

No files matched your search

@@ -173,9 +173,13 @@ pub struct Report {
pub ids: Vec<IdDiffers>,
pub private: Vec<PrivateBytes>,
/// How many times the player ended a program's compute encoder and made it again around a
/// dispatch an `m2v.privateBytes` record names (twice a dispatch): its own work, which no
/// count holds.
/// dispatch an `m2v.privateBytes` record names (twice a dispatch).
pub splits: u64,
/// The executed counts of the groups that held such a dispatch, which no group, frame or total
/// holds: the runtime's work for the player's splits is not told apart from the program's
/// there (a runtime may record the barriers a split needs at the program's next command or at
/// the commit).
pub split_executed: Counters,
/// The whole play's counts, the player's own work left out. Its calls are the calls played:
/// where a play stopped, the stopping call is the next.
pub total: Counts,
@@ -230,7 +234,11 @@ impl Report {
));
}
if self.splits > 0 {
lines.push(format!("split {}", self.splits));
let executed = self.split_executed.iter();
let executed: String = executed
.map(|(key, value)| format!(" {key}={value}"))
.collect();
lines.push(format!("split {} executed{executed}", self.splits));
}
lines.push(format!("total{}", counted(&self.total)));
lines
@@ -555,8 +563,10 @@ impl<'b, B: Backend> Player<'b, B> {
let ended = ended.and_then(|()| self.compare(stream, &mut left_out));
let now = self.backend.counters();
let mut executed = grown(&now, &start);
let split = &self.report.split_executed;
for (key, value) in &mut executed {
*value = value.saturating_sub(left_out.get(key).copied().unwrap_or(0));
let out = [&left_out, split].map(|out| out.get(key).copied().unwrap_or(0));
*value = value.saturating_sub(out.iter().sum());
}
let mut stream = self.fixed.clone();
for (_, group) in &self.report.completed {
@@ -1086,29 +1096,25 @@ impl<'b, B: Backend> Player<'b, B> {
let (buffer, location) = (around.buffer, around.location);
[staging, at, buffer, location, around.length]
};
self.uncounted(left_out, |player| {
let length = [Value::Uint((2 * half).max(16)), Value::Uint(0)];
player.own(device, "newBufferWithLength:options:", staging, &length)?;
player.own(device, "newFence", fence, &[])?;
for &(around, at) in &placed {
let mut before = stream.blob(&around.before)?;
sized(&around, &before)?;
if player.addresses.holds(around.buffer) {
player.relocate(&mut before, around.location);
}
*player.fixed.entry(WRITTEN_BYTES).or_default() += around.length;
player.backend.write(staging, at, &before)?;
let length = [Value::Uint((2 * half).max(16)), Value::Uint(0)];
self.own(device, "newBufferWithLength:options:", staging, &length)?;
self.own(device, "newFence", fence, &[])?;
for &(around, at) in &placed {
let mut before = stream.blob(&around.before)?;
sized(&around, &before)?;
if self.addresses.holds(around.buffer) {
self.relocate(&mut before, around.location);
}
player.blit_between(&made, fence, placed.iter().map(copy_in))
})?;
*self.fixed.entry(WRITTEN_BYTES).or_default() += around.length;
self.backend.write(staging, at, &before)?;
}
self.blit_between(&made, fence, placed.iter().map(copy_in))?;
self.step(stream, call, left_out)?;
let copy_out = |&(around, at): &(Around, u64)| {
let (buffer, location) = (around.buffer, around.location);
[buffer, location, staging, half + at, around.length]
};
self.uncounted(left_out, |player| {
player.blit_between(&made, fence, placed.iter().map(copy_out))
})?;
self.blit_between(&made, fence, placed.iter().map(copy_out))?;
let pending = self.pending.get_mut(&command_buffer);
let pending = pending.ok_or_else(|| invalid("a dispatch of no open command buffer"))?;
pending.snapshots.push(Snapshot {
@@ -1281,15 +1287,18 @@ impl<'b, B: Backend> Player<'b, B> {
.collect()
}
/// Wait for every command buffer that can complete, and record the counters' growth for them.
/// Wait for every command buffer that can complete, and record the counters' growth for them:
/// for a group that held a split (`split`), in the report's split counts instead.
fn drain(&mut self) -> Result<(), PlayError> {
let ready = self.runnable();
if ready.is_empty() {
return Ok(());
}
let mut split = false;
for id in &ready {
self.backend.wait(*id)?;
let pending = self.pending.remove(id).expect("a pending command buffer");
split |= !pending.snapshots.is_empty();
self.done.extend(pending.snapshots);
for (event, value) in pending.signals {
let known = self.events.entry(event).or_default();
@@ -1302,6 +1311,13 @@ impl<'b, B: Backend> Player<'b, B> {
self.committed.retain(|id| !ready.contains(id));
let now = self.backend.counters();
let executed = grown(&now, &self.baseline);
let executed = match split {
false => executed,
true => {
add(&mut self.report.split_executed, &executed);
Counters::new()
}
};
let group = Counts {
stream: self.fixed.clone(),
executed,
@@ -902,8 +902,9 @@ const OWN: u64 = (1 << 63) + 1;
/// with every call that set its state, dispatches, and the same with a blit that copies the ranges
/// out, each encoder after a fence the one before updated. At the completion it reads the bytes
/// after back and counts the words that differ from the recording's (here, the dispatch changed
/// nothing). The report counts the two splits; no count holds the player's calls or what the
/// runtime counted for them (its copies); a later dispatch plays as it is.
/// nothing). The stream's counts hold none of the player's calls; the report counts the two
/// splits, and the executed counts of the group that held them (its copies among them) are
/// reported apart, in no group, frame or total; a later dispatch plays as it is.
#[test]
fn a_dispatch_plays_between_its_private_bytes() {
let before: Vec<u8> = (0..24).collect();
@@ -1027,15 +1028,14 @@ fn a_dispatch_plays_between_its_private_bytes() {
);
assert_eq!(stream["written_bytes"], 28);
assert_eq!((kept.copies, report.splits), (4, 2));
assert!(lines.contains(&"split 2".to_string()));
let groups = report.completed.iter().map(|(_, counts)| &counts.executed);
for executed in groups.chain([&report.total.executed]) {
assert_eq!(
executed.get("copies").copied().unwrap_or(0),
0,
"{executed:?}"
);
}
let split = Counters::from([("copies", 4), ("submissions", 1)]);
assert_eq!(report.split_executed, split);
assert!(lines.contains(&"split 2 executed copies=4 submissions=1".to_string()));
assert_eq!(report.completed.len(), 1);
assert!(report.completed[0].1.executed.is_empty());
assert!(report.frames.is_empty());
let total = &report.total.executed;
assert!(total.values().all(|&value| value == 0), "{total:?}");
}
/// A record must name an earlier call, and that call a compute encoder's dispatch; a blob must hold
@@ -647,8 +647,9 @@ fn a_copied_buffer_starts_with_its_contents_and_ids_are_compared() {
/// encoder, each with `m2v.privateBytes` records of the whole buffer: before each, the player puts
/// the case's input in, and after each it compares what the kernel left with the bytes after, the
/// case's Metal output for the first and that output with one word changed for the second, which
/// is the one word the report counts. The player's splits are in no count: the same stream
/// without the records executes the same counts, group by group.
/// is the one word the report counts. The group that held the splits reports its executed counts
/// apart, in no group, frame or total: they hold the program's two dispatches and one
/// submission, as the same stream without the records executes them.
#[test]
fn a_private_buffer_takes_its_bytes_before_a_dispatch_and_is_compared_after() {
let case = public_case("copy-twelve-bytes-through-a-four-byte-element-pointer").unwrap();
@@ -730,18 +731,15 @@ fn a_private_buffer_takes_its_bytes_before_a_dispatch_and_is_compared_after() {
assert_eq!(differing, [(10, 0), (11, 1)], "{:?}", report.private);
assert_eq!(report.total.stream["written_bytes"], 64);
assert_eq!((report.splits, plain.splits), (4, 0));
let executed = |report: &Report| {
let groups = report
.completed
.iter()
.map(|(_, counts)| counts.executed.clone());
groups
.chain([report.total.executed.clone()])
.collect::<Vec<_>>()
};
assert_eq!(
executed(report),
executed(plain),
"the splits are in no count"
);
assert!(plain.split_executed.is_empty());
assert_eq!(report.completed.len(), 1);
assert!(report.completed[0].1.executed.is_empty());
// The pipeline the runtime makes in the background may land in any span.
for key in ["barriers", "copies", "dispatches", "submissions"] {
assert_eq!(report.total.executed[key], 0, "{key}");
}
for key in ["dispatches", "submissions"] {
let (split, alone) = (report.split_executed[key], plain.total.executed[key]);
assert_eq!(split, alone, "{key}");
}
}
+9 -6
View File
@@ -353,8 +353,7 @@ and the (name id, value) answer pairs.
same way. A fence of its own orders each of these encoders after the one before it. Once the
command buffer completed, it reads the bytes after back and counts the 4-byte words of each
range that differ from the recording's, relocated the same way. A difference is reported, and
the play goes on. Its own objects take ids from 2^63 + 1. The report counts the encoders it split
(`split`).
the play goes on. Its own objects take ids from 2^63 + 1.
- It reports, for each group of command buffers it waited for (normally the one just committed),
for each frame and in total, two sets of counts:
- **Fixed by the stream** (`stream`), the same on every play of the stream on any runtime: the
@@ -377,9 +376,12 @@ and the (name id, value) answer pairs.
plays can move a few draws and barriers from one group or frame to another. Only the stream's
counts are compared between plays.
Its own work is in no count: its readbacks, and around a dispatch an `m2v.privateBytes` record
names, its buffer, fence, blits and the encoders it ends and makes again. What the runtime
counted while the player's own calls ran is left out of the executed counts.
Its own readbacks are not counted. Its own work around a dispatch an `m2v.privateBytes` record
names (its buffer, fence and blits and the encoders it ends and makes again) is in none of the
stream's counts. The runtime's work for it cannot be told apart from the program's (a runtime
may record the barriers a split needs at the program's next command or at the commit), so a
group that held such a dispatch reports no executed counts: they are added up apart, on the
report's `split` line, and no frame or total holds them.
- A selector, argument or descriptor key the runtime's backend does not implement is a typed
refusal naming it; the run stops there and the report keeps what ran. The old runtime's backend
refuses rate maps, stage inputs, dynamic libraries, OpenCL mode, indirect command buffers,
@@ -392,7 +394,8 @@ and the (name id, value) answer pairs.
`check ID SHA256 match|differs|unrecorded`, `id ID RECORDED PLAYED` for each object whose runtime
gives another `gpuResourceID` than the program saw (both in hex, `PLAYED` `none` where the
runtime's getter raises), `private ID DISPATCH LOCATION+LENGTH match|differs N/WORDS` for each
`m2v.privateBytes` range compared, `split N` where the player split compute encoders around them,
`m2v.privateBytes` range compared, `split N executed COUNTS` where the player split compute
encoders around them (`N` the encoders split, `COUNTS` the executed counts of their groups),
`total COUNTS` (its `calls` the calls played: where
the play stopped, the stopping call is the next), `cut SEGMENT OFFSET` where the last segment ends
in a record cut short, then `ok` or `error WHAT`. `COUNTS` is `stream KEY=VALUE ... executed