Device loss relayed before any fence could be read: the recovery's hang and victims stand
Under the program's own MVK_CONFIG_RESUME_LOST_DEVICE off, MoltenVK marks the device lost before it reports the failed Metal command buffer. The relay then reads no fence (the wait answers the loss), so it gives every batch in flight the loss's code (DeviceRemoved, 11). The completion's failed wait then runs the recovery's answers (completion.rs: the oldest incomplete command buffer as the hang, GpuHang, the rest as its victims) and names that command buffer the hang in the device-recovered notice and against its queue; but CommandBufferShared::complete_seen let the relayed code win over that answer, and DeviceLost on a recovering line reads GpuRecoveryVictim. So the command buffer the notice named the hang answered GpuRecoveryVictim: the M3 Max's lane test a_gpu_fault_fails_its_command_buffer_and_the_queue_runs_on read it in 25 of 25 runs (m3-max-13699), where the runtime's README and the test say GpuHang, and Metal fails the command buffer that faulted with its own error, never as a victim. The test's expectation is the documented contract, so the runtime changes: a relayed DeviceRemoved leaves a recovery's answer (GpuHang or GpuRecoveryVictim) as it is; every other relayed code is still Metal's answer for its batch's work. The relay's loss is one named step (Relayed::lost), which a device test injects (CommandBuffer::relay_loss). Test: tests::device_recovery::a_relayed_loss_leaves_the_recovery_s_hang marks the loss with the relay's code on the busy command buffer in flight, fails what is pending as a failed wait does, recovers, and holds the command buffer the notice names the hang to GpuHang. Fails without the fix (GpuRecoveryVictim). Evidence in the report to the orchestrator.
This commit is contained in:
1 parent
6cbae4e537
commit
67510b5aca
3 files changed
+83
-8
No files matched your search
@@ -65,7 +65,7 @@ use super::copied::CopiesReached;
|
||||
use super::deferred::{Deferred, Prepared, StepInputs};
|
||||
use super::degradation::{Degradation, NoticesFor};
|
||||
use super::descriptor_arena::DescriptorArena;
|
||||
use super::device::relay::Relayed;
|
||||
use super::device::relay::{self, Relayed};
|
||||
use super::device::{lock, DeviceShared};
|
||||
use super::dirty_pages::DirtyCommit;
|
||||
use super::encoder::{Recorded, Segment};
|
||||
@@ -2388,6 +2388,14 @@ impl CommandBuffer {
|
||||
self.state().making_failure_injected = Some(error);
|
||||
}
|
||||
|
||||
/// Relay the device's loss to it, as the relay does to every batch in flight where it cannot
|
||||
/// read which one failed (`device/relay.rs`): a device test's injection
|
||||
/// (`tests::device_recovery`).
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
pub(crate) fn relay_loss(&self) {
|
||||
self.0.relayed.lost();
|
||||
}
|
||||
|
||||
/// Its state, locked, as a host step's draw or a commit's work holds it: a device test's
|
||||
/// (`tests::footprint_locks`).
|
||||
#[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))]
|
||||
@@ -5328,9 +5336,16 @@ impl CommandBufferShared {
|
||||
// (`revocation.rs`).
|
||||
let lost_hang = result == Err(CommandBufferError::GpuHang);
|
||||
// A failure the driver relayed for one of its batches is Metal's answer for its work
|
||||
// (`device/relay.rs`).
|
||||
// (`device/relay.rs`). The device's loss is not: where a recovery from it answered
|
||||
// already (`completion.rs`, the oldest incomplete command buffer as the hang and the
|
||||
// rest as its victims, as its notice names them), that answer stands.
|
||||
let recovered = matches!(
|
||||
result,
|
||||
Err(CommandBufferError::GpuHang | CommandBufferError::GpuRecoveryVictim)
|
||||
);
|
||||
let result = match (state.failure, self.relayed.failure()) {
|
||||
(Some(error), _) => Err(error),
|
||||
(None, Some((relay::DEVICE_REMOVED, _))) if recovered => result,
|
||||
(None, Some((code, description))) => {
|
||||
state.relayed_description = description;
|
||||
Err(CommandBufferError::of_metal_code(code))
|
||||
|
||||
@@ -36,7 +36,14 @@
|
||||
//! (`CommandBuffer::error_description`); a failure of the program's own submission is the program's
|
||||
//! to read (its own messenger hears it); and one of the runtime's own, or one no submission in
|
||||
//! flight explains (a Metal command buffer MoltenVK made for itself), loses the device: every
|
||||
//! command buffer in flight then finishes `DeviceLost`, and no later one is submitted.
|
||||
//! batch in flight then takes the loss's code (`DeviceRemoved`, 11), and no later one is
|
||||
//! submitted. So does every batch where no fence can be read, the device lost before the report
|
||||
//! (MoltenVK under the program's own `MVK_CONFIG_RESUME_LOST_DEVICE` off). Where the device's
|
||||
//! line recovers (`device/line.rs`), its command buffers answer as the recovery does: where the
|
||||
//! loss failed a wait for their fences, the command buffer of the oldest incomplete batch as the
|
||||
//! hang (`GpuHang`) and the rest as its victims (`command_buffer/completion.rs`), the loss's code
|
||||
//! leaving that answer as it is; where their fences signaled, each as a victim
|
||||
//! (`GpuRecoveryVictim`).
|
||||
//!
|
||||
//! **The loader word.** MoltenVK writes `ICD_LOADER_MAGIC` over the first word of an object it
|
||||
//! names in a message (`loader_word.rs`), the queue's here, where a layer between the loader and
|
||||
@@ -79,7 +86,7 @@ pub(super) fn setting() -> super::create::LayerSetting {
|
||||
|
||||
/// `MTLCommandBufferErrorDeviceRemoved`: the code a device lost by the relay gives its command
|
||||
/// buffers in flight.
|
||||
const DEVICE_REMOVED: u64 = 11;
|
||||
pub(crate) const DEVICE_REMOVED: u64 = 11;
|
||||
|
||||
/// The relay's messenger on an instance the runtime created, and the relay it reports to.
|
||||
pub(super) struct Messenger {
|
||||
@@ -173,7 +180,7 @@ impl Relay {
|
||||
.iter()
|
||||
.filter(|f| Arc::ptr_eq(&f.lost, &flights.lost))
|
||||
{
|
||||
each.fail_all(DEVICE_REMOVED);
|
||||
each.lose_all();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -205,6 +212,12 @@ impl Relayed {
|
||||
}
|
||||
}
|
||||
|
||||
/// The device was lost: its loss's code (`DeviceRemoved`), unless a failure was kept already
|
||||
/// (the module docs).
|
||||
pub(crate) fn lost(&self) {
|
||||
self.fail(DEVICE_REMOVED, None);
|
||||
}
|
||||
|
||||
/// The code and the description kept, if a failure was relayed.
|
||||
pub(crate) fn failure(&self) -> Option<(u64, Option<String>)> {
|
||||
lock(&self.0).clone()
|
||||
@@ -416,11 +429,12 @@ impl Flights {
|
||||
status.is_ok()
|
||||
}
|
||||
|
||||
/// Every batch in flight fails with `code`, unless it failed already.
|
||||
fn fail_all(&self, code: u64) {
|
||||
/// Every batch in flight takes the device's loss ([`Relayed::lost`]), unless it failed
|
||||
/// already.
|
||||
fn lose_all(&self) {
|
||||
for flight in lock(&self.log).iter() {
|
||||
if let By::Batch(failed) = &flight.by {
|
||||
failed.fail(code, None);
|
||||
failed.lost();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,6 +200,52 @@ fn a_loss_holds_the_hang_s_queue_until_the_recovery() {
|
||||
panic!("no loss of {ATTEMPTS} caught the busy command buffer in flight");
|
||||
}
|
||||
|
||||
/// A loss the driver reported before any fence could be read, as MoltenVK does under the
|
||||
/// program's own `MVK_CONFIG_RESUME_LOST_DEVICE` off (it marks the device lost first): the relay
|
||||
/// gives every batch in flight the loss's code (`device/relay.rs`), and the recovery's answers
|
||||
/// stand, the command buffer in flight failing as the hang its notice names, not as a victim.
|
||||
/// The M3 Max's GPU fault under that setting read `GpuRecoveryVictim` there in 25 of 25 runs
|
||||
/// (`runtime_lane::host_memory`'s `a_gpu_fault_fails_its_command_buffer_and_the_queue_runs_on`).
|
||||
#[test]
|
||||
fn a_relayed_loss_leaves_the_recovery_s_hang() {
|
||||
let scratch = Scratch::new();
|
||||
let heard = Heard::default();
|
||||
let device = heard_device(&scratch.0, &heard);
|
||||
let queue = device.new_command_queue().unwrap();
|
||||
for _ in 0..ATTEMPTS {
|
||||
let from = heard.lock().unwrap().len();
|
||||
let in_flight = busy(&device, &queue);
|
||||
let lost = in_flight.device().clone();
|
||||
lost.mark_lost();
|
||||
in_flight.relay_loss();
|
||||
lost.shared().completion.fail_in_flight();
|
||||
let answer = outcome(&in_flight);
|
||||
drop((in_flight, lost));
|
||||
// The next call recovers the device; its notice says whether the loss caught the copies
|
||||
// in flight, which else completed first.
|
||||
drop(queue.command_buffer().unwrap());
|
||||
let made = recovery_notices(&heard, from, "the device");
|
||||
assert_eq!(made.len(), 1, "one recovery announced {made:?}");
|
||||
if made[0].contains("no command buffer was in flight") {
|
||||
continue;
|
||||
}
|
||||
assert!(
|
||||
made[0].contains("failed as the hang (`GpuHang`)"),
|
||||
"{made:?}"
|
||||
);
|
||||
assert_eq!(
|
||||
answer,
|
||||
(
|
||||
CommandBufferStatus::Error,
|
||||
Some(CommandBufferError::GpuHang)
|
||||
),
|
||||
"the recovery named the command buffer in flight the hang: {made:?}"
|
||||
);
|
||||
return;
|
||||
}
|
||||
panic!("no loss of {ATTEMPTS} caught the busy command buffer in flight");
|
||||
}
|
||||
|
||||
/// A loss marked while `queue`'s busy command buffer is in flight, as a failed wait finds it:
|
||||
/// whether it caught that command buffer as the hang, which else completed first. Either way the
|
||||
/// next call recovers the device.
|
||||
|
||||
Reference in new issue
Block a user