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

Method GetFromContext

tensorflow/lite/kernels/cpu_backend_context.cc:23–47  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

21namespace tflite {
22
23CpuBackendContext* 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
49CpuBackendContext::CpuBackendContext()
50 : TfLiteInternalBackendContext(),

Callers

nothing calls this directly

Calls 4

GetExternalContextMethod · 0.80
SetMaxNumThreadsMethod · 0.80

Tested by

no test coverage detected