ArmNN
 25.11
Loading...
Searching...
No Matches
INetwork.hpp
Go to the documentation of this file.
1//
2// Copyright © 2017-2024 Arm Ltd and Contributors. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5#pragma once
6
10#include <armnn/IStrategy.hpp>
11#include <armnn/NetworkFwd.hpp>
12#include <armnn/Optional.hpp>
13#include <armnn/TensorFwd.hpp>
14#include <armnn/Logging.hpp>
16
17#include <memory>
18#include <vector>
19
20namespace armnn
21{
22/// @brief An input connection slot for a layer.
23/// The input slot can be connected to an output slot of the preceding layer in the graph.
24/// Only one connection to the input slot is allowed.
26{
27public:
28 virtual const IOutputSlot* GetConnection() const = 0;
29 virtual IOutputSlot* GetConnection() = 0;
32 virtual unsigned int GetSlotIndex() const = 0;
33
34 /// Sets the TensorInfo for this InputSlot. This can be used to override the TensorInfo and if set will be returned
35 /// instead of the TensorInfo for the Connected OutputSlot.
36 virtual void SetTensorInfo(const TensorInfo tensorInfo) = 0;
37 /// Gets the TensorInfo for this InputSlot. If the InputSlot's TensorInfo has not been set then this will get the
38 /// TensorInfo from the Connected TensorInfo.
39 virtual const TensorInfo& GetTensorInfo() const = 0;
40 /// Returns true if this InputSlot either has an overridden TensorInfo for this InputSlot that was set through a
41 /// call to SetTensorInfo() or is Connected to an OutputSlot that has its TensorInfo set.
42 virtual bool IsTensorInfoSet() const = 0;
43 /// Returns true if this InputSlot has an overridden TensorInfo that was set through a call to SetTensorInfo().
44 virtual bool IsTensorInfoOverridden() const = 0;
45
46protected:
47 /// Not user deletable.
49};
50
51/// @brief An output connection slot for a layer.
52/// The output slot may be connected to 1 or more input slots of subsequent layers in the graph.
54{
55public:
56 virtual unsigned int GetNumConnections() const = 0;
57 virtual const IInputSlot* GetConnection(unsigned int index) const = 0;
58 virtual IInputSlot* GetConnection(unsigned int outputindex) = 0;
59
60 virtual void SetTensorInfo(const TensorInfo& tensorInfo) = 0;
61 virtual const TensorInfo& GetTensorInfo() const = 0;
62 virtual bool IsTensorInfoSet() const = 0;
63
64 virtual int Connect(IInputSlot& destination) = 0;
65 virtual void Disconnect(IInputSlot& slot) = 0;
66
67 virtual unsigned int CalculateIndexOnOwner() const = 0;
68
69 virtual LayerGuid GetOwningLayerGuid() const = 0;
70
73
74protected:
75 /// Not user deletable.
77};
78
79/// @brief Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
81{
82public:
83 /// Returns the name of the layer
84 virtual const char* GetName() const = 0;
85
86 /// Returns the number of connectable input slots
87 virtual unsigned int GetNumInputSlots() const = 0;
88
89 /// Returns the number of connectable output slots
90 virtual unsigned int GetNumOutputSlots() const = 0;
91
92 /// Get a const input slot handle by slot index
93 virtual const IInputSlot& GetInputSlot(unsigned int index) const = 0;
94
95 /// Get the input slot handle by slot index
96 virtual IInputSlot& GetInputSlot(unsigned int index) = 0;
97
98 /// Get the const output slot handle by slot index
99 virtual const IOutputSlot& GetOutputSlot(unsigned int index) const = 0;
100
101 /// Get the output slot handle by slot index
102 virtual IOutputSlot& GetOutputSlot(unsigned int index) = 0;
103
104 /// Infer the shape of the output(s) based on the provided input shape(s)
105 virtual std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const = 0;
106
107 /// Returns the unique id of the layer
108 virtual LayerGuid GetGuid() const = 0;
109
110 /// Apply a visitor to this layer
111 virtual void ExecuteStrategy(IStrategy& strategy) const = 0;
112
113 /// Provide a hint for the optimizer as to which backend to prefer for this layer.
114 /// By providing a BackendSelectionHint there is no guarantee the input backend supports that layer.
115 /// If IsLayerSupported() returns false with the backend hint, we default to calling IsLayerSupported()
116 /// on the BackendPreferences vector. Use SetBackendId() if we can guarantee a backend supports that
117 /// layer (IsLayerSupported returns true for a specific backend).
118 virtual void BackendSelectionHint(Optional<BackendId> backend) = 0;
119
120 /// Returns the armnn::LayerType of this layer
121 virtual LayerType GetType() const = 0;
122
123 /// If the layer has a descriptor return it.
124 /// The base descriptor can then be cast to the correct descriptor class.
125 /// If the layer has no associated descriptor a struct of type NullDescriptor will be returned.
126 /// Note: NullDescriptors can be detected because they return true when
127 /// the BaseDescriptor IsNull function is invoked.
128 virtual const BaseDescriptor& GetParameters() const = 0;
129
130 /// Set the backend of the IConnectableLayer.
131 /// By using SetBackendId() we guarantee that the input backend supports that
132 /// layer (IsLayerSupported returns true for a specific backend). If there is
133 /// no guarantee the input backend supports that layer use BackendSelectionHint().
134 virtual void SetBackendId(const BackendId& id) = 0;
135
136 using ConstantTensors = std::vector<std::reference_wrapper<std::shared_ptr<ConstTensorHandle>>>;
137
138 // Returns ConstantTensors of this Layer if it has any, otherwise returns empty vector.
140
141 using ImmutableConstantTensors = std::vector<std::reference_wrapper<const std::shared_ptr<ConstTensorHandle>>>;
142
143 // Returns ConstantTensors of this Layer if it has any, otherwise returns empty vector.
145
146protected:
147 /// Objects are not deletable via the handle
149};
150
152{
153 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("Use ABI stable OptimizerOptionsOpaque instead.", "24.02")
155 : m_ReduceFp32ToFp16(false)
156 , m_Debug(false)
157 , m_DebugToFile(false)
158 , m_ReduceFp32ToBf16(false)
160 , m_ImportEnabled(false)
162 , m_ProfilingEnabled(false)
163 , m_ExportEnabled(false)
164 , m_AllowExpandedDims(false)
165 {}
166
167 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("Use ABI stable OptimizerOptionsOpaque instead.", "24.02")
168 OptimizerOptions(bool reduceFp32ToFp16, bool debug, bool reduceFp32ToBf16, bool importEnabled,
169 ModelOptions modelOptions = {}, bool exportEnabled = false, bool debugToFile = false)
170 : m_ReduceFp32ToFp16(reduceFp32ToFp16)
171 , m_Debug(debug)
172 , m_DebugToFile(debugToFile)
173 , m_ReduceFp32ToBf16(reduceFp32ToBf16)
175 , m_ImportEnabled(importEnabled)
176 , m_ModelOptions(modelOptions)
177 , m_ProfilingEnabled(false)
178 , m_ExportEnabled(exportEnabled)
179 , m_AllowExpandedDims(false)
180 {
181 }
182
183 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("Use ABI stable OptimizerOptionsOpaque instead.", "24.02")
184 OptimizerOptions(bool reduceFp32ToFp16, bool debug, bool reduceFp32ToBf16 = false,
186 bool importEnabled = false, ModelOptions modelOptions = {}, bool exportEnabled = false,
187 bool debugToFile = false, bool allowExpandedDims = false)
188 : m_ReduceFp32ToFp16(reduceFp32ToFp16)
189 , m_Debug(debug)
190 , m_DebugToFile(debugToFile)
191 , m_ReduceFp32ToBf16(reduceFp32ToBf16)
192 , m_shapeInferenceMethod(shapeInferenceMethod)
193 , m_ImportEnabled(importEnabled)
194 , m_ModelOptions(modelOptions)
195 , m_ProfilingEnabled(false)
196 , m_ExportEnabled(exportEnabled)
197 , m_AllowExpandedDims(allowExpandedDims)
198 {
199 }
200
201 const std::string ToString() const
202 {
203 std::stringstream stream;
204 stream << "OptimizerOptions: \n";
205 stream << "\tReduceFp32ToFp16: " << m_ReduceFp32ToFp16 << "\n";
206 stream << "\tReduceFp32ToBf16: " << m_ReduceFp32ToBf16 << "\n";
207 stream << "\tDebug: " << m_Debug << "\n";
208 stream << "\tDebug to file: " << m_DebugToFile << "\n";
209 stream << "\tShapeInferenceMethod: " <<
211 ? "ValidateOnly" : "InferAndValidate") << "\n";
212 stream << "\tImportEnabled: " << m_ImportEnabled << "\n";
213 stream << "\tExportEnabled: " << m_ExportEnabled << "\n";
214 stream << "\tProfilingEnabled: " << m_ProfilingEnabled << "\n";
215 stream << "\tAllowExpandedDims: " << m_AllowExpandedDims << "\n";
216
217 stream << "\tModelOptions: \n";
218 for (auto optionsGroup : m_ModelOptions)
219 {
220 for (size_t i=0; i < optionsGroup.GetOptionCount(); i++)
221 {
222 const armnn::BackendOptions::BackendOption option = optionsGroup.GetOption(i);
223 stream << "\t\tBackend: " << optionsGroup.GetBackendId() << "\n"
224 << "\t\t\tOption: " << option.GetName() << "\n"
225 << "\t\t\tValue: " << std::string(option.GetValue().ToString()) << "\n";
226 }
227 }
228
229 return stream.str();
230 }
231
232 /// Reduces all Fp32 operators in the model to Fp16 for faster processing.
233 /// @Note This feature works best if all operators of the model are in Fp32. ArmNN will add conversion layers
234 /// between layers that weren't in Fp32 in the first place or if the operator is not supported in Fp16.
235 /// The overhead of these conversions can lead to a slower overall performance if too many conversions are
236 /// required.
238
239 /// Add debug data for easier troubleshooting
241
242 /// Pass debug data to separate output files for easier troubleshooting
244
245 /// @Note This feature has been replaced by enabling Fast Math in compute library backend options.
246 /// This is currently a placeholder option
248
249 /// Infer output size when not available
251
252 /// Enable Import
254
255 /// Enable Model Options
257
258 /// Enable profiling dump of the optimizer phase
260
261 /// Enable Export
263
264 /// When calculating tensor sizes, dimensions of size == 1 will be ignored
266};
267
268/// ArmNN performs an optimization on each model/network before it gets loaded for execution. OptimizerOptions provides
269/// a set of features that allows the user to customize this optimization on a per model basis.
271
273{
274public:
278
279 OptimizerOptionsOpaque(const OptimizerOptions& OptimizerStruct);
280
282
283 OptimizerOptionsOpaque(bool reduceFp32ToFp16, bool debug, bool reduceFp32ToBf16, bool importEnabled,
284 ModelOptions modelOptions = {}, bool exportEnabled = false, bool debugToFile = false);
285
286 OptimizerOptionsOpaque(bool reduceFp32ToFp16, bool debug, bool reduceFp32ToBf16 = false,
288 bool importEnabled = false, ModelOptions modelOptions = {}, bool exportEnabled = false,
289 bool debugToFile = false, bool allowExpandedDims = false);
290
291 const std::string ToString() const;
292
293 bool GetProfilingEnabled() const;
294
295 bool GetImportEnabled() const;
296
297 bool GetExportEnabled() const;
298
299 bool GetReduceFp32ToFp16() const;
300
301 bool GetReduceFp32ToBf16() const;
302
303 bool GetDebugEnabled() const;
304
305 bool GetDebugToFileEnabled() const;
306
307 bool GetAllowExpandedDims() const;
308
310
312
313 void SetImportEnabled(bool ImportState);
314
315 void SetExportEnabled(bool ExportState);
316
317 void SetProfilingEnabled(bool ProfilingState);
318
319 void SetDebugEnabled(bool DebugState);
320
321 void SetDebugToFileEnabled(bool DebugFileState);
322
323 void SetReduceFp32ToFp16(bool ReduceFp32ToFp16State);
324
325 void SetShapeInferenceMethod(armnn::ShapeInferenceMethod ShapeInferenceMethodType);
326
328
329 void SetAllowExpandedDims(bool ExpandedDimsAllowed);
330
331private:
332
333 std::unique_ptr<armnn::OptimizerOptionsOpaqueImpl> p_OptimizerOptionsImpl;
334
335};
336
337class IWorkloadFactory;
338class NetworkImpl;
339using INetworkPtr = std::unique_ptr<INetwork, void(*)(INetwork* network)>;
340using IOptimizedNetworkPtr = std::unique_ptr<IOptimizedNetwork, void(*)(IOptimizedNetwork* network)>;
341
342using CompiledBlobDeleter = std::function<void(const void*)>;
343using CompiledBlobPtr = std::unique_ptr<void, CompiledBlobDeleter>;
344
345/// Main network class which provides the interface for building up a neural network.
346/// This object is subsequently required by the IRuntime::Load() method.
348{
349public:
350 static INetwork* CreateRaw(const NetworkOptions& networkOptions = {});
351 static INetworkPtr Create(const NetworkOptions& networkOptions = {});
352 static void Destroy(INetwork* network);
353
355
356 /// Adds an input layer to the network.
357 /// @param id - User generated id to uniquely identify a particular input. The same id needs to be specified.
358 /// when passing the inputs to the IRuntime::EnqueueWorkload() function.
359 /// @param name - Optional name for the layer.
360 /// @return - Interface for configuring the layer.
361 IConnectableLayer* AddInputLayer(LayerBindingId id, const char* name = nullptr);
362
363 /// Adds an ArgMinMax layer to the network.
364 /// @param desc - Parameters for the L2 normalization operation.
365 /// @param name - Optional name for the layer.
366 /// @return - Interface for configuring the layer.
368 const char* name = nullptr);
369
370 /// Adds a cast layer to the network.
371 /// @param name - Optional name for the layer.
372 /// @return - Interface for configuring the layer.
373 IConnectableLayer* AddCastLayer(const char* name = nullptr);
374
375 /// Add a Comparison layer to the network.
376 /// @param name - Optional name for the layer.
377 /// @param desc - Descriptor for the comparison operation.
378 /// @return - Interface for configuring the layer.
379 IConnectableLayer* AddComparisonLayer(const ComparisonDescriptor& comparisonDescriptor,
380 const char* name = nullptr);
381
382 /// Adds a concatenation layer to the network.
383 /// @param concatDescriptor - ConcatDescriptor (synonym for OriginsDescriptor) to configure the concatenation
384 /// process. Number of Views must be equal to the number of inputs, and their order
385 /// must match - e.g. first view corresponds to the first input, second view to the
386 /// second input, etc....
387 /// @param name - Optional name for the layer.
388 /// @return - Interface for configuring the layer.
389 IConnectableLayer* AddConcatLayer(const ConcatDescriptor& concatDescriptor,
390 const char* name = nullptr);
391
392 /// Adds a 2D convolution layer to the network.
393 /// @param convolution2dDescriptor - Description of the 2D convolution layer.
394 /// @param name - Optional name for the layer.
395 /// @return - Interface for configuring the layer.
397 const char* name = nullptr);
398
399 /// Adds a 3D convolution layer to the network.
400 /// @param convolution3dDescriptor - Description of the 3D convolution layer.
401 /// @param name - Optional name for the layer.
402 /// @return - Interface for configuring the layer.
404 const char* name = nullptr);
405
406 /// Adds a depth to space layer to the network.
407 /// @param depthToSpaceDescriptor - Parameters for the depth to space operation.
408 /// @param name - Optional name for the layer.
409 /// @return - Interface for configuring the layer.
411 const char* name = nullptr);
412
413 /// Adds a 2D depthwise convolution layer to the network.
414 /// @param convolution2dDescriptor - Description of the 2D depthwise convolution layer.
415 /// @param name - Optional name for the layer.
416 /// @return - Interface for configuring the layer.
418 const char* name = nullptr);
419
420 /// Adds a Dequantize layer to the network.
421 /// @return - Interface for configuring the layer.
422 IConnectableLayer* AddDequantizeLayer(const char* name = nullptr);
423
424 /// Adds a Detection PostProcess layer to the network.
425 /// @param descriptor - Description of the Detection PostProcess layer.
426 /// @param anchors - Tensor for anchors.
427 /// @param name - Optional name for the layer.
428 /// @return - Interface for configuring the layer.
430 const DetectionPostProcessDescriptor& descriptor,
431 const ConstTensor& anchors,
432 const char* name = nullptr);
433
434 /// Add an ElementwiseBinary layer to the network.
435 /// @param name - Optional name for the layer.
436 /// @param desc - Descriptor for the elementwiseBinary operations.
437 /// @return - Interface for configuring the layer.
439 const char* name = nullptr);
440
441 /// Add an ElementwiseUnary layer to the network.
442 /// @param name - Optional name for the layer.
443 /// @param desc - Descriptor for the elementwiseUnary operations.
444 /// @return - Interface for configuring the layer.
446 const char* name = nullptr);
447
448 /// Add an Fill layer to the network.
449 /// @param name - Optional name for the layer.
450 /// @param fillDescriptor - Descriptor for the fill operation.
451 /// @return - Interface for configuring the layer.
452 IConnectableLayer* AddFillLayer(const FillDescriptor& fillDescriptor,
453 const char* name = nullptr);
454
455
456 /// Adds a fully connected layer to the network.
457 /// @param fullyConnectedDescriptor - Description of the fully connected layer.
458 /// @return - Interface for configuring the layer.
459 ///
460 /// @note Weights and biases are passed in as inputs. If they are constant tensors you can simply store
461 /// them in a ConstantLayer as seen below. A full example can be found in samples/SimpleSample.cpp.
462 ///
463 /// @code
464 /// // Make sure the IsConstant flag is set on the weightsInfo before passing it to the ConstTensor.
465 /// ConstTensor weights(weightsInfo, weightsData);
466 ///
467 /// // Constant layer that now holds weights data for FullyConnected
468 /// IConnectableLayer* const constantWeightsLayer = myNetwork->AddConstantLayer(weights, "weights");
469 ///
470 /// FullyConnectedDescriptor fullyConnectedDesc;
471 /// IConnectableLayer* const fullyConnectedLayer = myNetwork->AddFullyConnectedLayer(fullyConnectedDesc,
472 /// "fully connected");
473 /// IConnectableLayer* InputLayer = myNetwork->AddInputLayer(0);
474 /// InputLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(0));
475 /// constantWeightsLayer->GetOutputSlot(0).Connect(fullyConnectedLayer->GetInputSlot(1));
476 /// @endcode
478 const char* name = nullptr);
479
480 /// Adds a Fused layer to the network.
481 /// Method use is for backend users.
482 /// @param fusedDescriptor - FusedDescriptor contains parameters for the Fused layer.
483 /// @param name - Optional name for the layer.
484 /// @return - Interface for configuring the layer.
485 IConnectableLayer* AddFusedLayer(const FusedDescriptor& fusedDescriptor,
486 const char* name = nullptr);
487
488 /// Adds a permute layer to the network.
489 /// @param permuteDescriptor - PermuteDescriptor to configure the permute.
490 /// @param name - Optional name for the layer.
491 /// @return - Interface for configuring the layer.
492 IConnectableLayer* AddPermuteLayer(const PermuteDescriptor& permuteDescriptor,
493 const char* name = nullptr);
494
495 /// Adds a batch to space ND layer to the network.
496 /// @param batchToSpaceNdDescriptor - Description of the layer.
497 /// @param name - Optional name for the layer.
498 /// @return - Interface for configuring the layer.
500 const char* name = nullptr);
501
502 /// Adds a 2D pooling layer to the network.
503 /// @param pooling2dDescriptor - Pooling2dDescriptor to configure the pooling.
504 /// @param name - Optional name for the layer.
505 /// @return - Interface for configuring the layer.
506 IConnectableLayer* AddPooling2dLayer(const Pooling2dDescriptor& pooling2dDescriptor,
507 const char* name = nullptr);
508
509 /// Adds a 3D pooling layer to the network.
510 /// @param pooling3dDescriptor - Pooling3dDescriptor to configure the pooling.
511 /// @param name - Optional name for the layer.
512 /// @return - Interface for configuring the layer.
513 IConnectableLayer* AddPooling3dLayer(const Pooling3dDescriptor& pooling3dDescriptor,
514 const char* name = nullptr);
515
516 /// Adds a Precompiled layer to the network.
517 /// Method use is for backend users.
518 /// @param preCompiledDescriptor - PreCompiledDescriptor contains parameters for the Precompiled layer.
519 /// @param compiledBlobPtr - CompiledBlobPtr pre-compiled object set for the Precompiled layer.
520 /// @param backend - optional BackendId set for the Precompiled layer.
521 /// @return - Interface for configuring the layer.
522 IConnectableLayer* AddPrecompiledLayer(const PreCompiledDescriptor& preCompiledDescriptor,
523 CompiledBlobPtr compiledBlobPtr,
524 const Optional<BackendId>& backend,
525 const char* name = nullptr);
526
527 /// Adds an activation layer to the network.
528 /// @param activationDescriptor - ActivationDescriptor to configure the activation.
529 /// @param name - Optional name for the layer.
530 /// @return - Interface for configuring the layer.
531 IConnectableLayer* AddActivationLayer(const ActivationDescriptor& activationDescriptor,
532 const char* name = nullptr);
533
534 /// Adds a normalization layer to the network.
535 /// @param normalizationDescriptor - NormalizationDescriptor to configure the normalization.
536 /// @param name - Optional name for the layer.
537 /// @return - Interface for configuring the layer.
539 const char* name = nullptr);
540
541 /// Adds a slice layer to the network.
542 /// @param sliceDescriptor - SliceDescriptor to configure the slice operation.
543 /// @param name - Optional name for the layer.
544 /// @return - Interface for configuring the layer.
545 IConnectableLayer* AddSliceLayer(const SliceDescriptor& sliceDescriptor, const char* name = nullptr);
546
547 /// Adds a softmax layer to the network.
548 /// If the data type is QAsymm8, then the output quantization parameters
549 /// must have a scale of 1/256 and an offset of 0
550 /// @param softmaxDescriptor - SoftmaxDescriptor to configure the softmax.
551 /// @param name - Optional name for the layer.
552 /// @return - Interface for configuring the layer.
553 IConnectableLayer* AddSoftmaxLayer(const SoftmaxDescriptor& softmaxDescriptor,
554 const char* name = nullptr);
555
556 /// Adds a splitter layer to the network.
557 /// @param splitterDescriptor - ViewsDescriptor to configure the splitting process.
558 /// Number of Views must be equal to the number of outputs,
559 /// and their order must match - e.g. first view corresponds to
560 /// the first output, second view to the second output, etc....
561 /// @param name - Optional name for the layer.
562 /// @return - Interface for configuring the layer.
563 IConnectableLayer* AddSplitterLayer(const ViewsDescriptor& splitterDescriptor,
564 const char* name = nullptr);
565
566 /// Adds a merge layer to the network.
567 /// @param name - Optional name for the layer.
568 /// @return - Interface for configuring the layer.
569 IConnectableLayer* AddMergeLayer(const char* name = nullptr);
570
571 /// Adds an addition layer to the network.
572 /// @param name - Optional name for the layer.
573 /// @return - Interface for configuring the layer.
574 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("Use AddElementwiseBinaryLayer instead", "24.02")
575 IConnectableLayer* AddAdditionLayer(const char* name = nullptr);
576
577 /// Adds a multiplication layer to the network.
578 /// @param name - Optional name for the layer.
579 /// @return - Interface for configuring the layer.
580 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("Use AddElementwiseBinaryLayer instead", "24.02")
581 IConnectableLayer* AddMultiplicationLayer(const char* name = nullptr);
582
583 /// Adds a batch normalization layer to the network.
584 /// @param mean - Pre-calculated mean for each channel.
585 /// @param variance - Pre-calculated variance for each channel.
586 /// @param beta - Per-channel additive factor.
587 /// @param gamma - Per-channel multiplicative factor.
588 /// @return - Interface for configuring the layer.
589 /// @param name - Optional name for the layer.
591 const ConstTensor& mean,
592 const ConstTensor& variance,
593 const ConstTensor& beta,
594 const ConstTensor& gamma,
595 const char* name = nullptr);
596
597 /// Adds a rank layer to the network.
598 /// @param name - Optional name for the layer.
599 /// @return - Interface for configuring the layer.
600 IConnectableLayer* AddRankLayer(const char* name = nullptr);
601
602 /// Adds a resize layer to the network.
603 /// @param resizeDescriptor - Parameters for the resize operation.
604 /// @param name - Optional name for the layer.
605 /// @return - Interface for configuring the layer.
606 IConnectableLayer* AddResizeLayer(const ResizeDescriptor& resizeDescriptor,
607 const char* name = nullptr);
608
609 /// Adds a reduce layer to the network.
610 /// @param ReduceDescriptor - Parameters for the reduce operation.
611 /// @param name - Optional name for the layer.
612 /// @return - Interface for configuring the layer.
613 IConnectableLayer* AddReduceLayer(const ReduceDescriptor& reduceDescriptor,
614 const char* name = nullptr);
615
616 /// Adds an instance normalization layer to the network.
617 /// @param desc - Parameters for the instance normalization operation.
618 /// @param name - Optional name for the layer.
619 /// @return - Interface for configuring the layer.
621 const char* name = nullptr);
622
623 /// Adds an L2 normalization layer to the network.
624 /// Normalization is performed along dimension 1, but requires a 4d input.
625 /// @param desc - Parameters for the L2 normalization operation.
626 /// @param name - Optional name for the layer.
627 /// @return - Interface for configuring the layer.
629 const char* name = nullptr);
630
631 /// Adds a log softmax layer to the network.
632 /// @param logSoftmaxDescriptor - LogSoftmaxDescriptor to configure the log softmax.
633 /// @param name - Optional name for the layer.
634 /// @return - Interface for configuring the layer.
635 IConnectableLayer* AddLogSoftmaxLayer(const LogSoftmaxDescriptor& logSoftmaxDescriptor,
636 const char* name = nullptr);
637
638 /// Adds a layer with no inputs and a single output, which always corresponds to
639 /// the passed in constant tensor.
640 /// @param input - Tensor to be provided as the only output of the layer. The layer will maintain
641 /// its own copy of the tensor data, meaning the memory referenced by @a input can
642 /// be freed or reused after this function is called.
643 /// @param name - Optional name for the layer.
644 /// @return - Interface for configuring the layer.
646 const char* name = nullptr);
647
648 /// Adds a reshape layer to the network.
649 /// @param reshapeDescriptor - Parameters for the reshape operation.
650 /// @param name - Optional name for the layer.
651 /// @return - Interface for configuring the layer.
652 IConnectableLayer* AddReshapeLayer(const ReshapeDescriptor& reshapeDescriptor,
653 const char* name = nullptr);
654
655 /// Adds a shape layer to the network.
656 /// @param name - Optional name for the layer.
657 /// @return - Interface for configuring the layer.
658 IConnectableLayer* AddShapeLayer(const char* name = nullptr);
659
660 /// Adds a space to batch layer to the network.
661 /// @param spaceToBatchNdDescriptor - Parameters for the space to batch operation.
662 /// @param name - Optional name for the layer.
663 /// @return - Interface for configuring the layer.
665 const char* name = nullptr);
666
667 /// Adds a space to depth layer to the network.
668 /// @param spaceToDepthDescriptor - Parameters for the space to depth operation.
669 /// @param name - Optional name for the layer.
670 /// @return - Interface for configuring the layer.
672 const char* name = nullptr);
673
674 /// Adds a floor layer to the network.
675 /// @param name - Optional name for the layer.
676 /// @return - Interface for configuring the layer.
677 IConnectableLayer* AddFloorLayer(const char* name = nullptr);
678
679 /// Adds an output layer to the network.
680 /// @param id - User generated id to uniquely identify a particular output. The same id needs to be specified
681 /// when passing the outputs to the IRuntime::EnqueueWorkload() function.
682 /// @param name - Optional name for the layer.
683 /// @return - Interface for configuring the layer.
684 IConnectableLayer* AddOutputLayer(LayerBindingId id, const char* name = nullptr);
685
686 /// Add a Lstm layer to the network
687 /// @param descriptor - Parameters for the Lstm operation
688 /// @param params - Weights and biases for the LSTM cell
689 /// @param name - Optional name for the layer
690 /// @return - Interface for configuring the layer.
692 const LstmInputParams& params,
693 const char* name = nullptr);
694
695 /// Adds a division layer to the network.
696 /// @param name - Optional name for the layer.
697 /// @return - Interface for configuring the layer.
698 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("Use AddElementwiseBinaryLayer instead", "24.02")
699 IConnectableLayer* AddDivisionLayer(const char* name = nullptr);
700
701 /// Adds a subtraction layer to the network.
702 /// @param name - Optional name for the layer.
703 /// @return - Interface for configuring the layer.
704 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("Use AddElementwiseBinaryLayer instead", "24.02")
705 IConnectableLayer* AddSubtractionLayer(const char* name = nullptr);
706
707 /// Add a Maximum layer to the network.
708 /// @param name - Optional name for the layer.
709 /// @return - Interface for configuring the layer.
710 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("Use AddElementwiseBinaryLayer instead", "24.02")
711 IConnectableLayer* AddMaximumLayer(const char* name = nullptr);
712
713 /// Add a Mean layer to the network.
714 /// @param meanDescriptor - Parameters for the mean operation.
715 /// @param name - Optional name for the layer.
716 /// @return - Interface for configuring the layer.
717 IConnectableLayer* AddMeanLayer(const MeanDescriptor& meanDescriptor, const char* name = nullptr);
718
719 /// Adds a fully pad layer to the network.
720 /// @param paddings - n by 2 tensor, where n is the rank of the input tensor,
721 /// such that paddings[i,0] indicates the amount of padding to add in front of dimonsion i, and
722 /// paddings[i,1] indicates the amount of padding to add after the end of dimension i
723 /// @param name - Optional name for the layer.
724 /// @return - Interface for configuring the layer.
725 IConnectableLayer* AddPadLayer(const PadDescriptor& padDescriptor,
726 const char* name = nullptr);
727
728 /// Add a quantize layer to the network
729 ///@param name - Optional name for the layer.
730 /// @return - Interface for configuring the layer.
731 IConnectableLayer* AddQuantizeLayer(const char* name = nullptr);
732
733 /// Adds a strided slice layer to the network.
734 /// @param StridedSliceDescriptor - Parameters for the strided slice operation.
735 /// @param name - Optional name for the layer.
736 /// @return - Interface for configuring the layer.
738 const char* name = nullptr);
739
740 /// Add a Minimum layer to the network.
741 /// @param name - Optional name for the layer.
742 /// @return - Interface for configuring the layer.
743 ARMNN_DEPRECATED_MSG_REMOVAL_DATE("Use AddElementwiseBinaryLayer instead", "24.02")
744 IConnectableLayer* AddMinimumLayer(const char* name = nullptr);
745
746 /// Add Gather layer to the network.
747 /// @param descriptor - Description of the gather layer.
748 /// @param name - Optional name for the layer.
749 /// @return - Interface for configuring the layer.
751 const char* name = nullptr);
752
753 /// Add GatherNd layer to the network.
754 /// @param name - Optional name for the layer.
755 /// @return - Interface for configuring the layer.
756 IConnectableLayer* AddGatherNdLayer(const char* name = nullptr);
757
758 /// Adds a switch layer to the network.
759 /// @param name - Optional name for the layer.
760 /// @return - Interface for configuring the layer.
761 IConnectableLayer* AddSwitchLayer(const char* name = nullptr);
762
763 /// Adds a PReLU layer to the network.
764 /// @param name - Optional name for the layer.
765 /// @return - Interface for configuring the layer.
766 IConnectableLayer* AddPreluLayer(const char* name = nullptr);
767
768 /// Adds a 2D transpose convolution layer to the network.
769 /// @param descriptor - Description of the 2D transpose convolution layer.
770 /// @param weights - Tensor for the weights data.
771 /// @param biases - Optional tensor for the bias data.
772 /// @param name - Optional name for the layer.
773 /// @return - Interface for configuring the layer.
775 const ConstTensor& weights,
776 const Optional<ConstTensor>& biases,
777 const char* name = nullptr);
778
779 /// Adds a transpose layer to the network.
780 /// @param transposeDescriptor - TransposeDescriptor to configure the transpose.
781 /// @param name - Optional name for the layer.
782 /// @return - Interface for configuring the layer.
783 IConnectableLayer* AddTransposeLayer(const TransposeDescriptor& transposeDescriptor,
784 const char* name = nullptr);
785
786 /// Adds a stack layer to the network.
787 /// @param descriptor - Description of the stack layer.
788 /// @param name - Optional name for the layer.
789 /// @return - Interface for configuring the layer.
791 const char* name = nullptr);
792
793 /// Add a stand-in layer for a type unknown to the Arm NN framework.
794 /// Note: Due to the nature of this layer, no validation can be performed by the framework.
795 /// Furthermore, Any model containing this layer cannot make use of dynamic tensors since the
796 /// tensor sizes cannot be inferred.
797 /// @descriptor - Descriptor for the StandIn layer.
798 /// @return - Interface for configuring the layer.
800 const char* name = nullptr);
801
802 /// Add a QuantizedLstm layer to the network
803 /// @param params - The weights and biases for the Quantized LSTM cell
804 /// @param name - Optional name for the layer
805 /// @return - Interface for configuring the layer.
807 const char* name = nullptr);
808
809 /// Add a QLstm layer to the network
810 /// @param descriptor - Parameters for the QLstm operation
811 /// @param params - Weights and biases for the layer
812 /// @param name - Optional name for the layer
813 /// @return - Interface for configuring the layer.
815 const LstmInputParams& params,
816 const char* name = nullptr);
817
818 /// Adds a Logical Binary layer to the network.
819 /// @param descriptor - Description of the Logical Binary layer.
820 /// @param name - Optional name for the layer.
821 /// @return - Interface for configuring the layer.
823 const char* name = nullptr);
824
825 /// Add a UnidirectionalSequenceLstm layer to the network
826 /// @param descriptor - Parameters for the UnidirectionalSequenceLstm operation
827 /// @param params - Weights and biases for the UnidirectionalSequenceLstm
828 /// @param name - Optional name for the layer
829 /// @return - Interface for configuring the layer.
831 const LstmInputParams& params,
832 const char* name = nullptr);
833
834 /// Add a ChannelShuffle layer to the network
835 /// @param descriptor - Parameters for the ChannelShuffle operation
836 /// @param name - Optional name for the layer
837 /// @return - Interface for configuring the layer
839 const char* name = nullptr);
840
841 /// Add a BatchMatMul layer to the network
842 /// @param descriptor - Parameters for the BatchMatMul operation
843 /// @param name - Optional name for the layer
844 /// @return - Interface for configuring the layer
846 const char* name = nullptr);
847
848 /// Add a ReverseV2 layer to the network
849 /// @param name - Optional name for the layer
850 /// @return - Interface for configuring the layer
851 IConnectableLayer* AddReverseV2Layer(const char* name = nullptr);
852
853 /// Add a Tile layer to the network
854 /// @param descriptor - Parameters for the Tile operation
855 /// @param name - Optional name for the layer
856 /// @return - Interface for configuring the layer
858 const char* name = nullptr);
859
860 /// Add a BroadcastTo layer to the network
861 /// @param descriptor - Parameters for the BroadcastTo operation
862 /// @param name - Optional name for the layer
863 /// @return - Interface for configuring the layer
865 const char* name = nullptr);
866
867 /// Add a ScatterNd layer to the network
868 /// @param descriptor - Parameters for the ScatterNd operation
869 /// @param name - Optional name for the layer
870 /// @return - Interface for configuring the layer
872 const char* name = nullptr);
873
874 void ExecuteStrategy(IStrategy& strategy) const;
875
876protected:
878
879 friend void VisitLayersTopologically(const INetwork* inputNetwork, IStrategy& strategy);
881 friend TensorInfo GetInputTensorInfo(const INetwork* network);
882 friend IOptimizedNetworkPtr Optimize(const INetwork& network,
883 const std::vector<BackendId>& backendPreferences,
884 const IDeviceSpec& deviceSpec,
885 const OptimizerOptions& options,
886 Optional<std::vector<std::string>&> messages);
887 friend IOptimizedNetworkPtr Optimize(const INetwork& network,
888 const std::vector<BackendId>& backendPreferences,
889 const IDeviceSpec& deviceSpec,
890 const OptimizerOptionsOpaque& options,
891 Optional<std::vector<std::string>&> messages);
892
893 INetwork(NetworkOptions networkOptions = {});
894
895 std::unique_ptr<NetworkImpl> pNetworkImpl;
896};
897
898struct BackendSettings;
899struct OptimizationResult;
901class IProfiler;
903{
904public:
905 static void Destroy(IOptimizedNetwork* network);
906
908 Status SerializeToDot(std::ostream& stream) const;
909
910 arm::pipe::ProfilingGuid GetGuid() const;
911
912 size_t GetNumInputs() const;
913 size_t GetNumOutputs() const;
914
915 void ExecuteStrategy(IStrategy& strategy) const;
916
917 /// Creates a copy of the IOptimizedNetwork. The IOptimizedNetwork will not be reoptimized,
918 /// the provided ModelOptions will only be used when creating a LoadedNetwork.
919 IOptimizedNetwork(const IOptimizedNetwork& other, const ModelOptions& modelOptions);
920 IOptimizedNetwork(std::unique_ptr<Graph> graph);
921 IOptimizedNetwork(std::unique_ptr<OptimizedNetworkImpl> impl);
923
924 const std::shared_ptr<IProfiler>& GetProfiler() const;
925
926protected:
927 friend class LoadedNetwork;
928
929 friend Graph& GetGraphForTesting(IOptimizedNetwork* optNetPtr);
931 friend IOptimizedNetworkPtr Optimize(const INetwork& inNetwork,
932 const std::vector<BackendId>& backendPreferences,
933 const IDeviceSpec& deviceSpec,
934 const OptimizerOptionsOpaque& options,
935 Optional<std::vector<std::string>&> messages);
936 friend IOptimizedNetworkPtr Optimize(const Graph& inGraph,
937 const std::vector<BackendId>& backendPreferences,
938 const IDeviceSpec& deviceSpec,
939 const OptimizerOptionsOpaque& options,
940 Optional<std::vector<std::string>&> messages);
941
942 IOptimizedNetwork(std::unique_ptr<Graph> graph, const ModelOptions& modelOptions);
943
944 std::unique_ptr<OptimizedNetworkImpl> pOptimizedNetworkImpl;
945};
946
947/// Create an optimized version of the network
948/// @param network INetwork description of the network to be optimized.
949/// @param backendPreferences The choice of the backend ordered by user preferences.
950/// @param deviceSpec DeviceSpec object as queried from the runtime. See IRuntime::GetDeviceSpec()
951/// @param messages If there are failures or warnings a string describing same will be added to the vector
952/// @param options OptimizerOptions object with optimizer configuration options
953/// @return An IOptimizedNetworkPtr interface to the optimized network, throws an exception derived from
954/// armnn::Exception if process fails.
955
957 const std::vector<BackendId>& backendPreferences,
958 const IDeviceSpec& deviceSpec,
960 Optional<std::vector<std::string>&> messages = EmptyOptional());
961
962/// Create an optimized version of the network
963/// @param inGraph Graph to be optimized.
964/// @param backendPreferences The choice of the backend ordered by user preferences.
965/// @param deviceSpec DeviceSpec object as queried from the runtime. See IRuntime::GetDeviceSpec()
966/// @param messages If there are failures or warnings a string describing same will be added to the vector
967/// @param options OptimizerOptions object with optimizer configuration options
968/// @return An IOptimizedNetworkPtr interface to the optimized network, throws an exception derived from
969/// armnn::Exception if process fails.
970
971IOptimizedNetworkPtr Optimize(const Graph& inGraph,
972 const std::vector<BackendId>& backendPreferences,
973 const IDeviceSpec& deviceSpec,
974 const OptimizerOptionsOpaque& options,
975 Optional<std::vector<std::string>&> messages = EmptyOptional());
976
977/// Accept legacy OptimizerOptions
978IOptimizedNetworkPtr Optimize(const Graph& inGraph,
979 const std::vector<BackendId>& backendPreferences,
980 const IDeviceSpec& deviceSpec,
981 const OptimizerOptions& options,
982 Optional<std::vector<std::string>&> messages = EmptyOptional());
983
984/// Accept legacy OptimizerOptions
986 const std::vector<BackendId>& backendPreferences,
987 const IDeviceSpec& deviceSpec,
988 const OptimizerOptions& options,
989 Optional<std::vector<std::string>&> messages = EmptyOptional());
990
991} //namespace armnn
#define ARMNN_DEPRECATED_MSG_REMOVAL_DATE(message, removed_in_release)
arm::pipe::ProfilingGuid LayerGuid
Define LayerGuid type.
Definition Types.hpp:26
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition Tensor.hpp:330
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition INetwork.hpp:81
std::vector< std::reference_wrapper< std::shared_ptr< ConstTensorHandle > > > ConstantTensors
Definition INetwork.hpp:136
virtual const IInputSlot & GetInputSlot(unsigned int index) const =0
Get a const input slot handle by slot index.
virtual const BaseDescriptor & GetParameters() const =0
If the layer has a descriptor return it.
std::vector< std::reference_wrapper< const std::shared_ptr< ConstTensorHandle > > > ImmutableConstantTensors
Definition INetwork.hpp:141
virtual const IOutputSlot & GetOutputSlot(unsigned int index) const =0
Get the const output slot handle by slot index.
virtual std::vector< TensorShape > InferOutputShapes(const std::vector< TensorShape > &inputShapes) const =0
Infer the shape of the output(s) based on the provided input shape(s)
virtual ConstantTensors GetConstantTensorsByRef()=0
virtual void ExecuteStrategy(IStrategy &strategy) const =0
Apply a visitor to this layer.
virtual IInputSlot & GetInputSlot(unsigned int index)=0
Get the input slot handle by slot index.
virtual void BackendSelectionHint(Optional< BackendId > backend)=0
Provide a hint for the optimizer as to which backend to prefer for this layer.
~IConnectableLayer()
Objects are not deletable via the handle.
Definition INetwork.hpp:148
virtual IOutputSlot & GetOutputSlot(unsigned int index)=0
Get the output slot handle by slot index.
virtual void SetBackendId(const BackendId &id)=0
Set the backend of the IConnectableLayer.
virtual unsigned int GetNumInputSlots() const =0
Returns the number of connectable input slots.
virtual unsigned int GetNumOutputSlots() const =0
Returns the number of connectable output slots.
virtual LayerType GetType() const =0
Returns the armnn::LayerType of this layer.
virtual ImmutableConstantTensors GetConstantTensorsByRef() const =0
virtual LayerGuid GetGuid() const =0
Returns the unique id of the layer.
virtual const char * GetName() const =0
Returns the name of the layer.
Device specific knowledge to be passed to the optimizer.
Definition Types.hpp:302
An input connection slot for a layer.
Definition INetwork.hpp:26
virtual IConnectableLayer & GetOwningIConnectableLayer()=0
virtual const IOutputSlot * GetConnection() const =0
virtual IOutputSlot * GetConnection()=0
virtual unsigned int GetSlotIndex() const =0
virtual bool IsTensorInfoSet() const =0
Returns true if this InputSlot either has an overridden TensorInfo for this InputSlot that was set th...
virtual const IConnectableLayer & GetOwningIConnectableLayer() const =0
virtual void SetTensorInfo(const TensorInfo tensorInfo)=0
Sets the TensorInfo for this InputSlot.
virtual const TensorInfo & GetTensorInfo() const =0
Gets the TensorInfo for this InputSlot.
virtual bool IsTensorInfoOverridden() const =0
Returns true if this InputSlot has an overridden TensorInfo that was set through a call to SetTensorI...
~IInputSlot()
Not user deletable.
Definition INetwork.hpp:48
Main network class which provides the interface for building up a neural network.
Definition INetwork.hpp:348
IConnectableLayer * AddFusedLayer(const FusedDescriptor &fusedDescriptor, const char *name=nullptr)
Adds a Fused layer to the network.
Definition Network.cpp:338
IConnectableLayer * AddElementwiseUnaryLayer(const ElementwiseUnaryDescriptor &elementwiseUnaryDescriptor, const char *name=nullptr)
Add an ElementwiseUnary layer to the network.
Definition Network.cpp:320
IConnectableLayer * AddLstmLayer(const LstmDescriptor &descriptor, const LstmInputParams &params, const char *name=nullptr)
Add a Lstm layer to the network.
Definition Network.cpp:501
IConnectableLayer * AddDivisionLayer(const char *name=nullptr)
Adds a division layer to the network.
Definition Network.cpp:508
IConnectableLayer * AddQuantizeLayer(const char *name=nullptr)
Add a quantize layer to the network.
Definition Network.cpp:540
friend TensorInfo GetInputTensorInfo(const INetwork *network)
IConnectableLayer * AddMergeLayer(const char *name=nullptr)
Adds a merge layer to the network.
Definition Network.cpp:404
IConnectableLayer * AddPermuteLayer(const PermuteDescriptor &permuteDescriptor, const char *name=nullptr)
Adds a permute layer to the network.
Definition Network.cpp:344
IConnectableLayer * AddSpaceToDepthLayer(const SpaceToDepthDescriptor &spaceToDepthDescriptor, const char *name=nullptr)
Adds a space to depth layer to the network.
Definition Network.cpp:486
IConnectableLayer * AddConstantLayer(const ConstTensor &input, const char *name=nullptr)
Adds a layer with no inputs and a single output, which always corresponds to the passed in constant t...
Definition Network.cpp:468
IConnectableLayer * AddGatherLayer(const GatherDescriptor &descriptor, const char *name=nullptr)
Add Gather layer to the network.
Definition Network.cpp:558
IConnectableLayer * AddRankLayer(const char *name=nullptr)
Adds a rank layer to the network.
Definition Network.cpp:433
IConnectableLayer * AddSwitchLayer(const char *name=nullptr)
Adds a switch layer to the network.
Definition Network.cpp:569
IConnectableLayer * AddQLstmLayer(const QLstmDescriptor &descriptor, const LstmInputParams &params, const char *name=nullptr)
Add a QLstm layer to the network.
Definition Network.cpp:616
INetwork(NetworkOptions networkOptions={})
Definition Network.cpp:45
IConnectableLayer * AddSoftmaxLayer(const SoftmaxDescriptor &softmaxDescriptor, const char *name=nullptr)
Adds a softmax layer to the network.
Definition Network.cpp:392
IConnectableLayer * AddDequantizeLayer(const char *name=nullptr)
Adds a Dequantize layer to the network.
Definition Network.cpp:300
IConnectableLayer * AddBroadcastToLayer(const BroadcastToDescriptor &descriptor, const char *name=nullptr)
Add a BroadcastTo layer to the network.
Definition Network.cpp:660
IConnectableLayer * AddConvolution2dLayer(const Convolution2dDescriptor &convolution2dDescriptor, const char *name=nullptr)
Adds a 2D convolution layer to the network.
Definition Network.cpp:272
IConnectableLayer * AddAdditionLayer(const char *name=nullptr)
Adds an addition layer to the network.
Definition Network.cpp:409
IConnectableLayer * AddQuantizedLstmLayer(const QuantizedLstmInputParams &params, const char *name=nullptr)
Add a QuantizedLstm layer to the network.
Definition Network.cpp:610
static INetworkPtr Create(const NetworkOptions &networkOptions={})
Definition Network.cpp:682
IConnectableLayer * AddTransposeConvolution2dLayer(const TransposeConvolution2dDescriptor &descriptor, const ConstTensor &weights, const Optional< ConstTensor > &biases, const char *name=nullptr)
Adds a 2D transpose convolution layer to the network.
Definition Network.cpp:579
std::unique_ptr< NetworkImpl > pNetworkImpl
Definition INetwork.hpp:895
IConnectableLayer * AddFloorLayer(const char *name=nullptr)
Adds a floor layer to the network.
Definition Network.cpp:492
IConnectableLayer * AddConvolution3dLayer(const Convolution3dDescriptor &convolution3dDescriptor, const char *name=nullptr)
Adds a 3D convolution layer to the network.
Definition Network.cpp:278
IConnectableLayer * AddFullyConnectedLayer(const FullyConnectedDescriptor &fullyConnectedDescriptor, const char *name=nullptr)
Adds a fully connected layer to the network.
Definition Network.cpp:332
IConnectableLayer * AddMinimumLayer(const char *name=nullptr)
Add a Minimum layer to the network.
Definition Network.cpp:551
IConnectableLayer * AddStackLayer(const StackDescriptor &descriptor, const char *name=nullptr)
Adds a stack layer to the network.
Definition Network.cpp:598
static void Destroy(INetwork *network)
Definition Network.cpp:687
IConnectableLayer * AddMaximumLayer(const char *name=nullptr)
Add a Maximum layer to the network.
Definition Network.cpp:522
IConnectableLayer * AddNormalizationLayer(const NormalizationDescriptor &normalizationDescriptor, const char *name=nullptr)
Adds a normalization layer to the network.
Definition Network.cpp:382
IConnectableLayer * AddPreluLayer(const char *name=nullptr)
Adds a PReLU layer to the network.
Definition Network.cpp:574
IConnectableLayer * AddPadLayer(const PadDescriptor &padDescriptor, const char *name=nullptr)
Adds a fully pad layer to the network.
Definition Network.cpp:534
IConnectableLayer * AddSplitterLayer(const ViewsDescriptor &splitterDescriptor, const char *name=nullptr)
Adds a splitter layer to the network.
Definition Network.cpp:398
void ExecuteStrategy(IStrategy &strategy) const
Definition Network.cpp:672
IConnectableLayer * AddSpaceToBatchNdLayer(const SpaceToBatchNdDescriptor &spaceToBatchNdDescriptor, const char *name=nullptr)
Adds a space to batch layer to the network.
Definition Network.cpp:480
IConnectableLayer * AddCastLayer(const char *name=nullptr)
Adds a cast layer to the network.
Definition Network.cpp:253
IConnectableLayer * AddStandInLayer(const StandInDescriptor &descriptor, const char *name=nullptr)
Add a stand-in layer for a type unknown to the Arm NN framework.
Definition Network.cpp:604
IConnectableLayer * AddChannelShuffleLayer(const ChannelShuffleDescriptor &descriptor, const char *name=nullptr)
Add a ChannelShuffle layer to the network.
Definition Network.cpp:637
IConnectableLayer * AddLogicalBinaryLayer(const LogicalBinaryDescriptor &descriptor, const char *name=nullptr)
Adds a Logical Binary layer to the network.
Definition Network.cpp:623
IConnectableLayer * AddLogSoftmaxLayer(const LogSoftmaxDescriptor &logSoftmaxDescriptor, const char *name=nullptr)
Adds a log softmax layer to the network.
Definition Network.cpp:462
IConnectableLayer * AddReshapeLayer(const ReshapeDescriptor &reshapeDescriptor, const char *name=nullptr)
Adds a reshape layer to the network.
Definition Network.cpp:474
IConnectableLayer * AddSliceLayer(const SliceDescriptor &sliceDescriptor, const char *name=nullptr)
Adds a slice layer to the network.
Definition Network.cpp:388
IConnectableLayer * AddBatchNormalizationLayer(const BatchNormalizationDescriptor &desc, const ConstTensor &mean, const ConstTensor &variance, const ConstTensor &beta, const ConstTensor &gamma, const char *name=nullptr)
Adds a batch normalization layer to the network.
Definition Network.cpp:423
IConnectableLayer * AddBatchToSpaceNdLayer(const BatchToSpaceNdDescriptor &batchToSpaceNdDescriptor, const char *name=nullptr)
Adds a batch to space ND layer to the network.
Definition Network.cpp:350
IConnectableLayer * AddActivationLayer(const ActivationDescriptor &activationDescriptor, const char *name=nullptr)
Adds an activation layer to the network.
Definition Network.cpp:376
IConnectableLayer * AddInputLayer(LayerBindingId id, const char *name=nullptr)
Adds an input layer to the network.
Definition Network.cpp:242
IConnectableLayer * AddElementwiseBinaryLayer(const ElementwiseBinaryDescriptor &elementwiseBinaryDescriptor, const char *name=nullptr)
Add an ElementwiseBinary layer to the network.
Definition Network.cpp:314
IConnectableLayer * AddL2NormalizationLayer(const L2NormalizationDescriptor &desc, const char *name=nullptr)
Adds an L2 normalization layer to the network.
Definition Network.cpp:456
IConnectableLayer * AddTransposeLayer(const TransposeDescriptor &transposeDescriptor, const char *name=nullptr)
Adds a transpose layer to the network.
Definition Network.cpp:587
static INetwork * CreateRaw(const NetworkOptions &networkOptions={})
Definition Network.cpp:677
friend IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options, Optional< std::vector< std::string > & > messages)
Accept legacy OptimizerOptions.
Definition Network.cpp:2274
IConnectableLayer * AddUnidirectionalSequenceLstmLayer(const UnidirectionalSequenceLstmDescriptor &descriptor, const LstmInputParams &params, const char *name=nullptr)
Add a UnidirectionalSequenceLstm layer to the network.
Definition Network.cpp:629
IConnectableLayer * AddMultiplicationLayer(const char *name=nullptr)
Adds a multiplication layer to the network.
Definition Network.cpp:416
friend class TestConnectionPreservation
Definition INetwork.hpp:880
IConnectableLayer * AddInstanceNormalizationLayer(const InstanceNormalizationDescriptor &desc, const char *name=nullptr)
Adds an instance normalization layer to the network.
Definition Network.cpp:450
IConnectableLayer * AddDetectionPostProcessLayer(const DetectionPostProcessDescriptor &descriptor, const ConstTensor &anchors, const char *name=nullptr)
Adds a Detection PostProcess layer to the network.
Definition Network.cpp:306
IConnectableLayer * AddStridedSliceLayer(const StridedSliceDescriptor &stridedSliceDescriptor, const char *name=nullptr)
Adds a strided slice layer to the network.
Definition Network.cpp:545
IConnectableLayer * AddTileLayer(const TileDescriptor &descriptor, const char *name=nullptr)
Add a Tile layer to the network.
Definition Network.cpp:654
IConnectableLayer * AddDepthwiseConvolution2dLayer(const DepthwiseConvolution2dDescriptor &convolution2dDescriptor, const char *name=nullptr)
Adds a 2D depthwise convolution layer to the network.
Definition Network.cpp:292
IConnectableLayer * AddComparisonLayer(const ComparisonDescriptor &comparisonDescriptor, const char *name=nullptr)
Add a Comparison layer to the network.
Definition Network.cpp:258
IConnectableLayer * AddMeanLayer(const MeanDescriptor &meanDescriptor, const char *name=nullptr)
Add a Mean layer to the network.
Definition Network.cpp:529
IConnectableLayer * AddResizeLayer(const ResizeDescriptor &resizeDescriptor, const char *name=nullptr)
Adds a resize layer to the network.
Definition Network.cpp:438
IConnectableLayer * AddArgMinMaxLayer(const ArgMinMaxDescriptor &desc, const char *name=nullptr)
Adds an ArgMinMax layer to the network.
Definition Network.cpp:247
IConnectableLayer * AddReduceLayer(const ReduceDescriptor &reduceDescriptor, const char *name=nullptr)
Adds a reduce layer to the network.
Definition Network.cpp:444
IConnectableLayer * AddPooling2dLayer(const Pooling2dDescriptor &pooling2dDescriptor, const char *name=nullptr)
Adds a 2D pooling layer to the network.
Definition Network.cpp:356
IConnectableLayer * AddConcatLayer(const ConcatDescriptor &concatDescriptor, const char *name=nullptr)
Adds a concatenation layer to the network.
Definition Network.cpp:265
IConnectableLayer * AddBatchMatMulLayer(const BatchMatMulDescriptor &descriptor, const char *name=nullptr)
Add a BatchMatMul layer to the network.
Definition Network.cpp:643
IConnectableLayer * AddPooling3dLayer(const Pooling3dDescriptor &pooling3dDescriptor, const char *name=nullptr)
Adds a 3D pooling layer to the network.
Definition Network.cpp:362
IConnectableLayer * AddPrecompiledLayer(const PreCompiledDescriptor &preCompiledDescriptor, CompiledBlobPtr compiledBlobPtr, const Optional< BackendId > &backend, const char *name=nullptr)
Adds a Precompiled layer to the network.
Definition Network.cpp:368
IConnectableLayer * AddSubtractionLayer(const char *name=nullptr)
Adds a subtraction layer to the network.
Definition Network.cpp:515
IConnectableLayer * AddDepthToSpaceLayer(const DepthToSpaceDescriptor &depthToSpaceDescriptor, const char *name=nullptr)
Adds a depth to space layer to the network.
Definition Network.cpp:285
friend void VisitLayersTopologically(const INetwork *inputNetwork, IStrategy &strategy)
IConnectableLayer * AddOutputLayer(LayerBindingId id, const char *name=nullptr)
Adds an output layer to the network.
Definition Network.cpp:496
IConnectableLayer * AddReverseV2Layer(const char *name=nullptr)
Add a ReverseV2 layer to the network.
Definition Network.cpp:649
IConnectableLayer * AddGatherNdLayer(const char *name=nullptr)
Add GatherNd layer to the network.
Definition Network.cpp:564
IConnectableLayer * AddShapeLayer(const char *name=nullptr)
Adds a shape layer to the network.
Definition Network.cpp:593
IConnectableLayer * AddFillLayer(const FillDescriptor &fillDescriptor, const char *name=nullptr)
Add an Fill layer to the network.
Definition Network.cpp:326
IConnectableLayer * AddScatterNdLayer(const ScatterNdDescriptor &descriptor, const char *name=nullptr)
Add a ScatterNd layer to the network.
Definition Network.cpp:666
Status PrintGraph()
Definition Network.cpp:237
friend Graph & GetGraphForTesting(IOptimizedNetwork *optNetPtr)
Definition TestUtils.cpp:49
Status SerializeToDot(std::ostream &stream) const
Definition Network.cpp:716
IOptimizedNetwork(const IOptimizedNetwork &other, const ModelOptions &modelOptions)
Creates a copy of the IOptimizedNetwork.
Definition Network.cpp:692
std::unique_ptr< OptimizedNetworkImpl > pOptimizedNetworkImpl
Definition INetwork.hpp:944
static void Destroy(IOptimizedNetwork *network)
Definition Network.cpp:706
size_t GetNumOutputs() const
Definition Network.cpp:736
void ExecuteStrategy(IStrategy &strategy) const
Definition Network.cpp:3277
friend class LoadedNetwork
Definition INetwork.hpp:927
const std::shared_ptr< IProfiler > & GetProfiler() const
Definition Network.cpp:721
size_t GetNumInputs() const
Definition Network.cpp:731
arm::pipe::ProfilingGuid GetGuid() const
Definition Network.cpp:726
friend IOptimizedNetworkPtr Optimize(const INetwork &inNetwork, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptionsOpaque &options, Optional< std::vector< std::string > & > messages)
Create an optimized version of the network.
Definition Network.cpp:2287
friend ModelOptions & GetModelOptionsForTesting(IOptimizedNetwork *optNetPtr)
Definition TestUtils.cpp:54
An output connection slot for a layer.
Definition INetwork.hpp:54
virtual IConnectableLayer & GetOwningIConnectableLayer()=0
virtual const IInputSlot * GetConnection(unsigned int index) const =0
virtual IInputSlot * GetConnection(unsigned int outputindex)=0
virtual unsigned int CalculateIndexOnOwner() const =0
virtual void SetTensorInfo(const TensorInfo &tensorInfo)=0
virtual unsigned int GetNumConnections() const =0
virtual bool IsTensorInfoSet() const =0
virtual int Connect(IInputSlot &destination)=0
virtual const IConnectableLayer & GetOwningIConnectableLayer() const =0
virtual const TensorInfo & GetTensorInfo() const =0
virtual LayerGuid GetOwningLayerGuid() const =0
virtual void Disconnect(IInputSlot &slot)=0
~IOutputSlot()
Not user deletable.
Definition INetwork.hpp:76
Private implementation of INetwork.
Definition Network.hpp:33
void AddModelOption(armnn::BackendOptions)
Definition Network.cpp:151
void SetDebugEnabled(bool DebugState)
Definition Network.cpp:126
OptimizerOptionsOpaque & operator=(OptimizerOptionsOpaque other)
Definition Network.cpp:96
void SetReduceFp32ToFp16(bool ReduceFp32ToFp16State)
Definition Network.cpp:136
armnn::ShapeInferenceMethod GetShapeInferenceMethod() const
Definition Network.cpp:201
void SetAllowExpandedDims(bool ExpandedDimsAllowed)
Definition Network.cpp:146
void SetProfilingEnabled(bool ProfilingState)
Definition Network.cpp:121
bool GetDebugToFileEnabled() const
Definition Network.cpp:186
void SetDebugToFileEnabled(bool DebugFileState)
Definition Network.cpp:131
void SetExportEnabled(bool ExportState)
Definition Network.cpp:116
const std::string ToString() const
Definition Network.cpp:206
void SetImportEnabled(bool ImportState)
Definition Network.cpp:111
armnn::ModelOptions GetModelOptions() const
Definition Network.cpp:196
void SetShapeInferenceMethod(armnn::ShapeInferenceMethod ShapeInferenceMethodType)
Definition Network.cpp:141
bool GetAllowExpandedDims() const
Definition Network.cpp:191
Copyright (c) 2021 ARM Limited and Contributors.
std::function< void(const void *)> CompiledBlobDeleter
Definition INetwork.hpp:342
std::vector< BackendOptions > NetworkOptions
LayerType
When adding a new layer, adapt also the LastLayer enum value in the enum class LayerType below.
Definition Types.hpp:494
std::vector< BackendOptions > ModelOptions
SpaceToDepthDescriptor DepthToSpaceDescriptor
A DepthToSpaceDescriptor for the DepthToSpaceLayer.
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition INetwork.hpp:340
Status
enumeration
Definition Types.hpp:43
OriginsDescriptor ConcatDescriptor
std::unique_ptr< void, CompiledBlobDeleter > CompiledBlobPtr
Definition INetwork.hpp:343
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptionsOpaque &options=OptimizerOptionsOpaque(), Optional< std::vector< std::string > & > messages=EmptyOptional())
Create an optimized version of the network.
Definition Network.cpp:2287
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition Types.hpp:311
SoftmaxDescriptor LogSoftmaxDescriptor
A LogSoftmaxDescriptor for the LogSoftmaxLayer.
LstmDescriptor UnidirectionalSequenceLstmDescriptor
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition INetwork.hpp:339
ShapeInferenceMethod
The ShapeInferenceMethod modify how the output shapes are treated.
Definition Types.hpp:237
@ ValidateOnly
Validate all output shapes.
Definition Types.hpp:239
An ActivationDescriptor for the ActivationLayer.
An ArgMinMaxDescriptor for ArgMinMaxLayer.
Struct for the users to pass backend specific options.
Base class for all descriptors.
A BatchMatMulDescriptor for the BatchMatMul operator.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
A ChannelShuffleDescriptor for the ChannelShuffle operator.
A ComparisonDescriptor for the ComparisonLayer.
A Convolution2dDescriptor for the Convolution2dLayer.
A Convolution3dDescriptor for the Convolution3dLayer.
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
A ElementwiseBinaryDescriptor for the ElementwiseBinaryLayer.
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
Definition Optional.hpp:32
A FillDescriptor for the FillLayer.
A FullyConnectedDescriptor for the FullyConnectedLayer.
A FusedDescriptor for the FusedLayer.
A GatherDescriptor for the GatherLayer.
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
A L2NormalizationDescriptor for the L2NormalizationLayer.
A LogicalBinaryDescriptor for the LogicalBinaryLayer.
An LstmDescriptor for the LstmLayer.
A MeanDescriptor for the MeanLayer.
A NormalizationDescriptor for the NormalizationLayer.
bool m_ExportEnabled
Enable Export.
Definition INetwork.hpp:262
bool m_ImportEnabled
Enable Import.
Definition INetwork.hpp:253
bool m_ReduceFp32ToBf16
@Note This feature has been replaced by enabling Fast Math in compute library backend options.
Definition INetwork.hpp:247
bool m_ProfilingEnabled
Enable profiling dump of the optimizer phase.
Definition INetwork.hpp:259
bool m_Debug
Add debug data for easier troubleshooting.
Definition INetwork.hpp:240
bool m_ReduceFp32ToFp16
Reduces all Fp32 operators in the model to Fp16 for faster processing.
Definition INetwork.hpp:237
ModelOptions m_ModelOptions
Enable Model Options.
Definition INetwork.hpp:256
const std::string ToString() const
Definition INetwork.hpp:201
ShapeInferenceMethod m_shapeInferenceMethod
Infer output size when not available.
Definition INetwork.hpp:250
bool m_AllowExpandedDims
When calculating tensor sizes, dimensions of size == 1 will be ignored.
Definition INetwork.hpp:265
bool m_DebugToFile
Pass debug data to separate output files for easier troubleshooting.
Definition INetwork.hpp:243
A PadDescriptor for the PadLayer.
A PermuteDescriptor for the PermuteLayer.
A Pooling2dDescriptor for the Pooling2dLayer.
A Pooling3dDescriptor for the Pooling3dLayer.
A PreCompiledDescriptor for the PreCompiledLayer.
A QLstmDescriptor for the QLstmLayer.
A ReduceDescriptor for the REDUCE operators.
A ReshapeDescriptor for the ReshapeLayer.
A ResizeDescriptor for the ResizeLayer.
A ScatterNdDescriptor for the ScatterNdLayer.
A SliceDescriptor for the SliceLayer.
A SoftmaxDescriptor for the SoftmaxLayer.
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
A StackDescriptor for the StackLayer.
A StandInDescriptor for the StandIn layer.
A StridedSliceDescriptor for the StridedSliceLayer.
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
A TransposeDescriptor for the TransposeLayer.
A ViewsDescriptor for the SplitterLayer.