# TfLiteRegistration


`#include <common.h>`

`https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration` 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 `TfLiteOperator` which is a more ABI-stable equivalent.

| ### Public attributes ||
|---|---|
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration_1a1a98307d27c2ea9c39bcd4b48da2c4fa)(TfLiteContext *context, TfLiteNode *node)` | `struct TfLiteAsyncKernel *(*` Retrieves asynchronous kernel. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration_1a1a87f0c20fb23deaa745c25a4e84a08f` | `int32_t` Builtin codes. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration_1aacbf4a103db7471e451428f409481c20` | `const char *` Custom op name. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration_1acb0eef469a41aa024925e88d0486eca8)(TfLiteContext *context, void *buffer)` | `void(*` The pointer `buffer` is the data previously returned by an init invocation. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration_1a93d4631a7edc80ef73cbebb579ab3a93)(TfLiteContext *context, const char *buffer, size_t length)` | `void *(*` Initializes the op from serialized data. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration_1a343fad1f4d69c5007ec9da7f084b32d9` | `uint64_t` Indicates if an operator's output may safely overwrite its inputs. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration_1aa146bb84a2c7c75d3590d8e556ddfb97)(TfLiteContext *context, TfLiteNode *node)` | `TfLiteStatus(*` Execute the node (should read `node->inputs` and output to `node->outputs`). |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration_1a6ecffde4e6466f86aa8f28d25de553d7)(TfLiteContext *context, TfLiteNode *node)` | `TfLiteStatus(*` prepare is called when the inputs this node depends on have been resized. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration_1ae06b37ce1c0e8bd2445948fe68797b77)(const TfLiteContext *context, const TfLiteNode *node)` | `const char *(*` `profiling_string` is called during summarization of profiling information in order to group executions together. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration_1affc92e22ea6d407187850c9b7b2655b2` | `TfLiteOperator *` The external (i.e. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration_1a8b6739c5e206a0976db9bad12e150f86` | `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](https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration) 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's `custom_options`.
  - `length` is the size of the buffer.

<br />

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.

NOTE: For a Delegate kernel, returns `TfLiteKernelInitFailed()` if it fails on the initialization. This eventually causes user's API call to InterpreterBuilder::operator() or Interpreter::ModifyGraphWithDelegate() to return an error.

### 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

```
TfLiteOperator * TfLiteRegistration::registration_external
```
The external (i.e.

ABI-stable) version of `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration`. Since we can't use internal types (such as `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-context#struct_tf_lite_context`) for C API to maintain ABI stability. C API user will provide `TfLiteOperator` to implement custom ops. We keep it inside of `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-registration#struct_tf_lite_registration` 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.