| 172 | } |
| 173 | |
| 174 | TfLiteStatus DoPrepare(TfLiteOpaqueContext* tfLiteContext, TfLiteOpaqueDelegate* tfLiteDelegate, void* data) |
| 175 | { |
| 176 | // We are required to have the void* data parameter in the function signature, but we don't actually use it. |
| 177 | armnn::IgnoreUnused(data); |
| 178 | |
| 179 | TfLiteIntArray* supportedOperators = |
| 180 | static_cast<::armnnOpaqueDelegate::ArmnnOpaqueDelegate*> |
| 181 | (TfLiteOpaqueDelegateGetData(tfLiteDelegate))->IdentifyOperatorsToDelegate(tfLiteContext); |
| 182 | if(supportedOperators == nullptr) |
| 183 | { |
| 184 | return kTfLiteError; |
| 185 | } |
| 186 | |
| 187 | // ArmNN Opaque Delegate Registration |
| 188 | TfLiteRegistrationExternal* kernelRegistration = |
| 189 | TfLiteRegistrationExternalCreate(kTfLiteBuiltinDelegate, |
| 190 | "armnn_delegate", |
| 191 | /*version=*/OPAQUE_DELEGATE_MAJOR_VERSION, nullptr); |
| 192 | if(kernelRegistration == nullptr) |
| 193 | { |
| 194 | return kTfLiteError; |
| 195 | } |
| 196 | |
| 197 | TfLiteRegistrationExternalSetInit( |
| 198 | kernelRegistration, |
| 199 | [](TfLiteOpaqueContext* tfLiteContext, const char* buffer, size_t length) -> void* |
| 200 | { |
| 201 | armnn::IgnoreUnused(length); |
| 202 | const TfLiteOpaqueDelegateParams* parameters = |
| 203 | reinterpret_cast<const TfLiteOpaqueDelegateParams*>(buffer); |
| 204 | if(parameters == nullptr) |
| 205 | { |
| 206 | TF_LITE_OPAQUE_KERNEL_LOG(tfLiteContext, |
| 207 | "TfLiteArmnnOpaqueDelegate: Unable to get parameters."); |
| 208 | return nullptr; |
| 209 | } |
| 210 | |
| 211 | return static_cast<void*>( |
| 212 | ArmnnSubgraph::Create(tfLiteContext, |
| 213 | parameters, |
| 214 | static_cast<::armnnOpaqueDelegate::ArmnnOpaqueDelegate*>( |
| 215 | parameters->delegate->opaque_delegate_builder->data))); |
| 216 | } |
| 217 | ); |
| 218 | |
| 219 | TfLiteRegistrationExternalSetFree( |
| 220 | kernelRegistration, |
| 221 | [](TfLiteOpaqueContext* tfLiteContext, void* buffer) -> void |
| 222 | { |
| 223 | armnn::IgnoreUnused(tfLiteContext); |
| 224 | if (buffer != nullptr) |
| 225 | { |
| 226 | delete static_cast<ArmnnSubgraph*>(buffer); |
| 227 | } |
| 228 | } |
| 229 | ); |
| 230 | |
| 231 | TfLiteRegistrationExternalSetPrepare( |
nothing calls this directly
no test coverage detected