Skip to main content

onnx_runtime_eager/
error.rs

1//! Error types for the eager execution engine (`docs/EAGER.md` §9, §10).
2//!
3//! Mirrors the `thiserror`-based `error.rs` style of the sibling runtime crates
4//! (e.g. `onnx-runtime-ep-api`, `onnx-runtime-shape-inference`): a crate-local
5//! [`Result`] alias plus one enum that wraps the lower-layer errors it can
6//! surface (ep-api, ir, shape-inference).
7
8use onnx_runtime_ir::DeviceId;
9
10/// A convenience `Result` alias for eager-dispatch operations.
11pub type Result<T> = std::result::Result<T, EagerError>;
12
13/// Errors produced while dispatching a single op in eager mode.
14#[derive(Debug, thiserror::Error)]
15pub enum EagerError {
16    /// No EP registered for the resolved device has a kernel for this op at the
17    /// requested opset (`docs/EAGER.md` §10.1 step 4).
18    #[error("no kernel for op '{op_type}' (domain {domain:?}) on device {device:?}")]
19    NoKernel {
20        op_type: String,
21        domain: String,
22        device: DeviceId,
23    },
24
25    /// Inputs live on more than one device. Eager mode never transfers
26    /// implicitly (`docs/EAGER.md` §1.6 / Design Decision): the caller must
27    /// `.to(device)` first.
28    #[error("mixed-device inputs {devices:?}: {hint}")]
29    MixedDeviceInputs {
30        devices: Vec<DeviceId>,
31        hint: String,
32    },
33
34    /// The resolved device has no execution provider registered in the context.
35    #[error("no execution provider registered for device {0:?}")]
36    NoEpForDevice(DeviceId),
37
38    /// Per-op output shape/dtype inference is missing or could not resolve to a
39    /// concrete, allocatable shape (`docs/EAGER.md` §9). The kernel-provided
40    /// inference fallback (§9.2) is DEFERRED, so an unresolved output is an
41    /// error rather than a fall-through.
42    #[error("shape inference failed for op '{op_type}' (domain {domain:?}): {reason}")]
43    ShapeInference {
44        op_type: String,
45        domain: String,
46        reason: String,
47    },
48
49    /// A lower-layer execution-provider / kernel error (allocation, execution).
50    #[error("execution provider error: {0}")]
51    Kernel(#[from] onnx_runtime_ep_api::EpError),
52
53    /// An error escaping the shape-inference engine itself.
54    #[error("shape-inference engine error: {0}")]
55    ShapeInferEngine(#[from] onnx_runtime_shape_inference::ShapeInferError),
56
57    /// An error escaping the IR layer.
58    #[error("ir error: {0}")]
59    Ir(#[from] onnx_runtime_ir::IrError),
60}