blob: bb2f3c319a8cf5a9df04ff40cbff00d8e80ce260 [file] [log] [blame]
Sadik Armagan3c24f432020-10-19 17:35:30 +01001//
Ryan OShead21abaf2022-06-10 14:49:11 +01002// Copyright © 2022 Arm Ltd and Contributors. All rights reserved.
Sadik Armagan3c24f432020-10-19 17:35:30 +01003// 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;
James Conroya0f8b152022-06-21 11:31:47 +0000397 armnn::MemorySource memorySource = armnn::MemorySource::Undefined;
Narumol Prangnawarat74a3cf52021-01-29 15:38:54 +0000398 if (delegate->m_Options.GetOptimizerOptions().m_ImportEnabled)
399 {
James Conroya0f8b152022-06-21 11:31:47 +0000400 memorySource = armnn::MemorySource::Malloc;
Narumol Prangnawarat74a3cf52021-01-29 15:38:54 +0000401 }
Colm Donelan3e32a872021-10-04 22:55:37 +0100402 armnn::INetworkProperties networkProperties(false,
James Conroya0f8b152022-06-21 11:31:47 +0000403 memorySource,
404 memorySource,
Colm Donelan3e32a872021-10-04 22:55:37 +0100405 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 {
Ryan OShead21abaf2022-06-10 14:49:11 +0100498 case kTfLiteBuiltinCustom:
499 {
500#if defined(ARMNN_POST_TFLITE_2_5)
501 // Custom operators are defined by the name rather than the builtin code.
502 // Parse the custom_name param in the registration to point to the correct visitor function.
503 std::string customOperatorName = tfLiteRegistration->custom_name;
504 if ( customOperatorName == "AveragePool3D" )
505 {
506 return VisitPooling3dOperator(delegateData,
507 tfLiteContext,
508 tfLiteNode,
509 nodeIndex,
510 customOperatorName);
511 }
512 else if (customOperatorName == "MaxPool3D")
513 {
514 return VisitPooling3dOperator(delegateData,
515 tfLiteContext,
516 tfLiteNode,
517 nodeIndex,
518 customOperatorName);
519 }
520#endif
521 // Invalid or unsupported custom operator
522 return kTfLiteError;
523 }
Sadik Armagan62483be2020-10-23 17:14:43 +0100524 case kTfLiteBuiltinAbs:
525 return VisitElementwiseUnaryOperator(delegateData,
526 tfLiteContext,
527 tfLiteNode,
528 nodeIndex,
529 armnn::UnaryOperation::Abs);
530 case kTfLiteBuiltinAdd:
531 return VisitElementwiseBinaryOperator(delegateData,
532 tfLiteContext,
533 tfLiteNode,
534 nodeIndex,
535 kTfLiteBuiltinAdd);
536 case kTfLiteBuiltinArgMax:
537 return VisitArgMinMaxOperator(delegateData,
538 tfLiteContext,
539 tfLiteNode,
540 nodeIndex,
541 kTfLiteBuiltinArgMax);
542 case kTfLiteBuiltinArgMin:
543 return VisitArgMinMaxOperator(delegateData,
544 tfLiteContext,
545 tfLiteNode,
546 nodeIndex,
547 kTfLiteBuiltinArgMin);
548 case kTfLiteBuiltinAveragePool2d:
Ryan OShead21abaf2022-06-10 14:49:11 +0100549 return VisitPooling2dOperator(delegateData,
Sadik Armagan62483be2020-10-23 17:14:43 +0100550 tfLiteContext,
551 tfLiteNode,
552 nodeIndex,
553 kTfLiteBuiltinAveragePool2d);
554 case kTfLiteBuiltinBatchToSpaceNd:
555 return VisitBatchToSpaceNdOperator(delegateData,
556 tfLiteContext,
557 tfLiteNode,
558 nodeIndex,
559 kTfLiteBuiltinBatchToSpaceNd);
Sadik Armagan937565b2021-04-21 14:03:28 +0100560 case kTfLiteBuiltinCast:
561 return VisitCastOperator(delegateData,
562 tfLiteContext,
563 tfLiteNode,
564 nodeIndex,
565 kTfLiteBuiltinCast);
Sadik Armagan62483be2020-10-23 17:14:43 +0100566 case kTfLiteBuiltinConcatenation:
567 return VisitControlOperator(delegateData,
568 tfLiteContext,
569 tfLiteNode,
570 nodeIndex,
571 kTfLiteBuiltinConcatenation);
572 case kTfLiteBuiltinConv2d:
573 return VisitConvolutionOperator(delegateData,
574 tfLiteContext,
575 tfLiteNode,
576 nodeIndex,
577 kTfLiteBuiltinConv2d);
Matthew Sloyan81ec9942021-10-12 10:26:30 +0100578// Conv3d is only correctly supported for external delegates from TF Lite v2.6, as there was a breaking bug in v2.5.
579#if defined(ARMNN_POST_TFLITE_2_5)
580 case kTfLiteBuiltinConv3d:
581 return VisitConvolutionOperator(delegateData,
582 tfLiteContext,
583 tfLiteNode,
584 nodeIndex,
585 kTfLiteBuiltinConv3d);
586#endif
Sadik Armagan62483be2020-10-23 17:14:43 +0100587 case kTfLiteBuiltinDepthToSpace:
588 return VisitDepthToSpaceOperator(delegateData,
589 tfLiteContext,
590 tfLiteNode,
591 nodeIndex,
592 kTfLiteBuiltinDepthToSpace);
593 case kTfLiteBuiltinDepthwiseConv2d:
594 return VisitConvolutionOperator(delegateData,
595 tfLiteContext,
596 tfLiteNode,
597 nodeIndex,
598 kTfLiteBuiltinDepthwiseConv2d);
599 case kTfLiteBuiltinDequantize:
600 return VisitDequantizeOperator(delegateData,
601 tfLiteContext,
602 tfLiteNode,
603 nodeIndex,
604 kTfLiteBuiltinDequantize);
605 case kTfLiteBuiltinDiv:
606 return VisitElementwiseBinaryOperator(delegateData,
607 tfLiteContext,
608 tfLiteNode,
609 nodeIndex,
610 kTfLiteBuiltinDiv);
611 case kTfLiteBuiltinElu:
612 return VisitActivationOperator(delegateData,
613 tfLiteContext,
614 tfLiteNode,
615 nodeIndex,
616 kTfLiteBuiltinElu);
617 case kTfLiteBuiltinEqual:
618 return VisitComparisonOperator(delegateData,
619 tfLiteContext,
620 tfLiteNode,
621 nodeIndex,
622 kTfLiteBuiltinEqual);
623 case kTfLiteBuiltinExp:
624 return VisitElementwiseUnaryOperator(delegateData,
625 tfLiteContext,
626 tfLiteNode,
627 nodeIndex,
628 armnn::UnaryOperation::Exp);
629 case kTfLiteBuiltinExpandDims:
630 return VisitExpandDimsOperator(delegateData,
631 tfLiteContext,
632 tfLiteNode,
633 nodeIndex,
634 kTfLiteBuiltinExpandDims);
635 case kTfLiteBuiltinFill:
636 return VisitFillOperator(delegateData,
637 tfLiteContext,
638 tfLiteNode,
639 nodeIndex,
640 kTfLiteBuiltinFill);
641 case kTfLiteBuiltinFloor:
642 return VisitFloorOperator(delegateData,
643 tfLiteContext,
644 tfLiteNode,
645 nodeIndex,
646 kTfLiteBuiltinFloor);
Jim Flynn4b2f3472021-10-13 21:20:07 +0100647 case kTfLiteBuiltinFloorDiv:
648 return VisitElementwiseBinaryOperator(delegateData,
649 tfLiteContext,
650 tfLiteNode,
651 nodeIndex,
652 kTfLiteBuiltinFloorDiv);
Sadik Armagan62483be2020-10-23 17:14:43 +0100653 case kTfLiteBuiltinFullyConnected:
654 return VisitFullyConnectedOperator(delegateData,
655 tfLiteContext,
656 tfLiteNode,
657 nodeIndex,
658 kTfLiteBuiltinFullyConnected);
659 case kTfLiteBuiltinGather:
660 return VisitGatherOperator(delegateData,
661 tfLiteContext,
662 tfLiteNode,
663 nodeIndex,
664 kTfLiteBuiltinGather);
Teresa Charlind5c0ed22022-04-25 18:23:41 +0100665 case kTfLiteBuiltinGatherNd:
666 return VisitGatherNdOperator(delegateData,
667 tfLiteContext,
668 tfLiteNode,
669 nodeIndex,
670 kTfLiteBuiltinGatherNd);
Sadik Armagan62483be2020-10-23 17:14:43 +0100671 case kTfLiteBuiltinGreater:
672 return VisitComparisonOperator(delegateData,
673 tfLiteContext,
674 tfLiteNode,
675 nodeIndex,
676 kTfLiteBuiltinGreater);
677 case kTfLiteBuiltinGreaterEqual:
678 return VisitComparisonOperator(delegateData,
679 tfLiteContext,
680 tfLiteNode,
681 nodeIndex,
682 kTfLiteBuiltinGreaterEqual);
683 case kTfLiteBuiltinHardSwish:
684 return VisitActivationOperator(delegateData,
685 tfLiteContext,
686 tfLiteNode,
687 nodeIndex,
688 kTfLiteBuiltinHardSwish);
689 case kTfLiteBuiltinL2Normalization:
Sadik Armagan4b227bb2021-01-22 10:53:38 +0000690 return VisitL2NormalizationOperator(delegateData,
691 tfLiteContext,
692 tfLiteNode,
693 nodeIndex,
694 kTfLiteBuiltinL2Normalization);
Sadik Armagan62483be2020-10-23 17:14:43 +0100695 case kTfLiteBuiltinL2Pool2d:
Ryan OShead21abaf2022-06-10 14:49:11 +0100696 return VisitPooling2dOperator(delegateData,
Sadik Armagan62483be2020-10-23 17:14:43 +0100697 tfLiteContext,
698 tfLiteNode,
699 nodeIndex,
700 kTfLiteBuiltinL2Pool2d);
701 case kTfLiteBuiltinLess:
702 return VisitComparisonOperator(delegateData,
703 tfLiteContext,
704 tfLiteNode,
705 nodeIndex,
706 kTfLiteBuiltinLess);
707 case kTfLiteBuiltinLessEqual:
708 return VisitComparisonOperator(delegateData,
709 tfLiteContext,
710 tfLiteNode,
711 nodeIndex,
712 kTfLiteBuiltinLessEqual);
713 case kTfLiteBuiltinLocalResponseNormalization:
Sadik Armagan4b227bb2021-01-22 10:53:38 +0000714 return VisitLocalResponseNormalizationOperator(delegateData,
715 tfLiteContext,
716 tfLiteNode,
717 nodeIndex,
718 kTfLiteBuiltinLocalResponseNormalization);
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000719 case kTfLiteBuiltinLogicalAnd:
720 return VisitLogicalBinaryOperator(delegateData,
721 tfLiteContext,
722 tfLiteNode,
723 nodeIndex,
724 kTfLiteBuiltinLogicalAnd,
725 armnn::LogicalBinaryOperation::LogicalAnd);
726 case kTfLiteBuiltinLogicalNot:
727 return VisitElementwiseUnaryOperator(delegateData,
728 tfLiteContext,
729 tfLiteNode,
730 nodeIndex,
731 armnn::UnaryOperation::LogicalNot);
732 case kTfLiteBuiltinLogicalOr:
733 return VisitLogicalBinaryOperator(delegateData,
734 tfLiteContext,
735 tfLiteNode,
736 nodeIndex,
737 kTfLiteBuiltinLogicalOr,
738 armnn::LogicalBinaryOperation::LogicalOr);
Sadik Armagan62483be2020-10-23 17:14:43 +0100739 case kTfLiteBuiltinLogistic:
740 return VisitActivationOperator(delegateData,
741 tfLiteContext,
742 tfLiteNode,
743 nodeIndex,
744 kTfLiteBuiltinLogistic);
745 case kTfLiteBuiltinLogSoftmax:
746 return VisitSoftmaxOperator(delegateData,
747 tfLiteContext,
748 tfLiteNode,
749 nodeIndex,
750 kTfLiteBuiltinLogSoftmax);
751 case kTfLiteBuiltinLstm:
752 return VisitLstmOperator(delegateData,
753 tfLiteContext,
754 tfLiteNode,
755 nodeIndex,
756 kTfLiteBuiltinLstm);
757 case kTfLiteBuiltinMaxPool2d:
Ryan OShead21abaf2022-06-10 14:49:11 +0100758 return VisitPooling2dOperator(delegateData,
Sadik Armagan62483be2020-10-23 17:14:43 +0100759 tfLiteContext,
760 tfLiteNode,
761 nodeIndex,
762 kTfLiteBuiltinMaxPool2d);
763 case kTfLiteBuiltinMaximum:
764 return VisitElementwiseBinaryOperator(delegateData,
765 tfLiteContext,
766 tfLiteNode,
767 nodeIndex,
768 kTfLiteBuiltinMaximum);
769 case kTfLiteBuiltinMean:
770 return VisitControlOperator(delegateData,
771 tfLiteContext,
772 tfLiteNode,
773 nodeIndex,
774 kTfLiteBuiltinMean);
775 case kTfLiteBuiltinMinimum:
776 return VisitElementwiseBinaryOperator(delegateData,
777 tfLiteContext,
778 tfLiteNode,
779 nodeIndex,
780 kTfLiteBuiltinMinimum);
Matthew Sloyanaf3a4ef2021-10-22 15:48:12 +0100781 case kTfLiteBuiltinMirrorPad:
782 return VisitPadOperator(delegateData,
783 tfLiteContext,
784 tfLiteNode,
785 nodeIndex,
786 kTfLiteBuiltinMirrorPad);
Sadik Armagan62483be2020-10-23 17:14:43 +0100787 case kTfLiteBuiltinMul:
788 return VisitElementwiseBinaryOperator(delegateData,
789 tfLiteContext,
790 tfLiteNode,
791 nodeIndex,
792 kTfLiteBuiltinMul);
793 case kTfLiteBuiltinNeg:
794 return VisitElementwiseUnaryOperator(delegateData,
795 tfLiteContext,
796 tfLiteNode,
797 nodeIndex,
798 armnn::UnaryOperation::Neg);
799 case kTfLiteBuiltinNotEqual:
800 return VisitComparisonOperator(delegateData,
801 tfLiteContext,
802 tfLiteNode,
803 nodeIndex,
804 kTfLiteBuiltinNotEqual);
Matthew Sloyana7a12f52021-05-06 10:05:28 +0100805 case kTfLiteBuiltinPack:
806 return VisitPackOperator(delegateData,
807 tfLiteContext,
808 tfLiteNode,
809 nodeIndex,
810 kTfLiteBuiltinPack);
Sadik Armagan62483be2020-10-23 17:14:43 +0100811 case kTfLiteBuiltinPad:
812 return VisitPadOperator(delegateData,
813 tfLiteContext,
814 tfLiteNode,
815 nodeIndex,
816 kTfLiteBuiltinPad);
817 case kTfLiteBuiltinPadv2:
818 return VisitPadOperator(delegateData,
819 tfLiteContext,
820 tfLiteNode,
821 nodeIndex,
822 kTfLiteBuiltinPadv2);
823 case kTfLiteBuiltinPrelu:
James Conroy39825482021-05-27 17:44:50 +0100824 return VisitPreluOperator(delegateData,
825 tfLiteContext,
826 tfLiteNode,
827 nodeIndex,
828 kTfLiteBuiltinPrelu);
Sadik Armagan62483be2020-10-23 17:14:43 +0100829 case kTfLiteBuiltinQuantize:
830 return VisitQuantizeOperator(delegateData,
831 tfLiteContext,
832 tfLiteNode,
833 nodeIndex,
834 kTfLiteBuiltinQuantize);
835 case kTfLiteBuiltinRank:
836 return VisitControlOperator(delegateData,
837 tfLiteContext,
838 tfLiteNode,
839 nodeIndex,
840 kTfLiteBuiltinRank);
Sadik Armagana2747482021-02-09 10:28:54 +0000841 case kTfLiteBuiltinReduceMax:
842 return VisitReduceOperator(delegateData,
843 tfLiteContext,
844 tfLiteNode,
845 nodeIndex,
846 kTfLiteBuiltinReduceMax);
847 case kTfLiteBuiltinReduceMin:
848 return VisitReduceOperator(delegateData,
849 tfLiteContext,
850 tfLiteNode,
851 nodeIndex,
852 kTfLiteBuiltinReduceMin);
Teresa Charlin4e3e8312021-08-05 12:34:37 +0100853 case kTfLiteBuiltinReduceProd:
854 return VisitReduceOperator(delegateData,
855 tfLiteContext,
856 tfLiteNode,
857 nodeIndex,
858 kTfLiteBuiltinReduceProd);
Sadik Armagan62483be2020-10-23 17:14:43 +0100859 case kTfLiteBuiltinRelu:
860 return VisitActivationOperator(delegateData,
861 tfLiteContext,
862 tfLiteNode,
863 nodeIndex,
864 kTfLiteBuiltinRelu);
865 case kTfLiteBuiltinReluN1To1:
866 return VisitActivationOperator(delegateData,
867 tfLiteContext,
868 tfLiteNode,
869 nodeIndex,
870 kTfLiteBuiltinReluN1To1);
871 case kTfLiteBuiltinRelu6:
872 return VisitActivationOperator(delegateData,
873 tfLiteContext,
874 tfLiteNode,
875 nodeIndex,
876 kTfLiteBuiltinRelu6);
877 case kTfLiteBuiltinReshape:
878 return VisitReshapeOperator(delegateData,
879 tfLiteContext,
880 tfLiteNode,
881 nodeIndex,
882 kTfLiteBuiltinReshape);
883 case kTfLiteBuiltinResizeBilinear:
884 return VisitResizeOperator(delegateData,
885 tfLiteContext,
886 tfLiteNode,
887 nodeIndex,
888 kTfLiteBuiltinResizeBilinear);
889 case kTfLiteBuiltinResizeNearestNeighbor:
890 return VisitResizeOperator(delegateData,
891 tfLiteContext,
892 tfLiteNode,
893 nodeIndex,
894 kTfLiteBuiltinResizeNearestNeighbor);
895 case kTfLiteBuiltinRsqrt:
896 return VisitElementwiseUnaryOperator(delegateData,
897 tfLiteContext,
898 tfLiteNode,
899 nodeIndex,
900 armnn::UnaryOperation::Rsqrt);
Keith Davis0176fd82021-06-01 17:36:32 +0100901 case kTfLiteBuiltinShape:
902 return VisitShapeOperator(delegateData,
903 tfLiteContext,
904 tfLiteNode,
905 nodeIndex,
906 kTfLiteBuiltinShape);
Sadik Armagan34fa1bd2020-11-27 12:40:52 +0000907 case kTfLiteBuiltinSplit:
908 return VisitSplitOperator(delegateData,
909 tfLiteContext,
910 tfLiteNode,
911 nodeIndex,
912 kTfLiteBuiltinSplit);
913 case kTfLiteBuiltinSplitV:
914 return VisitSplitVOperator(delegateData,
915 tfLiteContext,
916 tfLiteNode,
917 nodeIndex,
918 kTfLiteBuiltinSplitV);
Sadik Armagan62483be2020-10-23 17:14:43 +0100919 case kTfLiteBuiltinSqrt:
920 return VisitElementwiseUnaryOperator(delegateData,
921 tfLiteContext,
922 tfLiteNode,
923 nodeIndex,
924 armnn::UnaryOperation::Sqrt);
925 case kTfLiteBuiltinSqueeze:
926 return VisitSqueezeOperator(delegateData,
927 tfLiteContext,
928 tfLiteNode,
929 nodeIndex,
930 kTfLiteBuiltinSqueeze);
931 case kTfLiteBuiltinStridedSlice:
932 return VisitSliceOperator(delegateData,
933 tfLiteContext,
934 tfLiteNode,
935 nodeIndex,
936 kTfLiteBuiltinStridedSlice);
Sadik Armagana2747482021-02-09 10:28:54 +0000937 case kTfLiteBuiltinSum:
938 return VisitReduceOperator(delegateData,
939 tfLiteContext,
940 tfLiteNode,
941 nodeIndex,
942 kTfLiteBuiltinSum);
Sadik Armagan62483be2020-10-23 17:14:43 +0100943 case kTfLiteBuiltinTranspose:
944 return VisitTransposeOperator(delegateData,
945 tfLiteContext,
946 tfLiteNode,
947 nodeIndex,
948 kTfLiteBuiltinTranspose);
949 case kTfLiteBuiltinTransposeConv:
950 return VisitConvolutionOperator(delegateData,
951 tfLiteContext,
952 tfLiteNode,
953 nodeIndex,
954 kTfLiteBuiltinTransposeConv);
955 case kTfLiteBuiltinSoftmax:
956 return VisitSoftmaxOperator(delegateData,
957 tfLiteContext,
958 tfLiteNode,
959 nodeIndex,
960 kTfLiteBuiltinSoftmax);
961 case kTfLiteBuiltinSpaceToBatchNd:
962 return VisitSpaceToBatchNdOperator(delegateData,
963 tfLiteContext,
964 tfLiteNode,
965 nodeIndex,
966 kTfLiteBuiltinSpaceToBatchNd);
967 case kTfLiteBuiltinSpaceToDepth:
968 return VisitSpaceToDepthOperator(delegateData,
969 tfLiteContext,
970 tfLiteNode,
971 nodeIndex,
972 kTfLiteBuiltinSpaceToDepth);
973 case kTfLiteBuiltinSub:
974 return VisitElementwiseBinaryOperator(delegateData,
975 tfLiteContext,
976 tfLiteNode,
977 nodeIndex,
978 kTfLiteBuiltinSub);
979 case kTfLiteBuiltinTanh:
980 return VisitActivationOperator(delegateData,
981 tfLiteContext,
982 tfLiteNode,
983 nodeIndex,
984 kTfLiteBuiltinTanh);
Narumol Prangnawarat7684b182021-08-12 14:48:15 +0100985 case kTfLiteBuiltinUnidirectionalSequenceLstm:
986 return VisitUnidirectionalSequenceLstmOperator(delegateData,
987 tfLiteContext,
988 tfLiteNode,
989 nodeIndex,
990 kTfLiteBuiltinUnidirectionalSequenceLstm);
Kevin May8ab2d7a2021-05-07 09:32:51 +0100991 case kTfLiteBuiltinUnpack:
992 return VisitUnpackOperator(delegateData,
993 tfLiteContext,
994 tfLiteNode,
995 nodeIndex,
996 kTfLiteBuiltinUnpack);
Sadik Armagan62483be2020-10-23 17:14:43 +0100997 default:
998 return kTfLiteError;
999 }
Sadik Armagan3c24f432020-10-19 17:35:30 +01001000}
1001
1002} // armnnDelegate namespace