Skip to main content

ringkernel_core/hybrid/
error.rs

1//! Error types for hybrid processing.
2
3use std::fmt;
4
5/// Error type for hybrid processing operations.
6#[derive(Debug, Clone)]
7pub enum HybridError {
8    /// GPU is not available.
9    GpuNotAvailable,
10    /// GPU execution failed.
11    GpuExecutionFailed(String),
12    /// Workload size exceeds limits.
13    WorkloadTooLarge {
14        /// Requested size.
15        requested: usize,
16        /// Maximum allowed.
17        maximum: usize,
18    },
19    /// Configuration error.
20    ConfigError(String),
21    /// Resource allocation failed.
22    ResourceAllocationFailed(String),
23}
24
25impl fmt::Display for HybridError {
26    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27        match self {
28            HybridError::GpuNotAvailable => write!(f, "GPU is not available"),
29            HybridError::GpuExecutionFailed(msg) => write!(f, "GPU execution failed: {}", msg),
30            HybridError::WorkloadTooLarge { requested, maximum } => {
31                write!(f, "Workload size {} exceeds maximum {}", requested, maximum)
32            }
33            HybridError::ConfigError(msg) => write!(f, "Configuration error: {}", msg),
34            HybridError::ResourceAllocationFailed(msg) => {
35                write!(f, "Resource allocation failed: {}", msg)
36            }
37        }
38    }
39}
40
41impl std::error::Error for HybridError {}
42
43/// Result type for hybrid processing operations.
44pub type HybridResult<T> = Result<T, HybridError>;