blob: 0bd8d4b69bbf0f5261baa655872c5acb86d648df [file] [log] [blame]
telsoa014fcda012018-03-09 14:13:49 +00001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
David Beckecb56cd2018-09-05 12:52:57 +01003// SPDX-License-Identifier: MIT
telsoa014fcda012018-03-09 14:13:49 +00004//
Matteo Martincigh49124022019-01-11 13:25:59 +00005
telsoa014fcda012018-03-09 14:13:49 +00006#include "Network.hpp"
7#include "Graph.hpp"
8#include "Layer.hpp"
telsoa01c577f2c2018-08-31 09:22:23 +01009#include "DeviceSpec.hpp"
telsoa014fcda012018-03-09 14:13:49 +000010#include "Optimizer.hpp"
Matteo Martincigh49124022019-01-11 13:25:59 +000011#include "SubGraphSelector.hpp"
12#include "BackendSettings.hpp"
David Beckac42efd2018-09-26 17:41:13 +010013#include "optimizations/All.hpp"
telsoa014fcda012018-03-09 14:13:49 +000014
Aron Virginas-Tarc9cc8042018-11-01 16:15:57 +000015#include <backendsCommon/CpuTensorHandle.hpp>
16#include <backendsCommon/WorkloadFactory.hpp>
David Beck263e3492018-11-09 14:46:40 +000017#include <backendsCommon/BackendRegistry.hpp>
18#include <backendsCommon/IBackendInternal.hpp>
David Beckac42efd2018-09-26 17:41:13 +010019
20#include <armnn/Exceptions.hpp>
telsoa014fcda012018-03-09 14:13:49 +000021#include <armnn/Utils.hpp>
telsoa01c577f2c2018-08-31 09:22:23 +010022#include <armnn/TypesUtils.hpp>
telsoa014fcda012018-03-09 14:13:49 +000023
24#include <fcntl.h>
25#include <algorithm>
26#include <fstream>
27#include <memory>
telsoa01c577f2c2018-08-31 09:22:23 +010028#include <vector>
29#include <algorithm>
telsoa014fcda012018-03-09 14:13:49 +000030
31#include <boost/assert.hpp>
32#include <boost/format.hpp>
33#include <boost/log/trivial.hpp>
34#include <boost/numeric/conversion/converter_policies.hpp>
35#include <boost/cast.hpp>
36
37namespace armnn
38{
39
40armnn::INetwork* INetwork::CreateRaw()
41{
42 return new Network();
43}
44
45armnn::INetworkPtr INetwork::Create()
46{
47 return INetworkPtr(CreateRaw(), &INetwork::Destroy);
48}
49
50void INetwork::Destroy(INetwork* network)
51{
52 delete boost::polymorphic_downcast<Network*>(network);
53}
54
55Status Network::PrintGraph()
56{
57 m_Graph->Print();
58 return Status::Success;
59}
60
61void IOptimizedNetwork::Destroy(IOptimizedNetwork* network)
62{
63 delete boost::polymorphic_downcast<OptimizedNetwork*>(network);
64}
65
66Status OptimizedNetwork::PrintGraph()
67{
68 m_Graph->Print();
69 return Status::Success;
70}
71
surmeh01bceff2f2018-03-29 16:29:27 +010072Status OptimizedNetwork::SerializeToDot(std::ostream& stream) const
73{
74 return m_Graph->SerializeToDot(stream);
75}
76
Matteo Martincigh49124022019-01-11 13:25:59 +000077struct OptimizationResult
78{
79 bool m_Warning;
80 bool m_Error;
81
82 OptimizationResult()
83 : m_Warning(false)
84 , m_Error(false)
85 {}
86};
87
88void ReportError(const std::string& errorMessage,
89 Optional<std::vector<std::string>&> errorMessages)
90{
91 std::stringstream fullErrorMessage;
92 fullErrorMessage << "ERROR: " << errorMessage;
93 BOOST_LOG_TRIVIAL(warning) << fullErrorMessage.str();
94 if (errorMessages)
95 {
96 errorMessages.value().push_back(fullErrorMessage.str());
97 }
98}
99
100void ReportWarning(const std::string& warningMessage,
101 Optional<std::vector<std::string>&> warningMessages)
102{
103 std::stringstream fullWarningMessage;
104 fullWarningMessage << "WARNING: " << warningMessage;
105 BOOST_LOG_TRIVIAL(warning) << fullWarningMessage.str();
106 if (warningMessages)
107 {
108 warningMessages.value().push_back(fullWarningMessage.str());
109 }
110}
111
jimfly016b0b53d2018-10-08 14:43:01 +0100112bool CheckScaleSetOnQuantizedType(Layer* layer, Optional<std::vector<std::string>&> errMessages)
113{
114 bool noErrors = true;
115 unsigned int numOutputs = layer->GetNumOutputSlots();
116 for (unsigned int i = 0; i < numOutputs; i++) {
117 const OutputSlot &outputSlot = layer->GetOutputSlot(i);
118 const TensorInfo &info = outputSlot.GetTensorInfo();
119 if (DataType::QuantisedAsymm8 == info.GetDataType()) {
120 if (0.f == info.GetQuantizationScale()) {
121 noErrors = false;
122 std::stringstream ss;
Matteo Martincigh49124022019-01-11 13:25:59 +0000123 ss << "output " << i << " of layer " << GetLayerTypeAsCString(layer->GetType())
jimfly016b0b53d2018-10-08 14:43:01 +0100124 << " (" << layer->GetNameStr() << ") is of type"
125 << " Quantized 8 bit but its scale parameter has not been set";
Matteo Martincigh49124022019-01-11 13:25:59 +0000126 ReportError(ss.str(), errMessages);
jimfly016b0b53d2018-10-08 14:43:01 +0100127 }
128 }
129 }
130 return noErrors;
131}
132
Matteo Martincigh49124022019-01-11 13:25:59 +0000133OptimizationResult AssignBackends(OptimizedNetwork* optNetObjPtr,
134 BackendSettings& backendSettings,
135 Graph::Iterator& firstLayer,
136 Graph::Iterator& lastLayer,
137 Optional<std::vector<std::string>&> errMessages)
telsoa014fcda012018-03-09 14:13:49 +0000138{
Matteo Martincigh49124022019-01-11 13:25:59 +0000139 OptimizationResult result;
telsoa014fcda012018-03-09 14:13:49 +0000140
Matteo Martincigh49124022019-01-11 13:25:59 +0000141 // Helper lambda to compose meaningful error message before returning with error
142 auto ReturnWithError = [&](const Layer* layer)
telsoa01c577f2c2018-08-31 09:22:23 +0100143 {
jimfly016b0b53d2018-10-08 14:43:01 +0100144 std::stringstream failureMsg;
Matteo Martincigh49124022019-01-11 13:25:59 +0000145 failureMsg << "Layer of type " << GetLayerTypeAsCString(layer->GetType())
146 << " is not supported on any preferred backend " << backendSettings.m_PreferredBackends;
147 ReportError(failureMsg.str(), errMessages);
148
149 result.m_Error = true;
150 return result;
telsoa01c577f2c2018-08-31 09:22:23 +0100151 };
152
Matteo Martincigh49124022019-01-11 13:25:59 +0000153 auto availablePreferredBackends = backendSettings.GetAvailablePreferredBackends();
154 if (availablePreferredBackends.empty())
telsoa01c577f2c2018-08-31 09:22:23 +0100155 {
Matteo Martincigh49124022019-01-11 13:25:59 +0000156 std::stringstream failureMsg;
157 failureMsg << "No preferred backends are available";
158 ReportError(failureMsg.str(), errMessages);
159
160 result.m_Error = true;
161 return result;
162 }
163
164 for (auto it = firstLayer; it != lastLayer; ++it)
165 {
166 auto layer = *it;
telsoa01c577f2c2018-08-31 09:22:23 +0100167 DataType dataType = layer->GetDataType();
168 std::string reasonIfUnsupported;
169 bool found = false;
jimfly016b0b53d2018-10-08 14:43:01 +0100170 if (!CheckScaleSetOnQuantizedType(layer, errMessages))
171 {
172 // don't bomb immediately, find all the quantized outputs
173 // which haven't had a scale set and report them all back.
Matteo Martincigh49124022019-01-11 13:25:59 +0000174 result.m_Error = true;
jimfly016b0b53d2018-10-08 14:43:01 +0100175 }
Matteo Martincigh49124022019-01-11 13:25:59 +0000176
David Beckf0b48452018-10-19 15:20:56 +0100177 for (const auto& backend : availablePreferredBackends)
telsoa01c577f2c2018-08-31 09:22:23 +0100178 {
179 // need to set the compute device on the layer
180 // before we can check if it is supported
David Beck33f0ae02018-10-18 15:13:56 +0100181 layer->SetBackendId(backend);
telsoa01c577f2c2018-08-31 09:22:23 +0100182 if (!IWorkloadFactory::IsLayerSupported(*layer, dataType, reasonIfUnsupported))
183 {
184 if (dataType == DataType::Float16)
185 {
186 if (IWorkloadFactory::IsLayerSupported(*layer, DataType::Float32, reasonIfUnsupported)
187 && layer->GetType() != LayerType::ConvertFp32ToFp16
188 && layer->GetType() != LayerType::ConvertFp16ToFp32)
189 {
190 // Insert FP16 -> FP32 conversion layer before current layer
191 std::vector<ConvertFp16ToFp32Layer*> convertFp16ToFp32Layers =
192 InsertConvertFp16ToFp32LayersBefore(optNetObjPtr->GetGraph(), *layer);
193
194 // Insert FP32 -> FP16 conversion layer after current layer
195 std::vector<ConvertFp32ToFp16Layer*> convertFp32ToFp16Layers =
196 InsertConvertFp32ToFp16LayersAfter(optNetObjPtr->GetGraph(), *layer);
197
198 // Assign a supported backend to the newly introduced conversion layers
David Beckf0b48452018-10-19 15:20:56 +0100199 auto AssignFirstSupportedBackend = [&](Layer* layer, BackendId preferredBackend)
telsoa01c577f2c2018-08-31 09:22:23 +0100200 {
201 bool supportedBackendFound = false;
202 std::string reasonIfUnsupported;
203
204 // Try preferred backend first
David Beck33f0ae02018-10-18 15:13:56 +0100205 layer->SetBackendId(preferredBackend);
David Beck29c75de2018-10-23 13:35:58 +0100206 if (IWorkloadFactory::IsLayerSupported(*layer,
207 EmptyOptional(),
208 reasonIfUnsupported))
telsoa01c577f2c2018-08-31 09:22:23 +0100209 {
210 supportedBackendFound = true;
211 }
212 else
213 {
David Beckf0b48452018-10-19 15:20:56 +0100214 for (const auto& backend : availablePreferredBackends)
telsoa01c577f2c2018-08-31 09:22:23 +0100215 {
216 // Skip preferred backend (we already determined that it is not supported)
217 if (backend == preferredBackend)
218 {
219 continue;
220 }
221
David Beck33f0ae02018-10-18 15:13:56 +0100222 layer->SetBackendId(backend);
David Beck29c75de2018-10-23 13:35:58 +0100223 if (IWorkloadFactory::IsLayerSupported(*layer,
224 EmptyOptional(),
225 reasonIfUnsupported))
telsoa01c577f2c2018-08-31 09:22:23 +0100226 {
227 supportedBackendFound = true;
228 break;
229 }
230 }
231 }
232
233 return supportedBackendFound;
234 };
235
236 for (ConvertFp16ToFp32Layer* convertLayer : convertFp16ToFp32Layers)
237 {
238 if (!AssignFirstSupportedBackend(convertLayer, backend))
239 {
240 return ReturnWithError(convertLayer);
241 }
242 }
243
244 for (ConvertFp32ToFp16Layer* convertLayer : convertFp32ToFp16Layers)
245 {
246 if (!AssignFirstSupportedBackend(convertLayer, backend))
247 {
248 return ReturnWithError(convertLayer);
249 }
250 }
251
252 found = true;
253 break;
254 }
255 }
jimfly016b0b53d2018-10-08 14:43:01 +0100256 std::stringstream warningMsg;
Matteo Martincigh49124022019-01-11 13:25:59 +0000257 warningMsg << "Layer of type " << GetLayerTypeAsCString(layer->GetType())
David Beck33f0ae02018-10-18 15:13:56 +0100258 << " is not supported on requested backend " << layer->GetBackendId().Get()
jimfly016b0b53d2018-10-08 14:43:01 +0100259 << " for data type " << GetDataTypeName(dataType)
260 << " (reason: " << reasonIfUnsupported
261 << "), falling back to the next backend.";
Matteo Martincigh49124022019-01-11 13:25:59 +0000262 ReportWarning(warningMsg.str(), errMessages);
telsoa01c577f2c2018-08-31 09:22:23 +0100263 }
264 else
265 {
266 found = true;
Matteo Martincigh49124022019-01-11 13:25:59 +0000267 backendSettings.m_SelectedBackends.insert(backend);
telsoa01c577f2c2018-08-31 09:22:23 +0100268 break;
269 }
270 }
271
272 // If the layer is unsupported by any devices, log and return a null network.
Matteo Martincigh49124022019-01-11 13:25:59 +0000273 if (!found)
274 {
telsoa01c577f2c2018-08-31 09:22:23 +0100275 // NOTE: if the layer is not an operation queue type AND we have not got CpuRef as a
276 // fallback we should set the compute device on the layer to CpuRef (these are not
277 // available as accelerated operations, or are only available under certain
278 // conditions, currently they comprise MemCopy, Constant, Permute)
279 armnn::LayerType layerType = layer->GetType();
Matteo Martincigh49124022019-01-11 13:25:59 +0000280 if (!backendSettings.IsCpuRefUsed() && (layerType == armnn::LayerType::MemCopy ||
281 layerType == armnn::LayerType::Constant ||
282 layerType == armnn::LayerType::Permute))
telsoa01c577f2c2018-08-31 09:22:23 +0100283 {
Matteo Martincigh49124022019-01-11 13:25:59 +0000284 BackendId cpuBackendId(armnn::Compute::CpuRef);
285 layer->SetBackendId(cpuBackendId);
286 backendSettings.m_SelectedBackends.insert(cpuBackendId);
telsoa01c577f2c2018-08-31 09:22:23 +0100287 }
288 else
289 {
290 return ReturnWithError(layer);
291 }
292 }
293 }
Matteo Martincigh49124022019-01-11 13:25:59 +0000294
295 return result;
296}
297
Matteo Martincighadddddb2019-01-24 14:06:23 +0000298OptimizationResult AssignBackends(OptimizedNetwork* optNetObjPtr,
299 BackendSettings& backendSettings,
300 SubGraph& subGraph,
301 Optional<std::vector<std::string>&> errMessages)
Matteo Martincigh49124022019-01-11 13:25:59 +0000302{
Matteo Martincighadddddb2019-01-24 14:06:23 +0000303 Graph::Iterator firstLayer = subGraph.begin();
304 Graph::Iterator lastLayer = subGraph.end();
305 return AssignBackends(optNetObjPtr,
306 backendSettings,
307 firstLayer,
308 lastLayer,
309 errMessages);
310}
311
312OptimizationResult ApplyBackendOptimizations(OptimizedNetwork* optNetObjPtr,
313 BackendSettings& backendSettings,
314 Optional<std::vector<std::string>&> errMessages)
315{
316 BOOST_ASSERT(optNetObjPtr);
Matteo Martincigh49124022019-01-11 13:25:59 +0000317
318 OptimizationResult result;
319
Matteo Martincighadddddb2019-01-24 14:06:23 +0000320 // Get the optimized graph
321 Graph& optGraph = optNetObjPtr->GetGraph();
Matteo Martincigh49124022019-01-11 13:25:59 +0000322
Matteo Martincighadddddb2019-01-24 14:06:23 +0000323 // Get the entire graph as a sub-graph
324 SubGraph mainSubGraph(optGraph);
Matteo Martincigh49124022019-01-11 13:25:59 +0000325
Matteo Martincighadddddb2019-01-24 14:06:23 +0000326 // Run backend specific optimizations
327 auto const& backendRegistry = BackendRegistryInstance();
328 for (auto&& selectedBackend : backendSettings.m_SelectedBackends)
Matteo Martincigh49124022019-01-11 13:25:59 +0000329 {
Matteo Martincighadddddb2019-01-24 14:06:23 +0000330 auto backendFactory = backendRegistry.GetFactory(selectedBackend);
331 auto backendObjPtr = backendFactory();
332 BOOST_ASSERT(backendObjPtr);
333
334 // Select sub-graphs based on backend
335 SubGraphSelector::SubGraphs subGraphs =
336 SubGraphSelector::SelectSubGraphs(mainSubGraph,
337 // Select layers assigned to the requested backend
338 [&backendObjPtr](const Layer& layer)
339 {
340 return layer.GetType() != LayerType::Input &&
341 layer.GetType() != LayerType::Output &&
342 layer.GetBackendId() == backendObjPtr->GetId();
343 });
344 if (subGraphs.empty())
Matteo Martincigh49124022019-01-11 13:25:59 +0000345 {
Matteo Martincighadddddb2019-01-24 14:06:23 +0000346 // No sub-graphs found, try with next selected backend
347 continue;
Matteo Martincigh49124022019-01-11 13:25:59 +0000348 }
Matteo Martincighadddddb2019-01-24 14:06:23 +0000349
350 // Try to optimize each sub-graph
351 for (auto& subGraph : subGraphs)
Matteo Martincigh49124022019-01-11 13:25:59 +0000352 {
Matteo Martincighadddddb2019-01-24 14:06:23 +0000353 // Try to optimize the current sub-graph
354 bool optimizationAttempted = false;
355 SubGraph::SubGraphPtr optSubGraph = backendObjPtr->OptimizeSubGraph(*subGraph, optimizationAttempted);
Matteo Martincigh49124022019-01-11 13:25:59 +0000356
Matteo Martincighadddddb2019-01-24 14:06:23 +0000357 // Check if the optimization has been attempted
358 if (!optimizationAttempted)
Matteo Martincigh49124022019-01-11 13:25:59 +0000359 {
Matteo Martincighadddddb2019-01-24 14:06:23 +0000360 // No optimization attempted, keep the current sub-graph as it is and move to the next one
361 continue;
362 }
363
364 // Optimization attempted, check the resulting optimized sub-graph
365 if (optSubGraph)
366 {
367 // Sub-graph optimized, substitute the sub-graph with the new optimized one in the main optimized graph
368 optGraph.SubstituteSubGraph(std::move(subGraph), *optSubGraph);
369
370 // Assign the current backend to the optimized sub-graph
371 std::for_each(optSubGraph->begin(), optSubGraph->end(), [&selectedBackend](Layer* l)
372 {
373 BOOST_ASSERT(l);
374 l->SetBackendId(selectedBackend);
375 });
376
377 // Recreate the sub-graph representing the entire graph
378 mainSubGraph.Update(optGraph);
379 }
380 else
381 {
382 // An error occurred: the optimization was attempted but not performed, try different backends
383 std::stringstream warningMsg;
384 warningMsg << "Sub-graph failed to get optimized on " << backendObjPtr->GetId() << ". "
385 << "Re-assigning backends to " << subGraph->GetLayers().size() << " layers inside sub-graph";
386 ReportWarning(warningMsg.str(), errMessages);
387
388 // Failed to optimize the given sub-graph, re-assign the sub-graph layers to other available backends
389 if (!backendObjPtr->GetId().IsCpuRef())
390 {
391 // Add the current backend to the list of backends to ignore
392 backendSettings.m_IgnoredBackends.insert(backendObjPtr->GetId());
393 }
394 OptimizationResult reassignmentResult = AssignBackends(optNetObjPtr,
395 backendSettings,
396 *subGraph,
397 errMessages);
398 if (reassignmentResult.m_Error)
399 {
400 // Failed to re-assign one of the remaining backends to each layer of the sub-graph
401 result.m_Error = true;
402 return result;
403 }
Matteo Martincigh49124022019-01-11 13:25:59 +0000404 }
405 }
406 }
407
408 return result;
409}
410
411IOptimizedNetworkPtr Optimize(const INetwork& inNetwork,
412 const std::vector<BackendId>& backendPreferences,
413 const IDeviceSpec& deviceSpec,
414 const OptimizerOptions& options,
415 Optional<std::vector<std::string>&> errMessages)
416{
417 if (backendPreferences.empty())
418 {
419 throw armnn::InvalidArgumentException("Invoked Optimize with no backends specified");
420 }
421
422 const Network& network = *boost::polymorphic_downcast<const Network*>(&inNetwork);
423 std::unique_ptr<Graph> graph = std::make_unique<Graph>(network.GetGraph());
424
425 auto optNet = IOptimizedNetworkPtr(new OptimizedNetwork(std::move(graph)), &IOptimizedNetwork::Destroy);
426
427 OptimizedNetwork* optNetObjPtr = boost::polymorphic_downcast<OptimizedNetwork*>(optNet.get());
428
Matteo Martincighadddddb2019-01-24 14:06:23 +0000429 // Get the optimized graph
430 Graph& optGraph = optNetObjPtr->GetGraph();
431
Matteo Martincigh49124022019-01-11 13:25:59 +0000432 // Perform optimisation passes
433 using namespace optimizations;
Matteo Martincighadddddb2019-01-24 14:06:23 +0000434 Optimizer::Pass(optGraph, MakeOptimizations(SquashEqualPermuteSiblings(),
435 SquashEqualReshapeSiblings(),
436 OptimizeInversePermutes(),
437 MovePermuteUp(),
438 PermuteAsReshape(),
Nina Drozd861985f2019-04-18 14:48:51 +0100439 OptimizeConsecutiveReshapes(),
440 FoldPadIntoConvolution2d()));
Matteo Martincigh49124022019-01-11 13:25:59 +0000441
Matteo Martincighadddddb2019-01-24 14:06:23 +0000442 // Infer the tensor infos for all output slots. Throws an exception on failure
443 optGraph.InferTensorInfos();
Matteo Martincigh49124022019-01-11 13:25:59 +0000444
445 // If Fp32 to Fp16 optimization is set convert Fp32 network to Fp16
446 if (options.m_ReduceFp32ToFp16)
447 {
Matteo Martincighadddddb2019-01-24 14:06:23 +0000448 Optimizer::Pass(optGraph, MakeOptimizations(Fp32NetworkToFp16Converter()));
Matteo Martincigh49124022019-01-11 13:25:59 +0000449 }
450
451 // Initialize backend settings
452 BackendSettings backendSettings(backendPreferences, deviceSpec);
453 if (backendSettings.GetAvailablePreferredBackends().empty())
454 {
455 std::stringstream failureMsg;
456 failureMsg << "None of the preferred backends " << backendPreferences
457 << " are supported. Current platform provides " << backendSettings.m_SupportedBackends;
458 ReportError(failureMsg.str(), errMessages);
459 return IOptimizedNetworkPtr(nullptr, &IOptimizedNetwork::Destroy);
460 }
461
462 // Assign an available backend to each layer
Matteo Martincighadddddb2019-01-24 14:06:23 +0000463 Graph::Iterator firstLayer = optGraph.begin();
464 Graph::Iterator lastLayer = optGraph.end();
Matteo Martincigh49124022019-01-11 13:25:59 +0000465 OptimizationResult assigBackendsResult = AssignBackends(optNetObjPtr,
466 backendSettings,
467 firstLayer,
468 lastLayer,
469 errMessages);
470 if (assigBackendsResult.m_Error)
471 {
472 // Failed to assign a backend to each layer
jimfly016b0b53d2018-10-08 14:43:01 +0100473 return IOptimizedNetworkPtr(nullptr, &IOptimizedNetwork::Destroy);
474 }
telsoa01c577f2c2018-08-31 09:22:23 +0100475
Matteo Martincighadddddb2019-01-24 14:06:23 +0000476 Optimizer::Pass(optGraph, MakeOptimizations(OptimizeInverseConversionsFp16(),
477 OptimizeInverseConversionsFp32()));
telsoa01c577f2c2018-08-31 09:22:23 +0100478
Matteo Martincighadddddb2019-01-24 14:06:23 +0000479 // Apply the backend-specific optimizations
480 OptimizationResult backendOptimizationResult = ApplyBackendOptimizations(optNetObjPtr,
481 backendSettings,
482 errMessages);
483 if (backendOptimizationResult.m_Error)
Matteo Martincigh49124022019-01-11 13:25:59 +0000484 {
Matteo Martincighadddddb2019-01-24 14:06:23 +0000485 // Failed to apply the backend-specific optimizations
486 return IOptimizedNetworkPtr(nullptr, &IOptimizedNetwork::Destroy);
Matteo Martincigh49124022019-01-11 13:25:59 +0000487 }
488
Matteo Martincighadddddb2019-01-24 14:06:23 +0000489 // If the debug flag is set, then insert a DebugLayer after each layer
490 // Doing this after applying the backend optimizations as they might have changed some layers
491 if (options.m_Debug)
492 {
493 Optimizer::Pass(optGraph, MakeOptimizations(InsertDebugLayer()));
494 }
495
496 optGraph.AddCopyLayers();
telsoa01c577f2c2018-08-31 09:22:23 +0100497
498 // Convert constants
Matteo Martincighadddddb2019-01-24 14:06:23 +0000499 Optimizer::Pass(optGraph, MakeOptimizations(ConvertConstantsFloatToHalf()));
500 Optimizer::Pass(optGraph, MakeOptimizations(ConvertConstantsHalfToFloat()));
telsoa01c577f2c2018-08-31 09:22:23 +0100501
David Beck263e3492018-11-09 14:46:40 +0000502 // Run backend specific optimizations
Matteo Martincigh49124022019-01-11 13:25:59 +0000503 for (auto&& chosenBackend : backendSettings.m_SelectedBackends)
David Beck263e3492018-11-09 14:46:40 +0000504 {
505 auto factoryFun = BackendRegistryInstance().GetFactory(chosenBackend);
506 auto backendPtr = factoryFun();
507 BOOST_ASSERT(backendPtr.get() != nullptr);
508
509 auto backendSpecificOptimizations = backendPtr->GetOptimizations();
510 if (!backendSpecificOptimizations.empty())
511 {
512 Optimizer::Pass(optNetObjPtr->GetGraph(), backendSpecificOptimizations);
513 }
514 }
515
telsoa01c577f2c2018-08-31 09:22:23 +0100516 return optNet;
telsoa014fcda012018-03-09 14:13:49 +0000517}
518
519Network::Network()
520: m_Graph(std::make_unique<Graph>())
521{
522}
523
524Network::~Network()
525{
526}
527
528IConnectableLayer* Network::AddInputLayer(LayerBindingId id, const char* name)
529{
530 return m_Graph->AddLayer<InputLayer>(id, name);
531}
532
Éanna Ó Catháin4e1e1362018-11-12 11:36:34 +0000533IConnectableLayer* Network::AddBatchToSpaceNdLayer(const BatchToSpaceNdDescriptor& batchToSpaceNdDescriptor,
534 const char* name)
535{
536 return m_Graph->AddLayer<BatchToSpaceNdLayer>(batchToSpaceNdDescriptor, name);
537}
538
telsoa014fcda012018-03-09 14:13:49 +0000539IConnectableLayer* Network::AddFullyConnectedLayerImpl(const FullyConnectedDescriptor& fullyConnectedDescriptor,
telsoa01c577f2c2018-08-31 09:22:23 +0100540 const ConstTensor& weights,
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000541 const Optional<ConstTensor>& biases,
telsoa01c577f2c2018-08-31 09:22:23 +0100542 const char* name)
telsoa014fcda012018-03-09 14:13:49 +0000543{
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000544 if (fullyConnectedDescriptor.m_BiasEnabled && !biases.has_value())
telsoa014fcda012018-03-09 14:13:49 +0000545 {
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000546 throw InvalidArgumentException("AddFullyConnectedLayer: biases cannot be empty");
telsoa014fcda012018-03-09 14:13:49 +0000547 }
548
549 const auto layer = m_Graph->AddLayer<FullyConnectedLayer>(fullyConnectedDescriptor, name);
550
551 layer->m_Weight = std::make_unique<ScopedCpuTensorHandle>(weights);
552
553 if (fullyConnectedDescriptor.m_BiasEnabled)
554 {
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000555 layer->m_Bias = std::make_unique<ScopedCpuTensorHandle>(biases.value());
telsoa014fcda012018-03-09 14:13:49 +0000556 }
557
558 return layer;
559}
560
561IConnectableLayer* Network::AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
telsoa01c577f2c2018-08-31 09:22:23 +0100562 const ConstTensor& weights,
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000563 const Optional<ConstTensor>& biases,
telsoa01c577f2c2018-08-31 09:22:23 +0100564 const char* name)
telsoa014fcda012018-03-09 14:13:49 +0000565{
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000566 return AddFullyConnectedLayerImpl(fullyConnectedDescriptor, weights, biases, name);
telsoa014fcda012018-03-09 14:13:49 +0000567}
568
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000569/// @deprecated
570IConnectableLayer* Network::AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
571 const ConstTensor& weights,
572 const char* name)
573{
574 Optional<ConstTensor> biases = EmptyOptional();
575 return AddFullyConnectedLayerImpl(fullyConnectedDescriptor, weights, biases, name);
576}
577
578/// @deprecated
telsoa014fcda012018-03-09 14:13:49 +0000579IConnectableLayer* Network::AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
telsoa01c577f2c2018-08-31 09:22:23 +0100580 const ConstTensor& weights,
581 const ConstTensor& biases,
582 const char* name)
telsoa014fcda012018-03-09 14:13:49 +0000583{
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000584 Optional<ConstTensor> optionalBiases(biases);
585 return AddFullyConnectedLayerImpl(fullyConnectedDescriptor, weights, optionalBiases, name);
telsoa014fcda012018-03-09 14:13:49 +0000586}
587
588IConnectableLayer* Network::AddConvolution2dLayerImpl(const Convolution2dDescriptor& convolution2dDescriptor,
telsoa01c577f2c2018-08-31 09:22:23 +0100589 const ConstTensor& weights,
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000590 const Optional<ConstTensor>& biases,
telsoa01c577f2c2018-08-31 09:22:23 +0100591 const char* name)
telsoa014fcda012018-03-09 14:13:49 +0000592{
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000593 if (convolution2dDescriptor.m_BiasEnabled && !biases.has_value())
telsoa014fcda012018-03-09 14:13:49 +0000594 {
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000595 throw InvalidArgumentException("AddConvolution2dLayer: biases cannot be empty");
telsoa014fcda012018-03-09 14:13:49 +0000596 }
597
598 const auto layer = m_Graph->AddLayer<Convolution2dLayer>(convolution2dDescriptor, name);
599
600 layer->m_Weight = std::make_unique<ScopedCpuTensorHandle>(weights);
601
602 if (convolution2dDescriptor.m_BiasEnabled)
603 {
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000604 layer->m_Bias = std::make_unique<ScopedCpuTensorHandle>(biases.value());
telsoa014fcda012018-03-09 14:13:49 +0000605 }
606
607 return layer;
608}
609
610IConnectableLayer* Network::AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
telsoa01c577f2c2018-08-31 09:22:23 +0100611 const ConstTensor& weights,
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000612 const Optional<ConstTensor>& biases,
telsoa01c577f2c2018-08-31 09:22:23 +0100613 const char* name)
telsoa014fcda012018-03-09 14:13:49 +0000614{
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000615 return AddConvolution2dLayerImpl(convolution2dDescriptor, weights, biases, name);
telsoa014fcda012018-03-09 14:13:49 +0000616}
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000617
618/// @deprecated
619IConnectableLayer* Network::AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
620 const ConstTensor& weights,
621 const char* name)
622{
623 Optional<ConstTensor> biases = EmptyOptional();
624 return AddConvolution2dLayerImpl(convolution2dDescriptor, weights, biases, name);
625}
626
627/// @deprecated
telsoa014fcda012018-03-09 14:13:49 +0000628IConnectableLayer* Network::AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
telsoa01c577f2c2018-08-31 09:22:23 +0100629 const ConstTensor& weights,
630 const ConstTensor& biases,
631 const char* name)
telsoa014fcda012018-03-09 14:13:49 +0000632{
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000633 Optional<ConstTensor> optionalBiases(biases);
634 return AddConvolution2dLayerImpl(convolution2dDescriptor, weights, optionalBiases, name);
telsoa014fcda012018-03-09 14:13:49 +0000635}
636
637IConnectableLayer* Network::AddDepthwiseConvolution2dLayerImpl(
638 const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
639 const ConstTensor& weights,
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000640 const Optional<ConstTensor>& biases,
telsoa014fcda012018-03-09 14:13:49 +0000641 const char* name)
642{
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000643 if (convolution2dDescriptor.m_BiasEnabled && !biases.has_value())
telsoa014fcda012018-03-09 14:13:49 +0000644 {
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000645 throw InvalidArgumentException("AddDepthwiseConvolution2dLayer: biases cannot be empty");
telsoa014fcda012018-03-09 14:13:49 +0000646 }
647
Matteo Martincigh3d6898c2019-01-15 16:11:44 +0000648 const auto layer = m_Graph->AddLayer<DepthwiseConvolution2dLayer>(convolution2dDescriptor, name);
telsoa014fcda012018-03-09 14:13:49 +0000649
650 layer->m_Weight = std::make_unique<ScopedCpuTensorHandle>(weights);
651
652 if (convolution2dDescriptor.m_BiasEnabled)
653 {
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000654 layer->m_Bias = std::make_unique<ScopedCpuTensorHandle>(biases.value());
telsoa014fcda012018-03-09 14:13:49 +0000655 }
656
657 return layer;
658}
659
660IConnectableLayer* Network::AddDepthwiseConvolution2dLayer(
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000661 const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
662 const ConstTensor& weights,
663 const Optional<ConstTensor>& biases,
664 const char* name)
665{
666 return AddDepthwiseConvolution2dLayerImpl(convolution2dDescriptor, weights, biases, name);
667}
668
669/// @deprecated
670IConnectableLayer* Network::AddDepthwiseConvolution2dLayer(
telsoa014fcda012018-03-09 14:13:49 +0000671 const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
672 const ConstTensor& weights,
673 const char* name)
674{
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000675 Optional<ConstTensor> biases = EmptyOptional();
676 return AddDepthwiseConvolution2dLayerImpl(convolution2dDescriptor, weights, biases, name);
telsoa014fcda012018-03-09 14:13:49 +0000677}
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000678
679/// @deprecated
telsoa014fcda012018-03-09 14:13:49 +0000680IConnectableLayer* Network::AddDepthwiseConvolution2dLayer(
681 const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
682 const ConstTensor& weights,
683 const ConstTensor& biases,
684 const char* name)
685{
Aron Virginas-Tarad402702019-02-22 17:03:44 +0000686 Optional<ConstTensor> optionalBiases(biases);
687 return AddDepthwiseConvolution2dLayerImpl(convolution2dDescriptor, weights, optionalBiases, name);
telsoa014fcda012018-03-09 14:13:49 +0000688}
689
Narumol Prangnawarat94dd5d82019-01-23 18:06:26 +0000690IConnectableLayer* Network::AddDetectionPostProcessLayer(const armnn::DetectionPostProcessDescriptor& descriptor,
Narumol Prangnawarat6d302bf2019-02-04 11:46:26 +0000691 const ConstTensor& anchors, const char* name)
Narumol Prangnawarat94dd5d82019-01-23 18:06:26 +0000692{
Narumol Prangnawarat6d302bf2019-02-04 11:46:26 +0000693 const auto layer = m_Graph->AddLayer<DetectionPostProcessLayer>(descriptor, name);
694
695 layer->m_Anchors = std::make_unique<ScopedCpuTensorHandle>(anchors);
696
697 return layer;
Narumol Prangnawarat94dd5d82019-01-23 18:06:26 +0000698}
699
telsoa014fcda012018-03-09 14:13:49 +0000700IConnectableLayer* Network::AddPermuteLayer(const PermuteDescriptor& permuteDescriptor,
701 const char* name)
702{
703 return m_Graph->AddLayer<PermuteLayer>(permuteDescriptor, name);
704}
705
706IConnectableLayer* Network::AddPooling2dLayer(const Pooling2dDescriptor& pooling2dDescriptor,
707 const char* name)
708{
709 return m_Graph->AddLayer<Pooling2dLayer>(pooling2dDescriptor, name);
710}
711
712IConnectableLayer* Network::AddActivationLayer(const ActivationDescriptor& activationDescriptor,
713 const char* name)
714{
715 return m_Graph->AddLayer<ActivationLayer>(activationDescriptor, name);
716}
717
telsoa01c577f2c2018-08-31 09:22:23 +0100718IConnectableLayer* Network::AddNormalizationLayer(const NormalizationDescriptor&
719normalizationDescriptor,
telsoa014fcda012018-03-09 14:13:49 +0000720 const char* name)
721{
722 return m_Graph->AddLayer<NormalizationLayer>(normalizationDescriptor, name);
723}
724
725IConnectableLayer* Network::AddSoftmaxLayer(const SoftmaxDescriptor& softmaxDescriptor,
726 const char* name)
727{
728 return m_Graph->AddLayer<SoftmaxLayer>(softmaxDescriptor, name);
729}
730
731IConnectableLayer* Network::AddSplitterLayer(const ViewsDescriptor& splitterDescriptor,
732 const char* name)
733{
734 return m_Graph->AddLayer<SplitterLayer>(splitterDescriptor, name);
735}
736
Nattapat Chaimanowong5a4304a2018-11-28 10:44:37 +0000737IConnectableLayer* Network::AddMaximumLayer(const char* name)
738{
739 return m_Graph->AddLayer<MaximumLayer>(name);
740}
741
Éanna Ó Catháin20e58802018-12-04 10:29:06 +0000742IConnectableLayer* Network::AddMinimumLayer(const char* name)
743{
744 return m_Graph->AddLayer<MinimumLayer>(name);
745}
746
telsoa014fcda012018-03-09 14:13:49 +0000747IConnectableLayer* Network::AddMergerLayer(const OriginsDescriptor& mergerDescriptor,
748 const char* name)
749{
750 return m_Graph->AddLayer<MergerLayer>(mergerDescriptor, name);
751}
752
753IConnectableLayer* Network::AddAdditionLayer(const char* name)
754{
755 return m_Graph->AddLayer<AdditionLayer>(name);
756}
757
758IConnectableLayer* Network::AddMultiplicationLayer(const char* name)
759{
760 return m_Graph->AddLayer<MultiplicationLayer>(name);
761}
762
763IConnectableLayer* Network::AddOutputLayer(LayerBindingId id, const char* name)
764{
765 return m_Graph->AddLayer<OutputLayer>(id, name);
766}
767
768IConnectableLayer* Network::AddBatchNormalizationLayer(const BatchNormalizationDescriptor& desc,
769 const ConstTensor& mean,
770 const ConstTensor& variance,
771 const ConstTensor& beta,
772 const ConstTensor& gamma,
773 const char* name)
774{
775 const auto layer = m_Graph->AddLayer<BatchNormalizationLayer>(desc, name);
776
777 layer->m_Mean = std::make_unique<ScopedCpuTensorHandle>(mean);
778 layer->m_Variance = std::make_unique<ScopedCpuTensorHandle>(variance);
779 layer->m_Beta = std::make_unique<ScopedCpuTensorHandle>(beta);
780 layer->m_Gamma = std::make_unique<ScopedCpuTensorHandle>(gamma);
781
782 return layer;
783}
784
telsoa01c577f2c2018-08-31 09:22:23 +0100785IConnectableLayer* Network::AddResizeBilinearLayer(const ResizeBilinearDescriptor&
786resizeDescriptor, const char* name)
telsoa014fcda012018-03-09 14:13:49 +0000787{
788 return m_Graph->AddLayer<ResizeBilinearLayer>(resizeDescriptor,name);
789}
790
Matteo Martincighbcd3c852018-09-28 14:14:12 +0100791IConnectableLayer* Network::AddL2NormalizationLayer(const L2NormalizationDescriptor& desc,
792 const char* name)
telsoa014fcda012018-03-09 14:13:49 +0000793{
Matteo Martincighbcd3c852018-09-28 14:14:12 +0100794 return m_Graph->AddLayer<L2NormalizationLayer>(desc, name);
telsoa014fcda012018-03-09 14:13:49 +0000795}
796
797IConnectableLayer* Network::AddConstantLayer(const ConstTensor& input, const char* name)
798{
telsoa01c577f2c2018-08-31 09:22:23 +0100799 auto layer = m_Graph->AddLayer<ConstantLayer>(name);
800
801 layer->m_LayerOutput = std::make_unique<ScopedCpuTensorHandle>(input);
802
803 return layer;
telsoa014fcda012018-03-09 14:13:49 +0000804}
805
telsoa01c577f2c2018-08-31 09:22:23 +0100806IConnectableLayer* Network::AddReshapeLayer(const ReshapeDescriptor& reshapeDescriptor,
807 const char* name)
telsoa014fcda012018-03-09 14:13:49 +0000808{
809 return m_Graph->AddLayer<ReshapeLayer>(reshapeDescriptor, name);
810}
811
Nattapat Chaimanowong207ef9a2018-11-02 10:57:25 +0000812IConnectableLayer* Network::AddSpaceToBatchNdLayer(const SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor,
813 const char* name)
814{
815 return m_Graph->AddLayer<SpaceToBatchNdLayer>(spaceToBatchNdDescriptor, name);
816}
817
telsoa014fcda012018-03-09 14:13:49 +0000818IConnectableLayer* Network::AddFloorLayer(const char* name)
819{
820 return m_Graph->AddLayer<FloorLayer>(name);
821}
822
telsoa01c577f2c2018-08-31 09:22:23 +0100823IConnectableLayer* Network::AddLstmLayer(const LstmDescriptor& descriptor,
824 const LstmInputParams& params,
825 const char* name)
826{
827 const auto layer = m_Graph->AddLayer<LstmLayer>(descriptor, name);
828
829 //Lstm Basic Parameters
830 layer->m_BasicParameters.m_InputToForgetWeights =
831 std::make_unique<ScopedCpuTensorHandle>(*(params.m_InputToForgetWeights));
832 layer->m_BasicParameters.m_InputToCellWeights =
833 std::make_unique<ScopedCpuTensorHandle>(*(params.m_InputToCellWeights));
834 layer->m_BasicParameters.m_InputToOutputWeights =
835 std::make_unique<ScopedCpuTensorHandle>(*(params.m_InputToOutputWeights));
836 layer->m_BasicParameters.m_RecurrentToForgetWeights =
837 std::make_unique<ScopedCpuTensorHandle>(*(params.m_RecurrentToForgetWeights));
838 layer->m_BasicParameters.m_RecurrentToCellWeights =
839 std::make_unique<ScopedCpuTensorHandle>(*(params.m_RecurrentToCellWeights));
840 layer->m_BasicParameters.m_RecurrentToOutputWeights =
841 std::make_unique<ScopedCpuTensorHandle>(*(params.m_RecurrentToOutputWeights));
842 layer->m_BasicParameters.m_ForgetGateBias =
843 std::make_unique<ScopedCpuTensorHandle>(*(params.m_ForgetGateBias));
844 layer->m_BasicParameters.m_CellBias =
845 std::make_unique<ScopedCpuTensorHandle>(*(params.m_CellBias));
846 layer->m_BasicParameters.m_OutputGateBias =
847 std::make_unique<ScopedCpuTensorHandle>(*(params.m_OutputGateBias));
848
849 //Lstm Cifg parameters
850 if(!descriptor.m_CifgEnabled)
851 {
852 if(params.m_InputToInputWeights == nullptr)
853 {
854 throw InvalidArgumentException("AddLstmLayer: Input To Input Weights cannot be NULL");
855 }
856 if(params.m_RecurrentToInputWeights == nullptr)
857 {
858 throw InvalidArgumentException(
859 "AddLstmLayer: Recurrent To Input Weights cannot be NULL");
860 }
861 if(params.m_InputGateBias == nullptr)
862 {
863 throw InvalidArgumentException("AddLstmLayer: Input Gate Bias cannot be NULL");
864 }
865 layer->m_CifgParameters.m_InputToInputWeights =
866 std::make_unique<ScopedCpuTensorHandle>(*(params.m_InputToInputWeights));
867 layer->m_CifgParameters.m_RecurrentToInputWeights =
868 std::make_unique<ScopedCpuTensorHandle>(*(params.m_RecurrentToInputWeights));
869 // In the VTS tests, cell-to-input weights may be null, even if the other CIFG params are not.
870 if(params.m_CellToInputWeights != nullptr)
871 {
872 layer->m_CifgParameters.m_CellToInputWeights =
873 std::make_unique<ScopedCpuTensorHandle>(*(params.m_CellToInputWeights));
874 }
875 layer->m_CifgParameters.m_InputGateBias =
876 std::make_unique<ScopedCpuTensorHandle>(*(params.m_InputGateBias));
877 }
878
879 //Lstm projection parameters
880 if(descriptor.m_ProjectionEnabled)
881 {
882 if(params.m_ProjectionWeights == nullptr)
883 {
884 throw InvalidArgumentException("AddLstmLayer: Projection Weights cannot be NULL");
885 }
886 layer->m_ProjectionParameters.m_ProjectionWeights =
887 std::make_unique<ScopedCpuTensorHandle>(*(params.m_ProjectionWeights));
888 if(params.m_ProjectionBias != nullptr)
889 {
890 layer->m_ProjectionParameters.m_ProjectionBias =
891 std::make_unique<ScopedCpuTensorHandle>(*(params.m_ProjectionBias));
892 }
893 }
894
895 //Lstm Peephole params
896 if(descriptor.m_PeepholeEnabled)
897 {
898 if(params.m_CellToForgetWeights == nullptr)
899 {
900 throw InvalidArgumentException("AddLstmLayer: Cell To Forget Weights cannot be NULL");
901 }
902 if(params.m_CellToOutputWeights == nullptr)
903 {
904 throw InvalidArgumentException("AddLstmLayer: Cell To Output Weights cannot be NULL");
905 }
906 layer->m_PeepholeParameters.m_CellToForgetWeights =
907 std::make_unique<ScopedCpuTensorHandle>(*(params.m_CellToForgetWeights));
908 layer->m_PeepholeParameters.m_CellToOutputWeights =
909 std::make_unique<ScopedCpuTensorHandle>(*(params.m_CellToOutputWeights));
910 }
911 return layer;
912}
913
Francis Murtaghe7a86a42018-08-29 12:42:10 +0100914IConnectableLayer* Network::AddDivisionLayer(const char* name)
915{
916 return m_Graph->AddLayer<DivisionLayer>(name);
917}
918
David Beck19526222018-09-12 16:00:08 +0100919IConnectableLayer* Network::AddSubtractionLayer(const char* name)
920{
921 return m_Graph->AddLayer<SubtractionLayer>(name);
922}
923
narpra0132b90462018-09-13 11:07:48 +0100924IConnectableLayer* Network::AddMeanLayer(const MeanDescriptor& meanDescriptor, const char* name)
925{
926 return m_Graph->AddLayer<MeanLayer>(meanDescriptor,name);
927}
928
Mohamed Nour Abouelseoud5662c202018-09-24 13:30:09 +0100929IConnectableLayer* Network::AddPadLayer(const PadDescriptor& padDescriptor, const char* name)
930{
931 return m_Graph->AddLayer<PadLayer>(padDescriptor,name);
932}
933
Derek Lambertia9cca6a2019-03-25 15:41:58 +0000934IConnectableLayer *Network::AddQuantizeLayer(const char *name)
935{
936 return m_Graph->AddLayer<QuantizeLayer>(name);
937}
938
Nattapat Chaimanowonge4294fd2019-03-28 09:56:53 +0000939IConnectableLayer* Network::AddDequantizeLayer(const char* name)
940{
941 return m_Graph->AddLayer<DequantizeLayer>(name);
942}
943
Conor Kennedy430b5d82018-11-14 15:28:28 +0000944IConnectableLayer* Network::AddStridedSliceLayer(const StridedSliceDescriptor& stridedSliceDescriptor,
945 const char* name)
946{
947 return m_Graph->AddLayer<StridedSliceLayer>(stridedSliceDescriptor, name);
948}
949
Matteo Martincigh59a950c2018-12-13 12:48:25 +0000950IConnectableLayer* Network::AddGreaterLayer(const char* name)
951{
952 return m_Graph->AddLayer<GreaterLayer>(name);
953}
954
FrancisMurtagh20995952018-12-17 12:11:36 +0000955IConnectableLayer* Network::AddEqualLayer(const char* name)
956{
jimfly0184c70e62018-12-19 13:14:46 +0000957 return m_Graph->AddLayer<EqualLayer>(name);
FrancisMurtagh20995952018-12-17 12:11:36 +0000958}
959
Mohamed Nour Abouelseouda1d3c6a2018-12-27 12:39:16 +0000960IConnectableLayer* Network::AddRsqrtLayer(const char * name)
961{
962 return m_Graph->AddLayer<RsqrtLayer>(name);
963}
964
narpra01b89b05f2019-01-16 09:53:09 +0000965IConnectableLayer* Network::AddGatherLayer(const char* name)
966{
967 return m_Graph->AddLayer<GatherLayer>(name);
968}
969
Nattapat Chaimanowong1f886302019-04-05 13:37:19 +0100970IConnectableLayer* Network::AddMergeLayer(const char* name)
971{
972 return m_Graph->AddLayer<MergeLayer>(name);
973}
974
Sadik Armaganeff363d2019-04-05 15:25:46 +0100975IConnectableLayer* Network::AddSwitchLayer(const char* name)
976{
977 return m_Graph->AddLayer<SwitchLayer>(name);
978}
979
Mike Kelly8c1701a2019-02-11 17:01:27 +0000980void Network::Accept(ILayerVisitor& visitor) const
981{
982 for (auto layer : GetGraph())
983 {
984 layer->Accept(visitor);
985 };
986}
987
telsoa014fcda012018-03-09 14:13:49 +0000988OptimizedNetwork::OptimizedNetwork(std::unique_ptr<Graph> graph)
989 : m_Graph(std::move(graph))
990{
991}
992
993OptimizedNetwork::~OptimizedNetwork()
994{
995}
996
997} // namespace armnn