#[doc(hidden)]
#[macro_export]
macro_rules! static_assertions_send_sync {
($t:ty) => {
const _: fn() = || {
fn assert_send<T: Send>() {}
fn assert_sync<T: Sync>() {}
assert_send::<$t>();
assert_sync::<$t>();
};
};
}
#[derive(Debug, thiserror::Error)]
pub enum MlxError {
#[error("No Metal GPU device found — Apple Silicon required")]
DeviceNotFound,
#[error("Command buffer error: {0}")]
CommandBufferError(String),
#[error("Shader compilation error for '{name}': {message}")]
ShaderCompilationError {
name: String,
message: String,
},
#[error("Failed to allocate Metal buffer of {bytes} bytes")]
BufferAllocationError {
bytes: usize,
},
#[error("Invalid argument: {0}")]
InvalidArgument(String),
#[error("Kernel not found: {0}")]
KernelNotFound(String),
#[error("I/O error: {0}")]
IoError(String),
#[error("Safetensors error: {0}")]
SafetensorsError(String),
#[error("Quantization config error: {0}")]
QuantConfigError(String),
#[error("Unsupported dtype: {0}")]
UnsupportedDtype(String),
#[error("GGUF parse error: {0}")]
GgufParseError(String),
}
pub type Result<T> = std::result::Result<T, MlxError>;
impl MlxError {
pub fn is_transient(&self) -> bool {
matches!(self, MlxError::CommandBufferError(_))
}
}
static_assertions_send_sync!(MlxError);