Minor doc update to use TfLiteIntArray better
PiperOrigin-RevId: 316701561 Change-Id: If14f772f0053eb4ecb0bc225cc11e93e0f07adb0
This commit is contained in:
parent
e178928ea8
commit
9ee6864c2c
@ -85,6 +85,8 @@ To see it in code, let's define a delegate and call it `MyDelegate`, which can
|
|||||||
execute Conv2D and Mean operations faster.
|
execute Conv2D and Mean operations faster.
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
|
#include "tensorflow/lite/util.h"
|
||||||
|
|
||||||
// This is where the execution of the operations or whole graph happens.
|
// This is where the execution of the operations or whole graph happens.
|
||||||
// The class below has an empty implementation just as a guideline
|
// The class below has an empty implementation just as a guideline
|
||||||
// on the structure.
|
// on the structure.
|
||||||
@ -156,8 +158,7 @@ TfLiteRegistration GetMyDelegateNodeRegistration() {
|
|||||||
TfLiteStatus DelegatePrepare(TfLiteContext* context, TfLiteDelegate* delegate) {
|
TfLiteStatus DelegatePrepare(TfLiteContext* context, TfLiteDelegate* delegate) {
|
||||||
// Claim all nodes that can be evaluated by the delegate and ask the
|
// Claim all nodes that can be evaluated by the delegate and ask the
|
||||||
// framework to update the graph with delegate kernel instead.
|
// framework to update the graph with delegate kernel instead.
|
||||||
// Reserve 1 element, since we need first element to be size.
|
std::vector<int> supported_nodes;
|
||||||
std::vector<int> supported_nodes(1);
|
|
||||||
TfLiteIntArray* plan;
|
TfLiteIntArray* plan;
|
||||||
TF_LITE_ENSURE_STATUS(context->GetExecutionPlan(context, &plan));
|
TF_LITE_ENSURE_STATUS(context->GetExecutionPlan(context, &plan));
|
||||||
TfLiteNode* node;
|
TfLiteNode* node;
|
||||||
@ -169,17 +170,19 @@ TfLiteStatus DelegatePrepare(TfLiteContext* context, TfLiteDelegate* delegate) {
|
|||||||
supported_nodes.push_back(node_index);
|
supported_nodes.push_back(node_index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Set first element to the number of nodes to replace.
|
|
||||||
supported_nodes[0] = supported_nodes.size() - 1;
|
|
||||||
TfLiteRegistration my_delegate_kernel_registration =
|
TfLiteRegistration my_delegate_kernel_registration =
|
||||||
GetMyDelegateNodeRegistration();
|
GetMyDelegateNodeRegistration();
|
||||||
|
|
||||||
// This call split the graphs into subgraphs, for subgraphs that can be
|
// This call split the graphs into subgraphs, for subgraphs that can be
|
||||||
// handled by the delegate, it will replace it with a
|
// handled by the delegate, it will replace it with a
|
||||||
// 'my_delegate_kernel_registration'
|
// 'my_delegate_kernel_registration'
|
||||||
return context->ReplaceNodeSubsetsWithDelegateKernels(
|
TfLiteIntArray* supported_nodes_int_array =
|
||||||
|
::tflite::ConvertVectorToTfLiteIntArray(supported_nodes);
|
||||||
|
auto status = context->ReplaceNodeSubsetsWithDelegateKernels(
|
||||||
context, my_delegate_kernel_registration,
|
context, my_delegate_kernel_registration,
|
||||||
reinterpret_cast<TfLiteIntArray*>(supported_nodes.data()), delegate);
|
supported_nodes_int_array, delegate);
|
||||||
|
TfLiteIntArrayFree(supported_nodes_int_array);
|
||||||
|
return status
|
||||||
}
|
}
|
||||||
|
|
||||||
void FreeBufferHandle(TfLiteContext* context, TfLiteDelegate* delegate,
|
void FreeBufferHandle(TfLiteContext* context, TfLiteDelegate* delegate,
|
||||||
|
Loading…
Reference in New Issue
Block a user