Skip to main content

Engine

Struct Engine 

Source
pub struct Engine { /* private fields */ }
Expand description

RAII wrapper around one interpreter and session.

This type deliberately does not implement Send or Sync. The safe runtime keeps it on the model worker that created it.

Implementations§

Source§

impl Engine

Source

pub fn new(model: &[u8], config: Config) -> Result<Self, NativeError>

Create an engine from a model buffer.

Source

pub fn new_with_cache_file( model: &[u8], config: Config, cache_file: Option<&Path>, ) -> Result<Self, NativeError>

Create an engine with a persistent kernel cache loaded before session creation. The parent directory must already exist; no cache is used when None.

Source

pub fn effective_threads(&self) -> Option<usize>

Actual CPU thread count, or None for GPU sessions.

Source

pub fn inputs(&self) -> Result<Vec<TensorInfo>, NativeError>

Inspect all input tensors.

Source

pub fn outputs(&self) -> Result<Vec<TensorInfo>, NativeError>

Inspect all output tensors.

Source

pub fn write_input( &mut self, name: &str, data: &[f32], ) -> Result<(), NativeError>

Copy a named contiguous f32 input into MNN.

Source

pub fn write_input_index( &mut self, index: usize, data: &[f32], ) -> Result<(), NativeError>

Copy into a pre-resolved input slot; an invalid index is rejected by the bridge.

Source

pub fn resize_inputs( &mut self, shapes: &[(usize, &[i32])], ) -> Result<(), NativeError>

Resize every input in one transaction. Entries are (input_index, shape). All entries are checked before changing native tensors; native resize failures leave the session requiring another successful resize.

Source

pub fn save_cache(&mut self) -> Result<(), NativeError>

Persist kernel tuning data. A model without a configured cache is a no-op.

Source

pub fn run(&mut self) -> Result<(), NativeError>

Run one inference.

Source

pub fn read_output( &mut self, name: &str, data: &mut [f32], ) -> Result<(), NativeError>

Copy a named contiguous f32 output from MNN.

Source

pub fn read_output_index( &mut self, index: usize, data: &mut [f32], ) -> Result<(), NativeError>

Copy from a pre-resolved output slot; an invalid index is rejected by the bridge.

Trait Implementations§

Source§

impl Drop for Engine

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.