Skip to main content

mesh_sieve/accelerator/
error.rs

1//! Accelerator-specific errors.
2
3use thiserror::Error;
4
5/// Failures produced while compiling or executing an accelerator plan.
6#[derive(Debug, Error, Clone, PartialEq, Eq)]
7pub enum AcceleratorError {
8    /// The requested backend was not compiled in or could not initialize.
9    #[error("accelerator backend unavailable: {0}")]
10    BackendUnavailable(String),
11    /// No device exists at the requested ordinal.
12    #[error("CUDA device {ordinal} was not found")]
13    DeviceNotFound { ordinal: usize },
14    /// A resource was submitted through a different backend/context than the
15    /// one that created it.
16    #[error("accelerator resource belongs to backend {expected}, not backend {found}")]
17    BackendMismatch { expected: u64, found: u64 },
18    /// A state was submitted to a different compiled FVM plan.
19    #[error("FVM state belongs to plan {found}, not plan {expected}")]
20    PlanMismatch { expected: u64, found: u64 },
21    /// Device allocation failed.
22    #[error("device allocation of {bytes} bytes failed: {reason}")]
23    AllocationFailed { bytes: usize, reason: String },
24    /// Runtime kernel compilation failed.
25    #[error("CUDA kernel compilation failed: {0}")]
26    KernelCompilationFailed(String),
27    /// A compiled module could not be loaded.
28    #[error("CUDA module load failed: {0}")]
29    ModuleLoadFailed(String),
30    /// A named kernel was absent from a module.
31    #[error("CUDA kernel `{0}` was not found")]
32    KernelNotFound(String),
33    /// A kernel launch failed.
34    #[error("CUDA kernel launch failed: {0}")]
35    KernelLaunchFailed(String),
36    /// A CUDA stream index was outside the configured stream pool.
37    #[error("CUDA stream index {index} is out of range for {stream_count} streams")]
38    InvalidStreamIndex { index: usize, stream_count: usize },
39    /// A CUDA event operation failed.
40    #[error("CUDA event operation failed: {0}")]
41    EventFailed(String),
42    /// A CUDA numerical library call failed.
43    #[error("CUDA sparse-library operation failed: {0}")]
44    SparseLibraryFailed(String),
45    /// A host/device transfer failed.
46    #[error("device transfer failed: {0}")]
47    DeviceTransferFailed(String),
48    /// A topology-dependent plan is stale.
49    #[error("stale topology plan: expected version {expected}, found {found}")]
50    StaleTopologyPlan { expected: u64, found: u64 },
51    /// A section-dependent plan is stale.
52    #[error("stale atlas plan: expected version {expected}, found {found}")]
53    StaleAtlasPlan { expected: u64, found: u64 },
54    /// Geometry changed after plan compilation.
55    #[error("stale geometry plan: expected epoch {expected}, found {found}")]
56    StaleGeometryPlan { expected: u64, found: u64 },
57    /// Host input has a different length than its device buffer.
58    #[error("buffer length mismatch: expected {expected}, found {found}")]
59    LengthMismatch { expected: usize, found: usize },
60    /// A count or offset cannot be represented by the device ABI.
61    #[error("{what} value {value} exceeds the device ABI limit")]
62    IndexOverflow { what: &'static str, value: usize },
63    /// The value type cannot be used by the selected device.
64    #[error("unsupported device value type: {0}")]
65    UnsupportedDeviceType(&'static str),
66    /// Packed FVM data is internally inconsistent.
67    #[error("invalid accelerator plan: {0}")]
68    InvalidPlan(String),
69}