pub mod mil;
pub mod mlpackage;
pub mod proto {
include!(concat!(env!("OUT_DIR"), "/coreml.rs"));
}
mod chip;
pub use chip::{ChipInfo, ane_available, chip_info, is_available};
#[cfg(any(target_os = "macos", target_os = "ios"))]
mod ffi;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub mod backend;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub use backend::CoremlExecutable;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ComputeUnits {
#[default]
All,
CpuOnly,
CpuAndGpu,
CpuAndNeuralEngine,
}
impl ComputeUnits {
pub(crate) fn code(self) -> i32 {
match self {
ComputeUnits::All => 0,
ComputeUnits::CpuOnly => 1,
ComputeUnits::CpuAndGpu => 2,
ComputeUnits::CpuAndNeuralEngine => 3,
}
}
}
#[derive(Debug)]
pub enum CoremlError {
Unsupported(String),
DynamicShape(String),
Io(std::io::Error),
Runtime(String),
TooLarge {
what: String,
bytes: usize,
limit: usize,
},
}
impl std::fmt::Display for CoremlError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
CoremlError::Unsupported(s) => write!(f, "unsupported for CoreML: {s}"),
CoremlError::DynamicShape(s) => write!(f, "dynamic shape unsupported: {s}"),
CoremlError::Io(e) => write!(f, "io error: {e}"),
CoremlError::Runtime(s) => write!(f, "CoreML runtime error: {s}"),
CoremlError::TooLarge { what, bytes, limit } => write!(
f,
"{what} is {bytes} bytes, exceeding the {limit}-byte CoreML limit \
(~{:.2} GiB). Weights ≥10 elements already live in weight.bin; \
reduce inline constants, fold ops, or split the graph.",
*limit as f64 / (1u64 << 30) as f64
),
}
}
}
impl std::error::Error for CoremlError {}
impl From<std::io::Error> for CoremlError {
fn from(e: std::io::Error) -> Self {
CoremlError::Io(e)
}
}
pub type Result<T> = std::result::Result<T, CoremlError>;