Tests: an idle queue's copy of a long write, then a later sharer of a third queue with no host wait
What: every_device_copies_an_idle_queues_copy_of_a_long_write_into_a_later_sharer. Behind the busy gate, a writer on one queue makes six dispatches of x = x * 2 + 1, two kernels of unknown rate in turn, so a runtime that cuts by a kernel's rate makes six pieces, more than the device's room takes. Then a copy of its buffer is committed to an idle queue, and a copy of that copy is committed to a third idle queue, with no host wait. An empty command buffer committed after them is scheduled before the gate opens. The test asserts the words Metal's order gives: 63 in the written buffer, the first copy and the second. It prints the device's counts once the copies were seen, so a run shows its cuts and shared holds where the tree counts them. Why: the planner's (h3) shape. A command buffer held behind a cut sharer of another queue wants nothing for the device's room, so a later sharer of it on a third queue that no host wait sends could go before it. Metal submits the first copy at its commit, as its queue has nothing ahead of it, and its hazard tracking orders the second copy after it (the runtime README's "Queues, command buffers and events" rule, from the M3 Max rows of job m3-max-68673). The test uses only items that developmentc38852d665also has, so it runs there unchanged. Verified: not run when committed. Its lavapipe arms job (basec38852d665with this commit, and this tree) follows.
This commit is contained in:
1 parent
5f93a64342
commit
7cd99ae0b1
1 file changed
+63
@@ -139,6 +139,7 @@ pub(crate) mod on_device {
|
||||
use crate::buffer::BufferObject;
|
||||
use crate::device::lock;
|
||||
use crate::submit::{GROUP_RUN, IN_FLIGHT, UNSEEN_JOINS};
|
||||
use crate::tests::compute::on_device::step;
|
||||
use crate::tests::devices_of_the_cfgs_kind;
|
||||
use crate::{
|
||||
host_time, AllocationId, AllocationInfo, Block, BlockMappings, Buffer, CommandBuffer,
|
||||
@@ -2034,6 +2035,68 @@ pub(crate) mod on_device {
|
||||
});
|
||||
}
|
||||
|
||||
/// Behind the busy gate ([`Busy::new`]), a long writer runs on one queue: six dispatches of
|
||||
/// `x = x * 2 + 1`, two kernels of unknown rate in turn, so a runtime that cuts a command
|
||||
/// buffer into pieces of a kernel's rate makes six, more than the device's room takes, and
|
||||
/// the rest wait. A copy of what it writes is then committed to an idle queue, and a copy of
|
||||
/// that copy to a third idle queue, with no host wait for either. Once the submit thread has
|
||||
/// looked past the second copy (an empty command buffer committed after it is scheduled) the
|
||||
/// gate opens. Metal submits the first copy at its commit, its queue having nothing ahead of
|
||||
/// it, so its hazard tracking orders that copy after the writer and the second copy after it:
|
||||
/// both read every step. The device's counts once the copies were seen are printed, so a run
|
||||
/// shows the shape it held (the cuts and the copies held behind the writer, where counted).
|
||||
#[test]
|
||||
fn every_device_copies_an_idle_queues_copy_of_a_long_write_into_a_later_sharer() {
|
||||
each_device("command_sharer_behind_held", |name, _, device| {
|
||||
let mut arena = Arena::new(&device);
|
||||
let (written, copied, read) = (arena.buffer(), arena.buffer(), arena.buffer());
|
||||
let kernels = [step(&device), step(&device)];
|
||||
let (writing, copying, reading, probing) = (
|
||||
queue(&device),
|
||||
queue(&device),
|
||||
queue(&device),
|
||||
queue(&device),
|
||||
);
|
||||
let busy = Busy::new(&device);
|
||||
let writer = writing.command_buffer().expect("a command buffer");
|
||||
let mut encoder =
|
||||
(writer.compute_command_encoder(DispatchType::Serial)).expect("an encoder");
|
||||
encoder.set_buffer(Some(&written), 0, 0).expect("a buffer");
|
||||
for kernel in kernels.iter().cycle().take(6) {
|
||||
encoder.set_compute_pipeline_state(kernel).expect("a state");
|
||||
(encoder.dispatch_threadgroups([1, 1, 1], [64, 1, 1])).expect("a dispatch");
|
||||
}
|
||||
encoder.end_encoding();
|
||||
writer.commit().expect("a commit");
|
||||
within(name, || writer.status() != CommandBufferStatus::Committed);
|
||||
let copy = |queue: &CommandQueue, from: &Buffer, to: &Buffer| {
|
||||
let command_buffer = queue.command_buffer().expect("a command buffer");
|
||||
let mut blit = command_buffer.blit_command_encoder().expect("an encoder");
|
||||
(blit.copy_from_buffer_to_buffer(from, 0, to, 0, 256)).expect("a copy");
|
||||
blit.end_encoding();
|
||||
command_buffer.commit().expect("a commit");
|
||||
command_buffer
|
||||
};
|
||||
let first = copy(©ing, &written, &copied);
|
||||
let second = copy(&reading, &copied, &read);
|
||||
let probe = probing.command_buffer().expect("a command buffer");
|
||||
probe.commit().expect("a commit");
|
||||
within(name, || probe.status() != CommandBufferStatus::Committed);
|
||||
let counts = device.counters().metrics();
|
||||
println!("{name}: the device's counts once the copies were seen: {counts:?}");
|
||||
busy.open();
|
||||
for command_buffer in [&writer, &first, &second, &probe] {
|
||||
finished(name, command_buffer);
|
||||
assert_eq!(command_buffer.error(), None, "{name}");
|
||||
}
|
||||
assert_eq!(
|
||||
(word(&written), word(&copied), word(&read)),
|
||||
(63, 63, 63),
|
||||
"{name}: the write's six steps, the first copy and the second"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/// The expected run of queue A of [`two_queues`]: past `GROUP_RUN` with one more behind its
|
||||
/// oldest submission, so it has room for two.
|
||||
const LONG_RUN: u64 = 20_000_000;
|
||||
|
||||
Reference in new issue
Block a user