| 79 | } |
| 80 | |
| 81 | TfLiteStatus DoPrepare(TfLiteContext* tfLiteContext, TfLiteDelegate* tfLiteDelegate) |
| 82 | { |
| 83 | TfLiteIntArray* supportedOperators = |
| 84 | static_cast<::armnnDelegate::Delegate*>(tfLiteDelegate->data_)->IdentifyOperatorsToDelegate(tfLiteContext); |
| 85 | |
| 86 | // ArmNN Delegate Registration |
| 87 | static const TfLiteRegistration kArmnnSubgraphRegistration = { |
| 88 | // ArmnnSubgraph Init |
| 89 | .init = [](TfLiteContext* tfLiteContext, const char* buffer, size_t length) -> void* { |
| 90 | armnn::IgnoreUnused(length); |
| 91 | const TfLiteDelegateParams* parameters = reinterpret_cast<const TfLiteDelegateParams*>(buffer); |
| 92 | |
| 93 | return static_cast<void*>(ArmnnSubgraph::Create( |
| 94 | tfLiteContext, parameters, static_cast<::armnnDelegate::Delegate*>(parameters->delegate->data_))); |
| 95 | }, |
| 96 | // ArmnnSubgraph Free |
| 97 | .free = [](TfLiteContext*, void* buffer) -> void { |
| 98 | if (buffer != nullptr) |
| 99 | { |
| 100 | delete static_cast<ArmnnSubgraph*>(buffer); |
| 101 | } |
| 102 | |
| 103 | }, |
| 104 | // ArmnnSubgraph Prepare |
| 105 | .prepare = [](TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode) -> TfLiteStatus { |
| 106 | if (tfLiteNode->user_data == nullptr) |
| 107 | { |
| 108 | return kTfLiteError; |
| 109 | } |
| 110 | return static_cast<ArmnnSubgraph*>(tfLiteNode->user_data)->Prepare(tfLiteContext); |
| 111 | }, |
| 112 | // ArmnnSubgraph Invoke |
| 113 | .invoke = [](TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode) -> TfLiteStatus { |
| 114 | if (tfLiteNode->user_data == nullptr) |
| 115 | { |
| 116 | return kTfLiteError; |
| 117 | } |
| 118 | |
| 119 | return static_cast<ArmnnSubgraph*>(tfLiteNode->user_data)->Invoke(tfLiteContext, tfLiteNode); |
| 120 | }, |
| 121 | |
| 122 | .profiling_string = nullptr, |
| 123 | .builtin_code = kTfLiteBuiltinDelegate, |
| 124 | .custom_name = "TfLiteArmNnDelegate", |
| 125 | .version = 1, |
| 126 | .registration_external = nullptr, |
| 127 | .async_kernel = nullptr, |
| 128 | .inplace_operator = 0 |
| 129 | }; |
| 130 | |
| 131 | const TfLiteStatus status = |
| 132 | tfLiteContext->ReplaceNodeSubsetsWithDelegateKernels( |
| 133 | tfLiteContext, kArmnnSubgraphRegistration, supportedOperators, tfLiteDelegate); |
| 134 | |
| 135 | TfLiteIntArrayFree(supportedOperators); |
| 136 | return status; |
| 137 | |
| 138 | } |
nothing calls this directly
no test coverage detected