Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 1 | // |
Mike Kelly | 5446a4d | 2023-01-20 15:51:05 +0000 | [diff] [blame] | 2 | // Copyright © 2020-2023 Arm Ltd and Contributors. All rights reserved. |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include <armnn_delegate.hpp> |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 7 | |
Matthew Sloyan | ac001ee | 2021-02-03 10:43:04 +0000 | [diff] [blame] | 8 | #include "Version.hpp" |
| 9 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 10 | #include "Activation.hpp" |
| 11 | #include "ArgMinMax.hpp" |
Ryan OShea | 49ed0df | 2022-09-21 16:09:41 +0100 | [diff] [blame] | 12 | #include "BatchMatMul.hpp" |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 13 | #include "BatchSpace.hpp" |
Idriss Chaouch | cbf7929 | 2023-09-08 11:18:16 +0100 | [diff] [blame] | 14 | #include "BroadcastTo.hpp" |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 15 | #include "Comparison.hpp" |
| 16 | #include "Convolution.hpp" |
| 17 | #include "Control.hpp" |
| 18 | #include "ElementwiseBinary.hpp" |
| 19 | #include "ElementwiseUnary.hpp" |
| 20 | #include "Fill.hpp" |
| 21 | #include "FullyConnected.hpp" |
| 22 | #include "Gather.hpp" |
Teresa Charlin | d5c0ed2 | 2022-04-25 18:23:41 +0100 | [diff] [blame] | 23 | #include "GatherNd.hpp" |
Matthew Sloyan | c8eb955 | 2020-11-26 10:54:22 +0000 | [diff] [blame] | 24 | #include "LogicalBinary.hpp" |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 25 | #include "Lstm.hpp" |
| 26 | #include "Normalization.hpp" |
Matthew Sloyan | a7a12f5 | 2021-05-06 10:05:28 +0100 | [diff] [blame] | 27 | #include "Pack.hpp" |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 28 | #include "Pad.hpp" |
| 29 | #include "Pooling.hpp" |
James Conroy | 3982548 | 2021-05-27 17:44:50 +0100 | [diff] [blame] | 30 | #include "Prelu.hpp" |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 31 | #include "Quantization.hpp" |
| 32 | #include "Redefine.hpp" |
Sadik Armagan | a274748 | 2021-02-09 10:28:54 +0000 | [diff] [blame] | 33 | #include "Reduce.hpp" |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 34 | #include "Resize.hpp" |
Tracy Narine | 7306bbe | 2023-07-17 16:06:26 +0100 | [diff] [blame] | 35 | #include "ReverseV2.hpp" |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 36 | #include "Round.hpp" |
Keith Davis | 0176fd8 | 2021-06-01 17:36:32 +0100 | [diff] [blame] | 37 | #include "Shape.hpp" |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 38 | #include "Slice.hpp" |
Cathal Corbett | 839b932 | 2022-11-18 08:52:18 +0000 | [diff] [blame] | 39 | #include "StridedSlice.hpp" |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 40 | #include "Softmax.hpp" |
| 41 | #include "SpaceDepth.hpp" |
Sadik Armagan | 34fa1bd | 2020-11-27 12:40:52 +0000 | [diff] [blame] | 42 | #include "Split.hpp" |
Tianle Cheng | 92ce35c | 2023-07-25 16:41:00 +0100 | [diff] [blame] | 43 | #include "Tile.hpp" |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 44 | #include "Transpose.hpp" |
Narumol Prangnawarat | 7684b18 | 2021-08-12 14:48:15 +0100 | [diff] [blame] | 45 | #include "UnidirectionalSequenceLstm.hpp" |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 46 | #include "Unpack.hpp" |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 47 | |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 48 | #include <armnnUtils/Filesystem.hpp> |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 49 | #include <armnn/utility/Timer.hpp> |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 50 | #include <flatbuffers/flatbuffers.h> |
| 51 | #include <tensorflow/lite/context_util.h> |
Jim Flynn | 4b2f347 | 2021-10-13 21:20:07 +0100 | [diff] [blame] | 52 | #include <tensorflow/lite/schema/schema_generated.h> |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 53 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 54 | #include <algorithm> |
Matthew Sloyan | ac001ee | 2021-02-03 10:43:04 +0000 | [diff] [blame] | 55 | #include <iostream> |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 56 | #include <sstream> |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 57 | |
| 58 | namespace armnnDelegate |
| 59 | { |
| 60 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 61 | DelegateOptions TfLiteArmnnDelegateOptionsDefault() |
| 62 | { |
| 63 | DelegateOptions options(armnn::Compute::CpuRef); |
| 64 | return options; |
| 65 | } |
| 66 | |
| 67 | TfLiteDelegate* TfLiteArmnnDelegateCreate(armnnDelegate::DelegateOptions options) |
| 68 | { |
| 69 | auto* armnnDelegate = new ::armnnDelegate::Delegate(options); |
| 70 | return armnnDelegate->GetDelegate(); |
| 71 | } |
| 72 | |
| 73 | void TfLiteArmnnDelegateDelete(TfLiteDelegate* tfLiteDelegate) |
| 74 | { |
| 75 | if (tfLiteDelegate != nullptr) |
| 76 | { |
| 77 | delete static_cast<::armnnDelegate::Delegate*>(tfLiteDelegate->data_); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | TfLiteStatus DoPrepare(TfLiteContext* tfLiteContext, TfLiteDelegate* tfLiteDelegate) |
| 82 | { |
| 83 | TfLiteIntArray* supportedOperators = |
| 84 | static_cast<::armnnDelegate::Delegate*>(tfLiteDelegate->data_)->IdentifyOperatorsToDelegate(tfLiteContext); |
| 85 | |
| 86 | // ArmNN Delegate Registration |
| 87 | static const TfLiteRegistration kArmnnSubgraphRegistration = { |
| 88 | // ArmnnSubgraph Init |
| 89 | .init = [](TfLiteContext* tfLiteContext, const char* buffer, size_t length) -> void* { |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 90 | armnn::IgnoreUnused(length); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 91 | const TfLiteDelegateParams* parameters = reinterpret_cast<const TfLiteDelegateParams*>(buffer); |
| 92 | |
| 93 | return static_cast<void*>(ArmnnSubgraph::Create( |
| 94 | tfLiteContext, parameters, static_cast<::armnnDelegate::Delegate*>(parameters->delegate->data_))); |
| 95 | }, |
| 96 | // ArmnnSubgraph Free |
| 97 | .free = [](TfLiteContext* tfLiteContext, void* buffer) -> void { |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 98 | armnn::IgnoreUnused(tfLiteContext); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 99 | if (buffer != nullptr) |
| 100 | { |
| 101 | delete static_cast<ArmnnSubgraph*>(buffer); |
| 102 | } |
| 103 | }, |
| 104 | // ArmnnSubgraph Prepare |
| 105 | .prepare = [](TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode) -> TfLiteStatus { |
| 106 | if (tfLiteNode->user_data == nullptr) |
| 107 | { |
| 108 | return kTfLiteError; |
| 109 | } |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 110 | return static_cast<ArmnnSubgraph*>(tfLiteNode->user_data)->Prepare(tfLiteContext); |
| 111 | }, |
| 112 | // ArmnnSubgraph Invoke |
| 113 | .invoke = [](TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode) -> TfLiteStatus { |
| 114 | if (tfLiteNode->user_data == nullptr) |
| 115 | { |
| 116 | return kTfLiteError; |
| 117 | } |
| 118 | |
| 119 | return static_cast<ArmnnSubgraph*>(tfLiteNode->user_data)->Invoke(tfLiteContext, tfLiteNode); |
| 120 | }, |
| 121 | |
| 122 | .profiling_string = nullptr, |
| 123 | .builtin_code = kTfLiteBuiltinDelegate, |
| 124 | .custom_name = "TfLiteArmNnDelegate", |
| 125 | .version = 1, |
Colm Donelan | 718966f | 2022-10-10 10:06:12 +0100 | [diff] [blame] | 126 | .registration_external = nullptr, |
Matthew Sloyan | 76d0c4c | 2023-09-07 14:48:56 +0100 | [diff] [blame] | 127 | .async_kernel = nullptr, |
| 128 | .inplace_operator = 0 |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 129 | }; |
| 130 | |
| 131 | const TfLiteStatus status = |
| 132 | tfLiteContext->ReplaceNodeSubsetsWithDelegateKernels( |
| 133 | tfLiteContext, kArmnnSubgraphRegistration, supportedOperators, tfLiteDelegate); |
| 134 | |
| 135 | TfLiteIntArrayFree(supportedOperators); |
| 136 | return status; |
| 137 | |
| 138 | } |
| 139 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 140 | Delegate::Delegate(armnnDelegate::DelegateOptions options) |
Mike Kelly | 5446a4d | 2023-01-20 15:51:05 +0000 | [diff] [blame] | 141 | : m_Options(std::move(options)) |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 142 | { |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 143 | // Configures logging for ARMNN |
Colm Donelan | da7f2f9 | 2022-12-20 16:21:35 +0000 | [diff] [blame] | 144 | if (m_Options.IsLoggingEnabled()) |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 145 | { |
Colm Donelan | da7f2f9 | 2022-12-20 16:21:35 +0000 | [diff] [blame] | 146 | armnn::ConfigureLogging(true, true, m_Options.GetLoggingSeverity()); |
Jan Eilers | 2cd1847 | 2020-12-15 10:42:38 +0000 | [diff] [blame] | 147 | } |
Mike Kelly | 5446a4d | 2023-01-20 15:51:05 +0000 | [diff] [blame] | 148 | // Create/Get the static ArmNN Runtime. Note that the m_Runtime will be shared by all armnn_delegate |
| 149 | // instances so the RuntimeOptions cannot be altered for different armnn_delegate instances. |
| 150 | m_Runtime = GetRuntime(m_Options.GetRuntimeOptions()); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 151 | std::vector<armnn::BackendId> backends; |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 152 | if (m_Runtime) |
| 153 | { |
| 154 | const armnn::BackendIdSet supportedDevices = m_Runtime->GetDeviceSpec().GetSupportedBackends(); |
| 155 | for (auto& backend : m_Options.GetBackends()) |
| 156 | { |
| 157 | if (std::find(supportedDevices.cbegin(), supportedDevices.cend(), backend) == supportedDevices.cend()) |
| 158 | { |
Sadik Armagan | 0534e03 | 2020-10-27 17:30:18 +0000 | [diff] [blame] | 159 | TFLITE_LOG_PROD(tflite::TFLITE_LOG_INFO, |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 160 | "TfLiteArmnnDelegate: Requested unknown backend %s", backend.Get().c_str()); |
| 161 | } |
| 162 | else |
| 163 | { |
| 164 | backends.push_back(backend); |
Kevin May | 0425a37 | 2023-11-03 12:06:04 +0000 | [diff] [blame] | 165 | TFLITE_LOG_PROD(tflite::TFLITE_LOG_INFO, |
| 166 | "TfLiteArmnnDelegate: Added backend %s", backend.Get().c_str()); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | if (backends.empty()) |
| 172 | { |
| 173 | // No known backend specified |
| 174 | throw armnn::InvalidArgumentException("TfLiteArmnnDelegate: No known backend specified."); |
| 175 | } |
| 176 | m_Options.SetBackends(backends); |
| 177 | |
| 178 | TFLITE_LOG_PROD_ONCE(tflite::TFLITE_LOG_INFO, "TfLiteArmnnDelegate: Created TfLite ArmNN delegate."); |
| 179 | } |
| 180 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 181 | TfLiteIntArray* Delegate::IdentifyOperatorsToDelegate(TfLiteContext* tfLiteContext) |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 182 | { |
| 183 | TfLiteIntArray* executionPlan = nullptr; |
| 184 | if (tfLiteContext->GetExecutionPlan(tfLiteContext, &executionPlan) != kTfLiteOk) |
| 185 | { |
| 186 | TF_LITE_KERNEL_LOG(tfLiteContext, "TfLiteArmnnDelegate: Unable to get graph execution plan."); |
| 187 | return nullptr; |
| 188 | } |
| 189 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 190 | // Delegate data with null network |
| 191 | DelegateData delegateData(m_Options.GetBackends()); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 192 | |
| 193 | TfLiteIntArray* nodesToDelegate = TfLiteIntArrayCreate(executionPlan->size); |
| 194 | nodesToDelegate->size = 0; |
Sadik Armagan | bfa767c | 2022-02-09 14:58:03 +0000 | [diff] [blame] | 195 | |
| 196 | std::set<int32_t> unsupportedOperators; |
| 197 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 198 | for (int i = 0; i < executionPlan->size; ++i) |
| 199 | { |
| 200 | const int nodeIndex = executionPlan->data[i]; |
| 201 | |
| 202 | // If TfLite nodes can be delegated to ArmNN |
| 203 | TfLiteNode* tfLiteNode = nullptr; |
| 204 | TfLiteRegistration* tfLiteRegistration = nullptr; |
| 205 | if (tfLiteContext->GetNodeAndRegistration( |
| 206 | tfLiteContext, nodeIndex, &tfLiteNode, &tfLiteRegistration) != kTfLiteOk) |
| 207 | { |
| 208 | TF_LITE_KERNEL_LOG(tfLiteContext, |
| 209 | "TfLiteArmnnDelegate: Unable to get node and registration for node %d.", |
| 210 | nodeIndex); |
| 211 | continue; |
| 212 | } |
| 213 | |
Ryan OShea | 05b6a3e | 2023-01-11 15:27:50 +0000 | [diff] [blame] | 214 | TfLiteStatus visitStatus; |
| 215 | |
| 216 | try |
| 217 | { |
| 218 | visitStatus = ArmnnSubgraph::VisitNode( |
| 219 | delegateData, tfLiteContext, tfLiteRegistration, tfLiteNode, nodeIndex); |
| 220 | } |
| 221 | catch(std::exception& ex) |
| 222 | { |
| 223 | ARMNN_LOG(error) << "ArmNN Failed to visit node with error: " << ex.what(); |
| 224 | visitStatus = kTfLiteError; |
Ciara Sookarry | 3943615 | 2023-10-31 15:44:41 +0000 | [diff] [blame] | 225 | TF_LITE_KERNEL_LOG(tfLiteContext, |
| 226 | "Exception text: %s", |
| 227 | ex.what()); |
Ryan OShea | 05b6a3e | 2023-01-11 15:27:50 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | if ( visitStatus != kTfLiteOk) |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 231 | { |
| 232 | // node is not supported by ArmNN |
Sadik Armagan | bfa767c | 2022-02-09 14:58:03 +0000 | [diff] [blame] | 233 | unsupportedOperators.insert(tfLiteRegistration->builtin_code); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 234 | continue; |
| 235 | } |
| 236 | |
| 237 | nodesToDelegate->data[nodesToDelegate->size++] = nodeIndex; |
| 238 | } |
| 239 | |
Sadik Armagan | bfa767c | 2022-02-09 14:58:03 +0000 | [diff] [blame] | 240 | for (std::set<int32_t>::iterator it=unsupportedOperators.begin(); it!=unsupportedOperators.end(); ++it) |
| 241 | { |
| 242 | TF_LITE_KERNEL_LOG(tfLiteContext, |
| 243 | "Operator %s [%d] is not supported by armnn_delegate.", |
| 244 | tflite::EnumNameBuiltinOperator(tflite::BuiltinOperator(*it)), |
| 245 | *it); |
| 246 | } |
| 247 | |
Sadik Armagan | ca565c1 | 2022-08-16 12:17:24 +0100 | [diff] [blame] | 248 | if (!unsupportedOperators.empty() && m_Options.TfLiteRuntimeFallbackDisabled()) |
| 249 | { |
| 250 | std::stringstream exMessage; |
| 251 | exMessage << "TfLiteArmnnDelegate: There are unsupported operators in the model. "; |
| 252 | exMessage << "Not falling back to TfLite Runtime as fallback is disabled. "; |
| 253 | exMessage << "This should only be disabled under test conditions."; |
| 254 | throw armnn::Exception(exMessage.str()); |
| 255 | } |
Colm Donelan | 3811a97 | 2023-01-25 21:19:49 +0000 | [diff] [blame] | 256 | if (nodesToDelegate->size == 0) |
| 257 | { |
| 258 | ARMNN_LOG(info) << "No operators in this model are supported by the Arm NN TfLite delegate." << |
| 259 | " The model will be executed entirely by TfLite runtime."; |
| 260 | } |
Sadik Armagan | ca565c1 | 2022-08-16 12:17:24 +0100 | [diff] [blame] | 261 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 262 | std::sort(&nodesToDelegate->data[0], &nodesToDelegate->data[nodesToDelegate->size]); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 263 | return nodesToDelegate; |
| 264 | } |
| 265 | |
| 266 | TfLiteDelegate* Delegate::GetDelegate() |
| 267 | { |
| 268 | return &m_Delegate; |
| 269 | } |
| 270 | |
Matthew Sloyan | ac001ee | 2021-02-03 10:43:04 +0000 | [diff] [blame] | 271 | const std::string Delegate::GetVersion() |
| 272 | { |
| 273 | return DELEGATE_VERSION; |
| 274 | } |
| 275 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 276 | TfLiteStatus ArmnnSubgraph::AddInputLayer(DelegateData& delegateData, |
| 277 | TfLiteContext* tfLiteContext, |
| 278 | const TfLiteIntArray* inputs, |
| 279 | std::vector<armnn::BindingPointInfo>& inputBindings) |
| 280 | { |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 281 | const size_t numInputs = static_cast<size_t>(inputs->size); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 282 | for (unsigned int i = 0; i < numInputs; ++i) |
| 283 | { |
| 284 | const int32_t tensorId = inputs->data[i]; |
| 285 | const TfLiteTensor tensor = tfLiteContext->tensors[tensorId]; |
Sadik Armagan | 6e36a64 | 2020-11-10 21:18:41 +0000 | [diff] [blame] | 286 | // Do not create bindings for constant inputs |
| 287 | if (tensor.allocation_type == kTfLiteMmapRo) |
| 288 | { |
| 289 | continue; |
| 290 | } |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 291 | |
| 292 | auto bindingId = static_cast<armnn::LayerBindingId>((tensorId)); |
| 293 | armnn::IConnectableLayer* layer = delegateData.m_Network->AddInputLayer(bindingId); |
| 294 | |
| 295 | auto tensorInfo = GetTensorInfoForTfLiteTensor(tensor); |
| 296 | armnn::IOutputSlot& outputSlot = layer->GetOutputSlot(0); |
| 297 | outputSlot.SetTensorInfo(tensorInfo); |
| 298 | |
| 299 | // Store for creating connections |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 300 | delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)] = &outputSlot; |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 301 | |
Sadik Armagan | 6e36a64 | 2020-11-10 21:18:41 +0000 | [diff] [blame] | 302 | inputBindings.push_back(std::make_pair(bindingId, tensorInfo)); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 303 | } |
Sadik Armagan | 6e36a64 | 2020-11-10 21:18:41 +0000 | [diff] [blame] | 304 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 305 | return kTfLiteOk; |
| 306 | } |
| 307 | |
| 308 | TfLiteStatus ArmnnSubgraph::AddOutputLayer(DelegateData& delegateData, |
| 309 | TfLiteContext* tfLiteContext, |
| 310 | const TfLiteIntArray* outputs, |
| 311 | std::vector<armnn::BindingPointInfo>& outputBindings) |
| 312 | { |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 313 | const size_t numOutputs = static_cast<size_t>(outputs->size); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 314 | for (unsigned int i = 0; i < numOutputs; ++i) |
| 315 | { |
| 316 | const int32_t tensorId = outputs->data[i]; |
| 317 | const TfLiteTensor tensor = tfLiteContext->tensors[tensorId]; |
| 318 | |
| 319 | auto bindingId = static_cast<armnn::LayerBindingId>((tensorId)); |
| 320 | armnn::IConnectableLayer* layer = delegateData.m_Network->AddOutputLayer(bindingId); |
| 321 | |
| 322 | auto tensorInfo = GetTensorInfoForTfLiteTensor(tensor); |
Ryan OShea | c229b3f | 2023-06-27 22:34:54 +0100 | [diff] [blame] | 323 | |
| 324 | if (delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)] == nullptr) |
| 325 | { |
| 326 | return kTfLiteError; |
| 327 | } |
| 328 | |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 329 | delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)]->Connect(layer->GetInputSlot(0)); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 330 | outputBindings.push_back(std::make_pair(bindingId, tensorInfo)); |
| 331 | } |
| 332 | |
| 333 | return kTfLiteOk; |
| 334 | } |
| 335 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 336 | ArmnnSubgraph* ArmnnSubgraph::Create(TfLiteContext* tfLiteContext, |
| 337 | const TfLiteDelegateParams* parameters, |
| 338 | const Delegate* delegate) |
| 339 | { |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 340 | const auto startTime = armnn::GetTimeNow(); |
| 341 | ARMNN_LOG(info) << "ArmnnSubgraph creation"; |
| 342 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 343 | TfLiteIntArray* executionPlan; |
| 344 | if (tfLiteContext->GetExecutionPlan(tfLiteContext, &executionPlan) != kTfLiteOk) |
| 345 | { |
| 346 | return nullptr; |
| 347 | } |
| 348 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 349 | // Initialize DelegateData holds network and output slots information |
| 350 | DelegateData delegateData(delegate->m_Options.GetBackends()); |
| 351 | |
| 352 | // Build ArmNN Network |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 353 | armnn::NetworkOptions networkOptions = delegate->m_Options.GetOptimizerOptions().GetModelOptions(); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 354 | armnn::NetworkId networkId; |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 355 | delegateData.m_Network = armnn::INetwork::Create(networkOptions); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 356 | |
Sadik Armagan | 6e36a64 | 2020-11-10 21:18:41 +0000 | [diff] [blame] | 357 | delegateData.m_OutputSlotForNode = std::vector<armnn::IOutputSlot*>(tfLiteContext->tensors_size, nullptr); |
| 358 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 359 | std::vector<armnn::BindingPointInfo> inputBindings; |
| 360 | std::vector<armnn::BindingPointInfo> outputBindings; |
| 361 | |
| 362 | // Add input layer |
| 363 | auto status = AddInputLayer(delegateData, tfLiteContext, parameters->input_tensors, inputBindings); |
| 364 | if (status != kTfLiteOk) |
| 365 | { |
| 366 | throw armnn::Exception("TfLiteArmnnDelegate: Unable to add Inputs to the network!"); |
| 367 | } |
| 368 | |
| 369 | // Parse TfLite delegate nodes to ArmNN |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 370 | const auto parseStartTime = armnn::GetTimeNow(); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 371 | for (int i = 0; i < parameters->nodes_to_replace->size; ++i) |
| 372 | { |
| 373 | const int nodeIndex = parameters->nodes_to_replace->data[i]; |
| 374 | |
| 375 | TfLiteNode* tfLiteNode = nullptr; |
| 376 | TfLiteRegistration* tfLiteRegistration = nullptr; |
| 377 | if (tfLiteContext->GetNodeAndRegistration( |
| 378 | tfLiteContext, nodeIndex, &tfLiteNode, &tfLiteRegistration) != kTfLiteOk) |
| 379 | { |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 380 | throw armnn::Exception(&"TfLiteArmnnDelegate: Unable to get node registration: " [ nodeIndex]); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 381 | } |
| 382 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 383 | if (VisitNode(delegateData, tfLiteContext, tfLiteRegistration, tfLiteNode, nodeIndex) != kTfLiteOk) |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 384 | { |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 385 | throw armnn::Exception(&"TfLiteArmnnDelegate: Unable to parse node: " [ nodeIndex]); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 386 | } |
| 387 | } |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 388 | ARMNN_LOG(info) << "Parse nodes to ArmNN time: " << std::setprecision(2) |
| 389 | << std::fixed << armnn::GetTimeDuration(parseStartTime).count() << " ms"; |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 390 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 391 | // Add Output layer |
| 392 | status = AddOutputLayer(delegateData, tfLiteContext, parameters->output_tensors, outputBindings); |
| 393 | if (status != kTfLiteOk) |
| 394 | { |
| 395 | throw armnn::Exception("TfLiteArmnnDelegate: Unable to add Outputs to the network!"); |
| 396 | } |
| 397 | |
| 398 | // Optimize ArmNN network |
| 399 | armnn::IOptimizedNetworkPtr optNet(nullptr, nullptr); |
| 400 | try |
| 401 | { |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 402 | const auto optimizeStartTime = armnn::GetTimeNow(); |
Sadik Armagan | 6e36a64 | 2020-11-10 21:18:41 +0000 | [diff] [blame] | 403 | optNet = armnn::Optimize(*(delegateData.m_Network.get()), |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 404 | delegate->m_Options.GetBackends(), |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 405 | delegate->m_Runtime->GetDeviceSpec(), |
| 406 | delegate->m_Options.GetOptimizerOptions()); |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 407 | ARMNN_LOG(info) << "Optimize ArmnnSubgraph time: " << std::setprecision(2) |
| 408 | << std::fixed << armnn::GetTimeDuration(optimizeStartTime).count() << " ms"; |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 409 | } |
Ryan OShea | 05b6a3e | 2023-01-11 15:27:50 +0000 | [diff] [blame] | 410 | catch (std::exception& ex) |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 411 | { |
| 412 | std::stringstream exMessage; |
| 413 | exMessage << "TfLiteArmnnDelegate: Exception (" << ex.what() << ") caught from optimize."; |
| 414 | throw armnn::Exception(exMessage.str()); |
| 415 | } |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 416 | if (!optNet) |
| 417 | { |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 418 | // Optimize failed |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 419 | throw armnn::Exception("TfLiteArmnnDelegate: Unable to optimize the network!"); |
| 420 | } |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 421 | |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 422 | // If set, we will serialize the optimized model into a dot file. |
| 423 | const std::string serializeToDotFile = delegate->m_Options.GetSerializeToDot(); |
| 424 | if (!serializeToDotFile.empty()) |
| 425 | { |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 426 | ARMNN_LOG(info) << "Writing graph to dot file: " << serializeToDotFile; |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 427 | fs::path filename = serializeToDotFile; |
| 428 | std::fstream file(filename.c_str(), std::ios_base::out); |
| 429 | optNet->SerializeToDot(file); |
| 430 | } |
| 431 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 432 | try |
| 433 | { |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 434 | const auto loadStartTime = armnn::GetTimeNow(); |
| 435 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 436 | // Load graph into runtime |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 437 | std::string errorMessage; |
Narumol Prangnawarat | 74a3cf5 | 2021-01-29 15:38:54 +0000 | [diff] [blame] | 438 | armnn::Status loadingStatus; |
Francis Murtagh | 626bd90 | 2022-06-21 13:16:23 +0000 | [diff] [blame] | 439 | armnn::MemorySource inputSource = armnn::MemorySource::Undefined; |
| 440 | armnn::MemorySource outputSource = armnn::MemorySource::Undefined; |
| 441 | // There's a bit of an assumption here that the delegate will only support Malloc memory source. |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 442 | if (delegate->m_Options.GetOptimizerOptions().GetImportEnabled()) |
Narumol Prangnawarat | 74a3cf5 | 2021-01-29 15:38:54 +0000 | [diff] [blame] | 443 | { |
Francis Murtagh | 626bd90 | 2022-06-21 13:16:23 +0000 | [diff] [blame] | 444 | inputSource = armnn::MemorySource::Malloc; |
| 445 | } |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 446 | if (delegate->m_Options.GetOptimizerOptions().GetExportEnabled()) |
Francis Murtagh | 626bd90 | 2022-06-21 13:16:23 +0000 | [diff] [blame] | 447 | { |
| 448 | outputSource = armnn::MemorySource::Malloc; |
Narumol Prangnawarat | 74a3cf5 | 2021-01-29 15:38:54 +0000 | [diff] [blame] | 449 | } |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 450 | armnn::INetworkProperties networkProperties(false, |
Francis Murtagh | 626bd90 | 2022-06-21 13:16:23 +0000 | [diff] [blame] | 451 | inputSource, |
| 452 | outputSource, |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 453 | delegate->m_Options.GetInternalProfilingState(), |
| 454 | delegate->m_Options.GetInternalProfilingDetail()); |
| 455 | loadingStatus = delegate->m_Runtime->LoadNetwork(networkId, |
| 456 | std::move(optNet), |
| 457 | errorMessage, |
| 458 | networkProperties); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 459 | if (loadingStatus != armnn::Status::Success) |
| 460 | { |
Colm Donelan | 4514228 | 2021-10-21 23:39:52 +0100 | [diff] [blame] | 461 | // Network load failed. |
Colm Donelan | 194086f | 2022-11-14 17:23:07 +0000 | [diff] [blame] | 462 | throw armnn::Exception("TfLiteArmnnDelegate: Network could not be loaded: " + errorMessage); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 463 | } |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 464 | |
| 465 | ARMNN_LOG(info) << "Load ArmnnSubgraph time: " << std::setprecision(2) |
| 466 | << std::fixed << armnn::GetTimeDuration(loadStartTime).count() << " ms"; |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 467 | } |
| 468 | catch (std::exception& ex) |
| 469 | { |
| 470 | std::stringstream exMessage; |
| 471 | exMessage << "TfLiteArmnnDelegate: Exception (" << ex.what() << ") caught from LoadNetwork."; |
| 472 | throw armnn::Exception(exMessage.str()); |
| 473 | } |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 474 | |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 475 | // Register debug callback function |
| 476 | if (delegate->m_Options.GetDebugCallbackFunction().has_value()) |
| 477 | { |
| 478 | delegate->m_Runtime->RegisterDebugCallback(networkId, delegate->m_Options.GetDebugCallbackFunction().value()); |
| 479 | } |
| 480 | |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 481 | ARMNN_LOG(info) << "Overall ArmnnSubgraph creation time: " << std::setprecision(2) |
| 482 | << std::fixed << armnn::GetTimeDuration(startTime).count() << " ms\n"; |
| 483 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 484 | // Create a new SubGraph with networkId and runtime |
Mike Kelly | 5446a4d | 2023-01-20 15:51:05 +0000 | [diff] [blame] | 485 | return new ArmnnSubgraph(networkId, delegate->m_Runtime, inputBindings, outputBindings); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | TfLiteStatus ArmnnSubgraph::Prepare(TfLiteContext* tfLiteContext) |
| 489 | { |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 490 | armnn::IgnoreUnused(tfLiteContext); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 491 | return kTfLiteOk; |
| 492 | } |
| 493 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 494 | TfLiteStatus ArmnnSubgraph::Invoke(TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode) |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 495 | { |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 496 | // Prepare inputs |
| 497 | armnn::InputTensors inputTensors; |
| 498 | size_t inputIndex = 0; |
| 499 | for (auto inputIdx : tflite::TfLiteIntArrayView(tfLiteNode->inputs)) |
| 500 | { |
| 501 | TfLiteTensor* tensor = &tfLiteContext->tensors[inputIdx]; |
| 502 | if (tensor->allocation_type != kTfLiteMmapRo) |
| 503 | { |
| 504 | const armnn::BindingPointInfo& inputBinding = m_InputBindings[inputIndex]; |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 505 | armnn::TensorInfo inputTensorInfo = inputBinding.second; |
| 506 | inputTensorInfo.SetConstant(true); |
| 507 | const armnn::ConstTensor inputTensor(inputTensorInfo, tensor->data.data); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 508 | inputTensors.emplace_back(inputIdx, inputTensor); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 509 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 510 | ++inputIndex; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | // Prepare outputs |
| 515 | armnn::OutputTensors outputTensors; |
| 516 | size_t outputIndex = 0; |
| 517 | for (auto outputIdx : tflite::TfLiteIntArrayView(tfLiteNode->outputs)) |
| 518 | { |
| 519 | const armnn::BindingPointInfo& outputBinding = m_OutputBindings[outputIndex]; |
| 520 | TfLiteTensor* tensor = &tfLiteContext->tensors[outputIdx]; |
| 521 | const armnn::Tensor outputTensor(outputBinding.second, tensor->data.data); |
| 522 | outputTensors.emplace_back(outputIdx, outputTensor); |
| 523 | |
| 524 | ++outputIndex; |
| 525 | } |
| 526 | |
| 527 | // Run graph |
| 528 | auto status = m_Runtime->EnqueueWorkload(m_NetworkId, inputTensors, outputTensors); |
Colm Donelan | 4514228 | 2021-10-21 23:39:52 +0100 | [diff] [blame] | 529 | // The delegate holds its own Arm NN runtime so this is our last chance to print internal profiling data. |
| 530 | std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkId); |
| 531 | if (profiler && profiler->IsProfilingEnabled()) |
| 532 | { |
| 533 | profiler->Print(std::cout); |
| 534 | } |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 535 | return (status == armnn::Status::Success) ? kTfLiteOk : kTfLiteError; |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 536 | } |
| 537 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 538 | TfLiteStatus ArmnnSubgraph::VisitNode(DelegateData& delegateData, |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 539 | TfLiteContext* tfLiteContext, |
| 540 | TfLiteRegistration* tfLiteRegistration, |
| 541 | TfLiteNode* tfLiteNode, |
| 542 | int nodeIndex) |
| 543 | { |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 544 | switch (tfLiteRegistration->builtin_code) |
| 545 | { |
Ryan OShea | d21abaf | 2022-06-10 14:49:11 +0100 | [diff] [blame] | 546 | case kTfLiteBuiltinCustom: |
| 547 | { |
| 548 | #if defined(ARMNN_POST_TFLITE_2_5) |
| 549 | // Custom operators are defined by the name rather than the builtin code. |
| 550 | // Parse the custom_name param in the registration to point to the correct visitor function. |
| 551 | std::string customOperatorName = tfLiteRegistration->custom_name; |
| 552 | if ( customOperatorName == "AveragePool3D" ) |
| 553 | { |
| 554 | return VisitPooling3dOperator(delegateData, |
| 555 | tfLiteContext, |
| 556 | tfLiteNode, |
| 557 | nodeIndex, |
| 558 | customOperatorName); |
| 559 | } |
| 560 | else if (customOperatorName == "MaxPool3D") |
| 561 | { |
| 562 | return VisitPooling3dOperator(delegateData, |
| 563 | tfLiteContext, |
| 564 | tfLiteNode, |
| 565 | nodeIndex, |
| 566 | customOperatorName); |
| 567 | } |
| 568 | #endif |
| 569 | // Invalid or unsupported custom operator |
| 570 | return kTfLiteError; |
| 571 | } |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 572 | case kTfLiteBuiltinAbs: |
| 573 | return VisitElementwiseUnaryOperator(delegateData, |
| 574 | tfLiteContext, |
| 575 | tfLiteNode, |
| 576 | nodeIndex, |
| 577 | armnn::UnaryOperation::Abs); |
| 578 | case kTfLiteBuiltinAdd: |
| 579 | return VisitElementwiseBinaryOperator(delegateData, |
| 580 | tfLiteContext, |
| 581 | tfLiteNode, |
| 582 | nodeIndex, |
| 583 | kTfLiteBuiltinAdd); |
| 584 | case kTfLiteBuiltinArgMax: |
| 585 | return VisitArgMinMaxOperator(delegateData, |
| 586 | tfLiteContext, |
| 587 | tfLiteNode, |
| 588 | nodeIndex, |
| 589 | kTfLiteBuiltinArgMax); |
| 590 | case kTfLiteBuiltinArgMin: |
| 591 | return VisitArgMinMaxOperator(delegateData, |
| 592 | tfLiteContext, |
| 593 | tfLiteNode, |
| 594 | nodeIndex, |
| 595 | kTfLiteBuiltinArgMin); |
| 596 | case kTfLiteBuiltinAveragePool2d: |
Ryan OShea | d21abaf | 2022-06-10 14:49:11 +0100 | [diff] [blame] | 597 | return VisitPooling2dOperator(delegateData, |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 598 | tfLiteContext, |
| 599 | tfLiteNode, |
| 600 | nodeIndex, |
| 601 | kTfLiteBuiltinAveragePool2d); |
Ryan OShea | 49ed0df | 2022-09-21 16:09:41 +0100 | [diff] [blame] | 602 | case kTfLiteBuiltinBatchMatmul: |
| 603 | return VisitBatchMatMulOperator(delegateData, |
| 604 | tfLiteContext, |
| 605 | tfLiteNode, |
| 606 | nodeIndex, |
| 607 | kTfLiteBuiltinBatchMatmul); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 608 | case kTfLiteBuiltinBatchToSpaceNd: |
| 609 | return VisitBatchToSpaceNdOperator(delegateData, |
| 610 | tfLiteContext, |
| 611 | tfLiteNode, |
| 612 | nodeIndex, |
| 613 | kTfLiteBuiltinBatchToSpaceNd); |
Idriss Chaouch | cbf7929 | 2023-09-08 11:18:16 +0100 | [diff] [blame] | 614 | case kTfLiteBuiltinBroadcastTo: |
| 615 | return VisitBroadcastToOperator(delegateData, |
| 616 | tfLiteContext, |
| 617 | tfLiteNode, |
| 618 | nodeIndex, |
| 619 | kTfLiteBuiltinBroadcastTo); |
Sadik Armagan | 937565b | 2021-04-21 14:03:28 +0100 | [diff] [blame] | 620 | case kTfLiteBuiltinCast: |
| 621 | return VisitCastOperator(delegateData, |
| 622 | tfLiteContext, |
| 623 | tfLiteNode, |
| 624 | nodeIndex, |
| 625 | kTfLiteBuiltinCast); |
Teresa Charlin | 93f0ad0 | 2023-03-23 15:28:02 +0000 | [diff] [blame] | 626 | case kTfLiteBuiltinCeil: |
| 627 | return VisitElementwiseUnaryOperator(delegateData, |
| 628 | tfLiteContext, |
| 629 | tfLiteNode, |
| 630 | nodeIndex, |
| 631 | armnn::UnaryOperation::Ceil); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 632 | case kTfLiteBuiltinConcatenation: |
| 633 | return VisitControlOperator(delegateData, |
| 634 | tfLiteContext, |
| 635 | tfLiteNode, |
| 636 | nodeIndex, |
| 637 | kTfLiteBuiltinConcatenation); |
| 638 | case kTfLiteBuiltinConv2d: |
| 639 | return VisitConvolutionOperator(delegateData, |
| 640 | tfLiteContext, |
| 641 | tfLiteNode, |
| 642 | nodeIndex, |
| 643 | kTfLiteBuiltinConv2d); |
Matthew Sloyan | 81ec994 | 2021-10-12 10:26:30 +0100 | [diff] [blame] | 644 | // Conv3d is only correctly supported for external delegates from TF Lite v2.6, as there was a breaking bug in v2.5. |
| 645 | #if defined(ARMNN_POST_TFLITE_2_5) |
| 646 | case kTfLiteBuiltinConv3d: |
| 647 | return VisitConvolutionOperator(delegateData, |
| 648 | tfLiteContext, |
| 649 | tfLiteNode, |
| 650 | nodeIndex, |
| 651 | kTfLiteBuiltinConv3d); |
| 652 | #endif |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 653 | case kTfLiteBuiltinDepthToSpace: |
| 654 | return VisitDepthToSpaceOperator(delegateData, |
| 655 | tfLiteContext, |
| 656 | tfLiteNode, |
| 657 | nodeIndex, |
| 658 | kTfLiteBuiltinDepthToSpace); |
| 659 | case kTfLiteBuiltinDepthwiseConv2d: |
| 660 | return VisitConvolutionOperator(delegateData, |
| 661 | tfLiteContext, |
| 662 | tfLiteNode, |
| 663 | nodeIndex, |
| 664 | kTfLiteBuiltinDepthwiseConv2d); |
| 665 | case kTfLiteBuiltinDequantize: |
| 666 | return VisitDequantizeOperator(delegateData, |
| 667 | tfLiteContext, |
| 668 | tfLiteNode, |
| 669 | nodeIndex, |
| 670 | kTfLiteBuiltinDequantize); |
| 671 | case kTfLiteBuiltinDiv: |
| 672 | return VisitElementwiseBinaryOperator(delegateData, |
| 673 | tfLiteContext, |
| 674 | tfLiteNode, |
| 675 | nodeIndex, |
| 676 | kTfLiteBuiltinDiv); |
| 677 | case kTfLiteBuiltinElu: |
| 678 | return VisitActivationOperator(delegateData, |
| 679 | tfLiteContext, |
| 680 | tfLiteNode, |
| 681 | nodeIndex, |
| 682 | kTfLiteBuiltinElu); |
| 683 | case kTfLiteBuiltinEqual: |
| 684 | return VisitComparisonOperator(delegateData, |
| 685 | tfLiteContext, |
| 686 | tfLiteNode, |
| 687 | nodeIndex, |
| 688 | kTfLiteBuiltinEqual); |
| 689 | case kTfLiteBuiltinExp: |
| 690 | return VisitElementwiseUnaryOperator(delegateData, |
| 691 | tfLiteContext, |
| 692 | tfLiteNode, |
| 693 | nodeIndex, |
| 694 | armnn::UnaryOperation::Exp); |
| 695 | case kTfLiteBuiltinExpandDims: |
| 696 | return VisitExpandDimsOperator(delegateData, |
| 697 | tfLiteContext, |
| 698 | tfLiteNode, |
| 699 | nodeIndex, |
| 700 | kTfLiteBuiltinExpandDims); |
| 701 | case kTfLiteBuiltinFill: |
| 702 | return VisitFillOperator(delegateData, |
| 703 | tfLiteContext, |
| 704 | tfLiteNode, |
| 705 | nodeIndex, |
| 706 | kTfLiteBuiltinFill); |
| 707 | case kTfLiteBuiltinFloor: |
| 708 | return VisitFloorOperator(delegateData, |
| 709 | tfLiteContext, |
| 710 | tfLiteNode, |
| 711 | nodeIndex, |
| 712 | kTfLiteBuiltinFloor); |
Jim Flynn | 4b2f347 | 2021-10-13 21:20:07 +0100 | [diff] [blame] | 713 | case kTfLiteBuiltinFloorDiv: |
| 714 | return VisitElementwiseBinaryOperator(delegateData, |
| 715 | tfLiteContext, |
| 716 | tfLiteNode, |
| 717 | nodeIndex, |
| 718 | kTfLiteBuiltinFloorDiv); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 719 | case kTfLiteBuiltinFullyConnected: |
| 720 | return VisitFullyConnectedOperator(delegateData, |
| 721 | tfLiteContext, |
| 722 | tfLiteNode, |
| 723 | nodeIndex, |
| 724 | kTfLiteBuiltinFullyConnected); |
| 725 | case kTfLiteBuiltinGather: |
| 726 | return VisitGatherOperator(delegateData, |
| 727 | tfLiteContext, |
| 728 | tfLiteNode, |
| 729 | nodeIndex, |
| 730 | kTfLiteBuiltinGather); |
Teresa Charlin | d5c0ed2 | 2022-04-25 18:23:41 +0100 | [diff] [blame] | 731 | case kTfLiteBuiltinGatherNd: |
| 732 | return VisitGatherNdOperator(delegateData, |
| 733 | tfLiteContext, |
| 734 | tfLiteNode, |
| 735 | nodeIndex, |
| 736 | kTfLiteBuiltinGatherNd); |
Teresa Charlin | 077cddb | 2023-09-15 15:19:21 +0100 | [diff] [blame] | 737 | case kTfLiteBuiltinGelu: |
| 738 | return VisitActivationOperator(delegateData, |
| 739 | tfLiteContext, |
| 740 | tfLiteNode, |
| 741 | nodeIndex, |
| 742 | kTfLiteBuiltinGelu); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 743 | case kTfLiteBuiltinGreater: |
| 744 | return VisitComparisonOperator(delegateData, |
| 745 | tfLiteContext, |
| 746 | tfLiteNode, |
| 747 | nodeIndex, |
| 748 | kTfLiteBuiltinGreater); |
| 749 | case kTfLiteBuiltinGreaterEqual: |
| 750 | return VisitComparisonOperator(delegateData, |
| 751 | tfLiteContext, |
| 752 | tfLiteNode, |
| 753 | nodeIndex, |
| 754 | kTfLiteBuiltinGreaterEqual); |
| 755 | case kTfLiteBuiltinHardSwish: |
| 756 | return VisitActivationOperator(delegateData, |
| 757 | tfLiteContext, |
| 758 | tfLiteNode, |
| 759 | nodeIndex, |
| 760 | kTfLiteBuiltinHardSwish); |
| 761 | case kTfLiteBuiltinL2Normalization: |
Sadik Armagan | 4b227bb | 2021-01-22 10:53:38 +0000 | [diff] [blame] | 762 | return VisitL2NormalizationOperator(delegateData, |
| 763 | tfLiteContext, |
| 764 | tfLiteNode, |
| 765 | nodeIndex, |
| 766 | kTfLiteBuiltinL2Normalization); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 767 | case kTfLiteBuiltinL2Pool2d: |
Ryan OShea | d21abaf | 2022-06-10 14:49:11 +0100 | [diff] [blame] | 768 | return VisitPooling2dOperator(delegateData, |
Tianle Cheng | ae93173 | 2023-07-28 11:53:04 +0100 | [diff] [blame] | 769 | tfLiteContext, |
| 770 | tfLiteNode, |
| 771 | nodeIndex, |
| 772 | kTfLiteBuiltinL2Pool2d); |
| 773 | case kTfLiteBuiltinLeakyRelu: |
| 774 | return VisitActivationOperator(delegateData, |
| 775 | tfLiteContext, |
| 776 | tfLiteNode, |
| 777 | nodeIndex, |
| 778 | kTfLiteBuiltinLeakyRelu); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 779 | case kTfLiteBuiltinLess: |
| 780 | return VisitComparisonOperator(delegateData, |
| 781 | tfLiteContext, |
| 782 | tfLiteNode, |
| 783 | nodeIndex, |
| 784 | kTfLiteBuiltinLess); |
| 785 | case kTfLiteBuiltinLessEqual: |
| 786 | return VisitComparisonOperator(delegateData, |
| 787 | tfLiteContext, |
| 788 | tfLiteNode, |
| 789 | nodeIndex, |
| 790 | kTfLiteBuiltinLessEqual); |
| 791 | case kTfLiteBuiltinLocalResponseNormalization: |
Sadik Armagan | 4b227bb | 2021-01-22 10:53:38 +0000 | [diff] [blame] | 792 | return VisitLocalResponseNormalizationOperator(delegateData, |
| 793 | tfLiteContext, |
| 794 | tfLiteNode, |
| 795 | nodeIndex, |
| 796 | kTfLiteBuiltinLocalResponseNormalization); |
Teresa Charlin | b1f5f70 | 2022-07-12 14:16:24 +0100 | [diff] [blame] | 797 | case kTfLiteBuiltinLog: |
| 798 | return VisitElementwiseUnaryOperator(delegateData, |
| 799 | tfLiteContext, |
| 800 | tfLiteNode, |
| 801 | nodeIndex, |
| 802 | armnn::UnaryOperation::Log); |
Matthew Sloyan | c8eb955 | 2020-11-26 10:54:22 +0000 | [diff] [blame] | 803 | case kTfLiteBuiltinLogicalAnd: |
| 804 | return VisitLogicalBinaryOperator(delegateData, |
| 805 | tfLiteContext, |
| 806 | tfLiteNode, |
| 807 | nodeIndex, |
| 808 | kTfLiteBuiltinLogicalAnd, |
| 809 | armnn::LogicalBinaryOperation::LogicalAnd); |
| 810 | case kTfLiteBuiltinLogicalNot: |
| 811 | return VisitElementwiseUnaryOperator(delegateData, |
| 812 | tfLiteContext, |
| 813 | tfLiteNode, |
| 814 | nodeIndex, |
| 815 | armnn::UnaryOperation::LogicalNot); |
| 816 | case kTfLiteBuiltinLogicalOr: |
| 817 | return VisitLogicalBinaryOperator(delegateData, |
| 818 | tfLiteContext, |
| 819 | tfLiteNode, |
| 820 | nodeIndex, |
| 821 | kTfLiteBuiltinLogicalOr, |
| 822 | armnn::LogicalBinaryOperation::LogicalOr); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 823 | case kTfLiteBuiltinLogistic: |
| 824 | return VisitActivationOperator(delegateData, |
| 825 | tfLiteContext, |
| 826 | tfLiteNode, |
| 827 | nodeIndex, |
| 828 | kTfLiteBuiltinLogistic); |
| 829 | case kTfLiteBuiltinLogSoftmax: |
| 830 | return VisitSoftmaxOperator(delegateData, |
| 831 | tfLiteContext, |
| 832 | tfLiteNode, |
| 833 | nodeIndex, |
| 834 | kTfLiteBuiltinLogSoftmax); |
| 835 | case kTfLiteBuiltinLstm: |
| 836 | return VisitLstmOperator(delegateData, |
| 837 | tfLiteContext, |
| 838 | tfLiteNode, |
| 839 | nodeIndex, |
| 840 | kTfLiteBuiltinLstm); |
| 841 | case kTfLiteBuiltinMaxPool2d: |
Ryan OShea | d21abaf | 2022-06-10 14:49:11 +0100 | [diff] [blame] | 842 | return VisitPooling2dOperator(delegateData, |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 843 | tfLiteContext, |
| 844 | tfLiteNode, |
| 845 | nodeIndex, |
| 846 | kTfLiteBuiltinMaxPool2d); |
| 847 | case kTfLiteBuiltinMaximum: |
| 848 | return VisitElementwiseBinaryOperator(delegateData, |
| 849 | tfLiteContext, |
| 850 | tfLiteNode, |
| 851 | nodeIndex, |
| 852 | kTfLiteBuiltinMaximum); |
| 853 | case kTfLiteBuiltinMean: |
| 854 | return VisitControlOperator(delegateData, |
| 855 | tfLiteContext, |
| 856 | tfLiteNode, |
| 857 | nodeIndex, |
| 858 | kTfLiteBuiltinMean); |
| 859 | case kTfLiteBuiltinMinimum: |
| 860 | return VisitElementwiseBinaryOperator(delegateData, |
| 861 | tfLiteContext, |
| 862 | tfLiteNode, |
| 863 | nodeIndex, |
| 864 | kTfLiteBuiltinMinimum); |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 865 | case kTfLiteBuiltinMirrorPad: |
| 866 | return VisitPadOperator(delegateData, |
| 867 | tfLiteContext, |
| 868 | tfLiteNode, |
| 869 | nodeIndex, |
| 870 | kTfLiteBuiltinMirrorPad); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 871 | case kTfLiteBuiltinMul: |
| 872 | return VisitElementwiseBinaryOperator(delegateData, |
| 873 | tfLiteContext, |
| 874 | tfLiteNode, |
| 875 | nodeIndex, |
| 876 | kTfLiteBuiltinMul); |
| 877 | case kTfLiteBuiltinNeg: |
| 878 | return VisitElementwiseUnaryOperator(delegateData, |
| 879 | tfLiteContext, |
| 880 | tfLiteNode, |
| 881 | nodeIndex, |
| 882 | armnn::UnaryOperation::Neg); |
| 883 | case kTfLiteBuiltinNotEqual: |
| 884 | return VisitComparisonOperator(delegateData, |
| 885 | tfLiteContext, |
| 886 | tfLiteNode, |
| 887 | nodeIndex, |
| 888 | kTfLiteBuiltinNotEqual); |
Matthew Sloyan | a7a12f5 | 2021-05-06 10:05:28 +0100 | [diff] [blame] | 889 | case kTfLiteBuiltinPack: |
| 890 | return VisitPackOperator(delegateData, |
| 891 | tfLiteContext, |
| 892 | tfLiteNode, |
| 893 | nodeIndex, |
| 894 | kTfLiteBuiltinPack); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 895 | case kTfLiteBuiltinPad: |
| 896 | return VisitPadOperator(delegateData, |
| 897 | tfLiteContext, |
| 898 | tfLiteNode, |
| 899 | nodeIndex, |
| 900 | kTfLiteBuiltinPad); |
| 901 | case kTfLiteBuiltinPadv2: |
| 902 | return VisitPadOperator(delegateData, |
| 903 | tfLiteContext, |
| 904 | tfLiteNode, |
| 905 | nodeIndex, |
| 906 | kTfLiteBuiltinPadv2); |
John Mcloughlin | 0ec0087 | 2023-05-15 17:03:49 +0100 | [diff] [blame] | 907 | case kTfLiteBuiltinPow: |
| 908 | return VisitElementwiseBinaryOperator(delegateData, |
| 909 | tfLiteContext, |
| 910 | tfLiteNode, |
| 911 | nodeIndex, |
| 912 | kTfLiteBuiltinPow); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 913 | case kTfLiteBuiltinPrelu: |
James Conroy | 3982548 | 2021-05-27 17:44:50 +0100 | [diff] [blame] | 914 | return VisitPreluOperator(delegateData, |
| 915 | tfLiteContext, |
| 916 | tfLiteNode, |
| 917 | nodeIndex, |
| 918 | kTfLiteBuiltinPrelu); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 919 | case kTfLiteBuiltinQuantize: |
| 920 | return VisitQuantizeOperator(delegateData, |
| 921 | tfLiteContext, |
| 922 | tfLiteNode, |
| 923 | nodeIndex, |
| 924 | kTfLiteBuiltinQuantize); |
| 925 | case kTfLiteBuiltinRank: |
| 926 | return VisitControlOperator(delegateData, |
| 927 | tfLiteContext, |
| 928 | tfLiteNode, |
| 929 | nodeIndex, |
| 930 | kTfLiteBuiltinRank); |
Sadik Armagan | a274748 | 2021-02-09 10:28:54 +0000 | [diff] [blame] | 931 | case kTfLiteBuiltinReduceMax: |
| 932 | return VisitReduceOperator(delegateData, |
| 933 | tfLiteContext, |
| 934 | tfLiteNode, |
| 935 | nodeIndex, |
| 936 | kTfLiteBuiltinReduceMax); |
| 937 | case kTfLiteBuiltinReduceMin: |
| 938 | return VisitReduceOperator(delegateData, |
| 939 | tfLiteContext, |
| 940 | tfLiteNode, |
| 941 | nodeIndex, |
| 942 | kTfLiteBuiltinReduceMin); |
Teresa Charlin | 4e3e831 | 2021-08-05 12:34:37 +0100 | [diff] [blame] | 943 | case kTfLiteBuiltinReduceProd: |
| 944 | return VisitReduceOperator(delegateData, |
| 945 | tfLiteContext, |
| 946 | tfLiteNode, |
| 947 | nodeIndex, |
| 948 | kTfLiteBuiltinReduceProd); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 949 | case kTfLiteBuiltinRelu: |
| 950 | return VisitActivationOperator(delegateData, |
| 951 | tfLiteContext, |
| 952 | tfLiteNode, |
| 953 | nodeIndex, |
| 954 | kTfLiteBuiltinRelu); |
| 955 | case kTfLiteBuiltinReluN1To1: |
| 956 | return VisitActivationOperator(delegateData, |
| 957 | tfLiteContext, |
| 958 | tfLiteNode, |
| 959 | nodeIndex, |
| 960 | kTfLiteBuiltinReluN1To1); |
| 961 | case kTfLiteBuiltinRelu6: |
| 962 | return VisitActivationOperator(delegateData, |
| 963 | tfLiteContext, |
| 964 | tfLiteNode, |
| 965 | nodeIndex, |
| 966 | kTfLiteBuiltinRelu6); |
| 967 | case kTfLiteBuiltinReshape: |
| 968 | return VisitReshapeOperator(delegateData, |
| 969 | tfLiteContext, |
| 970 | tfLiteNode, |
| 971 | nodeIndex, |
| 972 | kTfLiteBuiltinReshape); |
| 973 | case kTfLiteBuiltinResizeBilinear: |
| 974 | return VisitResizeOperator(delegateData, |
| 975 | tfLiteContext, |
| 976 | tfLiteNode, |
| 977 | nodeIndex, |
| 978 | kTfLiteBuiltinResizeBilinear); |
| 979 | case kTfLiteBuiltinResizeNearestNeighbor: |
| 980 | return VisitResizeOperator(delegateData, |
| 981 | tfLiteContext, |
| 982 | tfLiteNode, |
| 983 | nodeIndex, |
| 984 | kTfLiteBuiltinResizeNearestNeighbor); |
Tracy Narine | 7306bbe | 2023-07-17 16:06:26 +0100 | [diff] [blame] | 985 | case kTfLiteBuiltinReverseV2: |
| 986 | return VisitReverseV2Operator(delegateData, |
| 987 | tfLiteContext, |
| 988 | tfLiteNode, |
| 989 | nodeIndex, |
| 990 | kTfLiteBuiltinReverseV2); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 991 | case kTfLiteBuiltinRsqrt: |
| 992 | return VisitElementwiseUnaryOperator(delegateData, |
| 993 | tfLiteContext, |
| 994 | tfLiteNode, |
| 995 | nodeIndex, |
| 996 | armnn::UnaryOperation::Rsqrt); |
Keith Davis | 0176fd8 | 2021-06-01 17:36:32 +0100 | [diff] [blame] | 997 | case kTfLiteBuiltinShape: |
| 998 | return VisitShapeOperator(delegateData, |
| 999 | tfLiteContext, |
| 1000 | tfLiteNode, |
| 1001 | nodeIndex, |
| 1002 | kTfLiteBuiltinShape); |
Teresa Charlin | b1f5f70 | 2022-07-12 14:16:24 +0100 | [diff] [blame] | 1003 | case kTfLiteBuiltinSin: |
| 1004 | return VisitElementwiseUnaryOperator(delegateData, |
| 1005 | tfLiteContext, |
| 1006 | tfLiteNode, |
| 1007 | nodeIndex, |
| 1008 | armnn::UnaryOperation::Sin); |
Sadik Armagan | 34fa1bd | 2020-11-27 12:40:52 +0000 | [diff] [blame] | 1009 | case kTfLiteBuiltinSplit: |
| 1010 | return VisitSplitOperator(delegateData, |
| 1011 | tfLiteContext, |
| 1012 | tfLiteNode, |
| 1013 | nodeIndex, |
| 1014 | kTfLiteBuiltinSplit); |
| 1015 | case kTfLiteBuiltinSplitV: |
| 1016 | return VisitSplitVOperator(delegateData, |
| 1017 | tfLiteContext, |
| 1018 | tfLiteNode, |
| 1019 | nodeIndex, |
| 1020 | kTfLiteBuiltinSplitV); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 1021 | case kTfLiteBuiltinSqrt: |
| 1022 | return VisitElementwiseUnaryOperator(delegateData, |
| 1023 | tfLiteContext, |
| 1024 | tfLiteNode, |
| 1025 | nodeIndex, |
| 1026 | armnn::UnaryOperation::Sqrt); |
John Mcloughlin | 0ec0087 | 2023-05-15 17:03:49 +0100 | [diff] [blame] | 1027 | case kTfLiteBuiltinSquaredDifference: |
| 1028 | return VisitElementwiseBinaryOperator(delegateData, |
| 1029 | tfLiteContext, |
| 1030 | tfLiteNode, |
| 1031 | nodeIndex, |
| 1032 | kTfLiteBuiltinSquaredDifference); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 1033 | case kTfLiteBuiltinSqueeze: |
| 1034 | return VisitSqueezeOperator(delegateData, |
| 1035 | tfLiteContext, |
| 1036 | tfLiteNode, |
| 1037 | nodeIndex, |
| 1038 | kTfLiteBuiltinSqueeze); |
Cathal Corbett | 839b932 | 2022-11-18 08:52:18 +0000 | [diff] [blame] | 1039 | case kTfLiteBuiltinSlice: |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 1040 | return VisitSliceOperator(delegateData, |
| 1041 | tfLiteContext, |
| 1042 | tfLiteNode, |
| 1043 | nodeIndex, |
Cathal Corbett | 839b932 | 2022-11-18 08:52:18 +0000 | [diff] [blame] | 1044 | kTfLiteBuiltinSlice); |
| 1045 | case kTfLiteBuiltinStridedSlice: |
| 1046 | return VisitStridedSliceOperator(delegateData, |
| 1047 | tfLiteContext, |
| 1048 | tfLiteNode, |
| 1049 | nodeIndex, |
| 1050 | kTfLiteBuiltinStridedSlice); |
Sadik Armagan | a274748 | 2021-02-09 10:28:54 +0000 | [diff] [blame] | 1051 | case kTfLiteBuiltinSum: |
| 1052 | return VisitReduceOperator(delegateData, |
| 1053 | tfLiteContext, |
| 1054 | tfLiteNode, |
| 1055 | nodeIndex, |
| 1056 | kTfLiteBuiltinSum); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 1057 | case kTfLiteBuiltinTranspose: |
| 1058 | return VisitTransposeOperator(delegateData, |
| 1059 | tfLiteContext, |
| 1060 | tfLiteNode, |
| 1061 | nodeIndex, |
| 1062 | kTfLiteBuiltinTranspose); |
| 1063 | case kTfLiteBuiltinTransposeConv: |
| 1064 | return VisitConvolutionOperator(delegateData, |
| 1065 | tfLiteContext, |
| 1066 | tfLiteNode, |
| 1067 | nodeIndex, |
| 1068 | kTfLiteBuiltinTransposeConv); |
| 1069 | case kTfLiteBuiltinSoftmax: |
| 1070 | return VisitSoftmaxOperator(delegateData, |
| 1071 | tfLiteContext, |
| 1072 | tfLiteNode, |
| 1073 | nodeIndex, |
| 1074 | kTfLiteBuiltinSoftmax); |
| 1075 | case kTfLiteBuiltinSpaceToBatchNd: |
| 1076 | return VisitSpaceToBatchNdOperator(delegateData, |
| 1077 | tfLiteContext, |
| 1078 | tfLiteNode, |
| 1079 | nodeIndex, |
| 1080 | kTfLiteBuiltinSpaceToBatchNd); |
| 1081 | case kTfLiteBuiltinSpaceToDepth: |
| 1082 | return VisitSpaceToDepthOperator(delegateData, |
| 1083 | tfLiteContext, |
| 1084 | tfLiteNode, |
| 1085 | nodeIndex, |
| 1086 | kTfLiteBuiltinSpaceToDepth); |
| 1087 | case kTfLiteBuiltinSub: |
| 1088 | return VisitElementwiseBinaryOperator(delegateData, |
| 1089 | tfLiteContext, |
| 1090 | tfLiteNode, |
| 1091 | nodeIndex, |
| 1092 | kTfLiteBuiltinSub); |
| 1093 | case kTfLiteBuiltinTanh: |
| 1094 | return VisitActivationOperator(delegateData, |
| 1095 | tfLiteContext, |
| 1096 | tfLiteNode, |
| 1097 | nodeIndex, |
| 1098 | kTfLiteBuiltinTanh); |
Tianle Cheng | 92ce35c | 2023-07-25 16:41:00 +0100 | [diff] [blame] | 1099 | case kTfLiteBuiltinTile: |
| 1100 | return VisitTileOperator(delegateData, |
| 1101 | tfLiteContext, |
| 1102 | tfLiteNode, |
| 1103 | nodeIndex, |
| 1104 | kTfLiteBuiltinTile); |
Narumol Prangnawarat | 7684b18 | 2021-08-12 14:48:15 +0100 | [diff] [blame] | 1105 | case kTfLiteBuiltinUnidirectionalSequenceLstm: |
| 1106 | return VisitUnidirectionalSequenceLstmOperator(delegateData, |
| 1107 | tfLiteContext, |
| 1108 | tfLiteNode, |
| 1109 | nodeIndex, |
| 1110 | kTfLiteBuiltinUnidirectionalSequenceLstm); |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 1111 | case kTfLiteBuiltinUnpack: |
| 1112 | return VisitUnpackOperator(delegateData, |
| 1113 | tfLiteContext, |
| 1114 | tfLiteNode, |
| 1115 | nodeIndex, |
| 1116 | kTfLiteBuiltinUnpack); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 1117 | default: |
| 1118 | return kTfLiteError; |
| 1119 | } |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | } // armnnDelegate namespace |