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

Method GetDelegates

tensorflow/lite/tools/benchmark/benchmark_tflite_model.cc:582–637  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

580#endif
581
582BenchmarkTfLiteModel::TfLiteDelegatePtrMap BenchmarkTfLiteModel::GetDelegates()
583 const {
584 TfLiteDelegatePtrMap delegates;
585 if (params_.Get<bool>("use_gpu")) {
586#if defined(__ANDROID__)
587 TfLiteGpuDelegateOptions gpu_opts = TfLiteGpuDelegateOptionsDefault();
588 gpu_opts.metadata =
589 model_ ? TfLiteGpuDelegateGetModelMetadata(model_->GetModel())
590 : nullptr;
591 gpu_opts.compile_options.precision_loss_allowed =
592 params_.Get<bool>("gpu_precision_loss_allowed") ? 1 : 0;
593 int32_t gl_obj_type = params_.Get<int32_t>("gpu_gl_object_type");
594 // We overwrite the gl object type to the recommended value if the specified
595 // isn't valid.
596 if (!IsValidGLObjectTypeInGPU(gl_obj_type)) {
597 gl_obj_type = TFLITE_GL_OBJECT_TYPE_FASTEST;
598 }
599 gpu_opts.compile_options.preferred_gl_object_type = gl_obj_type;
600 gpu_opts.compile_options.dynamic_batch_enabled = 0;
601 Interpreter::TfLiteDelegatePtr delegate =
602 evaluation::CreateGPUDelegate(model_.get(), &gpu_opts);
603#else
604 TFLITE_LOG(WARN) << "The GPU delegate compile options aren't supported to "
605 "be benchmarked on non-Android platforms.";
606 Interpreter::TfLiteDelegatePtr delegate =
607 evaluation::CreateGPUDelegate(model_.get());
608#endif
609
610 if (!delegate) {
611 TFLITE_LOG(WARN) << "GPU acceleration is unsupported on this platform.";
612 } else {
613 delegates.emplace("GPU", std::move(delegate));
614 }
615 }
616 if (params_.Get<bool>("use_nnapi")) {
617 StatefulNnApiDelegate::Options options;
618 std::string accelerator_name =
619 params_.Get<std::string>("nnapi_accelerator_name");
620 if (!accelerator_name.empty()) {
621 options.accelerator_name = accelerator_name.c_str();
622 }
623 Interpreter::TfLiteDelegatePtr delegate =
624 evaluation::CreateNNAPIDelegate(options);
625 if (!delegate) {
626 TFLITE_LOG(WARN) << "NNAPI acceleration is unsupported on this platform.";
627 } else {
628 delegates.emplace("NNAPI", std::move(delegate));
629 }
630 } else if (!params_.Get<std::string>("nnapi_accelerator_name").empty()) {
631 TFLITE_LOG(WARN)
632 << "`--use_nnapi=true` must be set for the provided NNAPI accelerator ("
633 << params_.Get<std::string>("nnapi_accelerator_name")
634 << ") to be used.";
635 }
636 return delegates;
637}
638
639std::unique_ptr<tflite::OpResolver> BenchmarkTfLiteModel::GetOpResolver()

Callers

nothing calls this directly

Calls 10

IsValidGLObjectTypeInGPUFunction · 0.85
CreateNNAPIDelegateFunction · 0.85
c_strMethod · 0.80
CreateGPUDelegateFunction · 0.50
GetModelMethod · 0.45
getMethod · 0.45
emplaceMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected