# TfLiteDelegate


`#include <common.h>`

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

## Summary

| ### Public attributes ||
|---|---|
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-delegate#struct_tf_lite_delegate_1a4fee5ac7e1ba441d4c364c323930c8d3)(TfLiteContext *context, struct TfLiteDelegate *delegate, TfLiteBufferHandle buffer_handle, TfLiteTensor *tensor)` | `TfLiteStatus(*` Copy the data from delegate buffer handle into raw memory of the given `tensor`. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-delegate#struct_tf_lite_delegate_1a94f6b1d6e2c16a2e9944012a93f5e70d)(TfLiteContext *context, struct TfLiteDelegate *delegate, TfLiteBufferHandle buffer_handle, TfLiteTensor *tensor)` | `TfLiteStatus(*` Copy the data from raw memory of the given `tensor` to delegate buffer handle. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-delegate#struct_tf_lite_delegate_1a66da14187ba32cbfd8e65f5b06d7c0ea)(TfLiteContext *context, struct TfLiteDelegate *delegate, TfLiteBufferHandle *handle)` | `void(*` Free the Delegate Buffer Handle. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-delegate#struct_tf_lite_delegate_1aa5f8c5a4ceb1bfb26c4d33a33d2afd3a)(TfLiteContext *context, struct TfLiteDelegate *delegate)` | `TfLiteStatus(*` Invoked by `ModifyGraphWithDelegate`. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-delegate#struct_tf_lite_delegate_1a90d8880e87c24835171a14eff0a22d98` | `void *` Data that delegate needs to identify itself. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-delegate#struct_tf_lite_delegate_1a4c32a68d8020c616f31338a048f055c5` | `int64_t` Bitmask flags. See the comments in `TfLiteDelegateFlags`. |
| `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-delegate#struct_tf_lite_delegate_1a5a0db5f3d47c3a069c9b1d6dc7326e0e` | `struct https://developers.google.com/edge/api/tflite/c/struct/tf-lite-opaque-delegate-builder#struct_tf_lite_opaque_delegate_builder *` The opaque delegate builder associated with this object. |

## Public attributes

### CopyFromBufferHandle

```
TfLiteStatus(* TfLiteDelegate::CopyFromBufferHandle)(TfLiteContext *context, struct TfLiteDelegate *delegate, TfLiteBufferHandle buffer_handle, TfLiteTensor *tensor)
```
Copy 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(* TfLiteDelegate::CopyToBufferHandle)(TfLiteContext *context, struct TfLiteDelegate *delegate, TfLiteBufferHandle buffer_handle, TfLiteTensor *tensor)
```
Copy 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(* TfLiteDelegate::FreeBufferHandle)(TfLiteContext *context, struct TfLiteDelegate *delegate, TfLiteBufferHandle *handle)
```
Free 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(* TfLiteDelegate::Prepare)(TfLiteContext *context, struct TfLiteDelegate *delegate)
```
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 * TfLiteDelegate::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 TfLiteDelegate::flags
```
Bitmask flags. See the comments in `TfLiteDelegateFlags`.

### opaque_delegate_builder

```
struct TfLiteOpaqueDelegateBuilder * TfLiteDelegate::opaque_delegate_builder
```
The opaque delegate builder associated with this object.

If set then the TF Lite runtime will give precedence to this field. E.g. instead of invoking `Prepare` via the function pointer inside the `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-delegate#struct_tf_lite_delegate` object, the runtime will first check if the corresponding function pointer inside `opaque_delegate_builder` is set and if so invoke that.

If this field is non-null, then the `Prepare` field (of the `https://developers.google.com/edge/api/tflite/c/struct/tf-lite-delegate#struct_tf_lite_delegate`) should be null.