use super::backend::BackendUnavailable;
use super::coverage::{Coverage, Dispatch, Fidelity};
use super::formula::{Formula, Precision};
use super::manifest::Manifest;
#[cfg(all(feature = "metal", target_os = "macos"))]
#[allow(unsafe_code)]
mod kernels;
#[cfg(all(feature = "metal", target_os = "macos"))]
pub(super) use kernels::{gemm_f32, map_f32};
pub(super) struct Metal;
impl Manifest for Metal {
const DISPATCH: Dispatch = Dispatch::Offered;
fn coverage(formula: Formula) -> Coverage {
match formula {
Formula::Gemm | Formula::Map => Coverage::Serves {
fidelity: Fidelity::Envelope,
precisions: &[Precision::F32],
},
Formula::WindowProduct
| Formula::ReduceWindow
| Formula::BatchNormTraining
| Formula::BatchNormInference => Coverage::Absent,
}
}
fn compiled() -> bool {
cfg!(all(feature = "metal", target_os = "macos"))
}
fn status() -> Result<(), BackendUnavailable> {
if !cfg!(feature = "metal") {
return Err(BackendUnavailable::NotCompiled);
}
if !cfg!(target_os = "macos") {
return Err(BackendUnavailable::PlatformUnsupported);
}
#[cfg(all(feature = "metal", target_os = "macos"))]
{
kernels::status()
}
#[cfg(not(all(feature = "metal", target_os = "macos")))]
{
unreachable!("the cfg! guards above cover this build")
}
}
}