# TfLiteOpaqueDelegateBuilder


`#include <common.h>`

`https://developers.google.com/edge/api/tflite/c/struct/tf-lite-opaque-delegate-builder#struct_tf_lite_opaque_delegate_builder` is used for constructing `TfLiteOpaqueDelegate`, see `TfLiteOpaqueDelegateCreate` in [c_api_opaque.h](https://developers.google.com/edge/api/tflite/c/c/api-opaque-8h-source#c__api__opaque_8h_source).

## Summary

NOTE: This struct is not ABI stable.

For forward source compatibility `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-opaque-delegate-builder#struct_tf_lite_opaque_delegate_builder` objects should be brace-initialized, so that all fields (including any that might be added in the future) get zero-initialized. The purpose of each field is exactly the same as with `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-delegate#struct_tf_lite_delegate`.

NOTE: This type is part of the TensorFlow Lite Extension APIs. We reserve the right to make changes to this API in future releases, potentially including non-backwards-compatible changes, on a different schedule than for the other TensorFlow Lite APIs. See <https://www.tensorflow.org/guide/versions#separate_version_number_for_tensorflow_lite_extension_apis>.

| ### Public attributes ||
|---|---|
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-opaque-delegate-builder#struct_tf_lite_opaque_delegate_builder_1a5e9463b374756c6de8431be431175540)(TfLiteOpaqueContext *context, TfLiteOpaqueDelegate *delegate, void *data, TfLiteBufferHandle buffer_handle, TfLiteOpaqueTensor *tensor)` | `TfLiteStatus(*` Copies the data from delegate buffer handle into raw memory of the given `tensor`. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-opaque-delegate-builder#struct_tf_lite_opaque_delegate_builder_1a827f5c9feda6c97979f29db928ef451b)(TfLiteOpaqueContext *context, TfLiteOpaqueDelegate *delegate, void *data, TfLiteBufferHandle buffer_handle, TfLiteOpaqueTensor *tensor)` | `TfLiteStatus(*` Copies the data from raw memory of the given `tensor` to delegate buffer handle. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-opaque-delegate-builder#struct_tf_lite_opaque_delegate_builder_1aa92d66ba53e7b29899ea59c2cc2ad5e7)(TfLiteOpaqueContext *context, TfLiteOpaqueDelegate *delegate, void *data, TfLiteBufferHandle *handle)` | `void(*` Frees the Delegate Buffer Handle. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-opaque-delegate-builder#struct_tf_lite_opaque_delegate_builder_1a02bf326e9df6018285ade841c4f0363a)(TfLiteOpaqueContext *context, TfLiteOpaqueDelegate *delegate, void *data)` | `TfLiteStatus(*` Invoked by ModifyGraphWithDelegate. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-opaque-delegate-builder#struct_tf_lite_opaque_delegate_builder_1a2c974a9e2ba6efabd530e3534f65176a` | `void *` Data that delegate needs to identify itself. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-opaque-delegate-builder#struct_tf_lite_opaque_delegate_builder_1a87d94c234238c4f44fd353ff5b7c91eb` | `int64_t` Bitmask flags. See the comments in `TfLiteDelegateFlags`. |

## Public attributes

### CopyFromBufferHandle

```
TfLiteStatus(* TfLiteOpaqueDelegateBuilder::CopyFromBufferHandle)(TfLiteOpaqueContext *context, TfLiteOpaqueDelegate *delegate, void *data, TfLiteBufferHandle buffer_handle, TfLiteOpaqueTensor *tensor)
```
Copies the data from delegate buffer handle into raw memory of the given `tensor`.

Note that the delegate is allowed to allocate the raw bytes as long as it follows the rules for kTfLiteDynamic tensors, in which case this cannot be null.

### CopyToBufferHandle

```
TfLiteStatus(* TfLiteOpaqueDelegateBuilder::CopyToBufferHandle)(TfLiteOpaqueContext *context, TfLiteOpaqueDelegate *delegate, void *data, TfLiteBufferHandle buffer_handle, TfLiteOpaqueTensor *tensor)
```
Copies the data from raw memory of the given `tensor` to delegate buffer handle.

This can be null if the delegate doesn't use its own buffer.

### FreeBufferHandle

```
void(* TfLiteOpaqueDelegateBuilder::FreeBufferHandle)(TfLiteOpaqueContext *context, TfLiteOpaqueDelegate *delegate, void *data, TfLiteBufferHandle *handle)
```
Frees the Delegate Buffer Handle.

Note: This only frees the handle, but this doesn't release the underlying resource (e.g. textures). The resources are either owned by application layer or the delegate. This can be null if the delegate doesn't use its own buffer.

### Prepare

```
TfLiteStatus(* TfLiteOpaqueDelegateBuilder::Prepare)(TfLiteOpaqueContext *context, TfLiteOpaqueDelegate *delegate, void *data)
```
Invoked by ModifyGraphWithDelegate.

This prepare is called, giving the delegate a view of the current graph through `TfLiteContext*`. It typically will look at the nodes and call `ReplaceNodeSubsetsWithDelegateKernels()` to ask the TensorFlow lite runtime to create macro-nodes to represent delegated subgraphs of the original graph.

### data

```
void * TfLiteOpaqueDelegateBuilder::data
```
Data that delegate needs to identify itself.

This data is owned by the delegate. The delegate is owned in the user code, so the delegate is responsible for deallocating this when it is destroyed.

### flags

```
int64_t TfLiteOpaqueDelegateBuilder::flags
```
Bitmask flags. See the comments in `TfLiteDelegateFlags`.