Skip to main content

onnx_runtime_memory/
error.rs

1//! Error types for planning and validation.
2
3use onnx_runtime_ir::ValueId;
4
5use crate::plan::SlotId;
6
7/// A failure that prevents the planner from producing any plan.
8#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
9pub enum PlanError {
10    /// The graph is not schedulable (contains a cycle), so no execution order
11    /// — and therefore no liveness — exists.
12    #[error("graph is not schedulable (cycle detected); cannot compute liveness")]
13    Cycle,
14}
15
16/// A violated correctness invariant found by [`crate::validate`].
17#[derive(Clone, Copy, Debug, PartialEq, Eq, thiserror::Error)]
18pub enum ValidateError {
19    /// Two values with overlapping live intervals were assigned the same slot —
20    /// one would clobber the other's still-live data.
21    #[error("values {a:?} and {b:?} have overlapping live intervals but share slot {slot:?}")]
22    SlotConflict {
23        a: ValueId,
24        b: ValueId,
25        slot: SlotId,
26    },
27    /// A value is assigned to a slot too small to hold it.
28    #[error("value {value:?} needs {needed} bytes but slot {slot:?} has capacity {capacity}")]
29    UndersizedSlot {
30        value: ValueId,
31        slot: SlotId,
32        needed: usize,
33        capacity: usize,
34    },
35    /// A buffer owner has no slot assignment in the plan.
36    #[error("buffer owner {value:?} has no slot assignment")]
37    MissingAssignment { value: ValueId },
38    /// A value is assigned to a slot id that does not exist in the plan.
39    #[error("value {value:?} references unknown slot {slot:?}")]
40    UnknownSlot { value: ValueId, slot: SlotId },
41    /// A zero-copy view outlives the source buffer it aliases (fold error): the
42    /// source could be recycled while the view still points into it.
43    #[error("view {view:?} is used at node {view_use} but its source {source_owner:?} is retired at node {source_end}")]
44    ViewOutlivesSource {
45        view: ValueId,
46        source_owner: ValueId,
47        view_use: usize,
48        source_end: usize,
49    },
50    /// The graph became unschedulable between planning and validation.
51    #[error("graph is not schedulable (cycle detected)")]
52    Cycle,
53}