MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / Prepare

Function Prepare

tensorflow/lite/delegates/flex/delegate.cc:33–75  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

31namespace delegate {
32
33TfLiteStatus 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, &registration));
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
77TfLiteStatus CopyFromBufferHandle(TfLiteContext* context,
78 TfLiteDelegate* delegate,

Callers

nothing calls this directly

Calls 14

IsFlexOpFunction · 0.85
TfLiteIntArrayFreeFunction · 0.85
c_strMethod · 0.80
GetExecutionPlanMethod · 0.80
GetKernelFunction · 0.70
TfLiteIntArrayViewClass · 0.50
PrepareMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected