#[cfg(not(feature = "std"))]
extern crate alloc;
#[cfg(not(feature = "std"))]
use alloc::string::String;
use core::fmt;
pub type GpuResult<T> = Result<T, GpuError>;
#[derive(Debug, Clone)]
#[non_exhaustive]
pub enum GpuError {
NoBackendAvailable,
InitializationFailed(String),
AllocationFailed(String),
TransferFailed(String),
ExecutionFailed(String),
InvalidSize(usize),
SizeMismatch { expected: usize, got: usize },
BackendError(String),
Unsupported(String),
SyncFailed(String),
}
impl fmt::Display for GpuError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::NoBackendAvailable => write!(f, "No GPU backend available"),
Self::InitializationFailed(msg) => write!(f, "GPU initialization failed: {msg}"),
Self::AllocationFailed(msg) => write!(f, "GPU memory allocation failed: {msg}"),
Self::TransferFailed(msg) => write!(f, "GPU data transfer failed: {msg}"),
Self::ExecutionFailed(msg) => write!(f, "GPU FFT execution failed: {msg}"),
Self::InvalidSize(size) => write!(f, "Invalid FFT size: {size}"),
Self::SizeMismatch { expected, got } => {
write!(f, "Size mismatch: expected {expected}, got {got}")
}
Self::BackendError(msg) => write!(f, "GPU backend error: {msg}"),
Self::Unsupported(msg) => write!(f, "Unsupported operation: {msg}"),
Self::SyncFailed(msg) => write!(f, "GPU synchronization failed: {msg}"),
}
}
}
#[cfg(feature = "std")]
impl std::error::Error for GpuError {}