| 376 | } |
| 377 | |
| 378 | TfLiteStatus DelegatePrepare(TfLiteContext* context, TfLiteDelegate* delegate) { |
| 379 | const TfLiteRegistration kRegistration = { |
| 380 | // .init |
| 381 | [](TfLiteContext* context, const char* buffer, size_t) -> void* { |
| 382 | const auto* params = |
| 383 | reinterpret_cast<const TfLiteDelegateParams*>(buffer); |
| 384 | auto* gpu_delegate = GetGpuDelegate(params->delegate); |
| 385 | // Everything below should happen in prepare function call, but TFLite |
| 386 | // for whatever reason forbids that. |
| 387 | const auto status = gpu_delegate->Prepare(context, params); |
| 388 | if (status.ok()) return gpu_delegate; |
| 389 | context->ReportError(context, "TfLiteGpuDelegate Prepare: %s", |
| 390 | status.error_message().c_str()); |
| 391 | return nullptr; |
| 392 | }, |
| 393 | // .free |
| 394 | [](TfLiteContext*, void* buffer) -> void {}, |
| 395 | // .prepare |
| 396 | [](TfLiteContext* context, TfLiteNode* node) -> TfLiteStatus { |
| 397 | return node->user_data ? kTfLiteOk : kTfLiteError; |
| 398 | }, |
| 399 | // .invoke |
| 400 | [](TfLiteContext* context, TfLiteNode* node) -> TfLiteStatus { |
| 401 | const auto status = GetGpuDelegate(node)->Invoke(context); |
| 402 | if (status.ok()) return kTfLiteOk; |
| 403 | context->ReportError(context, "TfLiteGpuDelegate Invoke: %s", |
| 404 | status.error_message().c_str()); |
| 405 | return kTfLiteError; |
| 406 | }, |
| 407 | nullptr, // .profiling_string |
| 408 | 0, // .builtin_code |
| 409 | "TfLiteGpuDelegate", // .custom_name |
| 410 | 1, // .version |
| 411 | }; |
| 412 | TfLiteIntArray* ops_to_replace = GetOpsToReplace(context); |
| 413 | const auto status = context->ReplaceNodeSubsetsWithDelegateKernels( |
| 414 | context, kRegistration, ops_to_replace, delegate); |
| 415 | TfLiteIntArrayFree(ops_to_replace); |
| 416 | return status; |
| 417 | } |
| 418 | |
| 419 | TfLiteStatus DelegateCopyFromBufferHandle(TfLiteContext* context, |
| 420 | TfLiteDelegate* delegate, |
nothing calls this directly
no test coverage detected