pub use crate::error::{BackendError, BackendResult as CpuResult, ErrorContext, ErrorContextExt};
pub use torsh_core::error::TorshError;
pub mod cpu_errors {
use super::*;
pub fn memory_allocation_error(message: impl Into<String>) -> TorshError {
let context = ErrorContext::new("memory_allocation")
.with_backend("CPU")
.with_details(message.into());
TorshError::AllocationError(context.format())
}
pub fn buffer_error(message: impl Into<String>) -> TorshError {
let context = ErrorContext::new("buffer_operation")
.with_backend("CPU")
.with_details(message.into());
TorshError::BackendError(context.format())
}
pub fn kernel_execution_error(message: impl Into<String>) -> TorshError {
let context = ErrorContext::new("kernel_execution")
.with_backend("CPU")
.with_details(message.into());
TorshError::ComputeError(context.format())
}
pub fn thread_pool_error(message: impl Into<String>) -> TorshError {
let context = ErrorContext::new("thread_pool")
.with_backend("CPU")
.with_details(message.into());
TorshError::BackendError(context.format())
}
pub fn simd_error(message: impl Into<String>) -> TorshError {
let context = ErrorContext::new("simd_operation")
.with_backend("CPU")
.with_details(message.into());
TorshError::ComputeError(context.format())
}
pub fn optimization_error(message: impl Into<String>) -> TorshError {
let context = ErrorContext::new("optimization")
.with_backend("CPU")
.with_details(message.into());
TorshError::BackendError(context.format())
}
pub fn invalid_parameter_error(message: impl Into<String>) -> TorshError {
let context = ErrorContext::new("parameter_validation")
.with_backend("CPU")
.with_details(message.into());
TorshError::InvalidArgument(context.format())
}
pub fn parsing_error(message: impl Into<String>) -> TorshError {
let context = ErrorContext::new("parsing")
.with_backend("CPU")
.with_details(message.into());
TorshError::BackendError(context.format())
}
pub fn serialization_error(message: impl Into<String>) -> TorshError {
let context = ErrorContext::new("serialization")
.with_backend("CPU")
.with_details(message.into());
TorshError::BackendError(context.format())
}
pub fn io_error(message: impl Into<String>) -> TorshError {
let context = ErrorContext::new("io_operation")
.with_backend("CPU")
.with_details(message.into());
TorshError::BackendError(context.format())
}
pub fn io_error_from_std(err: std::io::Error, operation: &str) -> TorshError {
let context = ErrorContext::new(operation)
.with_backend("CPU")
.with_details(err.to_string());
TorshError::BackendError(context.format())
}
}