The cutover's last mechanical step. The old runtime is deleted, so its name is free: the crate moves to crates/metal2vulkan-runtime, its package is metal2vulkan-runtime and its library metal2vulkan_runtime, and every reference in the tree follows (sources, tests, scripts, CI, generated tables and docs). It is now a published crate, as AGENTS.md said it would be once it took the name: version 0.2.0 with the other two, the translator pinned exactly (=0.2.0, as the translator pins the AIR front end), documentation, keywords and categories, and copies of the repository's four license files, which the published-crates test now holds equal to the root's for three crates. CI packages it with the others. Prose that said it was unpublished, or counted two published crates, says three. AGENTS.md: facts only. The crate table row, the published-crates and version sentences, and the paragraph on the old runtime, whose name the runtime now carries (listed for the owner). Made by one script run on this tip. Verified by the job named in the landing note.
387 lines
19 KiB
Rust
387 lines
19 KiB
Rust
//! What an event orders, measured on Metal: the four ordering facts `runtime_lane::events` holds
|
|
//! as assertions of the runtime against itself.
|
|
//!
|
|
//! An event's value only rises ([`super::shared_events`]) — these cases are about what it
|
|
//! **orders**. A command buffer's `encodeWaitForEvent:value:` holds that command buffer, and the
|
|
//! ones committed behind it on its own queue, until the value arrives; a command buffer's
|
|
//! `encodeSignalEvent:value:` raises it where it is encoded, not when the command buffer ends.
|
|
//! Five cases:
|
|
//!
|
|
//! - [`CROSS_QUEUE_WAIT`]: one queue's command buffer waits for an event the other's signals, and
|
|
//! the waiting one is committed **first**. Both run and both fills land.
|
|
//! - [`HIGHEST_SIGNAL`]: two queues signal one shared event with 7 and 4, in both submission
|
|
//! orders. The event ends at 7 either way.
|
|
//! - [`HELD_COMMAND_BUFFER`]: a command buffer held by a shared event the host raises later holds
|
|
//! back its own queue and not another's, neither of its handlers has run, and once the host
|
|
//! raises the event its scheduled handler runs before its completed one.
|
|
//! - [`SIGNAL_BEFORE_WAIT`]: the work ahead of a wait inside one command buffer runs, and its
|
|
//! signal lands, while the wait is still pending.
|
|
//! - [`WAIT_BEHIND_A_RUNNING_SIGNAL`]: one queue's command buffer runs a long GPU job and then
|
|
//! signals an event; another queue's command buffer, committed after it, waits for that value.
|
|
//! While the long job still runs, is the waiting one submitted (its wait on the GPU), or held
|
|
//! until the signal lands? For an `MTLEvent` and an `MTLSharedEvent` alike, as two rows.
|
|
//!
|
|
//! # A wait whose signal is submitted and running
|
|
//!
|
|
//! [`CROSS_QUEUE_WAIT`] reads a waiting command buffer's status while its signaller is not yet
|
|
//! committed, and [`HELD_COMMAND_BUFFER`] while only the host can raise the event: both answer
|
|
//! `Committed`, and neither says what Metal does once the signal is already on the GPU.
|
|
//! [`WAIT_BEHIND_A_RUNNING_SIGNAL`] asks that. The status is the proxy for "submitted": Metal's
|
|
//! `Scheduled` follows a command buffer's submission to the GPU, with its scheduled handlers run,
|
|
//! so `Scheduled` while the signaller still runs is "submitted, and so checked, before the signal
|
|
//! landed", and `Committed` is "held until it lands". The signaller signals a companion shared
|
|
//! event just before the event under test, and the companion is read last: a row whose companion
|
|
//! reads 1 had its signal land before the reading, so it records that alone and no reading,
|
|
//! which differs from Metal's recorded answer rather than passing for one. The long job is fills
|
|
//! alone ([`LONG_FILLS`] of [`LONG_FILL_BYTES`] into a private buffer): no loop runs on the GPU,
|
|
//! so nothing can hang.
|
|
//!
|
|
//! On `metal2vulkan-runtime` the `MTLEvent` row's waiting command buffer may still read `Committed`,
|
|
//! with no handler run, though its wait is met: the runtime schedules a command buffer once
|
|
//! its device's one submit thread is free, and Metal promises no time between a command buffer's
|
|
//! dependencies resolving and its scheduling. The case declares that in its allowances.
|
|
//!
|
|
//! # What this pulls forward
|
|
//!
|
|
//! Every one of these numbers was ours before. `runtime_lane::events` runs the shapes on the
|
|
//! runtime and asserts the answers the module's prose says Metal gave — "as measured on Metal",
|
|
//! "measured on the M3 and the M4" — with no Metal leg in the test and, for the statuses, no
|
|
//! measurement written down at all beyond the word in the comment. Here both sides run and the
|
|
//! answers are compared field by field, so the statuses, the handler order and the bytes are
|
|
//! Metal's.
|
|
//!
|
|
//! The commit order of [`CROSS_QUEUE_WAIT`] is the one that can deadlock. Two logical queues share
|
|
//! the device's `VkQueue`s — one on most devices — so a wait committed ahead of its signal
|
|
//! deadlocks unless the implementation holds it back instead of submitting in commit order. That
|
|
//! is a property of ours with a Metal answer behind it, and this is the first time the Metal answer
|
|
//! is recorded rather than described.
|
|
//!
|
|
//! # Why none of it can hang, and none of it holds a GPU
|
|
//!
|
|
//! Every event a command buffer waits for is one the probe itself raises, from the host or from a
|
|
//! command buffer already committed. Every wait of the probe's own thread is bounded: a command
|
|
//! buffer's progress is observed through its **handlers**, with a channel and a bound, because
|
|
//! Metal has no bounded `waitUntilCompleted`; a host wait for an event takes its bound as an
|
|
//! argument on both sides. A bound that runs out is recorded as a negative fact, never retried.
|
|
//!
|
|
//! The work is four fills of [`crate::event_orders::SCRATCH`] bytes. Nothing renders, nothing
|
|
//! dispatches, no loop runs on the GPU and nothing waits on a value no code here raises.
|
|
//!
|
|
//! # What is deliberately not here
|
|
//!
|
|
//! The lane's **tracked** resources across queues (`a_tracked_buffer_across_queues_follows_the_
|
|
//! commit_order` and its texture twin) are left out: the answer there is "what the order the
|
|
//! runtime schedules them in gives it", which is a fact about our scheduler with Metal's own
|
|
//! answer attached by a comment naming an M4. It is a real question and it deserves a case; it
|
|
//! needs the hazard-tracking vocabulary first, and a hazard between two queues needs work big
|
|
//! enough to overlap, which a bytes record of a small buffer cannot stand in for.
|
|
//!
|
|
//! The lane's refusals of an event command **with an encoder open** and **after the commit** are
|
|
//! left out, and must stay out: the lane's own prose says Metal asserts there, which ends Metal's
|
|
//! process. They are the shape the suite has no outcome kind for, and the round's rule is that
|
|
//! such a design is written down and left unbuilt. The runtime's typed refusals of both stay
|
|
//! `runtime_lane` assertions.
|
|
|
|
use crate::allowance::{Allowance, Justification, Loosening};
|
|
use crate::case::{Abort, Case, Input, MetalSource, Side};
|
|
use crate::event_orders::{
|
|
COMPLETED, HELD_FOR, LONG_FILLS, LONG_FILL_BYTES, RUNNING_WINDOW, SCHEDULED, SCRATCH,
|
|
SIGNAL_WAIT,
|
|
};
|
|
use crate::transcript::{Negative, Node, Observed, Sites, Value};
|
|
|
|
/// A wait committed before the signal that meets it.
|
|
pub const CROSS_QUEUE_WAIT: &str = "event-cross-queue-wait";
|
|
|
|
/// The slug of `docs/API.md`'s accepted difference that says `metal2vulkan-runtime` schedules a
|
|
/// command buffer waiting for a shared event's value as it is submitted
|
|
/// ([`shared_wait_scheduled_as_submitted`]).
|
|
const SHARED_WAIT_SCHEDULED_AS_SUBMITTED: &str =
|
|
"a-command-buffer-that-waits-for-a-shared-event-s-value-is-scheduled-as-it-is-submitted";
|
|
|
|
/// The declaration [`WAIT_BEHIND_A_RUNNING_SIGNAL`]'s `MTLSharedEvent` row needs on
|
|
/// `metal2vulkan-runtime`: the waiting command buffer's status while the signaller runs may be
|
|
/// `Committed` or `Scheduled`, and its handlers then none or the scheduled one.
|
|
///
|
|
/// **What it rests on**, the accepted difference [`SHARED_WAIT_SCHEDULED_AS_SUBMITTED`] names:
|
|
/// MTLCommandBuffer.h describes `Scheduled` as "All dependencies have been resolved and the
|
|
/// command buffer has been scheduled for execution", and `encodeWaitForEvent:value:` as a command
|
|
/// that "pauses execution of this command buffer until the specified event reaches a given
|
|
/// value", so execution pauses after scheduling. The runtime schedules a waiter whose signal is
|
|
/// submitted as it is submitted, for a shared event as for a plain one, once its submit thread is
|
|
/// free ([`SCHEDULED_ONCE_THE_SUBMIT_THREAD_IS_FREE`]). The M3 Max holds it at `Committed` with no
|
|
/// handler run until the value lands, which no documented Metal states.
|
|
///
|
|
/// **It loosens those two sites alone**; the event's value while the signaller runs still
|
|
/// compares exactly.
|
|
fn shared_wait_scheduled_as_submitted() -> Vec<Allowance> {
|
|
let justified = || Justification::accepted(SHARED_WAIT_SCHEDULED_AS_SUBMITTED);
|
|
vec![
|
|
Allowance::new(
|
|
"case/order/shared-event/waiting/status-while-the-signaller-runs",
|
|
Loosening::AnyOf(vec![
|
|
Value::unit_variant("Committed"),
|
|
Value::unit_variant("Scheduled"),
|
|
]),
|
|
justified(),
|
|
),
|
|
Allowance::new(
|
|
"case/order/shared-event/waiting/handlers-while-the-signaller-runs",
|
|
Loosening::AnyOf(vec![
|
|
Value::Nothing(Negative::RanNothing),
|
|
Value::Lines(vec![SCHEDULED.to_owned()]),
|
|
]),
|
|
justified(),
|
|
),
|
|
]
|
|
}
|
|
|
|
/// Two queues signalling one shared event, in both orders.
|
|
pub const HIGHEST_SIGNAL: &str = "event-highest-signal";
|
|
|
|
/// A command buffer held by a shared event the host raises later.
|
|
pub const HELD_COMMAND_BUFFER: &str = "event-held-command-buffer";
|
|
|
|
/// A signal encoded before a wait, inside one command buffer.
|
|
pub const SIGNAL_BEFORE_WAIT: &str = "event-signal-before-a-wait";
|
|
|
|
/// A wait committed behind a signal that is already submitted and still running.
|
|
pub const WAIT_BEHIND_A_RUNNING_SIGNAL: &str = "event-wait-behind-a-running-signal";
|
|
|
|
/// The two kinds of event [`WAIT_BEHIND_A_RUNNING_SIGNAL`] runs on, each a row: whether the event
|
|
/// is an `MTLSharedEvent`, and the row's name.
|
|
const EVENT_KINDS: [(bool, &str); 2] = [(false, "event"), (true, "shared-event")];
|
|
|
|
/// The values the two queues of [`HIGHEST_SIGNAL`] signal, in each submission order.
|
|
///
|
|
/// Both orders are rows of one case because the fact is the pair's: a lower signal cannot lower the
|
|
/// value, so whichever executed last the event holds the higher. One order alone would not say
|
|
/// that.
|
|
const SIGNAL_PAIRS: [[u64; 2]; 2] = [[7, 4], [4, 7]];
|
|
|
|
/// The site each row of the four cases sits at.
|
|
const AT: &str = "order";
|
|
|
|
/// The bytes every case's wait bounds fingerprint as: the window a negative fact is read after, and
|
|
/// the bound a host wait for a GPU signal is given.
|
|
///
|
|
/// Both are inputs because they are what the answers mean. A status read "while the event is
|
|
/// unsignalled" is read after the window; a host wait's `false` says "not within this long".
|
|
fn bounds() -> Vec<u8> {
|
|
let mut words = (HELD_FOR.as_millis() as u64).to_le_bytes().to_vec();
|
|
words.extend((SIGNAL_WAIT.as_millis() as u64).to_le_bytes());
|
|
words
|
|
}
|
|
|
|
/// A case over one ordering fact of the event family.
|
|
pub struct EventOrder {
|
|
name: &'static str,
|
|
shape: Shape,
|
|
}
|
|
|
|
/// Which experiment a case runs.
|
|
#[derive(Clone, Copy, Debug)]
|
|
enum Shape {
|
|
CrossQueueWait,
|
|
HighestSignal,
|
|
Held,
|
|
SignalBeforeWait,
|
|
WaitBehindRunningSignal,
|
|
}
|
|
|
|
/// The five cases.
|
|
pub fn all() -> Vec<EventOrder> {
|
|
[
|
|
(CROSS_QUEUE_WAIT, Shape::CrossQueueWait),
|
|
(HIGHEST_SIGNAL, Shape::HighestSignal),
|
|
(HELD_COMMAND_BUFFER, Shape::Held),
|
|
(SIGNAL_BEFORE_WAIT, Shape::SignalBeforeWait),
|
|
(WAIT_BEHIND_A_RUNNING_SIGNAL, Shape::WaitBehindRunningSignal),
|
|
]
|
|
.into_iter()
|
|
.map(|(name, shape)| EventOrder { name, shape })
|
|
.collect()
|
|
}
|
|
|
|
impl Case for EventOrder {
|
|
fn name(&self) -> &'static str {
|
|
self.name
|
|
}
|
|
|
|
fn metal_source(&self) -> MetalSource {
|
|
MetalSource::Run
|
|
}
|
|
|
|
fn allowances(&self) -> Vec<Allowance> {
|
|
// The cross-queue row is the one row of the family that reads an answer back out of a
|
|
// `Shared` buffer, and on a device without unified memory the runtime announces
|
|
// `shared-in-system-memory` for it (`crate::replay::shared_memory_notice` holds the whole
|
|
// reason). It declares the notices site alone: the scratch words still compare exactly.
|
|
//
|
|
// Measured on the RTX 5080 Laptop (615.71.09): the notice fired for
|
|
// `event-cross-queue-wait` alone, which was divergent on that field and nothing else, and
|
|
// the other three rows were exact (replay-nvidia.log). So the other three name nothing:
|
|
// what they read back is a count our side holds, not a buffer the device wrote.
|
|
match self.shape {
|
|
// The waiting command buffer's scratch is read back out of a `Shared` buffer, as
|
|
// the cross-queue row's is.
|
|
Shape::CrossQueueWait => vec![crate::replay::shared_memory_notice()],
|
|
Shape::WaitBehindRunningSignal => {
|
|
let mut allowances = vec![crate::replay::shared_memory_notice()];
|
|
allowances.extend(scheduled_once_the_submit_thread_is_free());
|
|
allowances.extend(shared_wait_scheduled_as_submitted());
|
|
allowances
|
|
}
|
|
Shape::HighestSignal | Shape::Held | Shape::SignalBeforeWait => Vec::new(),
|
|
}
|
|
}
|
|
|
|
fn inputs(&self) -> Result<Vec<Input>, String> {
|
|
let mut inputs = vec![
|
|
Input::bytes("scratch-bytes", &SCRATCH.to_le_bytes()),
|
|
Input::bytes("wait-bounds-millis", &bounds()),
|
|
];
|
|
match self.shape {
|
|
Shape::CrossQueueWait => {
|
|
let mut fills = Vec::new();
|
|
for byte in [
|
|
crate::event_orders::WAITING_BYTE,
|
|
crate::event_orders::SIGNALLING_BYTE,
|
|
] {
|
|
fills.push(byte);
|
|
}
|
|
inputs.push(Input::bytes("fill-bytes", &fills));
|
|
}
|
|
Shape::HighestSignal => {
|
|
let mut values = Vec::new();
|
|
for pair in SIGNAL_PAIRS {
|
|
for value in pair {
|
|
values.extend(value.to_le_bytes());
|
|
}
|
|
}
|
|
inputs.push(Input::bytes("signal-pairs", &values));
|
|
}
|
|
// The handler names are what the record holds, so a change to either word is a change
|
|
// to the case's inputs.
|
|
Shape::Held => inputs.push(Input::bytes(
|
|
"handler-names",
|
|
format!("{SCHEDULED},{COMPLETED}").as_bytes(),
|
|
)),
|
|
Shape::SignalBeforeWait => {}
|
|
// The long job's size and the window are what "while the signaller runs" means, and
|
|
// the handler names are what the record holds.
|
|
Shape::WaitBehindRunningSignal => {
|
|
let mut job = LONG_FILL_BYTES.to_le_bytes().to_vec();
|
|
job.extend(LONG_FILLS.to_le_bytes());
|
|
job.extend((RUNNING_WINDOW.as_millis() as u64).to_le_bytes());
|
|
inputs.push(Input::bytes("long-job-and-window", &job));
|
|
inputs.push(Input::bytes(
|
|
"handler-names",
|
|
format!("{SCHEDULED},{COMPLETED}").as_bytes(),
|
|
));
|
|
inputs.push(Input::bytes(
|
|
"fill-bytes",
|
|
&[crate::event_orders::WAITING_BYTE],
|
|
));
|
|
}
|
|
}
|
|
Ok(inputs)
|
|
}
|
|
|
|
fn record_runs(&self) -> u32 {
|
|
// Every one of these cases reads at least one **negative** fact after a window: this
|
|
// command buffer is not scheduled, that handler has not run, that signal has not landed.
|
|
// A negative fact read after a window is a race read, however wide the window, so more
|
|
// runs do not make it safe — they make it visible. The recording holds the set of outcomes
|
|
// with their frequencies, so a field that flaps says so instead of passing as whichever
|
|
// run came last.
|
|
5
|
|
}
|
|
|
|
fn run(&self, side: &mut dyn Side, sites: &mut Sites) -> Result<(), Abort> {
|
|
match self.shape {
|
|
Shape::CrossQueueWait => match side.event_cross_queue_wait() {
|
|
Ok(order) => sites.push(order.node(AT)),
|
|
// The row records the failure and the run ends: every fact the case has is in the
|
|
// one call, so there is nothing after it to read.
|
|
Err(failure) => sites.push(Node::leaf(AT, Observed::value(failure.recorded()))),
|
|
},
|
|
Shape::HighestSignal => {
|
|
for pair in SIGNAL_PAIRS {
|
|
let at = format!("{AT}/{}-then-{}", pair[0], pair[1]);
|
|
match side.event_highest_signal(pair) {
|
|
Ok(value) => sites.value(at, Value::Uint(value)),
|
|
// One order's answer is still readable where the other refused, so the
|
|
// sweep goes on.
|
|
Err(failure) => {
|
|
sites.push(Node::leaf(at, Observed::value(failure.recorded())))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Shape::Held => match side.held_command_buffer() {
|
|
Ok(order) => sites.push(order.node(AT)),
|
|
Err(failure) => sites.push(Node::leaf(AT, Observed::value(failure.recorded()))),
|
|
},
|
|
Shape::SignalBeforeWait => match side.signal_before_a_wait() {
|
|
Ok(order) => sites.push(order.node(AT)),
|
|
Err(failure) => sites.push(Node::leaf(AT, Observed::value(failure.recorded()))),
|
|
},
|
|
Shape::WaitBehindRunningSignal => {
|
|
for (shared, kind) in EVENT_KINDS {
|
|
let at = format!("{AT}/{kind}");
|
|
match side.event_wait_behind_a_running_signal(shared) {
|
|
Ok(order) => sites.push(order.node(at)),
|
|
// The other kind's answer is still readable where one refused.
|
|
Err(failure) => {
|
|
sites.push(Node::leaf(at, Observed::value(failure.recorded())))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Ok(())
|
|
}
|
|
}
|
|
|
|
/// The slug of `docs/API.md`'s accepted difference that says when `metal2vulkan-runtime` schedules a
|
|
/// command buffer ([`scheduled_once_the_submit_thread_is_free`]).
|
|
const SCHEDULED_ONCE_THE_SUBMIT_THREAD_IS_FREE: &str =
|
|
"the-runtime-schedules-a-command-buffer-once-its-submit-thread-is-free";
|
|
|
|
/// The declaration [`WAIT_BEHIND_A_RUNNING_SIGNAL`]'s `MTLEvent` row needs on `metal2vulkan-runtime`:
|
|
/// the waiting command buffer's status while the signaller runs may be `Committed` or
|
|
/// `Scheduled`, and its handlers then none or the scheduled one.
|
|
///
|
|
/// **What it rests on**, the accepted difference [`SCHEDULED_ONCE_THE_SUBMIT_THREAD_IS_FREE`]
|
|
/// names: Apple's `Scheduled` is "All dependencies have been resolved and the command buffer has
|
|
/// been scheduled for execution", with no time promised between the two, and the runtime
|
|
/// schedules a command buffer on its device's one submit thread, once that thread's earlier
|
|
/// `vkQueueSubmit2` calls have returned, whichever queue they were for. Where the signaller's call
|
|
/// outlasts the reading, the waiting one, its wait already met by that signal, is still
|
|
/// `Committed` with no handler run.
|
|
///
|
|
/// **It loosens those two sites alone.** The shared event's row has its own declaration
|
|
/// ([`shared_wait_scheduled_as_submitted`]).
|
|
fn scheduled_once_the_submit_thread_is_free() -> Vec<Allowance> {
|
|
let justified = || Justification::accepted(SCHEDULED_ONCE_THE_SUBMIT_THREAD_IS_FREE);
|
|
vec![
|
|
Allowance::new(
|
|
"case/order/event/waiting/status-while-the-signaller-runs",
|
|
Loosening::AnyOf(vec![
|
|
Value::unit_variant("Committed"),
|
|
Value::unit_variant("Scheduled"),
|
|
]),
|
|
justified(),
|
|
),
|
|
Allowance::new(
|
|
"case/order/event/waiting/handlers-while-the-signaller-runs",
|
|
Loosening::AnyOf(vec![
|
|
Value::Nothing(Negative::RanNothing),
|
|
Value::Lines(vec![SCHEDULED.to_owned()]),
|
|
]),
|
|
justified(),
|
|
),
|
|
]
|
|
}
|