virtio_accel_coreml/
lib.rs1#![cfg_attr(not(target_os = "macos"), forbid(unsafe_code))]
11
12mod artifact;
13mod lower;
14mod mlprogram;
15
16pub use artifact::{ArtifactBuildError, CoreMlArtifact, FeatureRole};
17pub use lower::{COREML_TOSA_TARGET, LoweringError, supports_tosa_dtype, supports_tosa_operator};
18pub use mlprogram::COREML_TOSA_INTEGER_TARGET;
19
20use virtio_accel_core::{ArtifactFormat, TargetIdentity};
21
22pub const ARTIFACT_FORMAT: ArtifactFormat = match ArtifactFormat::new(0x434d_4c50) {
24 Some(format) => format,
25 None => panic!("Core ML artifact format must be nonzero"),
26};
27
28pub const TARGET_IDENTITY: TargetIdentity = TargetIdentity([
30 0x434f_5245,
31 0x4d4c_0001,
32 0x414e_4503,
33 0x4d41_434f,
34 0x000e_0000,
35 0,
36 0,
37 0,
38 0,
39 0,
40 0,
41 0,
42]);
43
44pub const REQUIRED_RESIDENT_BYTES: u64 = u64::MAX;
50
51#[derive(Clone, Copy, Debug, PartialEq, Eq)]
53pub enum InitError {
54 UnsupportedPlatform,
56 InvalidModelRoot,
58 NeuralEngineUnavailable,
60}
61
62impl std::fmt::Display for InitError {
63 fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
64 write!(formatter, "{self:?}")
65 }
66}
67
68impl std::error::Error for InitError {}
69
70#[cfg(target_os = "macos")]
71mod macos;
72#[cfg(target_os = "macos")]
73pub use macos::{
74 CoreMlAccelerator, CoreMlBuffer, CoreMlContext, CoreMlEvent, CoreMlProgram, CoreMlQueue,
75};
76
77#[cfg(not(target_os = "macos"))]
79#[derive(Clone, Copy, Debug, Default)]
80pub struct CoreMlAccelerator;
81
82#[cfg(not(target_os = "macos"))]
83impl CoreMlAccelerator {
84 pub fn new(_model_root: impl AsRef<std::path::Path>) -> Result<Self, InitError> {
86 Err(InitError::UnsupportedPlatform)
87 }
88
89 pub fn new_tosa() -> Result<Self, InitError> {
91 Err(InitError::UnsupportedPlatform)
92 }
93}