use candle_core::DType;
use candle_core::Device;
use super::BackendSupport;
use super::DtypeBackendSupport;
use super::Support;
#[cfg(test)]
pub(crate) mod rules;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub enum Backend {
Cpu,
Metal,
Cuda,
}
impl Backend {
pub(crate) fn of(device: &Device) -> Self {
if device.is_cpu() {
Backend::Cpu
} else if device.is_metal() {
Backend::Metal
} else {
Backend::Cuda
}
}
pub(crate) fn name(self) -> &'static str {
match self {
Backend::Cpu => "cpu",
Backend::Metal => "metal",
Backend::Cuda => "cuda",
}
}
}
impl BackendSupport {
pub(crate) fn get(&self, backend: Backend) -> Support {
match backend {
Backend::Cpu => self.cpu,
Backend::Metal => self.metal,
Backend::Cuda => self.cuda,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct CellException {
pub dtype: DType,
pub backend: Backend,
pub status: Support,
pub reason: &'static str,
}
impl DtypeBackendSupport {
pub(crate) fn with_exceptions(mut self, exceptions: &[CellException]) -> Self {
for exception in exceptions {
let row = match exception.dtype {
DType::F16 => &mut self.f16,
DType::BF16 => &mut self.bf16,
_ => &mut self.f32,
};
let cell = match exception.backend {
Backend::Cpu => &mut row.cpu,
Backend::Metal => &mut row.metal,
Backend::Cuda => &mut row.cuda,
};
*cell = exception.status;
}
self
}
}