Skip to main content

TfLiteRegistration

Struct TfLiteRegistration 

Source
#[repr(C)]
pub struct TfLiteRegistration { pub init: Option<unsafe extern "C" fn(context: *mut TfLiteContext, buffer: *const c_char, length: usize) -> *mut c_void>, pub free: Option<unsafe extern "C" fn(context: *mut TfLiteContext, buffer: *mut c_void)>, pub prepare: Option<unsafe extern "C" fn(context: *mut TfLiteContext, node: *mut TfLiteNode) -> TfLiteStatus>, pub invoke: Option<unsafe extern "C" fn(context: *mut TfLiteContext, node: *mut TfLiteNode) -> TfLiteStatus>, pub profiling_string: Option<unsafe extern "C" fn(context: *const TfLiteContext, node: *const TfLiteNode) -> *const c_char>, pub builtin_code: i32, pub custom_name: *const c_char, pub version: c_int, pub registration_external: *mut TfLiteOperator, pub async_kernel: Option<unsafe extern "C" fn(context: *mut TfLiteContext, node: *mut TfLiteNode) -> *mut TfLiteAsyncKernel>, pub inplace_operator: u64, }
Expand description

TfLiteRegistration defines the implementation of an operation (a built-in op, custom op, or custom delegate kernel).

It is a struct containing “methods” (C function pointers) that will be invoked by the TF Lite runtime to evaluate instances of the operation.

See also TfLiteOperator which is a more ABI-stable equivalent.

Fields§

§init: Option<unsafe extern "C" fn(context: *mut TfLiteContext, buffer: *const c_char, length: usize) -> *mut c_void>

Initializes the op from serialized data. Called only once for the lifetime of the op, so any one-time allocations should be made here (unless they depend on tensor sizes).

  • If a built-in op: * buffer is the op’s params data (TfLiteLSTMParams*). * length is zero.
  • If custom op: * buffer is the op’s custom_options. * length is the size of the buffer.

Returns a type-punned (i.e. void*) opaque data (e.g. a primitive pointer or an instance of a struct).

The returned pointer will be stored with the node in the user_data field, accessible within prepare and invoke functions below.

NOTE: if the data is already in the desired format, simply implement this function to return nullptr and implement the free function to be a no-op.

§free: Option<unsafe extern "C" fn(context: *mut TfLiteContext, buffer: *mut c_void)>

The pointer buffer is the data previously returned by an init invocation.

§prepare: Option<unsafe extern "C" fn(context: *mut TfLiteContext, node: *mut TfLiteNode) -> TfLiteStatus>

prepare is called when the inputs this node depends on have been resized. context->ResizeTensor() can be called to request output tensors to be resized. Can be called multiple times for the lifetime of the op.

Returns kTfLiteOk on success.

§invoke: Option<unsafe extern "C" fn(context: *mut TfLiteContext, node: *mut TfLiteNode) -> TfLiteStatus>

Execute the node (should read node->inputs and output to node->outputs).

Returns kTfLiteOk on success.

§profiling_string: Option<unsafe extern "C" fn(context: *const TfLiteContext, node: *const TfLiteNode) -> *const c_char>

profiling_string is called during summarization of profiling information in order to group executions together. Providing a value here will cause a given op to appear multiple times is the profiling report. This is particularly useful for custom ops that can perform significantly different calculations depending on their user-data.

§builtin_code: i32

Builtin codes. If this kernel refers to a builtin this is the code of the builtin. This is so we can do marshaling to other frameworks like NN API.

Note: It is the responsibility of the registration binder to set this properly.

§custom_name: *const c_char

Custom op name. If the op is a builtin, this will be null.

Note: It is the responsibility of the registration binder to set this properly.

WARNING: This is an experimental interface that is subject to change.

§version: c_int

The version of the op. Note: It is the responsibility of the registration binder to set this properly.

§registration_external: *mut TfLiteOperator

The external (i.e. ABI-stable) version of TfLiteRegistration. Since we can’t use internal types (such as TfLiteContext) for C API to maintain ABI stability. C API user will provide TfLiteOperator to implement custom ops. We keep it inside of TfLiteRegistration and use it to route callbacks properly.

§async_kernel: Option<unsafe extern "C" fn(context: *mut TfLiteContext, node: *mut TfLiteNode) -> *mut TfLiteAsyncKernel>

Retrieves asynchronous kernel.

If the async_kernel field is nullptr, it means the operation described by this TfLiteRegistration object does not support asynchronous execution. Otherwise, the function that the field points to should only be called for delegate kernel nodes, i.e. node should be a delegate kernel node created by applying a delegate. If the function returns nullptr, that means that the underlying delegate does not support asynchronous execution for this node.

§inplace_operator: u64

Indicates if an operator’s output may safely overwrite its inputs. See the comments in TfLiteInPlaceOp.

Trait Implementations§

Source§

impl Clone for TfLiteRegistration

Source§

fn clone(&self) -> TfLiteRegistration

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TfLiteRegistration

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for TfLiteRegistration

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.