Skip to main content

cubecl_runtime/
poison.rs

1//! The one payload every error type carries when the device is lost/poisoned.
2
3use alloc::string::String;
4use cubecl_environment::backtrace::BackTrace;
5use thiserror::Error;
6
7/// A fault the driver makes sticky: an illegal address, a trap, an ECC error, a
8/// device lost outright. Nothing on the device can be trusted afterwards, and
9/// every later call on it fails the same way until the process exits.
10#[derive(Error, Clone)]
11#[cfg_attr(serializable, derive(serde::Serialize, serde::Deserialize))]
12#[error("{reason}\nBacktrace:\n{backtrace}")]
13pub struct DevicePoison {
14    /// The driver call that reported it.
15    pub reason: String,
16    /// The backtrace for this error.
17    #[cfg_attr(serializable, serde(skip))]
18    pub backtrace: BackTrace,
19}
20
21impl DevicePoison {
22    /// The fault, with the backtrace captured here.
23    pub fn new(reason: impl Into<String>) -> Self {
24        Self {
25            reason: reason.into(),
26            backtrace: BackTrace::capture(),
27        }
28    }
29}
30
31impl core::fmt::Debug for DevicePoison {
32    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
33        write!(f, "{self}")
34    }
35}