#![cfg_attr(not(target_os = "macos"), forbid(unsafe_code))]
mod artifact;
mod lower;
pub use artifact::{ArtifactBuildError, CoreMlArtifact, FeatureRole};
pub use lower::{COREML_TOSA_TARGET, LoweringError, supports_tosa_dtype, supports_tosa_operator};
use virtio_accel_core::{ArtifactFormat, TargetIdentity};
pub const ARTIFACT_FORMAT: ArtifactFormat = match ArtifactFormat::new(0x434d_4c50) {
Some(format) => format,
None => panic!("Core ML artifact format must be nonzero"),
};
pub const TARGET_IDENTITY: TargetIdentity = TargetIdentity([
0x434f_5245,
0x4d4c_0001,
0x414e_4503,
0x4d41_434f,
0x000e_0000,
0,
0,
0,
0,
0,
0,
0,
]);
pub const REQUIRED_RESIDENT_BYTES: u64 = u64::MAX;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum InitError {
UnsupportedPlatform,
InvalidModelRoot,
NeuralEngineUnavailable,
}
impl std::fmt::Display for InitError {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(formatter, "{self:?}")
}
}
impl std::error::Error for InitError {}
#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
pub use macos::{
CoreMlAccelerator, CoreMlBuffer, CoreMlContext, CoreMlEvent, CoreMlProgram, CoreMlQueue,
};
#[cfg(not(target_os = "macos"))]
#[derive(Clone, Copy, Debug, Default)]
pub struct CoreMlAccelerator;
#[cfg(not(target_os = "macos"))]
impl CoreMlAccelerator {
pub fn new(_model_root: impl AsRef<std::path::Path>) -> Result<Self, InitError> {
Err(InitError::UnsupportedPlatform)
}
pub fn new_tosa() -> Result<Self, InitError> {
Err(InitError::UnsupportedPlatform)
}
}