| 21 | namespace tflite { |
| 22 | |
| 23 | CpuBackendContext* CpuBackendContext::GetFromContext(TfLiteContext* context) { |
| 24 | auto* external_context = static_cast<ExternalCpuBackendContext*>( |
| 25 | context->GetExternalContext(context, kTfLiteCpuBackendContext)); |
| 26 | |
| 27 | if (external_context == nullptr) { |
| 28 | TF_LITE_FATAL( |
| 29 | "ExternalCpuBackendContext isn't properly initialized during TFLite " |
| 30 | "interpreter initialization."); |
| 31 | } |
| 32 | |
| 33 | auto* cpu_backend_context = static_cast<CpuBackendContext*>( |
| 34 | external_context->internal_backend_context()); |
| 35 | if (cpu_backend_context == nullptr) { |
| 36 | // We do the lazy initialization here for the TfLiteInternalBackendContext |
| 37 | // that's wrapped inside ExternalCpuBackendContext. |
| 38 | cpu_backend_context = new CpuBackendContext(); |
| 39 | if (context->recommended_num_threads != -1) { |
| 40 | cpu_backend_context->SetMaxNumThreads(context->recommended_num_threads); |
| 41 | } |
| 42 | external_context->set_internal_backend_context( |
| 43 | std::unique_ptr<TfLiteInternalBackendContext>(cpu_backend_context)); |
| 44 | } |
| 45 | |
| 46 | return cpu_backend_context; |
| 47 | } |
| 48 | |
| 49 | CpuBackendContext::CpuBackendContext() |
| 50 | : TfLiteInternalBackendContext(), |
nothing calls this directly
no test coverage detected