Files
rustytorch/crates/training/rtx-flash-metal-attention/src/error.rs
T
2026-03-04 00:08:42 +00:00

93 lines
2.4 KiB
Rust

//! Error types for Metal Flash Attention
use thiserror::Error;
/// Result type for Flash Attention operations
pub type FlashResult<T> = Result<T, FlashError>;
/// Errors that can occur during Flash Attention operations
#[derive(Error, Debug)]
pub enum FlashError {
/// Metal device or command queue error
#[error("Metal device error: {0}")]
DeviceError(String),
/// Shader compilation error
#[error("Shader compilation error: {0}")]
ShaderCompilation(String),
/// Pipeline creation error
#[error("Pipeline creation error: {0}")]
PipelineCreation(String),
/// Invalid tensor shape
#[error("Invalid tensor shape: {0}")]
InvalidShape(String),
/// Tensor dimension mismatch
#[error("Dimension mismatch: {0}")]
DimensionMismatch(String),
/// Tensor not on Metal device
#[error("Tensor not on Metal device: {0}")]
NotOnMetal(String),
/// Command buffer execution error
#[error("Execution error: {0}")]
Execution(String),
/// Configuration error
#[error("Configuration error: {0}")]
Configuration(String),
/// Unsupported operation
#[error("Unsupported operation: {0}")]
Unsupported(String),
/// Feature not available on this platform
#[error("Not available: {0}")]
NotAvailable(String),
}
impl FlashError {
/// Create a device error
pub fn device(msg: impl Into<String>) -> Self {
FlashError::DeviceError(msg.into())
}
/// Create a shader compilation error
pub fn shader(msg: impl Into<String>) -> Self {
FlashError::ShaderCompilation(msg.into())
}
/// Create a pipeline error
pub fn pipeline(msg: impl Into<String>) -> Self {
FlashError::PipelineCreation(msg.into())
}
/// Create an invalid shape error
pub fn shape(msg: impl Into<String>) -> Self {
FlashError::InvalidShape(msg.into())
}
/// Create a dimension mismatch error
pub fn dim_mismatch(msg: impl Into<String>) -> Self {
FlashError::DimensionMismatch(msg.into())
}
/// Create a not-on-Metal error
pub fn not_metal(msg: impl Into<String>) -> Self {
FlashError::NotOnMetal(msg.into())
}
/// Create an execution error
pub fn execution(msg: impl Into<String>) -> Self {
FlashError::Execution(msg.into())
}
/// Create a not-available error
pub fn not_available(msg: impl Into<String>) -> Self {
FlashError::NotAvailable(msg.into())
}
}