blob: b18d234d69ff4a8905179cd4abb7bde184c6ee16 [file] [log] [blame]
Sadik Armagan3c24f432020-10-19 17:35:30 +01001//
2// Copyright © 2020 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include <armnn_delegate.hpp>
Sadik Armagan62483be2020-10-23 17:14:43 +01007
Matthew Sloyanac001ee2021-02-03 10:43:04 +00008#include "Version.hpp"
9
Sadik Armagan62483be2020-10-23 17:14:43 +010010#include "Activation.hpp"
11#include "ArgMinMax.hpp"
12#include "BatchSpace.hpp"
13#include "Comparison.hpp"
14#include "Convolution.hpp"
15#include "Control.hpp"
16#include "ElementwiseBinary.hpp"
17#include "ElementwiseUnary.hpp"
18#include "Fill.hpp"
19#include "FullyConnected.hpp"
20#include "Gather.hpp"
Matthew Sloyanc8eb9552020-11-26 10:54:22 +000021#include "LogicalBinary.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010022#include "Lstm.hpp"
23#include "Normalization.hpp"
Matthew Sloyana7a12f52021-05-06 10:05:28 +010024#include "Pack.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010025#include "Pad.hpp"
26#include "Pooling.hpp"
James Conroy39825482021-05-27 17:44:50 +010027#include "Prelu.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010028#include "Quantization.hpp"
29#include "Redefine.hpp"
Sadik Armagana2747482021-02-09 10:28:54 +000030#include "Reduce.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010031#include "Resize.hpp"
32#include "Round.hpp"
Keith Davis0176fd82021-06-01 17:36:32 +010033#include "Shape.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010034#include "Slice.hpp"
35#include "Softmax.hpp"
36#include "SpaceDepth.hpp"
Sadik Armagan34fa1bd2020-11-27 12:40:52 +000037#include "Split.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010038#include "Transpose.hpp"
Narumol Prangnawarat7684b182021-08-12 14:48:15 +010039#include "UnidirectionalSequenceLstm.hpp"
Kevin May8ab2d7a2021-05-07 09:32:51 +010040#include "Unpack.hpp"
Sadik Armagan62483be2020-10-23 17:14:43 +010041
Colm Donelan3e32a872021-10-04 22:55:37 +010042#include <armnnUtils/Filesystem.hpp>
Jan Eilers17d34da2021-12-08 16:15:12 +000043#include <armnn/utility/Timer.hpp>
Sadik Armagan62483be2020-10-23 17:14:43 +010044#include <flatbuffers/flatbuffers.h>
45#include <tensorflow/lite/context_util.h>
Jim Flynn4b2f3472021-10-13 21:20:07 +010046#include <tensorflow/lite/schema/schema_generated.h>
Sadik Armagan62483be2020-10-23 17:14:43 +010047
Sadik Armagan3c24f432020-10-19 17:35:30 +010048#include <algorithm>
Matthew Sloyanac001ee2021-02-03 10:43:04 +000049#include <iostream>
Sadik Armagan62483be2020-10-23 17:14:43 +010050#include <sstream>
Sadik Armagan3c24f432020-10-19 17:35:30 +010051
52namespace armnnDelegate
53{
54
Sadik Armagan62483be2020-10-23 17:14:43 +010055DelegateOptions TfLiteArmnnDelegateOptionsDefault()
56{
57 DelegateOptions options(armnn::Compute::CpuRef);
58 return options;
59}
60
61TfLiteDelegate* TfLiteArmnnDelegateCreate(armnnDelegate::DelegateOptions options)
62{
63 auto* armnnDelegate = new ::armnnDelegate::Delegate(options);
64 return armnnDelegate->GetDelegate();
65}
66
67void TfLiteArmnnDelegateDelete(TfLiteDelegate* tfLiteDelegate)
68{
69 if (tfLiteDelegate != nullptr)
70 {
71 delete static_cast<::armnnDelegate::Delegate*>(tfLiteDelegate->data_);
72 }
73}
74
75TfLiteStatus DoPrepare(TfLiteContext* tfLiteContext, TfLiteDelegate* tfLiteDelegate)
76{
77 TfLiteIntArray* supportedOperators =
78 static_cast<::armnnDelegate::Delegate*>(tfLiteDelegate->data_)->IdentifyOperatorsToDelegate(tfLiteContext);
79
80 // ArmNN Delegate Registration
81 static const TfLiteRegistration kArmnnSubgraphRegistration = {
82 // ArmnnSubgraph Init
83 .init = [](TfLiteContext* tfLiteContext, const char* buffer, size_t length) -> void* {
Finn Williams6f9f9902020-11-13 13:23:15 +000084 armnn::IgnoreUnused(length);
Sadik Armagan62483be2020-10-23 17:14:43 +010085 const TfLiteDelegateParams* parameters = reinterpret_cast<const TfLiteDelegateParams*>(buffer);
86
87 return static_cast<void*>(ArmnnSubgraph::Create(
88 tfLiteContext, parameters, static_cast<::armnnDelegate::Delegate*>(parameters->delegate->data_)));
89 },
90 // ArmnnSubgraph Free
91 .free = [](TfLiteContext* tfLiteContext, void* buffer) -> void {
Finn Williams6f9f9902020-11-13 13:23:15 +000092 armnn::IgnoreUnused(tfLiteContext);
Sadik Armagan62483be2020-10-23 17:14:43 +010093 if (buffer != nullptr)
94 {
95 delete static_cast<ArmnnSubgraph*>(buffer);
96 }
97 },
98 // ArmnnSubgraph Prepare
99 .prepare = [](TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode) -> TfLiteStatus {
100 if (tfLiteNode->user_data == nullptr)
101 {
102 return kTfLiteError;
103 }
Sadik Armagan62483be2020-10-23 17:14:43 +0100104 return static_cast<ArmnnSubgraph*>(tfLiteNode->user_data)->Prepare(tfLiteContext);
105 },
106 // ArmnnSubgraph Invoke
107 .invoke = [](TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode) -> TfLiteStatus {
108 if (tfLiteNode->user_data == nullptr)
109 {
110 return kTfLiteError;
111 }
112
113 return static_cast<ArmnnSubgraph*>(tfLiteNode->user_data)->Invoke(tfLiteContext, tfLiteNode);
114 },
115
116 .profiling_string = nullptr,
117 .builtin_code = kTfLiteBuiltinDelegate,
118 .custom_name = "TfLiteArmNnDelegate",
119 .version = 1,
120 };
121
122 const TfLiteStatus status =
123 tfLiteContext->ReplaceNodeSubsetsWithDelegateKernels(
124 tfLiteContext, kArmnnSubgraphRegistration, supportedOperators, tfLiteDelegate);
125
126 TfLiteIntArrayFree(supportedOperators);
127 return status;
128
129}
130
Sadik Armagan3c24f432020-10-19 17:35:30 +0100131Delegate::Delegate(armnnDelegate::DelegateOptions options)
132 : m_Runtime(nullptr, nullptr),
133 m_Options(std::move(options))
134{
Jan Eilers2cd18472020-12-15 10:42:38 +0000135 // Configures logging for ARMNN
136 if (options.IsLoggingEnabled())
137 {
138 armnn::ConfigureLogging(true, true, options.GetLoggingSeverity());
139 }
140
Sadik Armagan3c24f432020-10-19 17:35:30 +0100141 // Create ArmNN Runtime
Jan Eilersb1c62f12021-10-26 14:56:47 +0100142 m_Runtime = armnn::IRuntime::Create(options.GetRuntimeOptions());
Sadik Armagan3c24f432020-10-19 17:35:30 +0100143
144 std::vector<armnn::BackendId> backends;
Sadik Armagan3c24f432020-10-19 17:35:30 +0100145 if (m_Runtime)
146 {
147 const armnn::BackendIdSet supportedDevices = m_Runtime->GetDeviceSpec().GetSupportedBackends();
148 for (auto& backend : m_Options.GetBackends())
149 {
150 if (std::find(supportedDevices.cbegin(), supportedDevices.cend(), backend) == supportedDevices.cend())
151 {
Sadik Armagan0534e032020-10-27 17:30:18 +0000152 TFLITE_LOG_PROD(tflite::TFLITE_LOG_INFO,
Sadik Armagan3c24f432020-10-19 17:35:30 +0100153 "TfLiteArmnnDelegate: Requested unknown backend %s", backend.Get().c_str());
154 }
155 else
156 {
157 backends.push_back(backend);
158 }
159 }
160 }
161
162 if (backends.empty())
163 {
164 // No known backend specified
165 throw armnn::InvalidArgumentException("TfLiteArmnnDelegate: No known backend specified.");
166 }
167 m_Options.SetBackends(backends);
168
169 TFLITE_LOG_PROD_ONCE(tflite::TFLITE_LOG_INFO, "TfLiteArmnnDelegate: Created TfLite ArmNN delegate.");
170}
171
Sadik Armagan62483be2020-10-23 17:14:43 +0100172TfLiteIntArray* Delegate::IdentifyOperatorsToDelegate(TfLiteContext* tfLiteContext)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100173{
174 TfLiteIntArray* executionPlan = nullptr;
175 if (tfLiteContext->GetExecutionPlan(tfLiteContext, &executionPlan) != kTfLiteOk)
176 {
177 TF_LITE_KERNEL_LOG(tfLiteContext, "TfLiteArmnnDelegate: Unable to get graph execution plan.");
178 return nullptr;
179 }
180
Sadik Armagan62483be2020-10-23 17:14:43 +0100181 // Delegate data with null network
182 DelegateData delegateData(m_Options.GetBackends());
Sadik Armagan3c24f432020-10-19 17:35:30 +0100183
184 TfLiteIntArray* nodesToDelegate = TfLiteIntArrayCreate(executionPlan->size);
185 nodesToDelegate->size = 0;
186 for (int i = 0; i < executionPlan->size; ++i)
187 {
188 const int nodeIndex = executionPlan->data[i];
189
190 // If TfLite nodes can be delegated to ArmNN
191 TfLiteNode* tfLiteNode = nullptr;
192 TfLiteRegistration* tfLiteRegistration = nullptr;
193 if (tfLiteContext->GetNodeAndRegistration(
194 tfLiteContext, nodeIndex, &tfLiteNode, &tfLiteRegistration) != kTfLiteOk)
195 {
196 TF_LITE_KERNEL_LOG(tfLiteContext,
197 "TfLiteArmnnDelegate: Unable to get node and registration for node %d.",
198 nodeIndex);
199 continue;
200 }
201
202 if (ArmnnSubgraph::VisitNode(
Sadik Armagan62483be2020-10-23 17:14:43 +0100203 delegateData, tfLiteContext, tfLiteRegistration, tfLiteNode, nodeIndex) != kTfLiteOk)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100204 {
205 // node is not supported by ArmNN
206 continue;
207 }
208
209 nodesToDelegate->data[nodesToDelegate->size++] = nodeIndex;
210 }
211
Sadik Armagan62483be2020-10-23 17:14:43 +0100212 std::sort(&nodesToDelegate->data[0], &nodesToDelegate->data[nodesToDelegate->size]);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100213 return nodesToDelegate;
214}
215
216TfLiteDelegate* Delegate::GetDelegate()
217{
218 return &m_Delegate;
219}
220
Matthew Sloyanac001ee2021-02-03 10:43:04 +0000221const std::string Delegate::GetVersion()
222{
223 return DELEGATE_VERSION;
224}
225
Sadik Armagan62483be2020-10-23 17:14:43 +0100226TfLiteStatus ArmnnSubgraph::AddInputLayer(DelegateData& delegateData,
227 TfLiteContext* tfLiteContext,
228 const TfLiteIntArray* inputs,
229 std::vector<armnn::BindingPointInfo>& inputBindings)
230{
Finn Williams6f9f9902020-11-13 13:23:15 +0000231 const size_t numInputs = static_cast<size_t>(inputs->size);
Sadik Armagan62483be2020-10-23 17:14:43 +0100232 for (unsigned int i = 0; i < numInputs; ++i)
233 {
234 const int32_t tensorId = inputs->data[i];
235 const TfLiteTensor tensor = tfLiteContext->tensors[tensorId];
Sadik Armagan6e36a642020-11-10 21:18:41 +0000236 // Do not create bindings for constant inputs
237 if (tensor.allocation_type == kTfLiteMmapRo)
238 {
239 continue;
240 }
Sadik Armagan62483be2020-10-23 17:14:43 +0100241
242 auto bindingId = static_cast<armnn::LayerBindingId>((tensorId));
243 armnn::IConnectableLayer* layer = delegateData.m_Network->AddInputLayer(bindingId);
244
245 auto tensorInfo = GetTensorInfoForTfLiteTensor(tensor);
246 armnn::IOutputSlot& outputSlot = layer->GetOutputSlot(0);
247 outputSlot.SetTensorInfo(tensorInfo);
248
249 // Store for creating connections
Finn Williams6f9f9902020-11-13 13:23:15 +0000250 delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)] = &outputSlot;
Sadik Armagan62483be2020-10-23 17:14:43 +0100251
Sadik Armagan6e36a642020-11-10 21:18:41 +0000252 inputBindings.push_back(std::make_pair(bindingId, tensorInfo));
Sadik Armagan62483be2020-10-23 17:14:43 +0100253 }
Sadik Armagan6e36a642020-11-10 21:18:41 +0000254
Sadik Armagan62483be2020-10-23 17:14:43 +0100255 return kTfLiteOk;
256}
257
258TfLiteStatus ArmnnSubgraph::AddOutputLayer(DelegateData& delegateData,
259 TfLiteContext* tfLiteContext,
260 const TfLiteIntArray* outputs,
261 std::vector<armnn::BindingPointInfo>& outputBindings)
262{
Finn Williams6f9f9902020-11-13 13:23:15 +0000263 const size_t numOutputs = static_cast<size_t>(outputs->size);
Sadik Armagan62483be2020-10-23 17:14:43 +0100264 for (unsigned int i = 0; i < numOutputs; ++i)
265 {
266 const int32_t tensorId = outputs->data[i];
267 const TfLiteTensor tensor = tfLiteContext->tensors[tensorId];
268
269 auto bindingId = static_cast<armnn::LayerBindingId>((tensorId));
270 armnn::IConnectableLayer* layer = delegateData.m_Network->AddOutputLayer(bindingId);
271
272 auto tensorInfo = GetTensorInfoForTfLiteTensor(tensor);
Finn Williams6f9f9902020-11-13 13:23:15 +0000273 ARMNN_ASSERT(delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)] != nullptr);
274 delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)]->Connect(layer->GetInputSlot(0));
Sadik Armagan62483be2020-10-23 17:14:43 +0100275 outputBindings.push_back(std::make_pair(bindingId, tensorInfo));
276 }
277
278 return kTfLiteOk;
279}
280
Sadik Armagan3c24f432020-10-19 17:35:30 +0100281ArmnnSubgraph* ArmnnSubgraph::Create(TfLiteContext* tfLiteContext,
282 const TfLiteDelegateParams* parameters,
283 const Delegate* delegate)
284{
Jan Eilers17d34da2021-12-08 16:15:12 +0000285 const auto startTime = armnn::GetTimeNow();
286 ARMNN_LOG(info) << "ArmnnSubgraph creation";
287
Sadik Armagan3c24f432020-10-19 17:35:30 +0100288 TfLiteIntArray* executionPlan;
289 if (tfLiteContext->GetExecutionPlan(tfLiteContext, &executionPlan) != kTfLiteOk)
290 {
291 return nullptr;
292 }
293
Sadik Armagan62483be2020-10-23 17:14:43 +0100294 // Initialize DelegateData holds network and output slots information
295 DelegateData delegateData(delegate->m_Options.GetBackends());
296
297 // Build ArmNN Network
Sadik Armagan3c24f432020-10-19 17:35:30 +0100298 armnn::NetworkOptions networkOptions = {};
299 armnn::NetworkId networkId;
Sadik Armagan62483be2020-10-23 17:14:43 +0100300 delegateData.m_Network = armnn::INetwork::Create(networkOptions);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100301
Sadik Armagan6e36a642020-11-10 21:18:41 +0000302 delegateData.m_OutputSlotForNode = std::vector<armnn::IOutputSlot*>(tfLiteContext->tensors_size, nullptr);
303
Sadik Armagan62483be2020-10-23 17:14:43 +0100304 std::vector<armnn::BindingPointInfo> inputBindings;
305 std::vector<armnn::BindingPointInfo> outputBindings;
306
307 // Add input layer
308 auto status = AddInputLayer(delegateData, tfLiteContext, parameters->input_tensors, inputBindings);
309 if (status != kTfLiteOk)
310 {
311 throw armnn::Exception("TfLiteArmnnDelegate: Unable to add Inputs to the network!");
312 }
313
314 // Parse TfLite delegate nodes to ArmNN
Jan Eilers17d34da2021-12-08 16:15:12 +0000315 const auto parseStartTime = armnn::GetTimeNow();
Sadik Armagan3c24f432020-10-19 17:35:30 +0100316 for (int i = 0; i < parameters->nodes_to_replace->size; ++i)
317 {
318 const int nodeIndex = parameters->nodes_to_replace->data[i];
319
320 TfLiteNode* tfLiteNode = nullptr;
321 TfLiteRegistration* tfLiteRegistration = nullptr;
322 if (tfLiteContext->GetNodeAndRegistration(
323 tfLiteContext, nodeIndex, &tfLiteNode, &tfLiteRegistration) != kTfLiteOk)
324 {
Finn Williams6f9f9902020-11-13 13:23:15 +0000325 throw armnn::Exception(&"TfLiteArmnnDelegate: Unable to get node registration: " [ nodeIndex]);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100326 }
327
Sadik Armagan62483be2020-10-23 17:14:43 +0100328 if (VisitNode(delegateData, tfLiteContext, tfLiteRegistration, tfLiteNode, nodeIndex) != kTfLiteOk)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100329 {
Finn Williams6f9f9902020-11-13 13:23:15 +0000330 throw armnn::Exception(&"TfLiteArmnnDelegate: Unable to parse node: " [ nodeIndex]);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100331 }
332 }
Jan Eilers17d34da2021-12-08 16:15:12 +0000333 ARMNN_LOG(info) << "Parse nodes to ArmNN time: " << std::setprecision(2)
334 << std::fixed << armnn::GetTimeDuration(parseStartTime).count() << " ms";
Sadik Armagan3c24f432020-10-19 17:35:30 +0100335
Sadik Armagan62483be2020-10-23 17:14:43 +0100336 // Add Output layer
337 status = AddOutputLayer(delegateData, tfLiteContext, parameters->output_tensors, outputBindings);
338 if (status != kTfLiteOk)
339 {
340 throw armnn::Exception("TfLiteArmnnDelegate: Unable to add Outputs to the network!");
341 }
342
343 // Optimize ArmNN network
344 armnn::IOptimizedNetworkPtr optNet(nullptr, nullptr);
345 try
346 {
Jan Eilers17d34da2021-12-08 16:15:12 +0000347 const auto optimizeStartTime = armnn::GetTimeNow();
Sadik Armagan6e36a642020-11-10 21:18:41 +0000348 optNet = armnn::Optimize(*(delegateData.m_Network.get()),
Sadik Armagan62483be2020-10-23 17:14:43 +0100349 delegate->m_Options.GetBackends(),
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000350 delegate->m_Runtime->GetDeviceSpec(),
351 delegate->m_Options.GetOptimizerOptions());
Jan Eilers17d34da2021-12-08 16:15:12 +0000352 ARMNN_LOG(info) << "Optimize ArmnnSubgraph time: " << std::setprecision(2)
353 << std::fixed << armnn::GetTimeDuration(optimizeStartTime).count() << " ms";
Sadik Armagan62483be2020-10-23 17:14:43 +0100354 }
355 catch (std::exception &ex)
356 {
357 std::stringstream exMessage;
358 exMessage << "TfLiteArmnnDelegate: Exception (" << ex.what() << ") caught from optimize.";
359 throw armnn::Exception(exMessage.str());
360 }
Sadik Armagan3c24f432020-10-19 17:35:30 +0100361 if (!optNet)
362 {
Sadik Armagan62483be2020-10-23 17:14:43 +0100363 // Optimize failed
Sadik Armagan3c24f432020-10-19 17:35:30 +0100364 throw armnn::Exception("TfLiteArmnnDelegate: Unable to optimize the network!");
365 }
Sadik Armagan62483be2020-10-23 17:14:43 +0100366
Colm Donelan3e32a872021-10-04 22:55:37 +0100367 // If set, we will serialize the optimized model into a dot file.
368 const std::string serializeToDotFile = delegate->m_Options.GetSerializeToDot();
369 if (!serializeToDotFile.empty())
370 {
Jan Eilers17d34da2021-12-08 16:15:12 +0000371 ARMNN_LOG(info) << "Writing graph to dot file: " << serializeToDotFile;
Colm Donelan3e32a872021-10-04 22:55:37 +0100372 fs::path filename = serializeToDotFile;
373 std::fstream file(filename.c_str(), std::ios_base::out);
374 optNet->SerializeToDot(file);
375 }
376
Sadik Armagan62483be2020-10-23 17:14:43 +0100377 try
378 {
Jan Eilers17d34da2021-12-08 16:15:12 +0000379 const auto loadStartTime = armnn::GetTimeNow();
380
Sadik Armagan62483be2020-10-23 17:14:43 +0100381 // Load graph into runtime
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000382 std::string errorMessage;
Narumol Prangnawarat74a3cf52021-01-29 15:38:54 +0000383 armnn::Status loadingStatus;
Colm Donelan3e32a872021-10-04 22:55:37 +0100384 armnn::MemorySource memorySource = armnn::MemorySource::Undefined;
Narumol Prangnawarat74a3cf52021-01-29 15:38:54 +0000385 if (delegate->m_Options.GetOptimizerOptions().m_ImportEnabled)
386 {
Colm Donelan3e32a872021-10-04 22:55:37 +0100387 memorySource = armnn::MemorySource::Malloc;
Narumol Prangnawarat74a3cf52021-01-29 15:38:54 +0000388 }
Colm Donelan3e32a872021-10-04 22:55:37 +0100389 armnn::INetworkProperties networkProperties(false,
390 memorySource,
391 memorySource,
392 delegate->m_Options.GetInternalProfilingState(),
393 delegate->m_Options.GetInternalProfilingDetail());
394 loadingStatus = delegate->m_Runtime->LoadNetwork(networkId,
395 std::move(optNet),
396 errorMessage,
397 networkProperties);
Sadik Armagan62483be2020-10-23 17:14:43 +0100398 if (loadingStatus != armnn::Status::Success)
399 {
Colm Donelan45142282021-10-21 23:39:52 +0100400 // Network load failed.
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000401 throw armnn::Exception("TfLiteArmnnDelegate: Network could not be loaded:" + errorMessage);
Sadik Armagan62483be2020-10-23 17:14:43 +0100402 }
Jan Eilers17d34da2021-12-08 16:15:12 +0000403
404 ARMNN_LOG(info) << "Load ArmnnSubgraph time: " << std::setprecision(2)
405 << std::fixed << armnn::GetTimeDuration(loadStartTime).count() << " ms";
Sadik Armagan62483be2020-10-23 17:14:43 +0100406 }
407 catch (std::exception& ex)
408 {
409 std::stringstream exMessage;
410 exMessage << "TfLiteArmnnDelegate: Exception (" << ex.what() << ") caught from LoadNetwork.";
411 throw armnn::Exception(exMessage.str());
412 }
Sadik Armagan3c24f432020-10-19 17:35:30 +0100413
Narumol Prangnawarat0b51d5a2021-01-20 15:58:29 +0000414 // Register debug callback function
415 if (delegate->m_Options.GetDebugCallbackFunction().has_value())
416 {
417 delegate->m_Runtime->RegisterDebugCallback(networkId, delegate->m_Options.GetDebugCallbackFunction().value());
418 }
419
Jan Eilers17d34da2021-12-08 16:15:12 +0000420 ARMNN_LOG(info) << "Overall ArmnnSubgraph creation time: " << std::setprecision(2)
421 << std::fixed << armnn::GetTimeDuration(startTime).count() << " ms\n";
422
Sadik Armagan3c24f432020-10-19 17:35:30 +0100423 // Create a new SubGraph with networkId and runtime
Sadik Armagan62483be2020-10-23 17:14:43 +0100424 return new ArmnnSubgraph(networkId, delegate->m_Runtime.get(), inputBindings, outputBindings);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100425}
426
427TfLiteStatus ArmnnSubgraph::Prepare(TfLiteContext* tfLiteContext)
428{
Finn Williams6f9f9902020-11-13 13:23:15 +0000429 armnn::IgnoreUnused(tfLiteContext);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100430 return kTfLiteOk;
431}
432
Sadik Armagan62483be2020-10-23 17:14:43 +0100433TfLiteStatus ArmnnSubgraph::Invoke(TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode)
Sadik Armagan3c24f432020-10-19 17:35:30 +0100434{
Sadik Armagan62483be2020-10-23 17:14:43 +0100435 // Prepare inputs
436 armnn::InputTensors inputTensors;
437 size_t inputIndex = 0;
438 for (auto inputIdx : tflite::TfLiteIntArrayView(tfLiteNode->inputs))
439 {
440 TfLiteTensor* tensor = &tfLiteContext->tensors[inputIdx];
441 if (tensor->allocation_type != kTfLiteMmapRo)
442 {
443 const armnn::BindingPointInfo& inputBinding = m_InputBindings[inputIndex];
Cathal Corbett5b8093c2021-10-22 11:12:07 +0100444 armnn::TensorInfo inputTensorInfo = inputBinding.second;
445 inputTensorInfo.SetConstant(true);
446 const armnn::ConstTensor inputTensor(inputTensorInfo, tensor->data.data);
Sadik Armagan62483be2020-10-23 17:14:43 +0100447 inputTensors.emplace_back(inputIdx, inputTensor);
Sadik Armagan3c24f432020-10-19 17:35:30 +0100448
Sadik Armagan62483be2020-10-23 17:14:43 +0100449 ++inputIndex;
450 }
451 }
452
453 // Prepare outputs
454 armnn::OutputTensors outputTensors;
455 size_t outputIndex = 0;
456 for (auto outputIdx : tflite::TfLiteIntArrayView(tfLiteNode->outputs))
457 {
458 const armnn::BindingPointInfo& outputBinding = m_OutputBindings[outputIndex];
459 TfLiteTensor* tensor = &tfLiteContext->tensors[outputIdx];
460 const armnn::Tensor outputTensor(outputBinding.second, tensor->data.data);
461 outputTensors.emplace_back(outputIdx, outputTensor);
462
463 ++outputIndex;
464 }
465
466 // Run graph
467 auto status = m_Runtime->EnqueueWorkload(m_NetworkId, inputTensors, outputTensors);
Colm Donelan45142282021-10-21 23:39:52 +0100468 // The delegate holds its own Arm NN runtime so this is our last chance to print internal profiling data.
469 std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkId);
470 if (profiler && profiler->IsProfilingEnabled())
471 {
472 profiler->Print(std::cout);
473 }
Sadik Armagan62483be2020-10-23 17:14:43 +0100474 return (status == armnn::Status::Success) ? kTfLiteOk : kTfLiteError;
Sadik Armagan3c24f432020-10-19 17:35:30 +0100475}
476
Sadik Armagan62483be2020-10-23 17:14:43 +0100477TfLiteStatus ArmnnSubgraph::VisitNode(DelegateData& delegateData,
Sadik Armagan3c24f432020-10-19 17:35:30 +0100478 TfLiteContext* tfLiteContext,
479 TfLiteRegistration* tfLiteRegistration,
480 TfLiteNode* tfLiteNode,
481 int nodeIndex)
482{
Sadik Armagan62483be2020-10-23 17:14:43 +0100483 switch (tfLiteRegistration->builtin_code)
484 {
485 case kTfLiteBuiltinAbs:
486 return VisitElementwiseUnaryOperator(delegateData,
487 tfLiteContext,
488 tfLiteNode,
489 nodeIndex,
490 armnn::UnaryOperation::Abs);
491 case kTfLiteBuiltinAdd:
492 return VisitElementwiseBinaryOperator(delegateData,
493 tfLiteContext,
494 tfLiteNode,
495 nodeIndex,
496 kTfLiteBuiltinAdd);
497 case kTfLiteBuiltinArgMax:
498 return VisitArgMinMaxOperator(delegateData,
499 tfLiteContext,
500 tfLiteNode,
501 nodeIndex,
502 kTfLiteBuiltinArgMax);
503 case kTfLiteBuiltinArgMin:
504 return VisitArgMinMaxOperator(delegateData,
505 tfLiteContext,
506 tfLiteNode,
507 nodeIndex,
508 kTfLiteBuiltinArgMin);
509 case kTfLiteBuiltinAveragePool2d:
510 return VisitPoolingOperator(delegateData,
511 tfLiteContext,
512 tfLiteNode,
513 nodeIndex,
514 kTfLiteBuiltinAveragePool2d);
515 case kTfLiteBuiltinBatchToSpaceNd:
516 return VisitBatchToSpaceNdOperator(delegateData,
517 tfLiteContext,
518 tfLiteNode,
519 nodeIndex,
520 kTfLiteBuiltinBatchToSpaceNd);
Sadik Armagan937565b2021-04-21 14:03:28 +0100521 case kTfLiteBuiltinCast:
522 return VisitCastOperator(delegateData,
523 tfLiteContext,
524 tfLiteNode,
525 nodeIndex,
526 kTfLiteBuiltinCast);
Sadik Armagan62483be2020-10-23 17:14:43 +0100527 case kTfLiteBuiltinConcatenation:
528 return VisitControlOperator(delegateData,
529 tfLiteContext,
530 tfLiteNode,
531 nodeIndex,
532 kTfLiteBuiltinConcatenation);
533 case kTfLiteBuiltinConv2d:
534 return VisitConvolutionOperator(delegateData,
535 tfLiteContext,
536 tfLiteNode,
537 nodeIndex,
538 kTfLiteBuiltinConv2d);
Matthew Sloyan81ec9942021-10-12 10:26:30 +0100539// Conv3d is only correctly supported for external delegates from TF Lite v2.6, as there was a breaking bug in v2.5.
540#if defined(ARMNN_POST_TFLITE_2_5)
541 case kTfLiteBuiltinConv3d:
542 return VisitConvolutionOperator(delegateData,
543 tfLiteContext,
544 tfLiteNode,
545 nodeIndex,
546 kTfLiteBuiltinConv3d);
547#endif
Sadik Armagan62483be2020-10-23 17:14:43 +0100548 case kTfLiteBuiltinDepthToSpace:
549 return VisitDepthToSpaceOperator(delegateData,
550 tfLiteContext,
551 tfLiteNode,
552 nodeIndex,
553 kTfLiteBuiltinDepthToSpace);
554 case kTfLiteBuiltinDepthwiseConv2d:
555 return VisitConvolutionOperator(delegateData,
556 tfLiteContext,
557 tfLiteNode,
558 nodeIndex,
559 kTfLiteBuiltinDepthwiseConv2d);
560 case kTfLiteBuiltinDequantize:
561 return VisitDequantizeOperator(delegateData,
562 tfLiteContext,
563 tfLiteNode,
564 nodeIndex,
565 kTfLiteBuiltinDequantize);
566 case kTfLiteBuiltinDiv:
567 return VisitElementwiseBinaryOperator(delegateData,
568 tfLiteContext,
569 tfLiteNode,
570 nodeIndex,
571 kTfLiteBuiltinDiv);
572 case kTfLiteBuiltinElu:
573 return VisitActivationOperator(delegateData,
574 tfLiteContext,
575 tfLiteNode,
576 nodeIndex,
577 kTfLiteBuiltinElu);
578 case kTfLiteBuiltinEqual:
579 return VisitComparisonOperator(delegateData,
580 tfLiteContext,
581 tfLiteNode,
582 nodeIndex,
583 kTfLiteBuiltinEqual);
584 case kTfLiteBuiltinExp:
585 return VisitElementwiseUnaryOperator(delegateData,
586 tfLiteContext,
587 tfLiteNode,
588 nodeIndex,
589 armnn::UnaryOperation::Exp);
590 case kTfLiteBuiltinExpandDims:
591 return VisitExpandDimsOperator(delegateData,
592 tfLiteContext,
593 tfLiteNode,
594 nodeIndex,
595 kTfLiteBuiltinExpandDims);
596 case kTfLiteBuiltinFill:
597 return VisitFillOperator(delegateData,
598 tfLiteContext,
599 tfLiteNode,
600 nodeIndex,
601 kTfLiteBuiltinFill);
602 case kTfLiteBuiltinFloor:
603 return VisitFloorOperator(delegateData,
604 tfLiteContext,
605 tfLiteNode,
606 nodeIndex,
607 kTfLiteBuiltinFloor);
Jim Flynn4b2f3472021-10-13 21:20:07 +0100608 case kTfLiteBuiltinFloorDiv:
609 return VisitElementwiseBinaryOperator(delegateData,
610 tfLiteContext,
611 tfLiteNode,
612 nodeIndex,
613 kTfLiteBuiltinFloorDiv);
Sadik Armagan62483be2020-10-23 17:14:43 +0100614 case kTfLiteBuiltinFullyConnected:
615 return VisitFullyConnectedOperator(delegateData,
616 tfLiteContext,
617 tfLiteNode,
618 nodeIndex,
619 kTfLiteBuiltinFullyConnected);
620 case kTfLiteBuiltinGather:
621 return VisitGatherOperator(delegateData,
622 tfLiteContext,
623 tfLiteNode,
624 nodeIndex,
625 kTfLiteBuiltinGather);
626 case kTfLiteBuiltinGatherNd:
627 return VisitGatherOperator(delegateData,
628 tfLiteContext,
629 tfLiteNode,
630 nodeIndex,
631 kTfLiteBuiltinGatherNd);
632 case kTfLiteBuiltinGreater:
633 return VisitComparisonOperator(delegateData,
634 tfLiteContext,
635 tfLiteNode,
636 nodeIndex,
637 kTfLiteBuiltinGreater);
638 case kTfLiteBuiltinGreaterEqual:
639 return VisitComparisonOperator(delegateData,
640 tfLiteContext,
641 tfLiteNode,
642 nodeIndex,
643 kTfLiteBuiltinGreaterEqual);
644 case kTfLiteBuiltinHardSwish:
645 return VisitActivationOperator(delegateData,
646 tfLiteContext,
647 tfLiteNode,
648 nodeIndex,
649 kTfLiteBuiltinHardSwish);
650 case kTfLiteBuiltinL2Normalization:
Sadik Armagan4b227bb2021-01-22 10:53:38 +0000651 return VisitL2NormalizationOperator(delegateData,
652 tfLiteContext,
653 tfLiteNode,
654 nodeIndex,
655 kTfLiteBuiltinL2Normalization);
Sadik Armagan62483be2020-10-23 17:14:43 +0100656 case kTfLiteBuiltinL2Pool2d:
657 return VisitPoolingOperator(delegateData,
658 tfLiteContext,
659 tfLiteNode,
660 nodeIndex,
661 kTfLiteBuiltinL2Pool2d);
662 case kTfLiteBuiltinLess:
663 return VisitComparisonOperator(delegateData,
664 tfLiteContext,
665 tfLiteNode,
666 nodeIndex,
667 kTfLiteBuiltinLess);
668 case kTfLiteBuiltinLessEqual:
669 return VisitComparisonOperator(delegateData,
670 tfLiteContext,
671 tfLiteNode,
672 nodeIndex,
673 kTfLiteBuiltinLessEqual);
674 case kTfLiteBuiltinLocalResponseNormalization:
Sadik Armagan4b227bb2021-01-22 10:53:38 +0000675 return VisitLocalResponseNormalizationOperator(delegateData,
676 tfLiteContext,
677 tfLiteNode,
678 nodeIndex,
679 kTfLiteBuiltinLocalResponseNormalization);
Matthew Sloyanc8eb9552020-11-26 10:54:22 +0000680 case kTfLiteBuiltinLogicalAnd:
681 return VisitLogicalBinaryOperator(delegateData,
682 tfLiteContext,
683 tfLiteNode,
684 nodeIndex,
685 kTfLiteBuiltinLogicalAnd,
686 armnn::LogicalBinaryOperation::LogicalAnd);
687 case kTfLiteBuiltinLogicalNot:
688 return VisitElementwiseUnaryOperator(delegateData,
689 tfLiteContext,
690 tfLiteNode,
691 nodeIndex,
692 armnn::UnaryOperation::LogicalNot);
693 case kTfLiteBuiltinLogicalOr:
694 return VisitLogicalBinaryOperator(delegateData,
695 tfLiteContext,
696 tfLiteNode,
697 nodeIndex,
698 kTfLiteBuiltinLogicalOr,
699 armnn::LogicalBinaryOperation::LogicalOr);
Sadik Armagan62483be2020-10-23 17:14:43 +0100700 case kTfLiteBuiltinLogistic:
701 return VisitActivationOperator(delegateData,
702 tfLiteContext,
703 tfLiteNode,
704 nodeIndex,
705 kTfLiteBuiltinLogistic);
706 case kTfLiteBuiltinLogSoftmax:
707 return VisitSoftmaxOperator(delegateData,
708 tfLiteContext,
709 tfLiteNode,
710 nodeIndex,
711 kTfLiteBuiltinLogSoftmax);
712 case kTfLiteBuiltinLstm:
713 return VisitLstmOperator(delegateData,
714 tfLiteContext,
715 tfLiteNode,
716 nodeIndex,
717 kTfLiteBuiltinLstm);
718 case kTfLiteBuiltinMaxPool2d:
719 return VisitPoolingOperator(delegateData,
720 tfLiteContext,
721 tfLiteNode,
722 nodeIndex,
723 kTfLiteBuiltinMaxPool2d);
724 case kTfLiteBuiltinMaximum:
725 return VisitElementwiseBinaryOperator(delegateData,
726 tfLiteContext,
727 tfLiteNode,
728 nodeIndex,
729 kTfLiteBuiltinMaximum);
730 case kTfLiteBuiltinMean:
731 return VisitControlOperator(delegateData,
732 tfLiteContext,
733 tfLiteNode,
734 nodeIndex,
735 kTfLiteBuiltinMean);
736 case kTfLiteBuiltinMinimum:
737 return VisitElementwiseBinaryOperator(delegateData,
738 tfLiteContext,
739 tfLiteNode,
740 nodeIndex,
741 kTfLiteBuiltinMinimum);
Matthew Sloyanaf3a4ef2021-10-22 15:48:12 +0100742 case kTfLiteBuiltinMirrorPad:
743 return VisitPadOperator(delegateData,
744 tfLiteContext,
745 tfLiteNode,
746 nodeIndex,
747 kTfLiteBuiltinMirrorPad);
Sadik Armagan62483be2020-10-23 17:14:43 +0100748 case kTfLiteBuiltinMul:
749 return VisitElementwiseBinaryOperator(delegateData,
750 tfLiteContext,
751 tfLiteNode,
752 nodeIndex,
753 kTfLiteBuiltinMul);
754 case kTfLiteBuiltinNeg:
755 return VisitElementwiseUnaryOperator(delegateData,
756 tfLiteContext,
757 tfLiteNode,
758 nodeIndex,
759 armnn::UnaryOperation::Neg);
760 case kTfLiteBuiltinNotEqual:
761 return VisitComparisonOperator(delegateData,
762 tfLiteContext,
763 tfLiteNode,
764 nodeIndex,
765 kTfLiteBuiltinNotEqual);
Matthew Sloyana7a12f52021-05-06 10:05:28 +0100766 case kTfLiteBuiltinPack:
767 return VisitPackOperator(delegateData,
768 tfLiteContext,
769 tfLiteNode,
770 nodeIndex,
771 kTfLiteBuiltinPack);
Sadik Armagan62483be2020-10-23 17:14:43 +0100772 case kTfLiteBuiltinPad:
773 return VisitPadOperator(delegateData,
774 tfLiteContext,
775 tfLiteNode,
776 nodeIndex,
777 kTfLiteBuiltinPad);
778 case kTfLiteBuiltinPadv2:
779 return VisitPadOperator(delegateData,
780 tfLiteContext,
781 tfLiteNode,
782 nodeIndex,
783 kTfLiteBuiltinPadv2);
784 case kTfLiteBuiltinPrelu:
James Conroy39825482021-05-27 17:44:50 +0100785 return VisitPreluOperator(delegateData,
786 tfLiteContext,
787 tfLiteNode,
788 nodeIndex,
789 kTfLiteBuiltinPrelu);
Sadik Armagan62483be2020-10-23 17:14:43 +0100790 case kTfLiteBuiltinQuantize:
791 return VisitQuantizeOperator(delegateData,
792 tfLiteContext,
793 tfLiteNode,
794 nodeIndex,
795 kTfLiteBuiltinQuantize);
796 case kTfLiteBuiltinRank:
797 return VisitControlOperator(delegateData,
798 tfLiteContext,
799 tfLiteNode,
800 nodeIndex,
801 kTfLiteBuiltinRank);
Sadik Armagana2747482021-02-09 10:28:54 +0000802 case kTfLiteBuiltinReduceMax:
803 return VisitReduceOperator(delegateData,
804 tfLiteContext,
805 tfLiteNode,
806 nodeIndex,
807 kTfLiteBuiltinReduceMax);
808 case kTfLiteBuiltinReduceMin:
809 return VisitReduceOperator(delegateData,
810 tfLiteContext,
811 tfLiteNode,
812 nodeIndex,
813 kTfLiteBuiltinReduceMin);
Teresa Charlin4e3e8312021-08-05 12:34:37 +0100814 case kTfLiteBuiltinReduceProd:
815 return VisitReduceOperator(delegateData,
816 tfLiteContext,
817 tfLiteNode,
818 nodeIndex,
819 kTfLiteBuiltinReduceProd);
Sadik Armagan62483be2020-10-23 17:14:43 +0100820 case kTfLiteBuiltinRelu:
821 return VisitActivationOperator(delegateData,
822 tfLiteContext,
823 tfLiteNode,
824 nodeIndex,
825 kTfLiteBuiltinRelu);
826 case kTfLiteBuiltinReluN1To1:
827 return VisitActivationOperator(delegateData,
828 tfLiteContext,
829 tfLiteNode,
830 nodeIndex,
831 kTfLiteBuiltinReluN1To1);
832 case kTfLiteBuiltinRelu6:
833 return VisitActivationOperator(delegateData,
834 tfLiteContext,
835 tfLiteNode,
836 nodeIndex,
837 kTfLiteBuiltinRelu6);
838 case kTfLiteBuiltinReshape:
839 return VisitReshapeOperator(delegateData,
840 tfLiteContext,
841 tfLiteNode,
842 nodeIndex,
843 kTfLiteBuiltinReshape);
844 case kTfLiteBuiltinResizeBilinear:
845 return VisitResizeOperator(delegateData,
846 tfLiteContext,
847 tfLiteNode,
848 nodeIndex,
849 kTfLiteBuiltinResizeBilinear);
850 case kTfLiteBuiltinResizeNearestNeighbor:
851 return VisitResizeOperator(delegateData,
852 tfLiteContext,
853 tfLiteNode,
854 nodeIndex,
855 kTfLiteBuiltinResizeNearestNeighbor);
856 case kTfLiteBuiltinRsqrt:
857 return VisitElementwiseUnaryOperator(delegateData,
858 tfLiteContext,
859 tfLiteNode,
860 nodeIndex,
861 armnn::UnaryOperation::Rsqrt);
Keith Davis0176fd82021-06-01 17:36:32 +0100862 case kTfLiteBuiltinShape:
863 return VisitShapeOperator(delegateData,
864 tfLiteContext,
865 tfLiteNode,
866 nodeIndex,
867 kTfLiteBuiltinShape);
Sadik Armagan34fa1bd2020-11-27 12:40:52 +0000868 case kTfLiteBuiltinSplit:
869 return VisitSplitOperator(delegateData,
870 tfLiteContext,
871 tfLiteNode,
872 nodeIndex,
873 kTfLiteBuiltinSplit);
874 case kTfLiteBuiltinSplitV:
875 return VisitSplitVOperator(delegateData,
876 tfLiteContext,
877 tfLiteNode,
878 nodeIndex,
879 kTfLiteBuiltinSplitV);
Sadik Armagan62483be2020-10-23 17:14:43 +0100880 case kTfLiteBuiltinSqrt:
881 return VisitElementwiseUnaryOperator(delegateData,
882 tfLiteContext,
883 tfLiteNode,
884 nodeIndex,
885 armnn::UnaryOperation::Sqrt);
886 case kTfLiteBuiltinSqueeze:
887 return VisitSqueezeOperator(delegateData,
888 tfLiteContext,
889 tfLiteNode,
890 nodeIndex,
891 kTfLiteBuiltinSqueeze);
892 case kTfLiteBuiltinStridedSlice:
893 return VisitSliceOperator(delegateData,
894 tfLiteContext,
895 tfLiteNode,
896 nodeIndex,
897 kTfLiteBuiltinStridedSlice);
Sadik Armagana2747482021-02-09 10:28:54 +0000898 case kTfLiteBuiltinSum:
899 return VisitReduceOperator(delegateData,
900 tfLiteContext,
901 tfLiteNode,
902 nodeIndex,
903 kTfLiteBuiltinSum);
Sadik Armagan62483be2020-10-23 17:14:43 +0100904 case kTfLiteBuiltinTranspose:
905 return VisitTransposeOperator(delegateData,
906 tfLiteContext,
907 tfLiteNode,
908 nodeIndex,
909 kTfLiteBuiltinTranspose);
910 case kTfLiteBuiltinTransposeConv:
911 return VisitConvolutionOperator(delegateData,
912 tfLiteContext,
913 tfLiteNode,
914 nodeIndex,
915 kTfLiteBuiltinTransposeConv);
916 case kTfLiteBuiltinSoftmax:
917 return VisitSoftmaxOperator(delegateData,
918 tfLiteContext,
919 tfLiteNode,
920 nodeIndex,
921 kTfLiteBuiltinSoftmax);
922 case kTfLiteBuiltinSpaceToBatchNd:
923 return VisitSpaceToBatchNdOperator(delegateData,
924 tfLiteContext,
925 tfLiteNode,
926 nodeIndex,
927 kTfLiteBuiltinSpaceToBatchNd);
928 case kTfLiteBuiltinSpaceToDepth:
929 return VisitSpaceToDepthOperator(delegateData,
930 tfLiteContext,
931 tfLiteNode,
932 nodeIndex,
933 kTfLiteBuiltinSpaceToDepth);
934 case kTfLiteBuiltinSub:
935 return VisitElementwiseBinaryOperator(delegateData,
936 tfLiteContext,
937 tfLiteNode,
938 nodeIndex,
939 kTfLiteBuiltinSub);
940 case kTfLiteBuiltinTanh:
941 return VisitActivationOperator(delegateData,
942 tfLiteContext,
943 tfLiteNode,
944 nodeIndex,
945 kTfLiteBuiltinTanh);
Narumol Prangnawarat7684b182021-08-12 14:48:15 +0100946 case kTfLiteBuiltinUnidirectionalSequenceLstm:
947 return VisitUnidirectionalSequenceLstmOperator(delegateData,
948 tfLiteContext,
949 tfLiteNode,
950 nodeIndex,
951 kTfLiteBuiltinUnidirectionalSequenceLstm);
Kevin May8ab2d7a2021-05-07 09:32:51 +0100952 case kTfLiteBuiltinUnpack:
953 return VisitUnpackOperator(delegateData,
954 tfLiteContext,
955 tfLiteNode,
956 nodeIndex,
957 kTfLiteBuiltinUnpack);
Sadik Armagan62483be2020-10-23 17:14:43 +0100958 default:
959 return kTfLiteError;
960 }
Sadik Armagan3c24f432020-10-19 17:35:30 +0100961}
962
963} // armnnDelegate namespace