MCPcopy Create free account
hub / github.com/ARM-software/armnn / TfLiteExecutor

Method TfLiteExecutor

tests/ExecuteNetwork/TfliteExecutor.cpp:64–225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62}
63
64TfLiteExecutor::TfLiteExecutor(const ExecuteNetworkParams& params, armnn::IRuntime::CreationOptions runtimeOptions)
65 : m_Params(params)
66{
67 using namespace std::chrono_literals;
68 m_Model = tflite::FlatBufferModel::BuildFromFile(m_Params.m_ModelPath.c_str());
69 if (!m_Model)
70 {
71 LogAndThrow("Failed to load TfLite model from: " + m_Params.m_ModelPath);
72 }
73 m_TfLiteInterpreter = std::make_unique<Interpreter>();
74 tflite::ops::builtin::BuiltinOpResolver resolver;
75
76 tflite::InterpreterBuilder builder(*m_Model, resolver);
77
78 if (m_Params.m_TfLiteExecutor == ExecuteNetworkParams::TfLiteExecutor::ArmNNTfLiteOpaqueDelegate)
79 {
80#if defined(ARMNN_TFLITE_OPAQUE_DELEGATE)
81 if (builder(&m_TfLiteInterpreter) != kTfLiteOk)
82 {
83 LogAndThrow("Error loading the model into the TfLiteInterpreter.");
84 }
85 // Populate a DelegateOptions from the ExecuteNetworkParams.
86 armnnDelegate::DelegateOptions delegateOptions = m_Params.ToDelegateOptions();
87 delegateOptions.SetRuntimeOptions(runtimeOptions);
88 std::unique_ptr<TfLiteDelegate, decltype(&armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateDelete)>
89 theArmnnDelegate(armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateCreate(delegateOptions),
90 armnnOpaqueDelegate::TfLiteArmnnOpaqueDelegateDelete);
91
92 // Register armnn_delegate to TfLiteInterpreter
93 auto result = m_TfLiteInterpreter->ModifyGraphWithDelegate(std::move(theArmnnDelegate));
94 if (result != kTfLiteOk)
95 {
96 LogAndThrow("Could not register ArmNN TfLite Opaque Delegate to TfLiteInterpreter: " +
97 TfLiteStatusToString(result) + ".");
98 }
99#else
100 LogAndThrow("Not built with Arm NN Tensorflow-Lite opaque delegate support.");
101#endif
102 }
103 else if (m_Params.m_TfLiteExecutor == ExecuteNetworkParams::TfLiteExecutor::ArmNNTfLiteDelegate)
104 {
105#if defined(ARMNN_TFLITE_DELEGATE)
106 if (builder(&m_TfLiteInterpreter) != kTfLiteOk)
107 {
108 LogAndThrow("Error loading the model into the TfLiteInterpreter.");
109 }
110 // Create the Armnn Delegate
111 // Populate a DelegateOptions from the ExecuteNetworkParams.
112 armnnDelegate::DelegateOptions delegateOptions = m_Params.ToDelegateOptions();
113 delegateOptions.SetRuntimeOptions(runtimeOptions);
114 std::unique_ptr<TfLiteDelegate, decltype(&armnnDelegate::TfLiteArmnnDelegateDelete)>
115 theArmnnDelegate(armnnDelegate::TfLiteArmnnDelegateCreate(delegateOptions),
116 armnnDelegate::TfLiteArmnnDelegateDelete);
117 // Register armnn_delegate to TfLiteInterpreter
118 auto result = m_TfLiteInterpreter->ModifyGraphWithDelegate(std::move(theArmnnDelegate));
119 if (result != kTfLiteOk)
120 {
121 // We'll make an exception for kTfLiteApplicationError and allow it through in special circumstances.

Callers

nothing calls this directly

Calls 11

LogAndThrowFunction · 0.85
TfLiteStatusToStringFunction · 0.85
IsConstantTensorFunction · 0.85
ToDelegateOptionsMethod · 0.80
SetRuntimeOptionsMethod · 0.80
AllocateTensorsMethod · 0.80
EmptyOptionalClass · 0.50
c_strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected