| 31 | namespace delegate { |
| 32 | |
| 33 | TfLiteStatus Prepare(TfLiteContext* context, TfLiteDelegate* delegate) { |
| 34 | // If the TensorFlow Lite thread count is explicitly configured, use it, |
| 35 | // otherwise rely on the default TensorFlow threading behavior. |
| 36 | tensorflow::SessionOptions session_options; |
| 37 | if (context->recommended_num_threads > 0) { |
| 38 | session_options.config.set_intra_op_parallelism_threads( |
| 39 | context->recommended_num_threads); |
| 40 | } |
| 41 | |
| 42 | auto status = reinterpret_cast<DelegateData*>(delegate->data_) |
| 43 | ->Prepare(session_options); |
| 44 | if (!status.ok()) { |
| 45 | context->ReportError(context, "Failed to initialize TensorFlow context: %s", |
| 46 | status.error_message().c_str()); |
| 47 | return kTfLiteError; |
| 48 | } |
| 49 | |
| 50 | // Get the nodes in the current execution plan. Interpreter owns this array. |
| 51 | TfLiteIntArray* plan; |
| 52 | TF_LITE_ENSURE_STATUS(context->GetExecutionPlan(context, &plan)); |
| 53 | |
| 54 | // Add all custom ops starting with "Flex" to list of supported nodes. |
| 55 | std::vector<int> supported_nodes; |
| 56 | for (int node_index : TfLiteIntArrayView(plan)) { |
| 57 | TfLiteNode* node; |
| 58 | TfLiteRegistration* registration; |
| 59 | TF_LITE_ENSURE_STATUS(context->GetNodeAndRegistration( |
| 60 | context, node_index, &node, ®istration)); |
| 61 | |
| 62 | if (IsFlexOp(registration->custom_name)) { |
| 63 | supported_nodes.push_back(node_index); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | // Request TFLite to partition the graph and make kernels for each independent |
| 68 | // node sub set. |
| 69 | TfLiteIntArray* size_and_nodes = |
| 70 | ConvertVectorToTfLiteIntArray(supported_nodes); |
| 71 | context->ReplaceNodeSubsetsWithDelegateKernels(context, GetKernel(), |
| 72 | size_and_nodes, delegate); |
| 73 | TfLiteIntArrayFree(size_and_nodes); |
| 74 | return kTfLiteOk; |
| 75 | } |
| 76 | |
| 77 | TfLiteStatus CopyFromBufferHandle(TfLiteContext* context, |
| 78 | TfLiteDelegate* delegate, |
nothing calls this directly
no test coverage detected