Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 1 | // |
Colm Donelan | 253d1bb | 2024-03-04 22:19:26 +0000 | [diff] [blame] | 2 | // Copyright © 2020-2024 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 | |
Colm Donelan | 253d1bb | 2024-03-04 22:19:26 +0000 | [diff] [blame] | 276 | ArmnnSubgraph::~ArmnnSubgraph() |
| 277 | { |
| 278 | // The delegate holds its own Arm NN runtime so this is our last chance to print internal profiling data. |
| 279 | std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkId); |
| 280 | if (profiler && profiler->IsProfilingEnabled()) |
| 281 | { |
| 282 | profiler->Print(std::cout); |
| 283 | } |
| 284 | } |
| 285 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 286 | TfLiteStatus ArmnnSubgraph::AddInputLayer(DelegateData& delegateData, |
| 287 | TfLiteContext* tfLiteContext, |
| 288 | const TfLiteIntArray* inputs, |
| 289 | std::vector<armnn::BindingPointInfo>& inputBindings) |
| 290 | { |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 291 | const size_t numInputs = static_cast<size_t>(inputs->size); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 292 | for (unsigned int i = 0; i < numInputs; ++i) |
| 293 | { |
| 294 | const int32_t tensorId = inputs->data[i]; |
| 295 | const TfLiteTensor tensor = tfLiteContext->tensors[tensorId]; |
Sadik Armagan | 6e36a64 | 2020-11-10 21:18:41 +0000 | [diff] [blame] | 296 | // Do not create bindings for constant inputs |
| 297 | if (tensor.allocation_type == kTfLiteMmapRo) |
| 298 | { |
| 299 | continue; |
| 300 | } |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 301 | |
| 302 | auto bindingId = static_cast<armnn::LayerBindingId>((tensorId)); |
| 303 | armnn::IConnectableLayer* layer = delegateData.m_Network->AddInputLayer(bindingId); |
| 304 | |
| 305 | auto tensorInfo = GetTensorInfoForTfLiteTensor(tensor); |
| 306 | armnn::IOutputSlot& outputSlot = layer->GetOutputSlot(0); |
| 307 | outputSlot.SetTensorInfo(tensorInfo); |
| 308 | |
| 309 | // Store for creating connections |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 310 | delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)] = &outputSlot; |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 311 | |
Sadik Armagan | 6e36a64 | 2020-11-10 21:18:41 +0000 | [diff] [blame] | 312 | inputBindings.push_back(std::make_pair(bindingId, tensorInfo)); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 313 | } |
Sadik Armagan | 6e36a64 | 2020-11-10 21:18:41 +0000 | [diff] [blame] | 314 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 315 | return kTfLiteOk; |
| 316 | } |
| 317 | |
| 318 | TfLiteStatus ArmnnSubgraph::AddOutputLayer(DelegateData& delegateData, |
| 319 | TfLiteContext* tfLiteContext, |
| 320 | const TfLiteIntArray* outputs, |
| 321 | std::vector<armnn::BindingPointInfo>& outputBindings) |
| 322 | { |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 323 | const size_t numOutputs = static_cast<size_t>(outputs->size); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 324 | for (unsigned int i = 0; i < numOutputs; ++i) |
| 325 | { |
| 326 | const int32_t tensorId = outputs->data[i]; |
| 327 | const TfLiteTensor tensor = tfLiteContext->tensors[tensorId]; |
| 328 | |
| 329 | auto bindingId = static_cast<armnn::LayerBindingId>((tensorId)); |
| 330 | armnn::IConnectableLayer* layer = delegateData.m_Network->AddOutputLayer(bindingId); |
| 331 | |
| 332 | auto tensorInfo = GetTensorInfoForTfLiteTensor(tensor); |
Ryan OShea | c229b3f | 2023-06-27 22:34:54 +0100 | [diff] [blame] | 333 | |
| 334 | if (delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)] == nullptr) |
| 335 | { |
| 336 | return kTfLiteError; |
| 337 | } |
| 338 | |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 339 | delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)]->Connect(layer->GetInputSlot(0)); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 340 | outputBindings.push_back(std::make_pair(bindingId, tensorInfo)); |
| 341 | } |
| 342 | |
| 343 | return kTfLiteOk; |
| 344 | } |
| 345 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 346 | ArmnnSubgraph* ArmnnSubgraph::Create(TfLiteContext* tfLiteContext, |
| 347 | const TfLiteDelegateParams* parameters, |
| 348 | const Delegate* delegate) |
| 349 | { |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 350 | const auto startTime = armnn::GetTimeNow(); |
| 351 | ARMNN_LOG(info) << "ArmnnSubgraph creation"; |
| 352 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 353 | TfLiteIntArray* executionPlan; |
| 354 | if (tfLiteContext->GetExecutionPlan(tfLiteContext, &executionPlan) != kTfLiteOk) |
| 355 | { |
| 356 | return nullptr; |
| 357 | } |
| 358 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 359 | // Initialize DelegateData holds network and output slots information |
| 360 | DelegateData delegateData(delegate->m_Options.GetBackends()); |
| 361 | |
| 362 | // Build ArmNN Network |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 363 | armnn::NetworkOptions networkOptions = delegate->m_Options.GetOptimizerOptions().GetModelOptions(); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 364 | armnn::NetworkId networkId; |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 365 | delegateData.m_Network = armnn::INetwork::Create(networkOptions); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 366 | |
Sadik Armagan | 6e36a64 | 2020-11-10 21:18:41 +0000 | [diff] [blame] | 367 | delegateData.m_OutputSlotForNode = std::vector<armnn::IOutputSlot*>(tfLiteContext->tensors_size, nullptr); |
| 368 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 369 | std::vector<armnn::BindingPointInfo> inputBindings; |
| 370 | std::vector<armnn::BindingPointInfo> outputBindings; |
| 371 | |
| 372 | // Add input layer |
| 373 | auto status = AddInputLayer(delegateData, tfLiteContext, parameters->input_tensors, inputBindings); |
| 374 | if (status != kTfLiteOk) |
| 375 | { |
| 376 | throw armnn::Exception("TfLiteArmnnDelegate: Unable to add Inputs to the network!"); |
| 377 | } |
| 378 | |
| 379 | // Parse TfLite delegate nodes to ArmNN |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 380 | const auto parseStartTime = armnn::GetTimeNow(); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 381 | for (int i = 0; i < parameters->nodes_to_replace->size; ++i) |
| 382 | { |
| 383 | const int nodeIndex = parameters->nodes_to_replace->data[i]; |
| 384 | |
| 385 | TfLiteNode* tfLiteNode = nullptr; |
| 386 | TfLiteRegistration* tfLiteRegistration = nullptr; |
| 387 | if (tfLiteContext->GetNodeAndRegistration( |
| 388 | tfLiteContext, nodeIndex, &tfLiteNode, &tfLiteRegistration) != kTfLiteOk) |
| 389 | { |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 390 | throw armnn::Exception(&"TfLiteArmnnDelegate: Unable to get node registration: " [ nodeIndex]); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 391 | } |
| 392 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 393 | if (VisitNode(delegateData, tfLiteContext, tfLiteRegistration, tfLiteNode, nodeIndex) != kTfLiteOk) |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 394 | { |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 395 | throw armnn::Exception(&"TfLiteArmnnDelegate: Unable to parse node: " [ nodeIndex]); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 396 | } |
| 397 | } |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 398 | ARMNN_LOG(info) << "Parse nodes to ArmNN time: " << std::setprecision(2) |
| 399 | << std::fixed << armnn::GetTimeDuration(parseStartTime).count() << " ms"; |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 400 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 401 | // Add Output layer |
| 402 | status = AddOutputLayer(delegateData, tfLiteContext, parameters->output_tensors, outputBindings); |
| 403 | if (status != kTfLiteOk) |
| 404 | { |
| 405 | throw armnn::Exception("TfLiteArmnnDelegate: Unable to add Outputs to the network!"); |
| 406 | } |
| 407 | |
| 408 | // Optimize ArmNN network |
| 409 | armnn::IOptimizedNetworkPtr optNet(nullptr, nullptr); |
| 410 | try |
| 411 | { |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 412 | const auto optimizeStartTime = armnn::GetTimeNow(); |
Sadik Armagan | 6e36a64 | 2020-11-10 21:18:41 +0000 | [diff] [blame] | 413 | optNet = armnn::Optimize(*(delegateData.m_Network.get()), |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 414 | delegate->m_Options.GetBackends(), |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 415 | delegate->m_Runtime->GetDeviceSpec(), |
| 416 | delegate->m_Options.GetOptimizerOptions()); |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 417 | ARMNN_LOG(info) << "Optimize ArmnnSubgraph time: " << std::setprecision(2) |
| 418 | << std::fixed << armnn::GetTimeDuration(optimizeStartTime).count() << " ms"; |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 419 | } |
Ryan OShea | 05b6a3e | 2023-01-11 15:27:50 +0000 | [diff] [blame] | 420 | catch (std::exception& ex) |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 421 | { |
| 422 | std::stringstream exMessage; |
| 423 | exMessage << "TfLiteArmnnDelegate: Exception (" << ex.what() << ") caught from optimize."; |
| 424 | throw armnn::Exception(exMessage.str()); |
| 425 | } |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 426 | if (!optNet) |
| 427 | { |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 428 | // Optimize failed |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 429 | throw armnn::Exception("TfLiteArmnnDelegate: Unable to optimize the network!"); |
| 430 | } |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 431 | |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 432 | // If set, we will serialize the optimized model into a dot file. |
| 433 | const std::string serializeToDotFile = delegate->m_Options.GetSerializeToDot(); |
| 434 | if (!serializeToDotFile.empty()) |
| 435 | { |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 436 | ARMNN_LOG(info) << "Writing graph to dot file: " << serializeToDotFile; |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 437 | fs::path filename = serializeToDotFile; |
| 438 | std::fstream file(filename.c_str(), std::ios_base::out); |
| 439 | optNet->SerializeToDot(file); |
| 440 | } |
| 441 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 442 | try |
| 443 | { |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 444 | const auto loadStartTime = armnn::GetTimeNow(); |
| 445 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 446 | // Load graph into runtime |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 447 | std::string errorMessage; |
Narumol Prangnawarat | 74a3cf5 | 2021-01-29 15:38:54 +0000 | [diff] [blame] | 448 | armnn::Status loadingStatus; |
Francis Murtagh | 626bd90 | 2022-06-21 13:16:23 +0000 | [diff] [blame] | 449 | armnn::MemorySource inputSource = armnn::MemorySource::Undefined; |
| 450 | armnn::MemorySource outputSource = armnn::MemorySource::Undefined; |
| 451 | // 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] | 452 | if (delegate->m_Options.GetOptimizerOptions().GetImportEnabled()) |
Narumol Prangnawarat | 74a3cf5 | 2021-01-29 15:38:54 +0000 | [diff] [blame] | 453 | { |
Francis Murtagh | 626bd90 | 2022-06-21 13:16:23 +0000 | [diff] [blame] | 454 | inputSource = armnn::MemorySource::Malloc; |
| 455 | } |
John Mcloughlin | c5ee0d7 | 2023-03-24 12:07:25 +0000 | [diff] [blame] | 456 | if (delegate->m_Options.GetOptimizerOptions().GetExportEnabled()) |
Francis Murtagh | 626bd90 | 2022-06-21 13:16:23 +0000 | [diff] [blame] | 457 | { |
| 458 | outputSource = armnn::MemorySource::Malloc; |
Narumol Prangnawarat | 74a3cf5 | 2021-01-29 15:38:54 +0000 | [diff] [blame] | 459 | } |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 460 | armnn::INetworkProperties networkProperties(false, |
Francis Murtagh | 626bd90 | 2022-06-21 13:16:23 +0000 | [diff] [blame] | 461 | inputSource, |
| 462 | outputSource, |
Colm Donelan | 3e32a87 | 2021-10-04 22:55:37 +0100 | [diff] [blame] | 463 | delegate->m_Options.GetInternalProfilingState(), |
| 464 | delegate->m_Options.GetInternalProfilingDetail()); |
| 465 | loadingStatus = delegate->m_Runtime->LoadNetwork(networkId, |
| 466 | std::move(optNet), |
| 467 | errorMessage, |
| 468 | networkProperties); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 469 | if (loadingStatus != armnn::Status::Success) |
| 470 | { |
Colm Donelan | 4514228 | 2021-10-21 23:39:52 +0100 | [diff] [blame] | 471 | // Network load failed. |
Colm Donelan | 194086f | 2022-11-14 17:23:07 +0000 | [diff] [blame] | 472 | throw armnn::Exception("TfLiteArmnnDelegate: Network could not be loaded: " + errorMessage); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 473 | } |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 474 | |
| 475 | ARMNN_LOG(info) << "Load ArmnnSubgraph time: " << std::setprecision(2) |
| 476 | << std::fixed << armnn::GetTimeDuration(loadStartTime).count() << " ms"; |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 477 | } |
| 478 | catch (std::exception& ex) |
| 479 | { |
| 480 | std::stringstream exMessage; |
| 481 | exMessage << "TfLiteArmnnDelegate: Exception (" << ex.what() << ") caught from LoadNetwork."; |
| 482 | throw armnn::Exception(exMessage.str()); |
| 483 | } |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 484 | |
Narumol Prangnawarat | 0b51d5a | 2021-01-20 15:58:29 +0000 | [diff] [blame] | 485 | // Register debug callback function |
| 486 | if (delegate->m_Options.GetDebugCallbackFunction().has_value()) |
| 487 | { |
| 488 | delegate->m_Runtime->RegisterDebugCallback(networkId, delegate->m_Options.GetDebugCallbackFunction().value()); |
| 489 | } |
| 490 | |
Jan Eilers | 17d34da | 2021-12-08 16:15:12 +0000 | [diff] [blame] | 491 | ARMNN_LOG(info) << "Overall ArmnnSubgraph creation time: " << std::setprecision(2) |
| 492 | << std::fixed << armnn::GetTimeDuration(startTime).count() << " ms\n"; |
| 493 | |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 494 | // Create a new SubGraph with networkId and runtime |
Mike Kelly | 5446a4d | 2023-01-20 15:51:05 +0000 | [diff] [blame] | 495 | return new ArmnnSubgraph(networkId, delegate->m_Runtime, inputBindings, outputBindings); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | TfLiteStatus ArmnnSubgraph::Prepare(TfLiteContext* tfLiteContext) |
| 499 | { |
Finn Williams | 6f9f990 | 2020-11-13 13:23:15 +0000 | [diff] [blame] | 500 | armnn::IgnoreUnused(tfLiteContext); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 501 | return kTfLiteOk; |
| 502 | } |
| 503 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 504 | TfLiteStatus ArmnnSubgraph::Invoke(TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode) |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 505 | { |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 506 | // Prepare inputs |
| 507 | armnn::InputTensors inputTensors; |
| 508 | size_t inputIndex = 0; |
| 509 | for (auto inputIdx : tflite::TfLiteIntArrayView(tfLiteNode->inputs)) |
| 510 | { |
| 511 | TfLiteTensor* tensor = &tfLiteContext->tensors[inputIdx]; |
| 512 | if (tensor->allocation_type != kTfLiteMmapRo) |
| 513 | { |
| 514 | const armnn::BindingPointInfo& inputBinding = m_InputBindings[inputIndex]; |
Cathal Corbett | 5b8093c | 2021-10-22 11:12:07 +0100 | [diff] [blame] | 515 | armnn::TensorInfo inputTensorInfo = inputBinding.second; |
| 516 | inputTensorInfo.SetConstant(true); |
| 517 | const armnn::ConstTensor inputTensor(inputTensorInfo, tensor->data.data); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 518 | inputTensors.emplace_back(inputIdx, inputTensor); |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 519 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 520 | ++inputIndex; |
| 521 | } |
| 522 | } |
| 523 | |
| 524 | // Prepare outputs |
| 525 | armnn::OutputTensors outputTensors; |
| 526 | size_t outputIndex = 0; |
| 527 | for (auto outputIdx : tflite::TfLiteIntArrayView(tfLiteNode->outputs)) |
| 528 | { |
| 529 | const armnn::BindingPointInfo& outputBinding = m_OutputBindings[outputIndex]; |
| 530 | TfLiteTensor* tensor = &tfLiteContext->tensors[outputIdx]; |
| 531 | const armnn::Tensor outputTensor(outputBinding.second, tensor->data.data); |
| 532 | outputTensors.emplace_back(outputIdx, outputTensor); |
| 533 | |
| 534 | ++outputIndex; |
| 535 | } |
| 536 | |
| 537 | // Run graph |
| 538 | auto status = m_Runtime->EnqueueWorkload(m_NetworkId, inputTensors, outputTensors); |
| 539 | return (status == armnn::Status::Success) ? kTfLiteOk : kTfLiteError; |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 540 | } |
| 541 | |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 542 | TfLiteStatus ArmnnSubgraph::VisitNode(DelegateData& delegateData, |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 543 | TfLiteContext* tfLiteContext, |
| 544 | TfLiteRegistration* tfLiteRegistration, |
| 545 | TfLiteNode* tfLiteNode, |
| 546 | int nodeIndex) |
| 547 | { |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 548 | switch (tfLiteRegistration->builtin_code) |
| 549 | { |
Ryan OShea | d21abaf | 2022-06-10 14:49:11 +0100 | [diff] [blame] | 550 | case kTfLiteBuiltinCustom: |
| 551 | { |
| 552 | #if defined(ARMNN_POST_TFLITE_2_5) |
| 553 | // Custom operators are defined by the name rather than the builtin code. |
| 554 | // Parse the custom_name param in the registration to point to the correct visitor function. |
| 555 | std::string customOperatorName = tfLiteRegistration->custom_name; |
| 556 | if ( customOperatorName == "AveragePool3D" ) |
| 557 | { |
| 558 | return VisitPooling3dOperator(delegateData, |
| 559 | tfLiteContext, |
| 560 | tfLiteNode, |
| 561 | nodeIndex, |
| 562 | customOperatorName); |
| 563 | } |
| 564 | else if (customOperatorName == "MaxPool3D") |
| 565 | { |
| 566 | return VisitPooling3dOperator(delegateData, |
| 567 | tfLiteContext, |
| 568 | tfLiteNode, |
| 569 | nodeIndex, |
| 570 | customOperatorName); |
| 571 | } |
| 572 | #endif |
| 573 | // Invalid or unsupported custom operator |
| 574 | return kTfLiteError; |
| 575 | } |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 576 | case kTfLiteBuiltinAbs: |
| 577 | return VisitElementwiseUnaryOperator(delegateData, |
| 578 | tfLiteContext, |
| 579 | tfLiteNode, |
| 580 | nodeIndex, |
| 581 | armnn::UnaryOperation::Abs); |
| 582 | case kTfLiteBuiltinAdd: |
| 583 | return VisitElementwiseBinaryOperator(delegateData, |
| 584 | tfLiteContext, |
| 585 | tfLiteNode, |
| 586 | nodeIndex, |
| 587 | kTfLiteBuiltinAdd); |
| 588 | case kTfLiteBuiltinArgMax: |
| 589 | return VisitArgMinMaxOperator(delegateData, |
| 590 | tfLiteContext, |
| 591 | tfLiteNode, |
| 592 | nodeIndex, |
| 593 | kTfLiteBuiltinArgMax); |
| 594 | case kTfLiteBuiltinArgMin: |
| 595 | return VisitArgMinMaxOperator(delegateData, |
| 596 | tfLiteContext, |
| 597 | tfLiteNode, |
| 598 | nodeIndex, |
| 599 | kTfLiteBuiltinArgMin); |
| 600 | case kTfLiteBuiltinAveragePool2d: |
Ryan OShea | d21abaf | 2022-06-10 14:49:11 +0100 | [diff] [blame] | 601 | return VisitPooling2dOperator(delegateData, |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 602 | tfLiteContext, |
| 603 | tfLiteNode, |
| 604 | nodeIndex, |
| 605 | kTfLiteBuiltinAveragePool2d); |
Ryan OShea | 49ed0df | 2022-09-21 16:09:41 +0100 | [diff] [blame] | 606 | case kTfLiteBuiltinBatchMatmul: |
| 607 | return VisitBatchMatMulOperator(delegateData, |
| 608 | tfLiteContext, |
| 609 | tfLiteNode, |
| 610 | nodeIndex, |
| 611 | kTfLiteBuiltinBatchMatmul); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 612 | case kTfLiteBuiltinBatchToSpaceNd: |
| 613 | return VisitBatchToSpaceNdOperator(delegateData, |
| 614 | tfLiteContext, |
| 615 | tfLiteNode, |
| 616 | nodeIndex, |
| 617 | kTfLiteBuiltinBatchToSpaceNd); |
Idriss Chaouch | cbf7929 | 2023-09-08 11:18:16 +0100 | [diff] [blame] | 618 | case kTfLiteBuiltinBroadcastTo: |
| 619 | return VisitBroadcastToOperator(delegateData, |
| 620 | tfLiteContext, |
| 621 | tfLiteNode, |
| 622 | nodeIndex, |
| 623 | kTfLiteBuiltinBroadcastTo); |
Sadik Armagan | 937565b | 2021-04-21 14:03:28 +0100 | [diff] [blame] | 624 | case kTfLiteBuiltinCast: |
| 625 | return VisitCastOperator(delegateData, |
| 626 | tfLiteContext, |
| 627 | tfLiteNode, |
| 628 | nodeIndex, |
| 629 | kTfLiteBuiltinCast); |
Teresa Charlin | 93f0ad0 | 2023-03-23 15:28:02 +0000 | [diff] [blame] | 630 | case kTfLiteBuiltinCeil: |
| 631 | return VisitElementwiseUnaryOperator(delegateData, |
| 632 | tfLiteContext, |
| 633 | tfLiteNode, |
| 634 | nodeIndex, |
| 635 | armnn::UnaryOperation::Ceil); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 636 | case kTfLiteBuiltinConcatenation: |
| 637 | return VisitControlOperator(delegateData, |
| 638 | tfLiteContext, |
| 639 | tfLiteNode, |
| 640 | nodeIndex, |
| 641 | kTfLiteBuiltinConcatenation); |
| 642 | case kTfLiteBuiltinConv2d: |
| 643 | return VisitConvolutionOperator(delegateData, |
| 644 | tfLiteContext, |
| 645 | tfLiteNode, |
| 646 | nodeIndex, |
| 647 | kTfLiteBuiltinConv2d); |
Matthew Sloyan | 81ec994 | 2021-10-12 10:26:30 +0100 | [diff] [blame] | 648 | // Conv3d is only correctly supported for external delegates from TF Lite v2.6, as there was a breaking bug in v2.5. |
| 649 | #if defined(ARMNN_POST_TFLITE_2_5) |
| 650 | case kTfLiteBuiltinConv3d: |
| 651 | return VisitConvolutionOperator(delegateData, |
| 652 | tfLiteContext, |
| 653 | tfLiteNode, |
| 654 | nodeIndex, |
| 655 | kTfLiteBuiltinConv3d); |
| 656 | #endif |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 657 | case kTfLiteBuiltinDepthToSpace: |
| 658 | return VisitDepthToSpaceOperator(delegateData, |
| 659 | tfLiteContext, |
| 660 | tfLiteNode, |
| 661 | nodeIndex, |
| 662 | kTfLiteBuiltinDepthToSpace); |
| 663 | case kTfLiteBuiltinDepthwiseConv2d: |
| 664 | return VisitConvolutionOperator(delegateData, |
| 665 | tfLiteContext, |
| 666 | tfLiteNode, |
| 667 | nodeIndex, |
| 668 | kTfLiteBuiltinDepthwiseConv2d); |
| 669 | case kTfLiteBuiltinDequantize: |
| 670 | return VisitDequantizeOperator(delegateData, |
| 671 | tfLiteContext, |
| 672 | tfLiteNode, |
| 673 | nodeIndex, |
| 674 | kTfLiteBuiltinDequantize); |
| 675 | case kTfLiteBuiltinDiv: |
| 676 | return VisitElementwiseBinaryOperator(delegateData, |
| 677 | tfLiteContext, |
| 678 | tfLiteNode, |
| 679 | nodeIndex, |
| 680 | kTfLiteBuiltinDiv); |
| 681 | case kTfLiteBuiltinElu: |
| 682 | return VisitActivationOperator(delegateData, |
| 683 | tfLiteContext, |
| 684 | tfLiteNode, |
| 685 | nodeIndex, |
| 686 | kTfLiteBuiltinElu); |
| 687 | case kTfLiteBuiltinEqual: |
| 688 | return VisitComparisonOperator(delegateData, |
| 689 | tfLiteContext, |
| 690 | tfLiteNode, |
| 691 | nodeIndex, |
| 692 | kTfLiteBuiltinEqual); |
| 693 | case kTfLiteBuiltinExp: |
| 694 | return VisitElementwiseUnaryOperator(delegateData, |
| 695 | tfLiteContext, |
| 696 | tfLiteNode, |
| 697 | nodeIndex, |
| 698 | armnn::UnaryOperation::Exp); |
| 699 | case kTfLiteBuiltinExpandDims: |
| 700 | return VisitExpandDimsOperator(delegateData, |
| 701 | tfLiteContext, |
| 702 | tfLiteNode, |
| 703 | nodeIndex, |
| 704 | kTfLiteBuiltinExpandDims); |
| 705 | case kTfLiteBuiltinFill: |
| 706 | return VisitFillOperator(delegateData, |
| 707 | tfLiteContext, |
| 708 | tfLiteNode, |
| 709 | nodeIndex, |
| 710 | kTfLiteBuiltinFill); |
| 711 | case kTfLiteBuiltinFloor: |
| 712 | return VisitFloorOperator(delegateData, |
| 713 | tfLiteContext, |
| 714 | tfLiteNode, |
| 715 | nodeIndex, |
| 716 | kTfLiteBuiltinFloor); |
Jim Flynn | 4b2f347 | 2021-10-13 21:20:07 +0100 | [diff] [blame] | 717 | case kTfLiteBuiltinFloorDiv: |
| 718 | return VisitElementwiseBinaryOperator(delegateData, |
| 719 | tfLiteContext, |
| 720 | tfLiteNode, |
| 721 | nodeIndex, |
| 722 | kTfLiteBuiltinFloorDiv); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 723 | case kTfLiteBuiltinFullyConnected: |
| 724 | return VisitFullyConnectedOperator(delegateData, |
| 725 | tfLiteContext, |
| 726 | tfLiteNode, |
| 727 | nodeIndex, |
| 728 | kTfLiteBuiltinFullyConnected); |
| 729 | case kTfLiteBuiltinGather: |
| 730 | return VisitGatherOperator(delegateData, |
| 731 | tfLiteContext, |
| 732 | tfLiteNode, |
| 733 | nodeIndex, |
| 734 | kTfLiteBuiltinGather); |
Teresa Charlin | d5c0ed2 | 2022-04-25 18:23:41 +0100 | [diff] [blame] | 735 | case kTfLiteBuiltinGatherNd: |
| 736 | return VisitGatherNdOperator(delegateData, |
| 737 | tfLiteContext, |
| 738 | tfLiteNode, |
| 739 | nodeIndex, |
| 740 | kTfLiteBuiltinGatherNd); |
Teresa Charlin | 077cddb | 2023-09-15 15:19:21 +0100 | [diff] [blame] | 741 | case kTfLiteBuiltinGelu: |
| 742 | return VisitActivationOperator(delegateData, |
| 743 | tfLiteContext, |
| 744 | tfLiteNode, |
| 745 | nodeIndex, |
| 746 | kTfLiteBuiltinGelu); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 747 | case kTfLiteBuiltinGreater: |
| 748 | return VisitComparisonOperator(delegateData, |
| 749 | tfLiteContext, |
| 750 | tfLiteNode, |
| 751 | nodeIndex, |
| 752 | kTfLiteBuiltinGreater); |
| 753 | case kTfLiteBuiltinGreaterEqual: |
| 754 | return VisitComparisonOperator(delegateData, |
| 755 | tfLiteContext, |
| 756 | tfLiteNode, |
| 757 | nodeIndex, |
| 758 | kTfLiteBuiltinGreaterEqual); |
| 759 | case kTfLiteBuiltinHardSwish: |
| 760 | return VisitActivationOperator(delegateData, |
| 761 | tfLiteContext, |
| 762 | tfLiteNode, |
| 763 | nodeIndex, |
| 764 | kTfLiteBuiltinHardSwish); |
| 765 | case kTfLiteBuiltinL2Normalization: |
Sadik Armagan | 4b227bb | 2021-01-22 10:53:38 +0000 | [diff] [blame] | 766 | return VisitL2NormalizationOperator(delegateData, |
| 767 | tfLiteContext, |
| 768 | tfLiteNode, |
| 769 | nodeIndex, |
| 770 | kTfLiteBuiltinL2Normalization); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 771 | case kTfLiteBuiltinL2Pool2d: |
Ryan OShea | d21abaf | 2022-06-10 14:49:11 +0100 | [diff] [blame] | 772 | return VisitPooling2dOperator(delegateData, |
Tianle Cheng | ae93173 | 2023-07-28 11:53:04 +0100 | [diff] [blame] | 773 | tfLiteContext, |
| 774 | tfLiteNode, |
| 775 | nodeIndex, |
| 776 | kTfLiteBuiltinL2Pool2d); |
| 777 | case kTfLiteBuiltinLeakyRelu: |
| 778 | return VisitActivationOperator(delegateData, |
| 779 | tfLiteContext, |
| 780 | tfLiteNode, |
| 781 | nodeIndex, |
| 782 | kTfLiteBuiltinLeakyRelu); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 783 | case kTfLiteBuiltinLess: |
| 784 | return VisitComparisonOperator(delegateData, |
| 785 | tfLiteContext, |
| 786 | tfLiteNode, |
| 787 | nodeIndex, |
| 788 | kTfLiteBuiltinLess); |
| 789 | case kTfLiteBuiltinLessEqual: |
| 790 | return VisitComparisonOperator(delegateData, |
| 791 | tfLiteContext, |
| 792 | tfLiteNode, |
| 793 | nodeIndex, |
| 794 | kTfLiteBuiltinLessEqual); |
| 795 | case kTfLiteBuiltinLocalResponseNormalization: |
Sadik Armagan | 4b227bb | 2021-01-22 10:53:38 +0000 | [diff] [blame] | 796 | return VisitLocalResponseNormalizationOperator(delegateData, |
| 797 | tfLiteContext, |
| 798 | tfLiteNode, |
| 799 | nodeIndex, |
| 800 | kTfLiteBuiltinLocalResponseNormalization); |
Teresa Charlin | b1f5f70 | 2022-07-12 14:16:24 +0100 | [diff] [blame] | 801 | case kTfLiteBuiltinLog: |
| 802 | return VisitElementwiseUnaryOperator(delegateData, |
| 803 | tfLiteContext, |
| 804 | tfLiteNode, |
| 805 | nodeIndex, |
| 806 | armnn::UnaryOperation::Log); |
Matthew Sloyan | c8eb955 | 2020-11-26 10:54:22 +0000 | [diff] [blame] | 807 | case kTfLiteBuiltinLogicalAnd: |
| 808 | return VisitLogicalBinaryOperator(delegateData, |
| 809 | tfLiteContext, |
| 810 | tfLiteNode, |
| 811 | nodeIndex, |
| 812 | kTfLiteBuiltinLogicalAnd, |
| 813 | armnn::LogicalBinaryOperation::LogicalAnd); |
| 814 | case kTfLiteBuiltinLogicalNot: |
| 815 | return VisitElementwiseUnaryOperator(delegateData, |
| 816 | tfLiteContext, |
| 817 | tfLiteNode, |
| 818 | nodeIndex, |
| 819 | armnn::UnaryOperation::LogicalNot); |
| 820 | case kTfLiteBuiltinLogicalOr: |
| 821 | return VisitLogicalBinaryOperator(delegateData, |
| 822 | tfLiteContext, |
| 823 | tfLiteNode, |
| 824 | nodeIndex, |
| 825 | kTfLiteBuiltinLogicalOr, |
| 826 | armnn::LogicalBinaryOperation::LogicalOr); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 827 | case kTfLiteBuiltinLogistic: |
| 828 | return VisitActivationOperator(delegateData, |
| 829 | tfLiteContext, |
| 830 | tfLiteNode, |
| 831 | nodeIndex, |
| 832 | kTfLiteBuiltinLogistic); |
| 833 | case kTfLiteBuiltinLogSoftmax: |
| 834 | return VisitSoftmaxOperator(delegateData, |
| 835 | tfLiteContext, |
| 836 | tfLiteNode, |
| 837 | nodeIndex, |
| 838 | kTfLiteBuiltinLogSoftmax); |
| 839 | case kTfLiteBuiltinLstm: |
| 840 | return VisitLstmOperator(delegateData, |
| 841 | tfLiteContext, |
| 842 | tfLiteNode, |
| 843 | nodeIndex, |
| 844 | kTfLiteBuiltinLstm); |
| 845 | case kTfLiteBuiltinMaxPool2d: |
Ryan OShea | d21abaf | 2022-06-10 14:49:11 +0100 | [diff] [blame] | 846 | return VisitPooling2dOperator(delegateData, |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 847 | tfLiteContext, |
| 848 | tfLiteNode, |
| 849 | nodeIndex, |
| 850 | kTfLiteBuiltinMaxPool2d); |
| 851 | case kTfLiteBuiltinMaximum: |
| 852 | return VisitElementwiseBinaryOperator(delegateData, |
| 853 | tfLiteContext, |
| 854 | tfLiteNode, |
| 855 | nodeIndex, |
| 856 | kTfLiteBuiltinMaximum); |
| 857 | case kTfLiteBuiltinMean: |
| 858 | return VisitControlOperator(delegateData, |
| 859 | tfLiteContext, |
| 860 | tfLiteNode, |
| 861 | nodeIndex, |
| 862 | kTfLiteBuiltinMean); |
| 863 | case kTfLiteBuiltinMinimum: |
| 864 | return VisitElementwiseBinaryOperator(delegateData, |
| 865 | tfLiteContext, |
| 866 | tfLiteNode, |
| 867 | nodeIndex, |
| 868 | kTfLiteBuiltinMinimum); |
Matthew Sloyan | af3a4ef | 2021-10-22 15:48:12 +0100 | [diff] [blame] | 869 | case kTfLiteBuiltinMirrorPad: |
| 870 | return VisitPadOperator(delegateData, |
| 871 | tfLiteContext, |
| 872 | tfLiteNode, |
| 873 | nodeIndex, |
| 874 | kTfLiteBuiltinMirrorPad); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 875 | case kTfLiteBuiltinMul: |
| 876 | return VisitElementwiseBinaryOperator(delegateData, |
| 877 | tfLiteContext, |
| 878 | tfLiteNode, |
| 879 | nodeIndex, |
| 880 | kTfLiteBuiltinMul); |
| 881 | case kTfLiteBuiltinNeg: |
| 882 | return VisitElementwiseUnaryOperator(delegateData, |
| 883 | tfLiteContext, |
| 884 | tfLiteNode, |
| 885 | nodeIndex, |
| 886 | armnn::UnaryOperation::Neg); |
| 887 | case kTfLiteBuiltinNotEqual: |
| 888 | return VisitComparisonOperator(delegateData, |
| 889 | tfLiteContext, |
| 890 | tfLiteNode, |
| 891 | nodeIndex, |
| 892 | kTfLiteBuiltinNotEqual); |
Matthew Sloyan | a7a12f5 | 2021-05-06 10:05:28 +0100 | [diff] [blame] | 893 | case kTfLiteBuiltinPack: |
| 894 | return VisitPackOperator(delegateData, |
| 895 | tfLiteContext, |
| 896 | tfLiteNode, |
| 897 | nodeIndex, |
| 898 | kTfLiteBuiltinPack); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 899 | case kTfLiteBuiltinPad: |
| 900 | return VisitPadOperator(delegateData, |
| 901 | tfLiteContext, |
| 902 | tfLiteNode, |
| 903 | nodeIndex, |
| 904 | kTfLiteBuiltinPad); |
| 905 | case kTfLiteBuiltinPadv2: |
| 906 | return VisitPadOperator(delegateData, |
| 907 | tfLiteContext, |
| 908 | tfLiteNode, |
| 909 | nodeIndex, |
| 910 | kTfLiteBuiltinPadv2); |
John Mcloughlin | 0ec0087 | 2023-05-15 17:03:49 +0100 | [diff] [blame] | 911 | case kTfLiteBuiltinPow: |
| 912 | return VisitElementwiseBinaryOperator(delegateData, |
| 913 | tfLiteContext, |
| 914 | tfLiteNode, |
| 915 | nodeIndex, |
| 916 | kTfLiteBuiltinPow); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 917 | case kTfLiteBuiltinPrelu: |
James Conroy | 3982548 | 2021-05-27 17:44:50 +0100 | [diff] [blame] | 918 | return VisitPreluOperator(delegateData, |
| 919 | tfLiteContext, |
| 920 | tfLiteNode, |
| 921 | nodeIndex, |
| 922 | kTfLiteBuiltinPrelu); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 923 | case kTfLiteBuiltinQuantize: |
| 924 | return VisitQuantizeOperator(delegateData, |
| 925 | tfLiteContext, |
| 926 | tfLiteNode, |
| 927 | nodeIndex, |
| 928 | kTfLiteBuiltinQuantize); |
| 929 | case kTfLiteBuiltinRank: |
| 930 | return VisitControlOperator(delegateData, |
| 931 | tfLiteContext, |
| 932 | tfLiteNode, |
| 933 | nodeIndex, |
| 934 | kTfLiteBuiltinRank); |
Sadik Armagan | a274748 | 2021-02-09 10:28:54 +0000 | [diff] [blame] | 935 | case kTfLiteBuiltinReduceMax: |
| 936 | return VisitReduceOperator(delegateData, |
| 937 | tfLiteContext, |
| 938 | tfLiteNode, |
| 939 | nodeIndex, |
| 940 | kTfLiteBuiltinReduceMax); |
| 941 | case kTfLiteBuiltinReduceMin: |
| 942 | return VisitReduceOperator(delegateData, |
| 943 | tfLiteContext, |
| 944 | tfLiteNode, |
| 945 | nodeIndex, |
| 946 | kTfLiteBuiltinReduceMin); |
Teresa Charlin | 4e3e831 | 2021-08-05 12:34:37 +0100 | [diff] [blame] | 947 | case kTfLiteBuiltinReduceProd: |
| 948 | return VisitReduceOperator(delegateData, |
| 949 | tfLiteContext, |
| 950 | tfLiteNode, |
| 951 | nodeIndex, |
| 952 | kTfLiteBuiltinReduceProd); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 953 | case kTfLiteBuiltinRelu: |
| 954 | return VisitActivationOperator(delegateData, |
| 955 | tfLiteContext, |
| 956 | tfLiteNode, |
| 957 | nodeIndex, |
| 958 | kTfLiteBuiltinRelu); |
| 959 | case kTfLiteBuiltinReluN1To1: |
| 960 | return VisitActivationOperator(delegateData, |
| 961 | tfLiteContext, |
| 962 | tfLiteNode, |
| 963 | nodeIndex, |
| 964 | kTfLiteBuiltinReluN1To1); |
| 965 | case kTfLiteBuiltinRelu6: |
| 966 | return VisitActivationOperator(delegateData, |
| 967 | tfLiteContext, |
| 968 | tfLiteNode, |
| 969 | nodeIndex, |
| 970 | kTfLiteBuiltinRelu6); |
| 971 | case kTfLiteBuiltinReshape: |
| 972 | return VisitReshapeOperator(delegateData, |
| 973 | tfLiteContext, |
| 974 | tfLiteNode, |
| 975 | nodeIndex, |
| 976 | kTfLiteBuiltinReshape); |
| 977 | case kTfLiteBuiltinResizeBilinear: |
| 978 | return VisitResizeOperator(delegateData, |
| 979 | tfLiteContext, |
| 980 | tfLiteNode, |
| 981 | nodeIndex, |
| 982 | kTfLiteBuiltinResizeBilinear); |
| 983 | case kTfLiteBuiltinResizeNearestNeighbor: |
| 984 | return VisitResizeOperator(delegateData, |
| 985 | tfLiteContext, |
| 986 | tfLiteNode, |
| 987 | nodeIndex, |
| 988 | kTfLiteBuiltinResizeNearestNeighbor); |
Tracy Narine | 7306bbe | 2023-07-17 16:06:26 +0100 | [diff] [blame] | 989 | case kTfLiteBuiltinReverseV2: |
| 990 | return VisitReverseV2Operator(delegateData, |
| 991 | tfLiteContext, |
| 992 | tfLiteNode, |
| 993 | nodeIndex, |
| 994 | kTfLiteBuiltinReverseV2); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 995 | case kTfLiteBuiltinRsqrt: |
| 996 | return VisitElementwiseUnaryOperator(delegateData, |
| 997 | tfLiteContext, |
| 998 | tfLiteNode, |
| 999 | nodeIndex, |
| 1000 | armnn::UnaryOperation::Rsqrt); |
Keith Davis | 0176fd8 | 2021-06-01 17:36:32 +0100 | [diff] [blame] | 1001 | case kTfLiteBuiltinShape: |
| 1002 | return VisitShapeOperator(delegateData, |
| 1003 | tfLiteContext, |
| 1004 | tfLiteNode, |
| 1005 | nodeIndex, |
| 1006 | kTfLiteBuiltinShape); |
Teresa Charlin | b1f5f70 | 2022-07-12 14:16:24 +0100 | [diff] [blame] | 1007 | case kTfLiteBuiltinSin: |
| 1008 | return VisitElementwiseUnaryOperator(delegateData, |
| 1009 | tfLiteContext, |
| 1010 | tfLiteNode, |
| 1011 | nodeIndex, |
| 1012 | armnn::UnaryOperation::Sin); |
Sadik Armagan | 34fa1bd | 2020-11-27 12:40:52 +0000 | [diff] [blame] | 1013 | case kTfLiteBuiltinSplit: |
| 1014 | return VisitSplitOperator(delegateData, |
| 1015 | tfLiteContext, |
| 1016 | tfLiteNode, |
| 1017 | nodeIndex, |
| 1018 | kTfLiteBuiltinSplit); |
| 1019 | case kTfLiteBuiltinSplitV: |
| 1020 | return VisitSplitVOperator(delegateData, |
| 1021 | tfLiteContext, |
| 1022 | tfLiteNode, |
| 1023 | nodeIndex, |
| 1024 | kTfLiteBuiltinSplitV); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 1025 | case kTfLiteBuiltinSqrt: |
| 1026 | return VisitElementwiseUnaryOperator(delegateData, |
| 1027 | tfLiteContext, |
| 1028 | tfLiteNode, |
| 1029 | nodeIndex, |
| 1030 | armnn::UnaryOperation::Sqrt); |
John Mcloughlin | 0ec0087 | 2023-05-15 17:03:49 +0100 | [diff] [blame] | 1031 | case kTfLiteBuiltinSquaredDifference: |
| 1032 | return VisitElementwiseBinaryOperator(delegateData, |
| 1033 | tfLiteContext, |
| 1034 | tfLiteNode, |
| 1035 | nodeIndex, |
| 1036 | kTfLiteBuiltinSquaredDifference); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 1037 | case kTfLiteBuiltinSqueeze: |
| 1038 | return VisitSqueezeOperator(delegateData, |
| 1039 | tfLiteContext, |
| 1040 | tfLiteNode, |
| 1041 | nodeIndex, |
| 1042 | kTfLiteBuiltinSqueeze); |
Cathal Corbett | 839b932 | 2022-11-18 08:52:18 +0000 | [diff] [blame] | 1043 | case kTfLiteBuiltinSlice: |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 1044 | return VisitSliceOperator(delegateData, |
| 1045 | tfLiteContext, |
| 1046 | tfLiteNode, |
| 1047 | nodeIndex, |
Cathal Corbett | 839b932 | 2022-11-18 08:52:18 +0000 | [diff] [blame] | 1048 | kTfLiteBuiltinSlice); |
| 1049 | case kTfLiteBuiltinStridedSlice: |
| 1050 | return VisitStridedSliceOperator(delegateData, |
| 1051 | tfLiteContext, |
| 1052 | tfLiteNode, |
| 1053 | nodeIndex, |
| 1054 | kTfLiteBuiltinStridedSlice); |
Sadik Armagan | a274748 | 2021-02-09 10:28:54 +0000 | [diff] [blame] | 1055 | case kTfLiteBuiltinSum: |
| 1056 | return VisitReduceOperator(delegateData, |
| 1057 | tfLiteContext, |
| 1058 | tfLiteNode, |
| 1059 | nodeIndex, |
| 1060 | kTfLiteBuiltinSum); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 1061 | case kTfLiteBuiltinTranspose: |
| 1062 | return VisitTransposeOperator(delegateData, |
| 1063 | tfLiteContext, |
| 1064 | tfLiteNode, |
| 1065 | nodeIndex, |
| 1066 | kTfLiteBuiltinTranspose); |
| 1067 | case kTfLiteBuiltinTransposeConv: |
| 1068 | return VisitConvolutionOperator(delegateData, |
| 1069 | tfLiteContext, |
| 1070 | tfLiteNode, |
| 1071 | nodeIndex, |
| 1072 | kTfLiteBuiltinTransposeConv); |
| 1073 | case kTfLiteBuiltinSoftmax: |
| 1074 | return VisitSoftmaxOperator(delegateData, |
| 1075 | tfLiteContext, |
| 1076 | tfLiteNode, |
| 1077 | nodeIndex, |
| 1078 | kTfLiteBuiltinSoftmax); |
| 1079 | case kTfLiteBuiltinSpaceToBatchNd: |
| 1080 | return VisitSpaceToBatchNdOperator(delegateData, |
| 1081 | tfLiteContext, |
| 1082 | tfLiteNode, |
| 1083 | nodeIndex, |
| 1084 | kTfLiteBuiltinSpaceToBatchNd); |
| 1085 | case kTfLiteBuiltinSpaceToDepth: |
| 1086 | return VisitSpaceToDepthOperator(delegateData, |
| 1087 | tfLiteContext, |
| 1088 | tfLiteNode, |
| 1089 | nodeIndex, |
| 1090 | kTfLiteBuiltinSpaceToDepth); |
| 1091 | case kTfLiteBuiltinSub: |
| 1092 | return VisitElementwiseBinaryOperator(delegateData, |
| 1093 | tfLiteContext, |
| 1094 | tfLiteNode, |
| 1095 | nodeIndex, |
| 1096 | kTfLiteBuiltinSub); |
| 1097 | case kTfLiteBuiltinTanh: |
| 1098 | return VisitActivationOperator(delegateData, |
| 1099 | tfLiteContext, |
| 1100 | tfLiteNode, |
| 1101 | nodeIndex, |
| 1102 | kTfLiteBuiltinTanh); |
Tianle Cheng | 92ce35c | 2023-07-25 16:41:00 +0100 | [diff] [blame] | 1103 | case kTfLiteBuiltinTile: |
| 1104 | return VisitTileOperator(delegateData, |
| 1105 | tfLiteContext, |
| 1106 | tfLiteNode, |
| 1107 | nodeIndex, |
| 1108 | kTfLiteBuiltinTile); |
Narumol Prangnawarat | 7684b18 | 2021-08-12 14:48:15 +0100 | [diff] [blame] | 1109 | case kTfLiteBuiltinUnidirectionalSequenceLstm: |
| 1110 | return VisitUnidirectionalSequenceLstmOperator(delegateData, |
| 1111 | tfLiteContext, |
| 1112 | tfLiteNode, |
| 1113 | nodeIndex, |
| 1114 | kTfLiteBuiltinUnidirectionalSequenceLstm); |
Kevin May | 8ab2d7a | 2021-05-07 09:32:51 +0100 | [diff] [blame] | 1115 | case kTfLiteBuiltinUnpack: |
| 1116 | return VisitUnpackOperator(delegateData, |
| 1117 | tfLiteContext, |
| 1118 | tfLiteNode, |
| 1119 | nodeIndex, |
| 1120 | kTfLiteBuiltinUnpack); |
Sadik Armagan | 62483be | 2020-10-23 17:14:43 +0100 | [diff] [blame] | 1121 | default: |
| 1122 | return kTfLiteError; |
| 1123 | } |
Sadik Armagan | 3c24f43 | 2020-10-19 17:35:30 +0100 | [diff] [blame] | 1124 | } |
| 1125 | |
| 1126 | } // armnnDelegate namespace |