TfLiteRegistration
#include <common.h>
TfLiteRegistration
defines the implementation of an operation (a built-in op, custom op, or custom delegate kernel).
Summary
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 TfLiteRegistrationExternal
which is a more ABI-stable equivalent.
Public attributes |
|
---|---|
async_kernel)(TfLiteContext *context, TfLiteNode *node)
|
struct TfLiteAsyncKernel *(*
Retrieves asynchronous kernel.
|
builtin_code
|
int32_t
Builtin codes.
|
custom_name
|
const char *
Custom op name.
|
free)(TfLiteContext *context, void *buffer)
|
void(*
The pointer
buffer is the data previously returned by an init invocation. |
init)(TfLiteContext *context, const char *buffer, size_t length)
|
void *(*
Initializes the op from serialized data.
|
inplace_operator
|
uint64_t
Indicates if an operator's output may safely overwrite its inputs.
|
invoke)(TfLiteContext *context, TfLiteNode *node)
|
TfLiteStatus(*
Execute the node (should read
node->inputs and output to node->outputs ). |
prepare)(TfLiteContext *context, TfLiteNode *node)
|
TfLiteStatus(*
prepare is called when the inputs this node depends on have been resized.
|
profiling_string)(const TfLiteContext *context, const TfLiteNode *node)
|
const char *(*
profiling_string is called during summarization of profiling information in order to group executions together. |
registration_external
|
TfLiteRegistrationExternal *
The external version of
TfLiteRegistration . |
version
|
int
The version of the op.
|
Public attributes
async_kernel
struct TfLiteAsyncKernel *(* TfLiteRegistration::async_kernel)(TfLiteContext *context, TfLiteNode *node)
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
.
builtin_code
int32_t TfLiteRegistration::builtin_code
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 char * TfLiteRegistration::custom_name
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.
free
void(* TfLiteRegistration::free)(TfLiteContext *context, void *buffer)
The pointer buffer
is the data previously returned by an init invocation.
init
void *(* TfLiteRegistration::init)(TfLiteContext *context, const char *buffer, size_t length)
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'scustom_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.
inplace_operator
uint64_t TfLiteRegistration::inplace_operator
Indicates if an operator's output may safely overwrite its inputs.
See the comments in TfLiteInPlaceOp
.
invoke
TfLiteStatus(* TfLiteRegistration::invoke)(TfLiteContext *context, TfLiteNode *node)
Execute the node (should read node->inputs
and output to node->outputs
).
Returns kTfLiteOk
on success.
prepare
TfLiteStatus(* TfLiteRegistration::prepare)(TfLiteContext *context, TfLiteNode *node)
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.
profiling_string
const char *(* TfLiteRegistration::profiling_string)(const TfLiteContext *context, const TfLiteNode *node)
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
.
registration_external
TfLiteRegistrationExternal * TfLiteRegistration::registration_external
The external 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 TfLiteRegistrationExternal
to implement custom ops. We keep it inside of TfLiteRegistration
and use it to route callbacks properly.
version
int TfLiteRegistration::version
The version of the op.
Note: It is the responsibility of the registration binder to set this properly.