blob: 6abf7398cc20302275dffbe01fe1d859078249a2 [file] [log] [blame]
Francis Murtaghc4fb0dd2023-03-16 17:01:56 +00001//
2// Copyright © 2023 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include <armnn_delegate.hpp>
Ryan OSheaac9607f2023-04-03 11:33:33 +01007#include <OpaqueDelegateUtils.hpp>
Francis Murtaghc4fb0dd2023-03-16 17:01:56 +00008
Francis Murtaghc4fb0dd2023-03-16 17:01:56 +00009#include "Activation.hpp"
10#include "ArgMinMax.hpp"
11#include "BatchMatMul.hpp"
12#include "BatchSpace.hpp"
Idriss Chaouchcbf79292023-09-08 11:18:16 +010013#include "BroadcastTo.hpp"
Francis Murtaghc4fb0dd2023-03-16 17:01:56 +000014#include "Comparison.hpp"
15#include "Convolution.hpp"
16#include "Control.hpp"
17#include "ElementwiseBinary.hpp"
18#include "ElementwiseUnary.hpp"
19#include "Fill.hpp"
20#include "FullyConnected.hpp"
21#include "Gather.hpp"
22#include "GatherNd.hpp"
23#include "LogicalBinary.hpp"
24#include "Lstm.hpp"
25#include "Normalization.hpp"
26#include "Pack.hpp"
27#include "Pad.hpp"
28#include "Pooling.hpp"
29#include "Prelu.hpp"
30#include "Quantization.hpp"
31#include "Redefine.hpp"
32#include "Reduce.hpp"
33#include "Resize.hpp"
Tracy Narine7306bbe2023-07-17 16:06:26 +010034#include "ReverseV2.hpp"
Francis Murtaghc4fb0dd2023-03-16 17:01:56 +000035#include "Round.hpp"
36#include "Shape.hpp"
37#include "Slice.hpp"
38#include "StridedSlice.hpp"
39#include "Softmax.hpp"
40#include "SpaceDepth.hpp"
41#include "Split.hpp"
Tianle Cheng92ce35c2023-07-25 16:41:00 +010042#include "Tile.hpp"
Francis Murtaghc4fb0dd2023-03-16 17:01:56 +000043#include "Transpose.hpp"
44#include "UnidirectionalSequenceLstm.hpp"
45#include "Unpack.hpp"
46
47#include <armnn/utility/IgnoreUnused.hpp>
48#include <armnnUtils/Filesystem.hpp>
49#include <armnn/utility/Timer.hpp>
50#include <flatbuffers/flatbuffers.h>
51#include <tensorflow/lite/context_util.h>
52#include <tensorflow/lite/schema/schema_generated.h>
53#include <tensorflow/lite/minimal_logging.h>
Francis Murtaghc4fb0dd2023-03-16 17:01:56 +000054
55#include <algorithm>
56#include <iostream>
57#include <sstream>
58
59namespace armnnOpaqueDelegate
60{
61
Narumol Prangnawarat26654cb2023-05-03 16:08:11 +010062static auto* g_delegate_plugin_ArmnnDelegatePlugin_ =
Ryan OShea59f8f652023-05-11 20:37:53 +010063 new tflite::delegates::DelegatePluginRegistry::Register("armnn_delegate",
Narumol Prangnawarat26654cb2023-05-03 16:08:11 +010064 ArmnnDelegatePlugin::New);
65
Francis Murtaghc4fb0dd2023-03-16 17:01:56 +000066ArmnnOpaqueDelegate::ArmnnOpaqueDelegate(armnnDelegate::DelegateOptions options)
67 : m_Options(std::move(options))
68{
69 // Configures logging for ARMNN
70 if (m_Options.IsLoggingEnabled())
71 {
72 armnn::ConfigureLogging(true, true, m_Options.GetLoggingSeverity());
73 }
74 // Create/Get the static ArmNN Runtime. Note that the m_Runtime will be shared by all armnn_delegate
75 // instances so the RuntimeOptions cannot be altered for different armnn_delegate instances.
76 m_Runtime = GetRuntime(m_Options.GetRuntimeOptions());
77 std::vector<armnn::BackendId> backends;
78 if (m_Runtime)
79 {
80 const armnn::BackendIdSet supportedDevices = m_Runtime->GetDeviceSpec().GetSupportedBackends();
81 for (auto& backend : m_Options.GetBackends())
82 {
83 if (std::find(supportedDevices.cbegin(), supportedDevices.cend(), backend) == supportedDevices.cend())
84 {
85 TFLITE_LOG_PROD(tflite::TFLITE_LOG_INFO,
Teresa Charlinf69ae562023-04-27 14:42:23 +010086 "TfLiteArmnnOpaqueDelegate: Requested unknown backend %s", backend.Get().c_str());
Francis Murtaghc4fb0dd2023-03-16 17:01:56 +000087 }
88 else
89 {
90 backends.push_back(backend);
91 }
92 }
93 }
94
95 if (backends.empty())
96 {
97 // No known backend specified
98 throw armnn::InvalidArgumentException("TfLiteArmnnOpaqueDelegate: No known backend specified.");
99 }
100 m_Options.SetBackends(backends);
101
102 TFLITE_LOG_PROD_ONCE(tflite::TFLITE_LOG_INFO, "TfLiteArmnnOpaqueDelegate: Created TfLite ArmNN delegate.");
103}
104
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100105TfLiteStatus DoPrepare(TfLiteOpaqueContext* tfLiteContext, TfLiteOpaqueDelegate* tfLiteDelegate, void* data)
Matthew Sloyan54cf0112023-04-03 16:32:57 +0100106{
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100107 // We are required to have the void* data parameter in the function signature, but we don't actually use it.
108 armnn::IgnoreUnused(data);
109
Matthew Sloyan54cf0112023-04-03 16:32:57 +0100110 TfLiteIntArray* supportedOperators =
111 static_cast<::armnnOpaqueDelegate::ArmnnOpaqueDelegate*>
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100112 (TfLiteOpaqueDelegateGetData(tfLiteDelegate))->IdentifyOperatorsToDelegate(tfLiteContext);
Matthew Sloyan54cf0112023-04-03 16:32:57 +0100113 if(supportedOperators == nullptr)
114 {
115 return kTfLiteError;
116 }
117
118 // ArmNN Opaque Delegate Registration
119 TfLiteRegistrationExternal* kernelRegistration =
Narumol Prangnawarat26654cb2023-05-03 16:08:11 +0100120 TfLiteRegistrationExternalCreate(kTfLiteBuiltinDelegate,
Ryan OShea59f8f652023-05-11 20:37:53 +0100121 "armnn_delegate",
Narumol Prangnawarat26654cb2023-05-03 16:08:11 +0100122 /*version=*/OPAQUE_DELEGATE_MAJOR_VERSION);
Matthew Sloyan54cf0112023-04-03 16:32:57 +0100123 if(kernelRegistration == nullptr)
124 {
125 return kTfLiteError;
126 }
127
128 TfLiteRegistrationExternalSetInit(
129 kernelRegistration,
130 [](TfLiteOpaqueContext* tfLiteContext, const char* buffer, size_t length) -> void*
131 {
132 armnn::IgnoreUnused(length);
133 const TfLiteOpaqueDelegateParams* parameters =
134 reinterpret_cast<const TfLiteOpaqueDelegateParams*>(buffer);
135 if(parameters == nullptr)
136 {
137 TF_LITE_OPAQUE_KERNEL_LOG(tfLiteContext,
138 "TfLiteArmnnOpaqueDelegate: Unable to get parameters.");
139 return nullptr;
140 }
141
142 return static_cast<void*>(
143 ArmnnSubgraph::Create(tfLiteContext,
144 parameters,
145 static_cast<::armnnOpaqueDelegate::ArmnnOpaqueDelegate*>(
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100146 parameters->delegate->opaque_delegate_builder->data)));
Matthew Sloyan54cf0112023-04-03 16:32:57 +0100147 }
148 );
149
150 TfLiteRegistrationExternalSetFree(
151 kernelRegistration,
152 [](TfLiteOpaqueContext* tfLiteContext, void* buffer) -> void
153 {
154 armnn::IgnoreUnused(tfLiteContext);
155 if (buffer != nullptr)
156 {
157 delete static_cast<ArmnnSubgraph*>(buffer);
158 }
159 }
160 );
161
162 TfLiteRegistrationExternalSetPrepare(
163 kernelRegistration,
164 [](TfLiteOpaqueContext* tfLiteContext, TfLiteOpaqueNode* tfLiteNode) -> TfLiteStatus
165 {
166 void* userData = TfLiteOpaqueNodeGetUserData(tfLiteNode);
167 if (userData == nullptr)
168 {
169 return kTfLiteError;
170 }
171 return static_cast<ArmnnSubgraph*>(userData)->Prepare(tfLiteContext);
172 }
173 );
174
175 TfLiteRegistrationExternalSetInvoke(
176 kernelRegistration,
177 [](TfLiteOpaqueContext* tfLiteContext, TfLiteOpaqueNode* tfLiteNode) -> TfLiteStatus
178 {
179 void* userData = TfLiteOpaqueNodeGetUserData(tfLiteNode);
180 if (userData == nullptr)
181 {
182 return kTfLiteError;
183 }
184
185 return static_cast<ArmnnSubgraph*>(userData)->Invoke(tfLiteContext, tfLiteNode);
186 }
187 );
188
189 const TfLiteStatus status =
190 TfLiteOpaqueContextReplaceNodeSubsetsWithDelegateKernels(
191 tfLiteContext, kernelRegistration, supportedOperators, tfLiteDelegate);
192
193 TfLiteIntArrayFree(supportedOperators);
194 return status;
195}
196
Francis Murtaghc4fb0dd2023-03-16 17:01:56 +0000197TfLiteOpaqueDelegate* TfLiteArmnnOpaqueDelegateCreate(const void* settings)
198{
199 // This method will always create Opaque Delegate with default settings until
200 // we have a DelegateOptions Constructor which can parse the void* settings
201 armnn::IgnoreUnused(settings);
202 auto options = TfLiteArmnnDelegateOptionsDefault();
203 auto* armnnDelegate = new ::armnnOpaqueDelegate::ArmnnOpaqueDelegate(options);
204 return TfLiteOpaqueDelegateCreate(armnnDelegate->GetDelegateBuilder());
205}
206
207::armnnDelegate::DelegateOptions TfLiteArmnnDelegateOptionsDefault()
208{
209 ::armnnDelegate::DelegateOptions options(armnn::Compute::CpuRef);
210 return options;
211}
212
213void TfLiteArmnnOpaqueDelegateDelete(TfLiteOpaqueDelegate* tfLiteDelegate)
214{
215 if (tfLiteDelegate != nullptr)
216 {
217 delete static_cast<::armnnOpaqueDelegate::ArmnnOpaqueDelegate*>(TfLiteOpaqueDelegateGetData(tfLiteDelegate));
218 TfLiteOpaqueDelegateDelete(tfLiteDelegate);
219 }
220}
221
Francis Murtaghc4fb0dd2023-03-16 17:01:56 +0000222const std::string ArmnnOpaqueDelegate::GetVersion() {
223 return OPAQUE_DELEGATE_VERSION;
224}
225
Matthew Sloyan54cf0112023-04-03 16:32:57 +0100226TfLiteIntArray* ArmnnOpaqueDelegate::IdentifyOperatorsToDelegate(TfLiteOpaqueContext* tfLiteContext)
227{
228 TfLiteIntArray* executionPlan = nullptr;
229 if (TfLiteOpaqueContextGetExecutionPlan(tfLiteContext, &executionPlan) != kTfLiteOk)
230 {
231 TF_LITE_OPAQUE_KERNEL_LOG(tfLiteContext, "TfLiteArmnnOpaqueDelegate: Unable to get graph execution plan.");
232 return nullptr;
233 }
234
235 // Delegate data with null network
236 DelegateData delegateData(m_Options.GetBackends());
237
238 TfLiteIntArray* nodesToDelegate = TfLiteIntArrayCreate(executionPlan->size);
239 if (nodesToDelegate == nullptr)
240 {
241 TF_LITE_OPAQUE_KERNEL_LOG(tfLiteContext,
242 "TfLiteArmnnOpaqueDelegate: Unable to create int array from execution plan.");
243 return nullptr;
244 }
245 nodesToDelegate->size = 0;
246
247 std::set<int32_t> unsupportedOperators;
248
249 for (int i = 0; i < executionPlan->size; ++i)
250 {
251 const int nodeIndex = executionPlan->data[i];
252
253 // If TfLiteOpaqueNodes can be delegated to ArmNN
254 TfLiteOpaqueNode* tfLiteNode = nullptr;
255 TfLiteRegistrationExternal* tfLiteRegistration = nullptr;
256
257 if (TfLiteOpaqueContextGetNodeAndRegistration(
258 tfLiteContext, nodeIndex, &tfLiteNode, &tfLiteRegistration) != kTfLiteOk)
259 {
260 TF_LITE_OPAQUE_KERNEL_LOG(tfLiteContext,
261 "TfLiteArmnnOpaqueDelegate: Unable to get node and registration for node %d.",
262 nodeIndex);
263 continue;
264 }
265
266 TfLiteStatus visitStatus;
267 try
268 {
269 visitStatus = ArmnnSubgraph::VisitNode(
270 delegateData, tfLiteContext, tfLiteRegistration, tfLiteNode, nodeIndex);
271 }
272 catch(std::exception& ex)
273 {
274 ARMNN_LOG(error) << "ArmNN Failed to visit node with error: " << ex.what();
275 visitStatus = kTfLiteError;
276 }
277
278 if (visitStatus != kTfLiteOk)
279 {
280 // node is not supported by ArmNN
281 unsupportedOperators.insert(TfLiteRegistrationExternalGetBuiltInCode(tfLiteRegistration));
282 continue;
283 }
284
285 nodesToDelegate->data[nodesToDelegate->size++] = nodeIndex;
286 }
287
288 for (std::set<int32_t>::iterator it=unsupportedOperators.begin(); it!=unsupportedOperators.end(); ++it)
289 {
290 TF_LITE_OPAQUE_KERNEL_LOG(tfLiteContext,
291 "Operator %s [%d] is not supported by armnn_opaque_delegate.",
292 tflite::EnumNameBuiltinOperator(tflite::BuiltinOperator(*it)),
293 *it);
294 }
295
296 if (!unsupportedOperators.empty() && m_Options.TfLiteRuntimeFallbackDisabled())
297 {
298 std::stringstream exMessage;
299 exMessage << "TfLiteArmnnOpaqueDelegate: There are unsupported operators in the model. ";
300 exMessage << "Not falling back to TfLite Runtime as fallback is disabled. ";
301 exMessage << "This should only be disabled under test conditions.";
302 throw armnn::Exception(exMessage.str());
303 }
304 if (nodesToDelegate->size == 0)
305 {
306 ARMNN_LOG(info) << "No operators in this model are supported by the Arm NN TfLite delegate." <<
307 " The model will be executed entirely by TfLite runtime.";
308 }
309
310 std::sort(&nodesToDelegate->data[0], &nodesToDelegate->data[nodesToDelegate->size]);
311 return nodesToDelegate;
312}
313
Ryan OSheaac9607f2023-04-03 11:33:33 +0100314TfLiteStatus ArmnnSubgraph::AddInputLayer(DelegateData& delegateData,
315 TfLiteOpaqueContext* tfLiteContext,
316 const TfLiteIntArray* inputs,
317 std::vector<armnn::BindingPointInfo>& inputBindings)
318{
319 const size_t numInputs = static_cast<size_t>(inputs->size);
320 for (unsigned int i = 0; i < numInputs; ++i)
321 {
322 const int32_t tensorId = inputs->data[i];
323 const TfLiteOpaqueTensor* tensor = TfLiteOpaqueContextGetOpaqueTensor(tfLiteContext, tensorId);
324
325 if(!tensor)
326 {
327 return kTfLiteError;
328 }
329
330 // Do not create bindings for constant inputs
331 if (TfLiteOpaqueTensorGetAllocationType(tensor) == kTfLiteMmapRo)
332 {
333 continue;
334 }
335
336 auto bindingId = static_cast<armnn::LayerBindingId>((tensorId));
337 armnn::IConnectableLayer* layer = delegateData.m_Network->AddInputLayer(bindingId);
338
339 auto tensorInfo = GetTensorInfoForTfLiteOpaqueTensor(tensor);
340 armnn::IOutputSlot& outputSlot = layer->GetOutputSlot(0);
341 outputSlot.SetTensorInfo(tensorInfo);
342
343 // Store for creating connections
344 delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)] = &outputSlot;
345
346 inputBindings.push_back(std::make_pair(bindingId, tensorInfo));
347 }
348
349 return kTfLiteOk;
350}
351
352TfLiteStatus ArmnnSubgraph::AddOutputLayer(DelegateData& delegateData,
353 TfLiteOpaqueContext* tfLiteContext,
354 const TfLiteIntArray* outputs,
355 std::vector<armnn::BindingPointInfo>& outputBindings)
356{
357 const size_t numOutputs = static_cast<size_t>(outputs->size);
358 for (unsigned int i = 0; i < numOutputs; ++i)
359 {
360 const int32_t tensorId = outputs->data[i];
361 const TfLiteOpaqueTensor* tensor = TfLiteOpaqueContextGetOpaqueTensor(tfLiteContext, tensorId);
362
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100363 if(!IsValid(tensor))
Ryan OSheaac9607f2023-04-03 11:33:33 +0100364 {
365 return kTfLiteError;
366 }
367
368 auto bindingId = static_cast<armnn::LayerBindingId>((tensorId));
369 armnn::IConnectableLayer* layer = delegateData.m_Network->AddOutputLayer(bindingId);
370
371 auto tensorInfo = GetTensorInfoForTfLiteOpaqueTensor(tensor);
Ryan OSheac229b3f2023-06-27 22:34:54 +0100372
373 if (delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)] == nullptr)
374 {
375 return kTfLiteError;
376 }
377
Ryan OSheaac9607f2023-04-03 11:33:33 +0100378 delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)]->Connect(layer->GetInputSlot(0));
379 outputBindings.push_back(std::make_pair(bindingId, tensorInfo));
380 }
381
382 return kTfLiteOk;
383}
384
385ArmnnSubgraph* ArmnnSubgraph::Create(TfLiteOpaqueContext* tfLiteContext,
386 const TfLiteOpaqueDelegateParams* parameters,
387 const ArmnnOpaqueDelegate* delegate)
388{
389 const auto startTime = armnn::GetTimeNow();
390 ARMNN_LOG(info) << "ArmnnSubgraph creation";
391
392 TfLiteIntArray* executionPlan;
393 if (TfLiteOpaqueContextGetExecutionPlan(tfLiteContext, &executionPlan) != kTfLiteOk)
394 {
395 return nullptr;
396 }
397
398 // Initialize DelegateData holds network and output slots information
399 DelegateData delegateData(delegate->m_Options.GetBackends());
400
401 // Build ArmNN Network
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000402 armnn::NetworkOptions networkOptions = delegate->m_Options.GetOptimizerOptions().GetModelOptions();
Ryan OSheaac9607f2023-04-03 11:33:33 +0100403 armnn::NetworkId networkId;
404 delegateData.m_Network = armnn::INetwork::Create(networkOptions);
405
406 delegateData.m_OutputSlotForNode = std::vector<armnn::IOutputSlot*>(
407 TfLiteOpaqueContextGetNumTensors(tfLiteContext), nullptr);
408
409 std::vector<armnn::BindingPointInfo> inputBindings;
410 std::vector<armnn::BindingPointInfo> outputBindings;
411
412 // Add input layer
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100413 if (AddInputLayer(delegateData, tfLiteContext, parameters->input_tensors, inputBindings) != kTfLiteOk)
Ryan OSheaac9607f2023-04-03 11:33:33 +0100414 {
415 throw armnn::Exception("TfLiteArmnnOpaqueDelegate: Unable to add Inputs to the network!");
416 }
417
418 // Parse TfLite delegate nodes to ArmNN
419 const auto parseStartTime = armnn::GetTimeNow();
420 for (int i = 0; i < parameters->nodes_to_replace->size; ++i)
421 {
422 const int nodeIndex = parameters->nodes_to_replace->data[i];
423
424 TfLiteOpaqueNode* tfLiteNode = nullptr;
425 TfLiteRegistrationExternal* tfLiteRegistration = nullptr;
426 if (TfLiteOpaqueContextGetNodeAndRegistration(
427 tfLiteContext, nodeIndex, &tfLiteNode, &tfLiteRegistration) != kTfLiteOk)
428 {
429 throw armnn::Exception(&"TfLiteArmnnOpaqueDelegate: Unable to get node registration: " [ nodeIndex]);
430 }
431
432 if (VisitNode(delegateData, tfLiteContext, tfLiteRegistration, tfLiteNode, nodeIndex) != kTfLiteOk)
433 {
434 throw armnn::Exception(&"TfLiteArmnnOpaqueDelegate: Unable to parse node: " [ nodeIndex]);
435 }
436 }
437 ARMNN_LOG(info) << "Parse nodes to ArmNN time: " << std::setprecision(2)
438 << std::fixed << armnn::GetTimeDuration(parseStartTime).count() << " ms";
439
440 // Add Output layer
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100441 if (AddOutputLayer(delegateData, tfLiteContext, parameters->output_tensors, outputBindings) != kTfLiteOk)
Ryan OSheaac9607f2023-04-03 11:33:33 +0100442 {
443 throw armnn::Exception("TfLiteArmnnOpaqueDelegate: Unable to add Outputs to the network!");
444 }
445
446 // Optimize ArmNN network
447 armnn::IOptimizedNetworkPtr optNet(nullptr, nullptr);
448 try
449 {
450 const auto optimizeStartTime = armnn::GetTimeNow();
451 optNet = armnn::Optimize(*(delegateData.m_Network.get()),
452 delegate->m_Options.GetBackends(),
453 delegate->m_Runtime->GetDeviceSpec(),
454 delegate->m_Options.GetOptimizerOptions());
455 ARMNN_LOG(info) << "Optimize ArmnnSubgraph time: " << std::setprecision(2)
456 << std::fixed << armnn::GetTimeDuration(optimizeStartTime).count() << " ms";
457 }
458 catch (std::exception& ex)
459 {
460 std::stringstream exMessage;
461 exMessage << "TfLiteArmnnOpaqueDelegate: Exception (" << ex.what() << ") caught from optimize.";
462 throw armnn::Exception(exMessage.str());
463 }
464 if (!optNet)
465 {
466 // Optimize failed
467 throw armnn::Exception("TfLiteArmnnOpaqueDelegate: Unable to optimize the network!");
468 }
469
470 // If set, we will serialize the optimized model into a dot file.
471 const std::string serializeToDotFile = delegate->m_Options.GetSerializeToDot();
472 if (!serializeToDotFile.empty())
473 {
474 ARMNN_LOG(info) << "Writing graph to dot file: " << serializeToDotFile;
475 fs::path filename = serializeToDotFile;
476 std::fstream file(filename.c_str(), std::ios_base::out);
477 optNet->SerializeToDot(file);
478 }
479
480 try
481 {
482 const auto loadStartTime = armnn::GetTimeNow();
483
484 // Load graph into runtime
485 std::string errorMessage;
486 armnn::Status loadingStatus;
487 armnn::MemorySource inputSource = armnn::MemorySource::Undefined;
488 armnn::MemorySource outputSource = armnn::MemorySource::Undefined;
489 // There's a bit of an assumption here that the delegate will only support Malloc memory source.
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000490 if (delegate->m_Options.GetOptimizerOptions().GetImportEnabled())
Ryan OSheaac9607f2023-04-03 11:33:33 +0100491 {
492 inputSource = armnn::MemorySource::Malloc;
493 }
John Mcloughlinc5ee0d72023-03-24 12:07:25 +0000494 if (delegate->m_Options.GetOptimizerOptions().GetExportEnabled())
Ryan OSheaac9607f2023-04-03 11:33:33 +0100495 {
496 outputSource = armnn::MemorySource::Malloc;
497 }
498 armnn::INetworkProperties networkProperties(false,
499 inputSource,
500 outputSource,
501 delegate->m_Options.GetInternalProfilingState(),
502 delegate->m_Options.GetInternalProfilingDetail());
503 loadingStatus = delegate->m_Runtime->LoadNetwork(networkId,
504 std::move(optNet),
505 errorMessage,
506 networkProperties);
507 if (loadingStatus != armnn::Status::Success)
508 {
509 // Network load failed.
510 throw armnn::Exception("TfLiteArmnnOpaqueDelegate: Network could not be loaded: " + errorMessage);
511 }
512
513 ARMNN_LOG(info) << "Load ArmnnSubgraph time: " << std::setprecision(2)
514 << std::fixed << armnn::GetTimeDuration(loadStartTime).count() << " ms";
515 }
516 catch (std::exception& ex)
517 {
518 std::stringstream exMessage;
519 exMessage << "TfLiteArmnnOpaqueDelegate: Exception (" << ex.what() << ") caught from LoadNetwork.";
520 throw armnn::Exception(exMessage.str());
521 }
522
523 // Register debug callback function
524 if (delegate->m_Options.GetDebugCallbackFunction().has_value())
525 {
526 delegate->m_Runtime->RegisterDebugCallback(networkId, delegate->m_Options.GetDebugCallbackFunction().value());
527 }
528
529 ARMNN_LOG(info) << "Overall ArmnnSubgraph creation time: " << std::setprecision(2)
530 << std::fixed << armnn::GetTimeDuration(startTime).count() << " ms\n";
531
532 // Create a new SubGraph with networkId and runtime
533 return new ArmnnSubgraph(networkId, delegate->m_Runtime, inputBindings, outputBindings);
534}
535
536TfLiteStatus ArmnnSubgraph::Prepare(TfLiteOpaqueContext* tfLiteContext)
537{
538 armnn::IgnoreUnused(tfLiteContext);
539 return kTfLiteOk;
540}
541
542TfLiteStatus ArmnnSubgraph::Invoke(TfLiteOpaqueContext* tfLiteContext, TfLiteOpaqueNode* tfLiteNode)
543{
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100544 // Get array of input indices, inputIndexArray is set from the TfLiteOpaqueNodeInputs function
545 // This function turns inputIndexArray into an int array of indices. These indices point to the tensors for
546 // each input slot in the node.
547 const int* inputIndexArray;
Ryan OSheaac9607f2023-04-03 11:33:33 +0100548 int numInputs;
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100549 if(TfLiteOpaqueNodeInputs(tfLiteNode, &inputIndexArray, &numInputs) != kTfLiteOk)
Ryan OSheaac9607f2023-04-03 11:33:33 +0100550 {
551 throw armnn::Exception("TfLiteArmnnOpaqueDelegate: Unable to load subgraph inputs!");
552 }
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100553 // Prepare inputs
554 armnn::InputTensors inputTensors;
555 size_t inputIndex = 0;
Ryan OSheaac9607f2023-04-03 11:33:33 +0100556 for (int inputIdx = 0; inputIdx < numInputs; inputIdx++)
557 {
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100558 TfLiteOpaqueTensor* tensor = TfLiteOpaqueContextGetOpaqueTensor(tfLiteContext, inputIndexArray[inputIdx]);
Ryan OSheaac9607f2023-04-03 11:33:33 +0100559
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100560 if(!IsValid(tensor))
Ryan OSheaac9607f2023-04-03 11:33:33 +0100561 {
562 return kTfLiteError;
563 }
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100564 // If tensor is not read only
Ryan OSheaac9607f2023-04-03 11:33:33 +0100565 if (TfLiteOpaqueTensorGetAllocationType(tensor) != kTfLiteMmapRo)
566 {
567 const armnn::BindingPointInfo& inputBinding = m_InputBindings[inputIndex];
568 armnn::TensorInfo inputTensorInfo = inputBinding.second;
569 inputTensorInfo.SetConstant(true);
570 const armnn::ConstTensor inputTensor(inputTensorInfo, TfLiteOpaqueTensorData(tensor));
Narumol Prangnawarat46e574e2023-05-05 16:39:05 +0100571 inputTensors.emplace_back(inputIndexArray[inputIdx], inputTensor);
Ryan OSheaac9607f2023-04-03 11:33:33 +0100572
573 ++inputIndex;
574 }
575 }
576
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100577 // Get array of output indices, outputIndexArray is set from the TfLiteOpaqueNodeOutputs function
578 // This function turns outputIndexArray into an int array of indices. These indices point to the tensors for
579 // each output slot in the node.
580 const int* outputIndexArray;
Ryan OSheaac9607f2023-04-03 11:33:33 +0100581 int numOutputs;
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100582 if(TfLiteOpaqueNodeOutputs(tfLiteNode, &outputIndexArray, &numOutputs) != kTfLiteOk)
Ryan OSheaac9607f2023-04-03 11:33:33 +0100583 {
584 throw armnn::Exception("TfLiteArmnnOpaqueDelegate: Unable to load subgraph outputs!");
585 }
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100586 // Assign the tensors from the outputIndexArray to the armnn BindingPointInfo
587 armnn::OutputTensors outputTensors;
Ryan OSheaac9607f2023-04-03 11:33:33 +0100588 for (int outputIdx = 0; outputIdx < numOutputs; outputIdx++)
589 {
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100590 const armnn::BindingPointInfo& outputBinding = m_OutputBindings[outputIdx];
591 TfLiteOpaqueTensor* tensor = TfLiteOpaqueContextGetOpaqueTensor(tfLiteContext, outputIndexArray[outputIdx]);
592 if(!IsValid(tensor))
Ryan OSheaac9607f2023-04-03 11:33:33 +0100593 {
594 return kTfLiteError;
595 }
596
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100597 const armnn::Tensor outputTensor(outputBinding.second, reinterpret_cast<TfLiteTensor*>(tensor)->data
598 .data);
599 outputTensors.emplace_back(outputIndexArray[outputIdx], outputTensor);
Ryan OSheaac9607f2023-04-03 11:33:33 +0100600 }
601
602 // Run graph
603 auto status = m_Runtime->EnqueueWorkload(m_NetworkId, inputTensors, outputTensors);
604 // The delegate holds its own Arm NN runtime so this is our last chance to print internal profiling data.
605 std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkId);
606 if (profiler && profiler->IsProfilingEnabled())
607 {
608 profiler->Print(std::cout);
609 }
610 return (status == armnn::Status::Success) ? kTfLiteOk : kTfLiteError;
611}
612
613TfLiteStatus ArmnnSubgraph::VisitNode(DelegateData& delegateData,
614 TfLiteOpaqueContext* tfLiteContext,
615 TfLiteRegistrationExternal* tfLiteRegistration,
616 TfLiteOpaqueNode* tfLiteNode,
617 int nodeIndex)
618{
619 switch (TfLiteRegistrationExternalGetBuiltInCode(tfLiteRegistration))
620 {
Teresa Charlinf69ae562023-04-27 14:42:23 +0100621 case kTfLiteBuiltinAbs:
622 return VisitElementwiseUnaryOperator(delegateData,
623 tfLiteContext,
624 tfLiteNode,
625 nodeIndex,
626 kTfLiteBuiltinAbs,
627 armnn::UnaryOperation::Abs);
David Monahan6c53f9f2023-04-27 15:21:19 +0100628 case kTfLiteBuiltinAdd:
629 return VisitElementwiseBinaryOperator(delegateData,
630 tfLiteContext,
631 tfLiteNode,
632 nodeIndex,
633 kTfLiteBuiltinAdd);
John Mcloughlin559d9092023-04-26 20:14:47 +0100634 case kTfLiteBuiltinArgMax:
635 return VisitArgMinMaxOperator(delegateData,
636 tfLiteContext,
637 tfLiteNode,
638 nodeIndex,
639 kTfLiteBuiltinArgMax);
640 case kTfLiteBuiltinArgMin:
641 return VisitArgMinMaxOperator(delegateData,
642 tfLiteContext,
643 tfLiteNode,
644 nodeIndex,
645 kTfLiteBuiltinArgMin);
Matthew Sloyan48ec8132023-04-27 17:04:47 +0100646 case kTfLiteBuiltinAveragePool2d:
647 return VisitPooling2dOperator(delegateData,
648 tfLiteContext,
649 tfLiteNode,
650 nodeIndex,
651 kTfLiteBuiltinAveragePool2d);
John Mcloughlin0422cf22023-04-27 16:55:00 +0100652 case kTfLiteBuiltinBatchMatmul:
653 return VisitBatchMatMulOperator(delegateData,
654 tfLiteContext,
655 tfLiteNode,
656 nodeIndex,
657 kTfLiteBuiltinBatchMatmul);
Idriss Chaouchcbf79292023-09-08 11:18:16 +0100658 case kTfLiteBuiltinBroadcastTo:
659 return VisitBroadcastToOperator(delegateData,
660 tfLiteContext,
661 tfLiteNode,
662 nodeIndex,
663 kTfLiteBuiltinBroadcastTo);
Kevin May81b66f32023-04-26 14:55:36 +0100664 case kTfLiteBuiltinBatchToSpaceNd:
665 return VisitBatchToSpaceNdOperator(delegateData,
666 tfLiteContext,
667 tfLiteNode,
668 nodeIndex,
669 kTfLiteBuiltinBatchToSpaceNd);
Ryan OSheaa37ccb02023-04-11 10:54:07 +0100670 case kTfLiteBuiltinCast:
671 return VisitCastOperator(delegateData,
672 tfLiteContext,
673 tfLiteNode,
674 nodeIndex,
675 kTfLiteBuiltinCast);
Teresa Charlinf69ae562023-04-27 14:42:23 +0100676 case kTfLiteBuiltinCeil:
677 return VisitElementwiseUnaryOperator(delegateData,
678 tfLiteContext,
679 tfLiteNode,
680 nodeIndex,
681 kTfLiteBuiltinCeil,
682 armnn::UnaryOperation::Ceil);
Matthew Sloyan2b04ec32023-04-26 11:42:46 +0100683 case kTfLiteBuiltinConcatenation:
684 return VisitControlOperator(delegateData,
685 tfLiteContext,
686 tfLiteNode,
687 nodeIndex,
688 kTfLiteBuiltinConcatenation);
Matthew Sloyan080ffd82023-04-24 12:53:04 +0100689 case kTfLiteBuiltinConv2d:
690 return VisitConvolutionOperator(delegateData,
691 tfLiteContext,
692 tfLiteNode,
693 nodeIndex,
694 kTfLiteBuiltinConv2d);
Francis Murtagh3a9e7ba2023-04-26 15:58:39 +0100695 case kTfLiteBuiltinConv3d:
696 return VisitConvolutionOperator(delegateData,
697 tfLiteContext,
698 tfLiteNode,
699 nodeIndex,
700 kTfLiteBuiltinConv3d);
Matthew Sloyan48ec8132023-04-27 17:04:47 +0100701 case kTfLiteBuiltinCustom:
702 {
703 // Custom operators are defined by the name rather than the builtin code.
704 // Parse the custom_name param in the registration to point to the correct visitor function.
705 std::string customOperatorName = TfLiteRegistrationExternalGetCustomName(tfLiteRegistration);
706 if ( customOperatorName == "AveragePool3D" )
707 {
708 return VisitPooling3dOperator(delegateData,
709 tfLiteContext,
710 tfLiteNode,
711 nodeIndex,
712 customOperatorName);
713 }
714 else if (customOperatorName == "MaxPool3D")
715 {
716 return VisitPooling3dOperator(delegateData,
717 tfLiteContext,
718 tfLiteNode,
719 nodeIndex,
720 customOperatorName);
721 }
722 // Invalid or unsupported custom operator
723 return kTfLiteError;
724 }
Matthew Sloyan080ffd82023-04-24 12:53:04 +0100725 case kTfLiteBuiltinDepthwiseConv2d:
726 return VisitConvolutionOperator(delegateData,
727 tfLiteContext,
728 tfLiteNode,
729 nodeIndex,
730 kTfLiteBuiltinDepthwiseConv2d);
Francis Murtagh36d94ef2023-04-28 14:05:43 +0100731 case kTfLiteBuiltinDequantize:
732 return VisitDequantizeOperator(delegateData,
733 tfLiteContext,
734 tfLiteNode,
735 nodeIndex,
736 kTfLiteBuiltinDequantize);
David Monahan6c53f9f2023-04-27 15:21:19 +0100737 case kTfLiteBuiltinDiv:
738 return VisitElementwiseBinaryOperator(delegateData,
739 tfLiteContext,
740 tfLiteNode,
741 nodeIndex,
742 kTfLiteBuiltinDiv);
Matthew Sloyan2b04ec32023-04-26 11:42:46 +0100743 case kTfLiteBuiltinEqual:
744 return VisitComparisonOperator(delegateData,
745 tfLiteContext,
746 tfLiteNode,
747 nodeIndex,
Teresa Charlinf69ae562023-04-27 14:42:23 +0100748 kTfLiteBuiltinEqual,
749 armnn::ComparisonOperation::Equal);
Teresa Charlin42362962023-04-28 14:23:33 +0100750 case kTfLiteBuiltinDepthToSpace:
751 return VisitDepthToSpaceOperator(delegateData,
752 tfLiteContext,
753 tfLiteNode,
754 nodeIndex,
755 kTfLiteBuiltinDepthToSpace);
756 case kTfLiteBuiltinElu:
757 return VisitActivationOperator(delegateData,
758 tfLiteContext,
759 tfLiteNode,
760 nodeIndex,
761 kTfLiteBuiltinElu);
Teresa Charlinf69ae562023-04-27 14:42:23 +0100762 case kTfLiteBuiltinExp:
763 return VisitElementwiseUnaryOperator(delegateData,
764 tfLiteContext,
765 tfLiteNode,
766 nodeIndex,
767 kTfLiteBuiltinExp,
768 armnn::UnaryOperation::Exp);
Matthew Sloyan3504e422023-05-03 13:53:02 +0100769 case kTfLiteBuiltinExpandDims:
770 return VisitExpandDimsOperator(delegateData,
771 tfLiteContext,
772 tfLiteNode,
773 nodeIndex,
774 kTfLiteBuiltinExpandDims);
Ryan OShea59f8f652023-05-11 20:37:53 +0100775 case kTfLiteBuiltinFill:
776 return VisitFillOperator(delegateData,
777 tfLiteContext,
778 tfLiteNode,
779 nodeIndex,
780 kTfLiteBuiltinFill);
Matthew Sloyan48ec8132023-04-27 17:04:47 +0100781 case kTfLiteBuiltinFloor:
782 return VisitFloorOperator(delegateData,
783 tfLiteContext,
784 tfLiteNode,
785 nodeIndex,
786 kTfLiteBuiltinFloor);
David Monahan6c53f9f2023-04-27 15:21:19 +0100787 case kTfLiteBuiltinFloorDiv:
788 return VisitElementwiseBinaryOperator(delegateData,
789 tfLiteContext,
790 tfLiteNode,
791 nodeIndex,
792 kTfLiteBuiltinFloorDiv);
Matthew Sloyan0bd4c622023-04-27 11:48:26 +0100793 case kTfLiteBuiltinFullyConnected:
794 return VisitFullyConnectedOperator(delegateData,
795 tfLiteContext,
796 tfLiteNode,
797 nodeIndex,
798 kTfLiteBuiltinFullyConnected);
Kevin Mayb2831c52023-04-26 17:27:24 +0100799 case kTfLiteBuiltinGather:
800 return VisitGatherOperator(delegateData,
801 tfLiteContext,
802 tfLiteNode,
803 nodeIndex,
804 kTfLiteBuiltinGather);
805 case kTfLiteBuiltinGatherNd:
806 return VisitGatherNdOperator(delegateData,
807 tfLiteContext,
808 tfLiteNode,
809 nodeIndex,
810 kTfLiteBuiltinGatherNd);
Teresa Charlin077cddb2023-09-15 15:19:21 +0100811 case kTfLiteBuiltinGelu:
812 return VisitActivationOperator(delegateData,
813 tfLiteContext,
814 tfLiteNode,
815 nodeIndex,
816 kTfLiteBuiltinGelu);
Matthew Sloyan2b04ec32023-04-26 11:42:46 +0100817 case kTfLiteBuiltinGreater:
818 return VisitComparisonOperator(delegateData,
819 tfLiteContext,
820 tfLiteNode,
821 nodeIndex,
Teresa Charlinf69ae562023-04-27 14:42:23 +0100822 kTfLiteBuiltinGreater,
823 armnn::ComparisonOperation::Greater);
Matthew Sloyan2b04ec32023-04-26 11:42:46 +0100824 case kTfLiteBuiltinGreaterEqual:
825 return VisitComparisonOperator(delegateData,
826 tfLiteContext,
827 tfLiteNode,
828 nodeIndex,
Teresa Charlinf69ae562023-04-27 14:42:23 +0100829 kTfLiteBuiltinGreaterEqual,
830 armnn::ComparisonOperation::GreaterOrEqual);
Matthew Sloyan0bd4c622023-04-27 11:48:26 +0100831 case kTfLiteBuiltinHardSwish:
832 return VisitActivationOperator(delegateData,
833 tfLiteContext,
834 tfLiteNode,
835 nodeIndex,
836 kTfLiteBuiltinHardSwish);
Teresa Charlinf69ae562023-04-27 14:42:23 +0100837 case kTfLiteBuiltinL2Normalization:
838 return VisitL2NormalizationOperator(delegateData,
839 tfLiteContext,
840 tfLiteNode,
841 nodeIndex,
842 kTfLiteBuiltinL2Normalization);
Matthew Sloyan48ec8132023-04-27 17:04:47 +0100843 case kTfLiteBuiltinL2Pool2d:
844 return VisitPooling2dOperator(delegateData,
845 tfLiteContext,
846 tfLiteNode,
847 nodeIndex,
848 kTfLiteBuiltinL2Pool2d);
Tianle Chengae931732023-07-28 11:53:04 +0100849 case kTfLiteBuiltinLeakyRelu:
850 return VisitActivationOperator(delegateData,
851 tfLiteContext,
852 tfLiteNode,
853 nodeIndex,
854 kTfLiteBuiltinLeakyRelu);
Matthew Sloyan2b04ec32023-04-26 11:42:46 +0100855 case kTfLiteBuiltinLess:
856 return VisitComparisonOperator(delegateData,
857 tfLiteContext,
858 tfLiteNode,
859 nodeIndex,
Teresa Charlinf69ae562023-04-27 14:42:23 +0100860 kTfLiteBuiltinLess,
861 armnn::ComparisonOperation::Less);
Matthew Sloyan2b04ec32023-04-26 11:42:46 +0100862 case kTfLiteBuiltinLessEqual:
863 return VisitComparisonOperator(delegateData,
864 tfLiteContext,
865 tfLiteNode,
866 nodeIndex,
Teresa Charlinf69ae562023-04-27 14:42:23 +0100867 kTfLiteBuiltinLessEqual,
868 armnn::ComparisonOperation::LessOrEqual);
Matthew Sloyan0bd4c622023-04-27 11:48:26 +0100869 case kTfLiteBuiltinLogistic:
870 return VisitActivationOperator(delegateData,
871 tfLiteContext,
872 tfLiteNode,
873 nodeIndex,
874 kTfLiteBuiltinLogistic);
Teresa Charlinf69ae562023-04-27 14:42:23 +0100875 case kTfLiteBuiltinLocalResponseNormalization:
876 return VisitLocalResponseNormalizationOperator(delegateData,
877 tfLiteContext,
878 tfLiteNode,
879 nodeIndex,
880 kTfLiteBuiltinLocalResponseNormalization);
881 case kTfLiteBuiltinLog:
882 return VisitElementwiseUnaryOperator(delegateData,
883 tfLiteContext,
884 tfLiteNode,
885 nodeIndex,
886 kTfLiteBuiltinLog,
887 armnn::UnaryOperation::Log);
888 case kTfLiteBuiltinLogicalAnd:
889 return VisitLogicalBinaryOperator(delegateData,
890 tfLiteContext,
891 tfLiteNode,
892 nodeIndex,
893 kTfLiteBuiltinLogicalAnd,
894 armnn::LogicalBinaryOperation::LogicalAnd);
895 case kTfLiteBuiltinLogicalNot:
896 return VisitElementwiseUnaryOperator(delegateData,
897 tfLiteContext,
898 tfLiteNode,
899 nodeIndex,
900 kTfLiteBuiltinLogicalNot,
901 armnn::UnaryOperation::LogicalNot);
902 case kTfLiteBuiltinLogicalOr:
903 return VisitLogicalBinaryOperator(delegateData,
904 tfLiteContext,
905 tfLiteNode,
906 nodeIndex,
907 kTfLiteBuiltinLogicalOr,
908 armnn::LogicalBinaryOperation::LogicalOr);
Teresa Charlin42362962023-04-28 14:23:33 +0100909 case kTfLiteBuiltinLogSoftmax:
910 return VisitSoftmaxOperator(delegateData,
911 tfLiteContext,
912 tfLiteNode,
913 nodeIndex,
914 kTfLiteBuiltinLogSoftmax);
Matthew Sloyan48ec8132023-04-27 17:04:47 +0100915 case kTfLiteBuiltinLstm:
916 return VisitLstmOperator(delegateData,
917 tfLiteContext,
918 tfLiteNode,
919 nodeIndex,
920 kTfLiteBuiltinLstm);
921 case kTfLiteBuiltinMaxPool2d:
922 return VisitPooling2dOperator(delegateData,
923 tfLiteContext,
924 tfLiteNode,
925 nodeIndex,
926 kTfLiteBuiltinMaxPool2d);
David Monahan6c53f9f2023-04-27 15:21:19 +0100927 case kTfLiteBuiltinMaximum:
928 return VisitElementwiseBinaryOperator(delegateData,
929 tfLiteContext,
930 tfLiteNode,
931 nodeIndex,
932 kTfLiteBuiltinMaximum);
Matthew Sloyan2b04ec32023-04-26 11:42:46 +0100933 case kTfLiteBuiltinMean:
934 return VisitControlOperator(delegateData,
935 tfLiteContext,
936 tfLiteNode,
937 nodeIndex,
938 kTfLiteBuiltinMean);
David Monahan6c53f9f2023-04-27 15:21:19 +0100939 case kTfLiteBuiltinMinimum:
940 return VisitElementwiseBinaryOperator(delegateData,
941 tfLiteContext,
942 tfLiteNode,
943 nodeIndex,
944 kTfLiteBuiltinMinimum);
Ryan OShea59f8f652023-05-11 20:37:53 +0100945 case kTfLiteBuiltinMirrorPad:
946 return VisitPadOperator(delegateData,
947 tfLiteContext,
948 tfLiteNode,
949 nodeIndex,
950 kTfLiteBuiltinMirrorPad);
David Monahan6c53f9f2023-04-27 15:21:19 +0100951 case kTfLiteBuiltinMul:
952 return VisitElementwiseBinaryOperator(delegateData,
953 tfLiteContext,
954 tfLiteNode,
955 nodeIndex,
956 kTfLiteBuiltinMul);
Teresa Charlinf69ae562023-04-27 14:42:23 +0100957 case kTfLiteBuiltinNeg:
958 return VisitElementwiseUnaryOperator(delegateData,
959 tfLiteContext,
960 tfLiteNode,
961 nodeIndex,
962 kTfLiteBuiltinNeg,
963 armnn::UnaryOperation::Neg);
Matthew Sloyan2b04ec32023-04-26 11:42:46 +0100964 case kTfLiteBuiltinNotEqual:
965 return VisitComparisonOperator(delegateData,
966 tfLiteContext,
967 tfLiteNode,
968 nodeIndex,
Teresa Charlinf69ae562023-04-27 14:42:23 +0100969 kTfLiteBuiltinNotEqual,
970 armnn::ComparisonOperation::NotEqual);
Teresa Charlinecebb0f2023-04-27 21:37:56 +0100971 case kTfLiteBuiltinPack:
972 return VisitPackOperator(delegateData,
973 tfLiteContext,
974 tfLiteNode,
975 nodeIndex,
976 kTfLiteBuiltinPack);
977 case kTfLiteBuiltinPad:
978 return VisitPadOperator(delegateData,
979 tfLiteContext,
980 tfLiteNode,
981 nodeIndex,
982 kTfLiteBuiltinPad);
983 case kTfLiteBuiltinPadv2:
984 return VisitPadOperator(delegateData,
985 tfLiteContext,
986 tfLiteNode,
987 nodeIndex,
988 kTfLiteBuiltinPadv2);
John Mcloughlin0ec00872023-05-15 17:03:49 +0100989 case kTfLiteBuiltinPow:
990 return VisitElementwiseBinaryOperator(delegateData,
991 tfLiteContext,
992 tfLiteNode,
993 nodeIndex,
994 kTfLiteBuiltinPow);
Matthew Sloyan0bd4c622023-04-27 11:48:26 +0100995 case kTfLiteBuiltinPrelu:
996 return VisitPreluOperator(delegateData,
997 tfLiteContext,
998 tfLiteNode,
999 nodeIndex,
1000 kTfLiteBuiltinPrelu);
Francis Murtagh36d94ef2023-04-28 14:05:43 +01001001 case kTfLiteBuiltinQuantize:
1002 return VisitQuantizeOperator(delegateData,
1003 tfLiteContext,
1004 tfLiteNode,
1005 nodeIndex,
1006 kTfLiteBuiltinQuantize);
John Mcloughlin083586d2023-04-28 18:36:52 +01001007 case kTfLiteBuiltinReduceMax:
1008 return VisitReduceOperator(delegateData,
1009 tfLiteContext,
1010 tfLiteNode,
1011 nodeIndex,
1012 kTfLiteBuiltinReduceMax);
1013 case kTfLiteBuiltinReduceMin:
1014 return VisitReduceOperator(delegateData,
1015 tfLiteContext,
1016 tfLiteNode,
1017 nodeIndex,
1018 kTfLiteBuiltinReduceMin);
1019 case kTfLiteBuiltinReduceProd:
1020 return VisitReduceOperator(delegateData,
1021 tfLiteContext,
1022 tfLiteNode,
1023 nodeIndex,
1024 kTfLiteBuiltinReduceProd);
Matthew Sloyan0bd4c622023-04-27 11:48:26 +01001025 case kTfLiteBuiltinRelu:
1026 return VisitActivationOperator(delegateData,
1027 tfLiteContext,
1028 tfLiteNode,
1029 nodeIndex,
1030 kTfLiteBuiltinRelu);
1031 case kTfLiteBuiltinReluN1To1:
1032 return VisitActivationOperator(delegateData,
1033 tfLiteContext,
1034 tfLiteNode,
1035 nodeIndex,
1036 kTfLiteBuiltinReluN1To1);
1037 case kTfLiteBuiltinRelu6:
1038 return VisitActivationOperator(delegateData,
1039 tfLiteContext,
1040 tfLiteNode,
1041 nodeIndex,
1042 kTfLiteBuiltinRelu6);
Matthew Sloyanc49aacc2023-04-28 17:27:26 +01001043 case kTfLiteBuiltinReshape:
1044 return VisitReshapeOperator(delegateData,
1045 tfLiteContext,
1046 tfLiteNode,
1047 nodeIndex,
1048 kTfLiteBuiltinReshape);
John Mcloughlin083586d2023-04-28 18:36:52 +01001049 case kTfLiteBuiltinResizeNearestNeighbor:
1050 return VisitResizeOperator(delegateData,
1051 tfLiteContext,
1052 tfLiteNode,
1053 nodeIndex,
1054 kTfLiteBuiltinResizeNearestNeighbor);
1055 case kTfLiteBuiltinResizeBilinear:
1056 return VisitResizeOperator(delegateData,
1057 tfLiteContext,
1058 tfLiteNode,
1059 nodeIndex,
1060 kTfLiteBuiltinResizeBilinear);
Tracy Narine7306bbe2023-07-17 16:06:26 +01001061 case kTfLiteBuiltinReverseV2:
1062 return VisitReverseV2Operator(delegateData,
1063 tfLiteContext,
1064 tfLiteNode,
1065 nodeIndex,
1066 kTfLiteBuiltinReverseV2);
Teresa Charlinf69ae562023-04-27 14:42:23 +01001067 case kTfLiteBuiltinRsqrt:
1068 return VisitElementwiseUnaryOperator(delegateData,
1069 tfLiteContext,
1070 tfLiteNode,
1071 nodeIndex,
1072 kTfLiteBuiltinRsqrt,
1073 armnn::UnaryOperation::Rsqrt);
John Mcloughlin0422cf22023-04-27 16:55:00 +01001074 case kTfLiteBuiltinShape:
1075 return VisitShapeOperator(delegateData,
1076 tfLiteContext,
1077 tfLiteNode,
1078 nodeIndex,
1079 kTfLiteBuiltinShape);
Teresa Charlinf69ae562023-04-27 14:42:23 +01001080 case kTfLiteBuiltinSin:
1081 return VisitElementwiseUnaryOperator(delegateData,
1082 tfLiteContext,
1083 tfLiteNode,
1084 nodeIndex,
1085 kTfLiteBuiltinSin,
1086 armnn::UnaryOperation::Sin);
Teresa Charlin86b03572023-04-28 13:19:12 +01001087 case kTfLiteBuiltinSlice:
1088 return VisitSliceOperator(delegateData,
1089 tfLiteContext,
1090 tfLiteNode,
1091 nodeIndex,
1092 kTfLiteBuiltinSlice);
Teresa Charlin42362962023-04-28 14:23:33 +01001093 case kTfLiteBuiltinSoftmax:
1094 return VisitSoftmaxOperator(delegateData,
1095 tfLiteContext,
1096 tfLiteNode,
1097 nodeIndex,
1098 kTfLiteBuiltinSoftmax);
Kevin May81b66f32023-04-26 14:55:36 +01001099 case kTfLiteBuiltinSpaceToBatchNd:
1100 return VisitSpaceToBatchNdOperator(delegateData,
1101 tfLiteContext,
1102 tfLiteNode,
1103 nodeIndex,
1104 kTfLiteBuiltinSpaceToBatchNd);
Teresa Charlin42362962023-04-28 14:23:33 +01001105 case kTfLiteBuiltinSpaceToDepth:
1106 return VisitSpaceToDepthOperator(delegateData,
1107 tfLiteContext,
1108 tfLiteNode,
1109 nodeIndex,
1110 kTfLiteBuiltinSpaceToDepth);
David Monahanc833cef2023-05-03 15:53:03 +01001111 case kTfLiteBuiltinSplit:
1112 return VisitSplitOperator(delegateData,
1113 tfLiteContext,
1114 tfLiteNode,
1115 nodeIndex,
1116 kTfLiteBuiltinSplit);
1117 case kTfLiteBuiltinSplitV:
1118 return VisitSplitVOperator(delegateData,
1119 tfLiteContext,
1120 tfLiteNode,
1121 nodeIndex,
1122 kTfLiteBuiltinSplitV);
John Mcloughlin0ec00872023-05-15 17:03:49 +01001123 case kTfLiteBuiltinSquaredDifference:
1124 return VisitElementwiseBinaryOperator(delegateData,
1125 tfLiteContext,
1126 tfLiteNode,
1127 nodeIndex,
1128 kTfLiteBuiltinSquaredDifference);
David Monahan6c53f9f2023-04-27 15:21:19 +01001129 case kTfLiteBuiltinSub:
1130 return VisitElementwiseBinaryOperator(delegateData,
1131 tfLiteContext,
1132 tfLiteNode,
1133 nodeIndex,
1134 kTfLiteBuiltinSub);
Teresa Charlinf69ae562023-04-27 14:42:23 +01001135 case kTfLiteBuiltinSqrt:
1136 return VisitElementwiseUnaryOperator(delegateData,
1137 tfLiteContext,
1138 tfLiteNode,
1139 nodeIndex,
1140 kTfLiteBuiltinSqrt,
1141 armnn::UnaryOperation::Sqrt);
Matthew Sloyan3504e422023-05-03 13:53:02 +01001142 case kTfLiteBuiltinSqueeze:
1143 return VisitSqueezeOperator(delegateData,
1144 tfLiteContext,
1145 tfLiteNode,
1146 nodeIndex,
1147 kTfLiteBuiltinSqueeze);
Teresa Charlin86b03572023-04-28 13:19:12 +01001148 case kTfLiteBuiltinStridedSlice:
1149 return VisitStridedSliceOperator(delegateData,
1150 tfLiteContext,
1151 tfLiteNode,
1152 nodeIndex,
1153 kTfLiteBuiltinStridedSlice);
John Mcloughlin083586d2023-04-28 18:36:52 +01001154 case kTfLiteBuiltinSum:
1155 return VisitReduceOperator(delegateData,
1156 tfLiteContext,
1157 tfLiteNode,
1158 nodeIndex,
1159 kTfLiteBuiltinSum);
Matthew Sloyan0bd4c622023-04-27 11:48:26 +01001160 case kTfLiteBuiltinTanh:
1161 return VisitActivationOperator(delegateData,
1162 tfLiteContext,
1163 tfLiteNode,
1164 nodeIndex,
1165 kTfLiteBuiltinTanh);
Tianle Cheng92ce35c2023-07-25 16:41:00 +01001166 case kTfLiteBuiltinTile:
1167 return VisitTileOperator(delegateData,
1168 tfLiteContext,
1169 tfLiteNode,
1170 nodeIndex,
1171 kTfLiteBuiltinTile);
Teresa Charlin42362962023-04-28 14:23:33 +01001172 case kTfLiteBuiltinTranspose:
1173 return VisitTransposeOperator(delegateData,
Tianle Cheng92ce35c2023-07-25 16:41:00 +01001174 tfLiteContext,
1175 tfLiteNode,
1176 nodeIndex,
1177 kTfLiteBuiltinTranspose);
Francis Murtagh3a9e7ba2023-04-26 15:58:39 +01001178 case kTfLiteBuiltinTransposeConv:
1179 return VisitConvolutionOperator(delegateData,
1180 tfLiteContext,
1181 tfLiteNode,
1182 nodeIndex,
1183 kTfLiteBuiltinTransposeConv);
Matthew Sloyan74be13e2023-05-03 17:34:00 +01001184 case kTfLiteBuiltinUnidirectionalSequenceLstm:
1185 return VisitUnidirectionalSequenceLstmOperator(delegateData,
1186 tfLiteContext,
1187 tfLiteNode,
1188 nodeIndex,
1189 kTfLiteBuiltinUnidirectionalSequenceLstm);
Teresa Charlinecebb0f2023-04-27 21:37:56 +01001190 case kTfLiteBuiltinUnpack:
1191 return VisitUnpackOperator(delegateData,
1192 tfLiteContext,
1193 tfLiteNode,
1194 nodeIndex,
1195 kTfLiteBuiltinUnpack);
Ryan OSheaac9607f2023-04-03 11:33:33 +01001196 default:
1197 return kTfLiteError;
1198 }
1199}
Francis Murtagh3a9e7ba2023-04-26 15:58:39 +01001200} // armnnOpaqueDelegate namespace