Files
rustytorch/crates/integration/rtx-rustybooks/src/error.rs
T
2026-03-04 00:08:42 +00:00

74 lines
2.1 KiB
Rust

//! Error types for RustyBooks integration
use thiserror::Error;
/// Errors that can occur during RustyBooks integration operations
#[derive(Error, Debug)]
pub enum IntegrationError {
/// GPU device not available
#[error("GPU device not available: {0}")]
DeviceNotAvailable(String),
/// Memory allocation failed
#[error("Memory allocation failed: requested {requested} bytes, available {available}")]
AllocationFailed { requested: usize, available: usize },
/// Storage I/O error
#[error("Storage I/O error: {0}")]
StorageError(String),
/// Transfer error
#[error("Transfer error: {0}")]
TransferError(String),
/// Profiling error
#[error("Profiling error: {0}")]
ProfilingError(String),
/// Kernel execution error
#[error("Kernel execution error: {0}")]
KernelError(String),
/// Shape mismatch
#[error("Shape mismatch: expected {expected}, got {actual}")]
ShapeMismatch { expected: String, actual: String },
/// Feature not available
#[error("Feature not available: {0}")]
FeatureNotAvailable(String),
/// Backend error from gpu-direct
#[cfg(feature = "direct-storage")]
#[error("gpu-direct error: {0}")]
GpuDirectError(#[from] gpu_direct::metal::MetalError),
/// Backend error from gpu-profiler
#[cfg(feature = "profiling")]
#[error("gpu-profiler error: {0}")]
GpuProfilerError(#[from] gpu_profiler::metal::ProfilerError),
/// Backend error from tensor-accelerator
#[cfg(feature = "tma")]
#[error("tensor-accelerator error: {0}")]
TensorAcceleratorError(#[from] tensor_accelerator::metal::TensorError),
/// Generic error
#[error("{0}")]
Other(String),
}
/// Result type for RustyBooks integration
pub type Result<T> = std::result::Result<T, IntegrationError>;
impl From<std::io::Error> for IntegrationError {
fn from(err: std::io::Error) -> Self {
IntegrationError::StorageError(err.to_string())
}
}
impl From<anyhow::Error> for IntegrationError {
fn from(err: anyhow::Error) -> Self {
IntegrationError::Other(err.to_string())
}
}