use core::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SparseWeightRowsError {
SizeOverflow,
AllocationTooLarge {
requested: usize,
cap: usize,
},
HostAllocationFailed {
requested: usize,
},
}
impl fmt::Display for SparseWeightRowsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::SizeOverflow => f.write_str("sparse Metal weight-row size overflow"),
Self::AllocationTooLarge { requested, cap } => write!(
f,
"sparse Metal weight rows require {requested} bytes, cap {cap} bytes"
),
Self::HostAllocationFailed { requested } => write!(
f,
"sparse Metal weight-row host allocation failed for {requested} bytes"
),
}
}
}
impl std::error::Error for SparseWeightRowsError {}
pub(super) fn allocation_error(error: j2k_core::HostAllocationError) -> SparseWeightRowsError {
SparseWeightRowsError::HostAllocationFailed {
requested: error.requested_bytes(),
}
}