blob: 6e1a91f9e473071fb627730152a9e37e74833d9a [file] [log] [blame]
Sadik Armagan3c24f432020-10-19 17:35:30 +01001//
2// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include <armnn_delegate.hpp>
Sadik Armagan62483be2020-10-23 17:14:43 +01007
Matthew Sloyanac001ee2021-02-03 10:43:04 +00008#include "Version.hpp"
9
Sadik Armagan62483be2020-10-23 17:14:43 +010010#include "Activation.hpp"
11#include "ArgMinMax.hpp"
12#include "BatchSpace.hpp"
13#include "Comparison.hpp"
14#include "Convolution.hpp"
15#include "Control.hpp"
16#include "ElementwiseBinary.hpp"
17#include "ElementwiseUnary.hpp"
18#include "Fill.hpp"
19#include "FullyConnected.hpp"
20#include "Gather.hpp"
Teresa Charlind5c0ed22022-04-25 18:23:41 +010021#include "GatherNd.hpp"
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000022#include "LogicalBinary.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010023#include "Lstm.hpp"
24#include "Normalization.hpp"
Matthew Sloyana7a12f52021-05-06 10:05:28 +010025#include "Pack.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010026#include "Pad.hpp"
27#include "Pooling.hpp"
James Conroy39825482021-05-27 17:44:50 +010028#include "Prelu.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010029#include "Quantization.hpp"
30#include "Redefine.hpp"
Sadik Armagana2747482021-02-09 10:28:54 +000031#include "Reduce.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010032#include "Resize.hpp"
33#include "Round.hpp"
Keith Davis0176fd82021-06-01 17:36:32 +010034#include "Shape.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010035#include "Slice.hpp"
36#include "Softmax.hpp"
37#include "SpaceDepth.hpp"
Sadik Armagan34fa1bd2020-11-27 12:40:52 +000038#include "Split.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010039#include "Transpose.hpp"
Narumol Prangnawarat7684b182021-08-12 14:48:15 +010040#include "UnidirectionalSequenceLstm.hpp"
Kevin May8ab2d7a2021-05-07 09:32:51 +010041#include "Unpack.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010042
Colm Donelan3e32a872021-10-04 22:55:37 +010043#include <armnnUtils/Filesystem.hpp>
Jan Eilers17d34da2021-12-08 16:15:12 +000044#include <armnn/utility/Timer.hpp>
Sadik Armagan62483be2020-10-23 17:14:43 +010045#include <flatbuffers/flatbuffers.h>
46#include <tensorflow/lite/context_util.h>
Jim Flynn4b2f3472021-10-13 21:20:07 +010047#include <tensorflow/lite/schema/schema_generated.h>
Sadik Armagan62483be2020-10-23 17:14:43 +010048
Sadik Armagan3c24f432020-10-19 17:35:30 +010049#include <algorithm>
Matthew Sloyanac001ee2021-02-03 10:43:04 +000050#include <iostream>
Sadik Armagan62483be2020-10-23 17:14:43 +010051#include <sstream>
Sadik Armagan3c24f432020-10-19 17:35:30 +010052
53namespace armnnDelegate
54{
55
Sadik Armagan62483be2020-10-23 17:14:43 +010056DelegateOptions TfLiteArmnnDelegateOptionsDefault()
57{
58 DelegateOptions options(armnn::Compute::CpuRef);
59 return options;
60}
61
62TfLiteDelegate* TfLiteArmnnDelegateCreate(armnnDelegate::DelegateOptions options)
63{
64 auto* armnnDelegate = new ::armnnDelegate::Delegate(options);
65 return armnnDelegate->GetDelegate();
66}
67
68void TfLiteArmnnDelegateDelete(TfLiteDelegate* tfLiteDelegate)
69{
70 if (tfLiteDelegate != nullptr)
71 {
72 delete static_cast<::armnnDelegate::Delegate*>(tfLiteDelegate->data_);
73 }
74}
75
76TfLiteStatus DoPrepare(TfLiteContext* tfLiteContext, TfLiteDelegate* tfLiteDelegate)
77{
78 TfLiteIntArray* supportedOperators =
79 static_cast<::armnnDelegate::Delegate*>(tfLiteDelegate->data_)->IdentifyOperatorsToDelegate(tfLiteContext);
80
81 // ArmNN Delegate Registration
82 static const TfLiteRegistration kArmnnSubgraphRegistration = {
83 // ArmnnSubgraph Init
84 .init = [](TfLiteContext* tfLiteContext, const char* buffer, size_t length) -> void* {
Finn Williams6f9f9902020-11-13 13:23:15 +000085 armnn::IgnoreUnused(length);
Sadik Armagan62483be2020-10-23 17:14:43 +010086 const TfLiteDelegateParams* parameters = reinterpret_cast<const TfLiteDelegateParams*>(buffer);
87
88 return static_cast<void*>(ArmnnSubgraph::Create(
89 tfLiteContext, parameters, static_cast<::armnnDelegate::Delegate*>(parameters->delegate->data_)));
90 },
91 // ArmnnSubgraph Free
92 .free = [](TfLiteContext* tfLiteContext, void* buffer) -> void {
Finn Williams6f9f9902020-11-13 13:23:15 +000093 armnn::IgnoreUnused(tfLiteContext);
Sadik Armagan62483be2020-10-23 17:14:43 +010094 if (buffer != nullptr)
95 {
96 delete static_cast<ArmnnSubgraph*>(buffer);
97 }
98 },
99 // ArmnnSubgraph Prepare
100 .prepare = [](TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode) -> TfLiteStatus {
101 if (tfLiteNode->user_data == nullptr)
102 {
103 return kTfLiteError;
104 }
Sadik Armagan62483be2020-10-23 17:14:43 +0100105 return static_cast<ArmnnSubgraph*>(tfLiteNode->user_data)->Prepare(tfLiteContext);
106 },
107 // ArmnnSubgraph Invoke
108 .invoke = [](TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode) -> TfLiteStatus {
109 if (tfLiteNode->user_data == nullptr)
110 {
111 return kTfLiteError;
112 }
113
114 return static_cast<ArmnnSubgraph*>(tfLiteNode->user_data)->Invoke(tfLiteContext, tfLiteNode);
115 },
116
117 .profiling_string = nullptr,
118 .builtin_code = kTfLiteBuiltinDelegate,
119 .custom_name = "TfLiteArmNnDelegate",
120 .version = 1,
121 };
122
123 const TfLiteStatus status =
124 tfLiteContext->ReplaceNodeSubsetsWithDelegateKernels(
125 tfLiteContext, kArmnnSubgraphRegistration, supportedOperators, tfLiteDelegate);
126
127 TfLiteIntArrayFree(supportedOperators);
128 return status;
129
130}
131
Sadik Armagan3c24f432020-10-19 17:35:30 +0100132Delegate::Delegate(armnnDelegate::DelegateOptions options)
133 : m_Runtime(nullptr, nullptr),
134 m_Options(std::move(options))
135{
Jan Eilers2cd18472020-12-15 10:42:38 +0000136 // Configures logging for ARMNN
137 if (options.IsLoggingEnabled())
138 {
139 armnn::ConfigureLogging(true, true, options.GetLoggingSeverity());
140 }
141
Sadik Armagan3c24f432020-10-19 17:35:30 +0100142 // Create ArmNN Runtime
Jan Eilersb1c62f12021-10-26 14:56:47 +0100143 m_Runtime = armnn::IRuntime::Create(options.GetRuntimeOptions());
Sadik Armagan3c24f432020-10-19 17:35:30 +0100144
145 std::vector<armnn::BackendId> backends;
Sadik Armagan3c24f432020-10-19 17:35:30 +0100146 if (m_Runtime)
147 {
148 const armnn::BackendIdSet supportedDevices = m_Runtime->GetDeviceSpec().GetSupportedBackends();
149 for (auto& backend : m_Options.GetBackends())
150 {
151 if (std::find(supportedDevices.cbegin(), supportedDevices.cend(), backend) == supportedDevices.cend())
152 {
Sadik Armagan0534e032020-10-27 17:30:18 +0000153 TFLITE_LOG_PROD(tflite::TFLITE_LOG_INFO,
Sadik Armagan3c24f432020-10-19 17:35:30 +0100154 "TfLiteArmnnDelegate: Requested unknown backend %s", backend.Get().c_str());
155 }
156 else
157 {
158 backends.push_back(backend);
159 }
160 }
161 }
162
163 if (backends.empty())
164 {
165 // No known backend specified
166 throw armnn::InvalidArgumentException("TfLiteArmnnDelegate: No known backend specified.");
167 }
168 m_Options.SetBackends(backends);
169
170 TFLITE_LOG_PROD_ONCE(tflite::TFLITE_LOG_INFO, "TfLiteArmnnDelegate: Created TfLite ArmNN delegate.");
171}
172
Sadik Armagan62483be2020-10-23 17:14:43 +0100173TfLiteIntArray* Delegate::IdentifyOperatorsToDelegate(TfLiteContext* tfLiteContext)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100174{
175 TfLiteIntArray* executionPlan = nullptr;
176 if (tfLiteContext->GetExecutionPlan(tfLiteContext, &executionPlan) != kTfLiteOk)
177 {
178 TF_LITE_KERNEL_LOG(tfLiteContext, "TfLiteArmnnDelegate: Unable to get graph execution plan.");
179 return nullptr;
180 }
181
Sadik Armagan62483be2020-10-23 17:14:43 +0100182 // Delegate data with null network
183 DelegateData delegateData(m_Options.GetBackends());
Sadik Armagan3c24f432020-10-19 17:35:30 +0100184
185 TfLiteIntArray* nodesToDelegate = TfLiteIntArrayCreate(executionPlan->size);
186 nodesToDelegate->size = 0;
Sadik Armaganbfa767c2022-02-09 14:58:03 +0000187
188 std::set<int32_t> unsupportedOperators;
189
Sadik Armagan3c24f432020-10-19 17:35:30 +0100190 for (int i = 0; i < executionPlan->size; ++i)
191 {
192 const int nodeIndex = executionPlan->data[i];
193
194 // If TfLite nodes can be delegated to ArmNN
195 TfLiteNode* tfLiteNode = nullptr;
196 TfLiteRegistration* tfLiteRegistration = nullptr;
197 if (tfLiteContext->GetNodeAndRegistration(
198 tfLiteContext, nodeIndex, &tfLiteNode, &tfLiteRegistration) != kTfLiteOk)
199 {
200 TF_LITE_KERNEL_LOG(tfLiteContext,
201 "TfLiteArmnnDelegate: Unable to get node and registration for node %d.",
202 nodeIndex);
203 continue;
204 }
205
206 if (ArmnnSubgraph::VisitNode(
Sadik Armagan62483be2020-10-23 17:14:43 +0100207 delegateData, tfLiteContext, tfLiteRegistration, tfLiteNode, nodeIndex) != kTfLiteOk)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100208 {
209 // node is not supported by ArmNN
Sadik Armaganbfa767c2022-02-09 14:58:03 +0000210 unsupportedOperators.insert(tfLiteRegistration->builtin_code);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100211 continue;
212 }
213
214 nodesToDelegate->data[nodesToDelegate->size++] = nodeIndex;
215 }
216
Sadik Armaganbfa767c2022-02-09 14:58:03 +0000217 for (std::set<int32_t>::iterator it=unsupportedOperators.begin(); it!=unsupportedOperators.end(); ++it)
218 {
219 TF_LITE_KERNEL_LOG(tfLiteContext,
220 "Operator %s [%d] is not supported by armnn_delegate.",
221 tflite::EnumNameBuiltinOperator(tflite::BuiltinOperator(*it)),
222 *it);
223 }
224
Sadik Armagan62483be2020-10-23 17:14:43 +0100225 std::sort(&nodesToDelegate->data[0], &nodesToDelegate->data[nodesToDelegate->size]);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100226 return nodesToDelegate;
227}
228
229TfLiteDelegate* Delegate::GetDelegate()
230{
231 return &m_Delegate;
232}
233
Matthew Sloyanac001ee2021-02-03 10:43:04 +0000234const std::string Delegate::GetVersion()
235{
236 return DELEGATE_VERSION;
237}
238
Sadik Armagan62483be2020-10-23 17:14:43 +0100239TfLiteStatus ArmnnSubgraph::AddInputLayer(DelegateData& delegateData,
240 TfLiteContext* tfLiteContext,
241 const TfLiteIntArray* inputs,
242 std::vector<armnn::BindingPointInfo>& inputBindings)
243{
Finn Williams6f9f9902020-11-13 13:23:15 +0000244 const size_t numInputs = static_cast<size_t>(inputs->size);
Sadik Armagan62483be2020-10-23 17:14:43 +0100245 for (unsigned int i = 0; i < numInputs; ++i)
246 {
247 const int32_t tensorId = inputs->data[i];
248 const TfLiteTensor tensor = tfLiteContext->tensors[tensorId];
Sadik Armagan6e36a642020-11-10 21:18:41 +0000249 // Do not create bindings for constant inputs
250 if (tensor.allocation_type == kTfLiteMmapRo)
251 {
252 continue;
253 }
Sadik Armagan62483be2020-10-23 17:14:43 +0100254
255 auto bindingId = static_cast<armnn::LayerBindingId>((tensorId));
256 armnn::IConnectableLayer* layer = delegateData.m_Network->AddInputLayer(bindingId);
257
258 auto tensorInfo = GetTensorInfoForTfLiteTensor(tensor);
259 armnn::IOutputSlot& outputSlot = layer->GetOutputSlot(0);
260 outputSlot.SetTensorInfo(tensorInfo);
261
262 // Store for creating connections
Finn Williams6f9f9902020-11-13 13:23:15 +0000263 delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)] = &outputSlot;
Sadik Armagan62483be2020-10-23 17:14:43 +0100264
Sadik Armagan6e36a642020-11-10 21:18:41 +0000265 inputBindings.push_back(std::make_pair(bindingId, tensorInfo));
Sadik Armagan62483be2020-10-23 17:14:43 +0100266 }
Sadik Armagan6e36a642020-11-10 21:18:41 +0000267
Sadik Armagan62483be2020-10-23 17:14:43 +0100268 return kTfLiteOk;
269}
270
271TfLiteStatus ArmnnSubgraph::AddOutputLayer(DelegateData& delegateData,
272 TfLiteContext* tfLiteContext,
273 const TfLiteIntArray* outputs,
274 std::vector<armnn::BindingPointInfo>& outputBindings)
275{
Finn Williams6f9f9902020-11-13 13:23:15 +0000276 const size_t numOutputs = static_cast<size_t>(outputs->size);
Sadik Armagan62483be2020-10-23 17:14:43 +0100277 for (unsigned int i = 0; i < numOutputs; ++i)
278 {
279 const int32_t tensorId = outputs->data[i];
280 const TfLiteTensor tensor = tfLiteContext->tensors[tensorId];
281
282 auto bindingId = static_cast<armnn::LayerBindingId>((tensorId));
283 armnn::IConnectableLayer* layer = delegateData.m_Network->AddOutputLayer(bindingId);
284
285 auto tensorInfo = GetTensorInfoForTfLiteTensor(tensor);
Finn Williams6f9f9902020-11-13 13:23:15 +0000286 ARMNN_ASSERT(delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)] != nullptr);
287 delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)]->Connect(layer->GetInputSlot(0));
Sadik Armagan62483be2020-10-23 17:14:43 +0100288 outputBindings.push_back(std::make_pair(bindingId, tensorInfo));
289 }
290
291 return kTfLiteOk;
292}
293
Sadik Armagan3c24f432020-10-19 17:35:30 +0100294ArmnnSubgraph* ArmnnSubgraph::Create(TfLiteContext* tfLiteContext,
295 const TfLiteDelegateParams* parameters,
296 const Delegate* delegate)
297{
Jan Eilers17d34da2021-12-08 16:15:12 +0000298 const auto startTime = armnn::GetTimeNow();
299 ARMNN_LOG(info) << "ArmnnSubgraph creation";
300
Sadik Armagan3c24f432020-10-19 17:35:30 +0100301 TfLiteIntArray* executionPlan;
302 if (tfLiteContext->GetExecutionPlan(tfLiteContext, &executionPlan) != kTfLiteOk)
303 {
304 return nullptr;
305 }
306
Sadik Armagan62483be2020-10-23 17:14:43 +0100307 // Initialize DelegateData holds network and output slots information
308 DelegateData delegateData(delegate->m_Options.GetBackends());
309
310 // Build ArmNN Network
Mike Kelly80512b02022-05-16 23:10:42 +0100311 armnn::NetworkOptions networkOptions = delegate->m_Options.GetOptimizerOptions().m_ModelOptions;
Sadik Armagan3c24f432020-10-19 17:35:30 +0100312 armnn::NetworkId networkId;
Sadik Armagan62483be2020-10-23 17:14:43 +0100313 delegateData.m_Network = armnn::INetwork::Create(networkOptions);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100314
Sadik Armagan6e36a642020-11-10 21:18:41 +0000315 delegateData.m_OutputSlotForNode = std::vector<armnn::IOutputSlot*>(tfLiteContext->tensors_size, nullptr);
316
Sadik Armagan62483be2020-10-23 17:14:43 +0100317 std::vector<armnn::BindingPointInfo> inputBindings;
318 std::vector<armnn::BindingPointInfo> outputBindings;
319
320 // Add input layer
321 auto status = AddInputLayer(delegateData, tfLiteContext, parameters->input_tensors, inputBindings);
322 if (status != kTfLiteOk)
323 {
324 throw armnn::Exception("TfLiteArmnnDelegate: Unable to add Inputs to the network!");
325 }
326
327 // Parse TfLite delegate nodes to ArmNN
Jan Eilers17d34da2021-12-08 16:15:12 +0000328 const auto parseStartTime = armnn::GetTimeNow();
Sadik Armagan3c24f432020-10-19 17:35:30 +0100329 for (int i = 0; i < parameters->nodes_to_replace->size; ++i)
330 {
331 const int nodeIndex = parameters->nodes_to_replace->data[i];
332
333 TfLiteNode* tfLiteNode = nullptr;
334 TfLiteRegistration* tfLiteRegistration = nullptr;
335 if (tfLiteContext->GetNodeAndRegistration(
336 tfLiteContext, nodeIndex, &tfLiteNode, &tfLiteRegistration) != kTfLiteOk)
337 {
Finn Williams6f9f9902020-11-13 13:23:15 +0000338 throw armnn::Exception(&"TfLiteArmnnDelegate: Unable to get node registration: " [ nodeIndex]);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100339 }
340
Sadik Armagan62483be2020-10-23 17:14:43 +0100341 if (VisitNode(delegateData, tfLiteContext, tfLiteRegistration, tfLiteNode, nodeIndex) != kTfLiteOk)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100342 {
Finn Williams6f9f9902020-11-13 13:23:15 +0000343 throw armnn::Exception(&"TfLiteArmnnDelegate: Unable to parse node: " [ nodeIndex]);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100344 }
345 }
Jan Eilers17d34da2021-12-08 16:15:12 +0000346 ARMNN_LOG(info) << "Parse nodes to ArmNN time: " << std::setprecision(2)
347 << std::fixed << armnn::GetTimeDuration(parseStartTime).count() << " ms";
Sadik Armagan3c24f432020-10-19 17:35:30 +0100348
Sadik Armagan62483be2020-10-23 17:14:43 +0100349 // Add Output layer
350 status = AddOutputLayer(delegateData, tfLiteContext, parameters->output_tensors, outputBindings);
351 if (status != kTfLiteOk)
352 {
353 throw armnn::Exception("TfLiteArmnnDelegate: Unable to add Outputs to the network!");
354 }
355
356 // Optimize ArmNN network
357 armnn::IOptimizedNetworkPtr optNet(nullptr, nullptr);
358 try
359 {
Jan Eilers17d34da2021-12-08 16:15:12 +0000360 const auto optimizeStartTime = armnn::GetTimeNow();
Sadik Armagan6e36a642020-11-10 21:18:41 +0000361 optNet = armnn::Optimize(*(delegateData.m_Network.get()),
Sadik Armagan62483be2020-10-23 17:14:43 +0100362 delegate->m_Options.GetBackends(),
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000363 delegate->m_Runtime->GetDeviceSpec(),
364 delegate->m_Options.GetOptimizerOptions());
Jan Eilers17d34da2021-12-08 16:15:12 +0000365 ARMNN_LOG(info) << "Optimize ArmnnSubgraph time: " << std::setprecision(2)
366 << std::fixed << armnn::GetTimeDuration(optimizeStartTime).count() << " ms";
Sadik Armagan62483be2020-10-23 17:14:43 +0100367 }
368 catch (std::exception &ex)
369 {
370 std::stringstream exMessage;
371 exMessage << "TfLiteArmnnDelegate: Exception (" << ex.what() << ") caught from optimize.";
372 throw armnn::Exception(exMessage.str());
373 }
Sadik Armagan3c24f432020-10-19 17:35:30 +0100374 if (!optNet)
375 {
Sadik Armagan62483be2020-10-23 17:14:43 +0100376 // Optimize failed
Sadik Armagan3c24f432020-10-19 17:35:30 +0100377 throw armnn::Exception("TfLiteArmnnDelegate: Unable to optimize the network!");
378 }
Sadik Armagan62483be2020-10-23 17:14:43 +0100379
Colm Donelan3e32a872021-10-04 22:55:37 +0100380 // If set, we will serialize the optimized model into a dot file.
381 const std::string serializeToDotFile = delegate->m_Options.GetSerializeToDot();
382 if (!serializeToDotFile.empty())
383 {
Jan Eilers17d34da2021-12-08 16:15:12 +0000384 ARMNN_LOG(info) << "Writing graph to dot file: " << serializeToDotFile;
Colm Donelan3e32a872021-10-04 22:55:37 +0100385 fs::path filename = serializeToDotFile;
386 std::fstream file(filename.c_str(), std::ios_base::out);
387 optNet->SerializeToDot(file);
388 }
389
Sadik Armagan62483be2020-10-23 17:14:43 +0100390 try
391 {
Jan Eilers17d34da2021-12-08 16:15:12 +0000392 const auto loadStartTime = armnn::GetTimeNow();
393
Sadik Armagan62483be2020-10-23 17:14:43 +0100394 // Load graph into runtime
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000395 std::string errorMessage;
Narumol Prangnawarat74a3cf52021-01-29 15:38:54 +0000396 armnn::Status loadingStatus;
Colm Donelan3e32a872021-10-04 22:55:37 +0100397 armnn::MemorySource memorySource = armnn::MemorySource::Undefined;
Narumol Prangnawarat74a3cf52021-01-29 15:38:54 +0000398 if (delegate->m_Options.GetOptimizerOptions().m_ImportEnabled)
399 {
Colm Donelan3e32a872021-10-04 22:55:37 +0100400 memorySource = armnn::MemorySource::Malloc;
Narumol Prangnawarat74a3cf52021-01-29 15:38:54 +0000401 }
Colm Donelan3e32a872021-10-04 22:55:37 +0100402 armnn::INetworkProperties networkProperties(false,
403 memorySource,
404 memorySource,
405 delegate->m_Options.GetInternalProfilingState(),
406 delegate->m_Options.GetInternalProfilingDetail());
407 loadingStatus = delegate->m_Runtime->LoadNetwork(networkId,
408 std::move(optNet),
409 errorMessage,
410 networkProperties);
Sadik Armagan62483be2020-10-23 17:14:43 +0100411 if (loadingStatus != armnn::Status::Success)
412 {
Colm Donelan45142282021-10-21 23:39:52 +0100413 // Network load failed.
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000414 throw armnn::Exception("TfLiteArmnnDelegate: Network could not be loaded:" + errorMessage);
Sadik Armagan62483be2020-10-23 17:14:43 +0100415 }
Jan Eilers17d34da2021-12-08 16:15:12 +0000416
417 ARMNN_LOG(info) << "Load ArmnnSubgraph time: " << std::setprecision(2)
418 << std::fixed << armnn::GetTimeDuration(loadStartTime).count() << " ms";
Sadik Armagan62483be2020-10-23 17:14:43 +0100419 }
420 catch (std::exception& ex)
421 {
422 std::stringstream exMessage;
423 exMessage << "TfLiteArmnnDelegate: Exception (" << ex.what() << ") caught from LoadNetwork.";
424 throw armnn::Exception(exMessage.str());
425 }
Sadik Armagan3c24f432020-10-19 17:35:30 +0100426
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000427 // Register debug callback function
428 if (delegate->m_Options.GetDebugCallbackFunction().has_value())
429 {
430 delegate->m_Runtime->RegisterDebugCallback(networkId, delegate->m_Options.GetDebugCallbackFunction().value());
431 }
432
Jan Eilers17d34da2021-12-08 16:15:12 +0000433 ARMNN_LOG(info) << "Overall ArmnnSubgraph creation time: " << std::setprecision(2)
434 << std::fixed << armnn::GetTimeDuration(startTime).count() << " ms\n";
435
Sadik Armagan3c24f432020-10-19 17:35:30 +0100436 // Create a new SubGraph with networkId and runtime
Sadik Armagan62483be2020-10-23 17:14:43 +0100437 return new ArmnnSubgraph(networkId, delegate->m_Runtime.get(), inputBindings, outputBindings);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100438}
439
440TfLiteStatus ArmnnSubgraph::Prepare(TfLiteContext* tfLiteContext)
441{
Finn Williams6f9f9902020-11-13 13:23:15 +0000442 armnn::IgnoreUnused(tfLiteContext);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100443 return kTfLiteOk;
444}
445
Sadik Armagan62483be2020-10-23 17:14:43 +0100446TfLiteStatus ArmnnSubgraph::Invoke(TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100447{
Sadik Armagan62483be2020-10-23 17:14:43 +0100448 // Prepare inputs
449 armnn::InputTensors inputTensors;
450 size_t inputIndex = 0;
451 for (auto inputIdx : tflite::TfLiteIntArrayView(tfLiteNode->inputs))
452 {
453 TfLiteTensor* tensor = &tfLiteContext->tensors[inputIdx];
454 if (tensor->allocation_type != kTfLiteMmapRo)
455 {
456 const armnn::BindingPointInfo& inputBinding = m_InputBindings[inputIndex];
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100457 armnn::TensorInfo inputTensorInfo = inputBinding.second;
458 inputTensorInfo.SetConstant(true);
459 const armnn::ConstTensor inputTensor(inputTensorInfo, tensor->data.data);
Sadik Armagan62483be2020-10-23 17:14:43 +0100460 inputTensors.emplace_back(inputIdx, inputTensor);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100461
Sadik Armagan62483be2020-10-23 17:14:43 +0100462 ++inputIndex;
463 }
464 }
465
466 // Prepare outputs
467 armnn::OutputTensors outputTensors;
468 size_t outputIndex = 0;
469 for (auto outputIdx : tflite::TfLiteIntArrayView(tfLiteNode->outputs))
470 {
471 const armnn::BindingPointInfo& outputBinding = m_OutputBindings[outputIndex];
472 TfLiteTensor* tensor = &tfLiteContext->tensors[outputIdx];
473 const armnn::Tensor outputTensor(outputBinding.second, tensor->data.data);
474 outputTensors.emplace_back(outputIdx, outputTensor);
475
476 ++outputIndex;
477 }
478
479 // Run graph
480 auto status = m_Runtime->EnqueueWorkload(m_NetworkId, inputTensors, outputTensors);
Colm Donelan45142282021-10-21 23:39:52 +0100481 // The delegate holds its own Arm NN runtime so this is our last chance to print internal profiling data.
482 std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkId);
483 if (profiler && profiler->IsProfilingEnabled())
484 {
485 profiler->Print(std::cout);
486 }
Sadik Armagan62483be2020-10-23 17:14:43 +0100487 return (status == armnn::Status::Success) ? kTfLiteOk : kTfLiteError;
Sadik Armagan3c24f432020-10-19 17:35:30 +0100488}
489
Sadik Armagan62483be2020-10-23 17:14:43 +0100490TfLiteStatus ArmnnSubgraph::VisitNode(DelegateData& delegateData,
Sadik Armagan3c24f432020-10-19 17:35:30 +0100491 TfLiteContext* tfLiteContext,
492 TfLiteRegistration* tfLiteRegistration,
493 TfLiteNode* tfLiteNode,
494 int nodeIndex)
495{
Sadik Armagan62483be2020-10-23 17:14:43 +0100496 switch (tfLiteRegistration->builtin_code)
497 {
498 case kTfLiteBuiltinAbs:
499 return VisitElementwiseUnaryOperator(delegateData,
500 tfLiteContext,
501 tfLiteNode,
502 nodeIndex,
503 armnn::UnaryOperation::Abs);
504 case kTfLiteBuiltinAdd:
505 return VisitElementwiseBinaryOperator(delegateData,
506 tfLiteContext,
507 tfLiteNode,
508 nodeIndex,
509 kTfLiteBuiltinAdd);
510 case kTfLiteBuiltinArgMax:
511 return VisitArgMinMaxOperator(delegateData,
512 tfLiteContext,
513 tfLiteNode,
514 nodeIndex,
515 kTfLiteBuiltinArgMax);
516 case kTfLiteBuiltinArgMin:
517 return VisitArgMinMaxOperator(delegateData,
518 tfLiteContext,
519 tfLiteNode,
520 nodeIndex,
521 kTfLiteBuiltinArgMin);
522 case kTfLiteBuiltinAveragePool2d:
523 return VisitPoolingOperator(delegateData,
524 tfLiteContext,
525 tfLiteNode,
526 nodeIndex,
527 kTfLiteBuiltinAveragePool2d);
528 case kTfLiteBuiltinBatchToSpaceNd:
529 return VisitBatchToSpaceNdOperator(delegateData,
530 tfLiteContext,
531 tfLiteNode,
532 nodeIndex,
533 kTfLiteBuiltinBatchToSpaceNd);
Sadik Armagan937565b2021-04-21 14:03:28 +0100534 case kTfLiteBuiltinCast:
535 return VisitCastOperator(delegateData,
536 tfLiteContext,
537 tfLiteNode,
538 nodeIndex,
539 kTfLiteBuiltinCast);
Sadik Armagan62483be2020-10-23 17:14:43 +0100540 case kTfLiteBuiltinConcatenation:
541 return VisitControlOperator(delegateData,
542 tfLiteContext,
543 tfLiteNode,
544 nodeIndex,
545 kTfLiteBuiltinConcatenation);
546 case kTfLiteBuiltinConv2d:
547 return VisitConvolutionOperator(delegateData,
548 tfLiteContext,
549 tfLiteNode,
550 nodeIndex,
551 kTfLiteBuiltinConv2d);
Matthew Sloyan81ec9942021-10-12 10:26:30 +0100552// Conv3d is only correctly supported for external delegates from TF Lite v2.6, as there was a breaking bug in v2.5.
553#if defined(ARMNN_POST_TFLITE_2_5)
554 case kTfLiteBuiltinConv3d:
555 return VisitConvolutionOperator(delegateData,
556 tfLiteContext,
557 tfLiteNode,
558 nodeIndex,
559 kTfLiteBuiltinConv3d);
560#endif
Sadik Armagan62483be2020-10-23 17:14:43 +0100561 case kTfLiteBuiltinDepthToSpace:
562 return VisitDepthToSpaceOperator(delegateData,
563 tfLiteContext,
564 tfLiteNode,
565 nodeIndex,
566 kTfLiteBuiltinDepthToSpace);
567 case kTfLiteBuiltinDepthwiseConv2d:
568 return VisitConvolutionOperator(delegateData,
569 tfLiteContext,
570 tfLiteNode,
571 nodeIndex,
572 kTfLiteBuiltinDepthwiseConv2d);
573 case kTfLiteBuiltinDequantize:
574 return VisitDequantizeOperator(delegateData,
575 tfLiteContext,
576 tfLiteNode,
577 nodeIndex,
578 kTfLiteBuiltinDequantize);
579 case kTfLiteBuiltinDiv:
580 return VisitElementwiseBinaryOperator(delegateData,
581 tfLiteContext,
582 tfLiteNode,
583 nodeIndex,
584 kTfLiteBuiltinDiv);
585 case kTfLiteBuiltinElu:
586 return VisitActivationOperator(delegateData,
587 tfLiteContext,
588 tfLiteNode,
589 nodeIndex,
590 kTfLiteBuiltinElu);
591 case kTfLiteBuiltinEqual:
592 return VisitComparisonOperator(delegateData,
593 tfLiteContext,
594 tfLiteNode,
595 nodeIndex,
596 kTfLiteBuiltinEqual);
597 case kTfLiteBuiltinExp:
598 return VisitElementwiseUnaryOperator(delegateData,
599 tfLiteContext,
600 tfLiteNode,
601 nodeIndex,
602 armnn::UnaryOperation::Exp);
603 case kTfLiteBuiltinExpandDims:
604 return VisitExpandDimsOperator(delegateData,
605 tfLiteContext,
606 tfLiteNode,
607 nodeIndex,
608 kTfLiteBuiltinExpandDims);
609 case kTfLiteBuiltinFill:
610 return VisitFillOperator(delegateData,
611 tfLiteContext,
612 tfLiteNode,
613 nodeIndex,
614 kTfLiteBuiltinFill);
615 case kTfLiteBuiltinFloor:
616 return VisitFloorOperator(delegateData,
617 tfLiteContext,
618 tfLiteNode,
619 nodeIndex,
620 kTfLiteBuiltinFloor);
Jim Flynn4b2f3472021-10-13 21:20:07 +0100621 case kTfLiteBuiltinFloorDiv:
622 return VisitElementwiseBinaryOperator(delegateData,
623 tfLiteContext,
624 tfLiteNode,
625 nodeIndex,
626 kTfLiteBuiltinFloorDiv);
Sadik Armagan62483be2020-10-23 17:14:43 +0100627 case kTfLiteBuiltinFullyConnected:
628 return VisitFullyConnectedOperator(delegateData,
629 tfLiteContext,
630 tfLiteNode,
631 nodeIndex,
632 kTfLiteBuiltinFullyConnected);
633 case kTfLiteBuiltinGather:
634 return VisitGatherOperator(delegateData,
635 tfLiteContext,
636 tfLiteNode,
637 nodeIndex,
638 kTfLiteBuiltinGather);
Teresa Charlind5c0ed22022-04-25 18:23:41 +0100639 case kTfLiteBuiltinGatherNd:
640 return VisitGatherNdOperator(delegateData,
641 tfLiteContext,
642 tfLiteNode,
643 nodeIndex,
644 kTfLiteBuiltinGatherNd);
Sadik Armagan62483be2020-10-23 17:14:43 +0100645 case kTfLiteBuiltinGreater:
646 return VisitComparisonOperator(delegateData,
647 tfLiteContext,
648 tfLiteNode,
649 nodeIndex,
650 kTfLiteBuiltinGreater);
651 case kTfLiteBuiltinGreaterEqual:
652 return VisitComparisonOperator(delegateData,
653 tfLiteContext,
654 tfLiteNode,
655 nodeIndex,
656 kTfLiteBuiltinGreaterEqual);
657 case kTfLiteBuiltinHardSwish:
658 return VisitActivationOperator(delegateData,
659 tfLiteContext,
660 tfLiteNode,
661 nodeIndex,
662 kTfLiteBuiltinHardSwish);
663 case kTfLiteBuiltinL2Normalization:
Sadik Armagan4b227bb2021-01-22 10:53:38 +0000664 return VisitL2NormalizationOperator(delegateData,
665 tfLiteContext,
666 tfLiteNode,
667 nodeIndex,
668 kTfLiteBuiltinL2Normalization);
Sadik Armagan62483be2020-10-23 17:14:43 +0100669 case kTfLiteBuiltinL2Pool2d:
670 return VisitPoolingOperator(delegateData,
671 tfLiteContext,
672 tfLiteNode,
673 nodeIndex,
674 kTfLiteBuiltinL2Pool2d);
675 case kTfLiteBuiltinLess:
676 return VisitComparisonOperator(delegateData,
677 tfLiteContext,
678 tfLiteNode,
679 nodeIndex,
680 kTfLiteBuiltinLess);
681 case kTfLiteBuiltinLessEqual:
682 return VisitComparisonOperator(delegateData,
683 tfLiteContext,
684 tfLiteNode,
685 nodeIndex,
686 kTfLiteBuiltinLessEqual);
687 case kTfLiteBuiltinLocalResponseNormalization:
Sadik Armagan4b227bb2021-01-22 10:53:38 +0000688 return VisitLocalResponseNormalizationOperator(delegateData,
689 tfLiteContext,
690 tfLiteNode,
691 nodeIndex,
692 kTfLiteBuiltinLocalResponseNormalization);
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000693 case kTfLiteBuiltinLogicalAnd:
694 return VisitLogicalBinaryOperator(delegateData,
695 tfLiteContext,
696 tfLiteNode,
697 nodeIndex,
698 kTfLiteBuiltinLogicalAnd,
699 armnn::LogicalBinaryOperation::LogicalAnd);
700 case kTfLiteBuiltinLogicalNot:
701 return VisitElementwiseUnaryOperator(delegateData,
702 tfLiteContext,
703 tfLiteNode,
704 nodeIndex,
705 armnn::UnaryOperation::LogicalNot);
706 case kTfLiteBuiltinLogicalOr:
707 return VisitLogicalBinaryOperator(delegateData,
708 tfLiteContext,
709 tfLiteNode,
710 nodeIndex,
711 kTfLiteBuiltinLogicalOr,
712 armnn::LogicalBinaryOperation::LogicalOr);
Sadik Armagan62483be2020-10-23 17:14:43 +0100713 case kTfLiteBuiltinLogistic:
714 return VisitActivationOperator(delegateData,
715 tfLiteContext,
716 tfLiteNode,
717 nodeIndex,
718 kTfLiteBuiltinLogistic);
719 case kTfLiteBuiltinLogSoftmax:
720 return VisitSoftmaxOperator(delegateData,
721 tfLiteContext,
722 tfLiteNode,
723 nodeIndex,
724 kTfLiteBuiltinLogSoftmax);
725 case kTfLiteBuiltinLstm:
726 return VisitLstmOperator(delegateData,
727 tfLiteContext,
728 tfLiteNode,
729 nodeIndex,
730 kTfLiteBuiltinLstm);
731 case kTfLiteBuiltinMaxPool2d:
732 return VisitPoolingOperator(delegateData,
733 tfLiteContext,
734 tfLiteNode,
735 nodeIndex,
736 kTfLiteBuiltinMaxPool2d);
737 case kTfLiteBuiltinMaximum:
738 return VisitElementwiseBinaryOperator(delegateData,
739 tfLiteContext,
740 tfLiteNode,
741 nodeIndex,
742 kTfLiteBuiltinMaximum);
743 case kTfLiteBuiltinMean:
744 return VisitControlOperator(delegateData,
745 tfLiteContext,
746 tfLiteNode,
747 nodeIndex,
748 kTfLiteBuiltinMean);
749 case kTfLiteBuiltinMinimum:
750 return VisitElementwiseBinaryOperator(delegateData,
751 tfLiteContext,
752 tfLiteNode,
753 nodeIndex,
754 kTfLiteBuiltinMinimum);
Matthew Sloyanaf3a4ef2021-10-22 15:48:12 +0100755 case kTfLiteBuiltinMirrorPad:
756 return VisitPadOperator(delegateData,
757 tfLiteContext,
758 tfLiteNode,
759 nodeIndex,
760 kTfLiteBuiltinMirrorPad);
Sadik Armagan62483be2020-10-23 17:14:43 +0100761 case kTfLiteBuiltinMul:
762 return VisitElementwiseBinaryOperator(delegateData,
763 tfLiteContext,
764 tfLiteNode,
765 nodeIndex,
766 kTfLiteBuiltinMul);
767 case kTfLiteBuiltinNeg:
768 return VisitElementwiseUnaryOperator(delegateData,
769 tfLiteContext,
770 tfLiteNode,
771 nodeIndex,
772 armnn::UnaryOperation::Neg);
773 case kTfLiteBuiltinNotEqual:
774 return VisitComparisonOperator(delegateData,
775 tfLiteContext,
776 tfLiteNode,
777 nodeIndex,
778 kTfLiteBuiltinNotEqual);
Matthew Sloyana7a12f52021-05-06 10:05:28 +0100779 case kTfLiteBuiltinPack:
780 return VisitPackOperator(delegateData,
781 tfLiteContext,
782 tfLiteNode,
783 nodeIndex,
784 kTfLiteBuiltinPack);
Sadik Armagan62483be2020-10-23 17:14:43 +0100785 case kTfLiteBuiltinPad:
786 return VisitPadOperator(delegateData,
787 tfLiteContext,
788 tfLiteNode,
789 nodeIndex,
790 kTfLiteBuiltinPad);
791 case kTfLiteBuiltinPadv2:
792 return VisitPadOperator(delegateData,
793 tfLiteContext,
794 tfLiteNode,
795 nodeIndex,
796 kTfLiteBuiltinPadv2);
797 case kTfLiteBuiltinPrelu:
James Conroy39825482021-05-27 17:44:50 +0100798 return VisitPreluOperator(delegateData,
799 tfLiteContext,
800 tfLiteNode,
801 nodeIndex,
802 kTfLiteBuiltinPrelu);
Sadik Armagan62483be2020-10-23 17:14:43 +0100803 case kTfLiteBuiltinQuantize:
804 return VisitQuantizeOperator(delegateData,
805 tfLiteContext,
806 tfLiteNode,
807 nodeIndex,
808 kTfLiteBuiltinQuantize);
809 case kTfLiteBuiltinRank:
810 return VisitControlOperator(delegateData,
811 tfLiteContext,
812 tfLiteNode,
813 nodeIndex,
814 kTfLiteBuiltinRank);
Sadik Armagana2747482021-02-09 10:28:54 +0000815 case kTfLiteBuiltinReduceMax:
816 return VisitReduceOperator(delegateData,
817 tfLiteContext,
818 tfLiteNode,
819 nodeIndex,
820 kTfLiteBuiltinReduceMax);
821 case kTfLiteBuiltinReduceMin:
822 return VisitReduceOperator(delegateData,
823 tfLiteContext,
824 tfLiteNode,
825 nodeIndex,
826 kTfLiteBuiltinReduceMin);
Teresa Charlin4e3e8312021-08-05 12:34:37 +0100827 case kTfLiteBuiltinReduceProd:
828 return VisitReduceOperator(delegateData,
829 tfLiteContext,
830 tfLiteNode,
831 nodeIndex,
832 kTfLiteBuiltinReduceProd);
Sadik Armagan62483be2020-10-23 17:14:43 +0100833 case kTfLiteBuiltinRelu:
834 return VisitActivationOperator(delegateData,
835 tfLiteContext,
836 tfLiteNode,
837 nodeIndex,
838 kTfLiteBuiltinRelu);
839 case kTfLiteBuiltinReluN1To1:
840 return VisitActivationOperator(delegateData,
841 tfLiteContext,
842 tfLiteNode,
843 nodeIndex,
844 kTfLiteBuiltinReluN1To1);
845 case kTfLiteBuiltinRelu6:
846 return VisitActivationOperator(delegateData,
847 tfLiteContext,
848 tfLiteNode,
849 nodeIndex,
850 kTfLiteBuiltinRelu6);
851 case kTfLiteBuiltinReshape:
852 return VisitReshapeOperator(delegateData,
853 tfLiteContext,
854 tfLiteNode,
855 nodeIndex,
856 kTfLiteBuiltinReshape);
857 case kTfLiteBuiltinResizeBilinear:
858 return VisitResizeOperator(delegateData,
859 tfLiteContext,
860 tfLiteNode,
861 nodeIndex,
862 kTfLiteBuiltinResizeBilinear);
863 case kTfLiteBuiltinResizeNearestNeighbor:
864 return VisitResizeOperator(delegateData,
865 tfLiteContext,
866 tfLiteNode,
867 nodeIndex,
868 kTfLiteBuiltinResizeNearestNeighbor);
869 case kTfLiteBuiltinRsqrt:
870 return VisitElementwiseUnaryOperator(delegateData,
871 tfLiteContext,
872 tfLiteNode,
873 nodeIndex,
874 armnn::UnaryOperation::Rsqrt);
Keith Davis0176fd82021-06-01 17:36:32 +0100875 case kTfLiteBuiltinShape:
876 return VisitShapeOperator(delegateData,
877 tfLiteContext,
878 tfLiteNode,
879 nodeIndex,
880 kTfLiteBuiltinShape);
Sadik Armagan34fa1bd2020-11-27 12:40:52 +0000881 case kTfLiteBuiltinSplit:
882 return VisitSplitOperator(delegateData,
883 tfLiteContext,
884 tfLiteNode,
885 nodeIndex,
886 kTfLiteBuiltinSplit);
887 case kTfLiteBuiltinSplitV:
888 return VisitSplitVOperator(delegateData,
889 tfLiteContext,
890 tfLiteNode,
891 nodeIndex,
892 kTfLiteBuiltinSplitV);
Sadik Armagan62483be2020-10-23 17:14:43 +0100893 case kTfLiteBuiltinSqrt:
894 return VisitElementwiseUnaryOperator(delegateData,
895 tfLiteContext,
896 tfLiteNode,
897 nodeIndex,
898 armnn::UnaryOperation::Sqrt);
899 case kTfLiteBuiltinSqueeze:
900 return VisitSqueezeOperator(delegateData,
901 tfLiteContext,
902 tfLiteNode,
903 nodeIndex,
904 kTfLiteBuiltinSqueeze);
905 case kTfLiteBuiltinStridedSlice:
906 return VisitSliceOperator(delegateData,
907 tfLiteContext,
908 tfLiteNode,
909 nodeIndex,
910 kTfLiteBuiltinStridedSlice);
Sadik Armagana2747482021-02-09 10:28:54 +0000911 case kTfLiteBuiltinSum:
912 return VisitReduceOperator(delegateData,
913 tfLiteContext,
914 tfLiteNode,
915 nodeIndex,
916 kTfLiteBuiltinSum);
Sadik Armagan62483be2020-10-23 17:14:43 +0100917 case kTfLiteBuiltinTranspose:
918 return VisitTransposeOperator(delegateData,
919 tfLiteContext,
920 tfLiteNode,
921 nodeIndex,
922 kTfLiteBuiltinTranspose);
923 case kTfLiteBuiltinTransposeConv:
924 return VisitConvolutionOperator(delegateData,
925 tfLiteContext,
926 tfLiteNode,
927 nodeIndex,
928 kTfLiteBuiltinTransposeConv);
929 case kTfLiteBuiltinSoftmax:
930 return VisitSoftmaxOperator(delegateData,
931 tfLiteContext,
932 tfLiteNode,
933 nodeIndex,
934 kTfLiteBuiltinSoftmax);
935 case kTfLiteBuiltinSpaceToBatchNd:
936 return VisitSpaceToBatchNdOperator(delegateData,
937 tfLiteContext,
938 tfLiteNode,
939 nodeIndex,
940 kTfLiteBuiltinSpaceToBatchNd);
941 case kTfLiteBuiltinSpaceToDepth:
942 return VisitSpaceToDepthOperator(delegateData,
943 tfLiteContext,
944 tfLiteNode,
945 nodeIndex,
946 kTfLiteBuiltinSpaceToDepth);
947 case kTfLiteBuiltinSub:
948 return VisitElementwiseBinaryOperator(delegateData,
949 tfLiteContext,
950 tfLiteNode,
951 nodeIndex,
952 kTfLiteBuiltinSub);
953 case kTfLiteBuiltinTanh:
954 return VisitActivationOperator(delegateData,
955 tfLiteContext,
956 tfLiteNode,
957 nodeIndex,
958 kTfLiteBuiltinTanh);
Narumol Prangnawarat7684b182021-08-12 14:48:15 +0100959 case kTfLiteBuiltinUnidirectionalSequenceLstm:
960 return VisitUnidirectionalSequenceLstmOperator(delegateData,
961 tfLiteContext,
962 tfLiteNode,
963 nodeIndex,
964 kTfLiteBuiltinUnidirectionalSequenceLstm);
Kevin May8ab2d7a2021-05-07 09:32:51 +0100965 case kTfLiteBuiltinUnpack:
966 return VisitUnpackOperator(delegateData,
967 tfLiteContext,
968 tfLiteNode,
969 nodeIndex,
970 kTfLiteBuiltinUnpack);
Sadik Armagan62483be2020-10-23 17:14:43 +0100971 default:
972 return kTfLiteError;
973 }
Sadik Armagan3c24f432020-10-19 17:35:30 +0100974}
975
976} // armnnDelegate namespace