ArmNN
 20.05
INetwork.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6 
7 #include <armnn/Deprecated.hpp>
10 #include <armnn/NetworkFwd.hpp>
11 #include <armnn/Optional.hpp>
12 #include <armnn/TensorFwd.hpp>
13 #include <armnn/Types.hpp>
14 #include <armnn/Deprecated.hpp>
15 
16 #include <memory>
17 #include <vector>
18 
19 namespace armnn
20 {
21 /// @brief An input connection slot for a layer.
22 /// The input slot can be connected to an output slot of the preceding layer in the graph.
23 /// Only one connection to the input slot is allowed.
25 {
26 public:
27  virtual const IOutputSlot* GetConnection() const = 0;
28  virtual IOutputSlot* GetConnection() = 0;
29 
30 protected:
31  /// Not user deletable.
33 };
34 
35 /// @brief An output connection slot for a layer.
36 /// The output slot may be connected to 1 or more input slots of subsequent layers in the graph.
38 {
39 public:
40  virtual unsigned int GetNumConnections() const = 0;
41  virtual const IInputSlot* GetConnection(unsigned int index) const = 0;
42  virtual IInputSlot* GetConnection(unsigned int index) = 0;
43 
44  virtual void SetTensorInfo(const TensorInfo& tensorInfo) = 0;
45  virtual const TensorInfo& GetTensorInfo() const = 0;
46  virtual bool IsTensorInfoSet() const = 0;
47 
48  virtual int Connect(IInputSlot& destination) = 0;
49  virtual void Disconnect(IInputSlot& slot) = 0;
50 
51  virtual unsigned int CalculateIndexOnOwner() const = 0;
52 
53  virtual LayerGuid GetOwningLayerGuid() const = 0;
54 
55 protected:
56  /// Not user deletable.
58 };
59 
60 /// @brief Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
62 {
63 public:
64  /// Returns the name of the layer
65  virtual const char* GetName() const = 0;
66 
67  /// Returns the number of connectable input slots
68  virtual unsigned int GetNumInputSlots() const = 0;
69 
70  /// Returns the number of connectable output slots
71  virtual unsigned int GetNumOutputSlots() const = 0;
72 
73  /// Get a const input slot handle by slot index
74  virtual const IInputSlot& GetInputSlot(unsigned int index) const = 0;
75 
76  /// Get the input slot handle by slot index
77  virtual IInputSlot& GetInputSlot(unsigned int index) = 0;
78 
79  /// Get the const output slot handle by slot index
80  virtual const IOutputSlot& GetOutputSlot(unsigned int index) const = 0;
81 
82  /// Get the output slot handle by slot index
83  virtual IOutputSlot& GetOutputSlot(unsigned int index) = 0;
84 
85  /// Infer the shape of the output(s) based on the provided input shape(s)
86  virtual std::vector<TensorShape> InferOutputShapes(const std::vector<TensorShape>& inputShapes) const = 0;
87 
88  /// Returns the unique id of the layer
89  virtual LayerGuid GetGuid() const = 0;
90 
91  /// Apply a visitor to this layer
92  virtual void Accept(ILayerVisitor& visitor) const = 0;
93 
94  /// Provide a hint for the optimizer as to which backend to prefer for this layer
95  virtual void BackendSelectionHint(Optional<BackendId> backend) = 0;
96 protected:
97  /// Objects are not deletable via the handle
99 };
100 
101 using INetworkPtr = std::unique_ptr<INetwork, void(*)(INetwork* network)>;
102 
103 /// Main network class which provides the interface for building up a neural network.
104 /// This object is subsequently required by the IRuntime::Load() method.
105 class INetwork
106 {
107 public:
108  static INetwork* CreateRaw();
109  static INetworkPtr Create();
110  static void Destroy(INetwork* network);
111 
112  virtual Status PrintGraph() = 0;
113 
114  /// Adds an input layer to the network.
115  /// @param id - User generated id to uniquely identify a particular input. The same id needs to be specified.
116  /// when passing the inputs to the IRuntime::EnqueueWorkload() function.
117  /// @param name - Optional name for the layer.
118  /// @return - Interface for configuring the layer.
119  virtual IConnectableLayer* AddInputLayer(LayerBindingId id, const char* name = nullptr) = 0;
120 
121  /// Adds an ArgMinMax layer to the network.
122  /// @param desc - Parameters for the L2 normalization operation.
123  /// @param name - Optional name for the layer.
124  /// @return - Interface for configuring the layer.
125  virtual IConnectableLayer* AddArgMinMaxLayer(const ArgMinMaxDescriptor& desc,
126  const char* name = nullptr) = 0;
127 
128  /// Add a Comparison layer to the network.
129  /// @param name - Optional name for the layer.
130  /// @param desc - Descriptor for the comparison operation.
131  /// @ return - Interface for configuring the layer.
132  virtual IConnectableLayer* AddComparisonLayer(const ComparisonDescriptor& comparisonDescriptor,
133  const char* name = nullptr) = 0;
134 
135  /// Adds a concatenation layer to the network.
136  /// @param concatDescriptor - ConcatDescriptor (synonym for OriginsDescriptor) to configure the concatenation
137  /// process. Number of Views must be equal to the number of inputs, and their order
138  /// must match - e.g. first view corresponds to the first input, second view to the
139  /// second input, etc....
140  /// @param name - Optional name for the layer.
141  /// @return - Interface for configuring the layer.
142  virtual IConnectableLayer* AddConcatLayer(const ConcatDescriptor& concatDescriptor,
143  const char* name = nullptr) = 0;
144 
145  /// Adds a 2D convolution layer to the network.
146  /// @param convolution2dDescriptor - Description of the 2D convolution layer.
147  /// @param weights - Tensor for the weights data.
148  /// @param biases - Optional tensor for the bias data. If specified, must match the output tensor shape.
149  /// @param name - Optional name for the layer.
150  /// @return - Interface for configuring the layer.
151  virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
152  const ConstTensor& weights,
153  const Optional<ConstTensor>& biases,
154  const char* name = nullptr) = 0;
155 
156  ARMNN_DEPRECATED_MSG("This AddConvolution2dLayer overload is deprecated")
157  virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
158  const ConstTensor& weights,
159  const char* name = nullptr) = 0;
160 
161  ARMNN_DEPRECATED_MSG("This AddConvolution2dLayer overload is deprecated")
162  virtual IConnectableLayer* AddConvolution2dLayer(const Convolution2dDescriptor& convolution2dDescriptor,
163  const ConstTensor& weights,
164  const ConstTensor& biases,
165  const char* name = nullptr) = 0;
166 
167  /// Adds a depth to space layer to the network.
168  /// @param depthToSpaceDescriptor - Parameters for the depth to space operation.
169  /// @param name - Optional name for the layer.
170  /// @return - Interface for configuring the layer.
171  virtual IConnectableLayer* AddDepthToSpaceLayer(const DepthToSpaceDescriptor& depthToSpaceDescriptor,
172  const char* name = nullptr) = 0;
173 
174  /// Adds a 2D depthwise convolution layer to the network.
175  /// @param convolution2dDescriptor - Description of the 2D depthwise convolution layer.
176  /// @param weights - Tensor for the weights. Expected format: [channelMultiplier, inputChannels, height, width].
177  /// @param biases Optional tensor for the bias data. If specified, must match the output tensor shape.
178  /// @param name - Optional name for the layer.
179  /// @return - Interface for configuring the layer.
180  virtual IConnectableLayer* AddDepthwiseConvolution2dLayer(
181  const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
182  const ConstTensor& weights,
183  const Optional<ConstTensor>& biases,
184  const char* name = nullptr) = 0;
185 
186  ARMNN_DEPRECATED_MSG("This AddDepthwiseConvolution2dLayer overload is deprecated")
187  virtual IConnectableLayer* AddDepthwiseConvolution2dLayer(
188  const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
189  const ConstTensor& weights,
190  const char* name = nullptr) = 0;
191 
192  ARMNN_DEPRECATED_MSG("This AddDepthwiseConvolution2dLayer overload is deprecated")
193  virtual IConnectableLayer* AddDepthwiseConvolution2dLayer(
194  const DepthwiseConvolution2dDescriptor& convolution2dDescriptor,
195  const ConstTensor& weights,
196  const ConstTensor& biases,
197  const char* name = nullptr) = 0;
198 
199  /// Adds a Dequantize layer to the network.
200  /// @return - Interface for configuring the layer.
201  virtual IConnectableLayer* AddDequantizeLayer(const char* name = nullptr) = 0;
202 
203  /// Adds a Detection PostProcess layer to the network.
204  /// @param descriptor - Description of the Detection PostProcess layer.
205  /// @param anchors - Tensor for anchors.
206  /// @param name - Optional name for the layer.
207  /// @return - Interface for configuring the layer.
208  virtual IConnectableLayer* AddDetectionPostProcessLayer(
209  const DetectionPostProcessDescriptor& descriptor,
210  const ConstTensor& anchors,
211  const char* name = nullptr) = 0;
212 
213  /// Add an ElementwiseUnary layer to the network.
214  /// @param name - Optional name for the layer.
215  /// @param desc - Descriptor for the elementwiseUnary operation.
216  /// @ return - Interface for configuring the layer.
217  virtual IConnectableLayer* AddElementwiseUnaryLayer(const ElementwiseUnaryDescriptor& elementwiseUnaryDescriptor,
218  const char* name = nullptr) = 0;
219 
220  /// Adds a fully connected layer to the network.
221  /// @param fullyConnectedDescriptor - Description of the fully connected layer.
222  /// @param weights - Tensor for the weights data.
223  /// @param biases - Optional tensor for the bias data.
224  /// @param name - Optional name for the layer.
225  /// @return - Interface for configuring the layer.
226  virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
227  const ConstTensor& weights,
228  const Optional<ConstTensor>& biases,
229  const char* name = nullptr) = 0;
230 
231  ARMNN_DEPRECATED_MSG("This AddFullyConnectedLayer overload is deprecated")
232  virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
233  const ConstTensor& weights,
234  const char* name = nullptr) = 0;
235 
236  ARMNN_DEPRECATED_MSG("This AddFullyConnectedLayer overload is deprecated")
237  virtual IConnectableLayer* AddFullyConnectedLayer(const FullyConnectedDescriptor& fullyConnectedDescriptor,
238  const ConstTensor& weights,
239  const ConstTensor& biases,
240  const char* name = nullptr) = 0;
241 
242  /// Adds a permute layer to the network.
243  /// @param permuteDescriptor - PermuteDescriptor to configure the permute.
244  /// @param name - Optional name for the layer.
245  /// @return - Interface for configuring the layer.
246  virtual IConnectableLayer* AddPermuteLayer(const PermuteDescriptor& permuteDescriptor,
247  const char* name = nullptr) = 0;
248 
249  /// Adds a batch to space ND layer to the network.
250  /// @param batchToSpaceNdDescriptor - Description of the layer.
251  /// @param name - Optional name for the layer.
252  /// @return - Interface for configuring the layer.
253  virtual IConnectableLayer* AddBatchToSpaceNdLayer(const BatchToSpaceNdDescriptor& batchToSpaceNdDescriptor,
254  const char* name = nullptr) = 0;
255 
256  /// Adds a pooling layer to the network.
257  /// @param pooling2dDescriptor - Pooling2dDescriptor to configure the pooling.
258  /// @param name - Optional name for the layer.
259  /// @return - Interface for configuring the layer.
260  virtual IConnectableLayer* AddPooling2dLayer(const Pooling2dDescriptor& pooling2dDescriptor,
261  const char* name = nullptr) = 0;
262 
263  /// Adds an activation layer to the network.
264  /// @param activationDescriptor - ActivationDescriptor to configure the activation.
265  /// @param name - Optional name for the layer.
266  /// @return - Interface for configuring the layer.
267  virtual IConnectableLayer* AddActivationLayer(const ActivationDescriptor& activationDescriptor,
268  const char* name = nullptr) = 0;
269 
270  /// Adds a normalization layer to the network.
271  /// @param normalizationDescriptor - NormalizationDescriptor to configure the normalization.
272  /// @param name - Optional name for the layer.
273  /// @return - Interface for configuring the layer.
274  virtual IConnectableLayer* AddNormalizationLayer(const NormalizationDescriptor& normalizationDescriptor,
275  const char* name = nullptr) = 0;
276 
277  /// Adds a slice layer to the network.
278  /// @param sliceDescriptor - SliceDescriptor to configure the slice operation.
279  /// @param name - Optional name for the layer.
280  /// @return - Interface for configuring the layer.
281  virtual IConnectableLayer* AddSliceLayer(const SliceDescriptor& sliceDescriptor, const char* name = nullptr) = 0;
282 
283  /// Adds a softmax layer to the network.
284  /// If the data type is QAsymm8, then the output quantization parameters
285  /// must have a scale of 1/256 and an offset of 0
286  /// @param softmaxDescriptor - SoftmaxDescriptor to configure the softmax.
287  /// @param name - Optional name for the layer.
288  /// @return - Interface for configuring the layer.
289  virtual IConnectableLayer* AddSoftmaxLayer(const SoftmaxDescriptor& softmaxDescriptor,
290  const char* name = nullptr) = 0;
291 
292  /// Adds a splitter layer to the network.
293  /// @param splitterDescriptor - ViewsDescriptor to configure the splitting process.
294  /// Number of Views must be equal to the number of outputs,
295  /// and their order must match - e.g. first view corresponds to
296  /// the first output, second view to the second output, etc....
297  /// @param name - Optional name for the layer.
298  /// @return - Interface for configuring the layer.
299  virtual IConnectableLayer* AddSplitterLayer(const ViewsDescriptor& splitterDescriptor,
300  const char* name = nullptr) = 0;
301 
302  /// Adds a merge layer to the network.
303  /// @param name - Optional name for the layer.
304  /// @return - Interface for configuring the layer.
305  virtual IConnectableLayer* AddMergeLayer(const char* name = nullptr) = 0;
306 
307  /// Adds a concat layer to the network.
308  /// @param mergerDescriptor - MergerDescriptor (synonym for OriginsDescriptor) to configure the concatenation
309  /// process. Number of Views must be equal to the number of inputs, and their order
310  /// must match - e.g. first view corresponds to the first input, second view to the
311  /// second input, etc....
312  /// @param name - Optional name for the layer.
313  /// @return - Interface for configuring the layer.
314  ARMNN_DEPRECATED_MSG("Use AddConcatLayer instead")
315  virtual IConnectableLayer* AddMergerLayer(const MergerDescriptor& mergerDescriptor,
316  const char* name = nullptr) = 0;
317 
318  /// Add absolute layer to the network.
319  /// @param name - Optional name for the layer.
320  /// @ return - Interface for configuring the layer.
321  ARMNN_DEPRECATED_MSG("Use AddElementwiseUnaryLayer instead")
322  virtual IConnectableLayer* AddAbsLayer(const char* name = nullptr) = 0;
323 
324  /// Adds an addition layer to the network.
325  /// @param name - Optional name for the layer.
326  /// @return - Interface for configuring the layer.
327  virtual IConnectableLayer* AddAdditionLayer(const char* name = nullptr) = 0;
328 
329  /// Adds a multiplication layer to the network.
330  /// @param name - Optional name for the layer.
331  /// @return - Interface for configuring the layer.
332  virtual IConnectableLayer* AddMultiplicationLayer(const char* name = nullptr) = 0;
333 
334  /// Adds a batch normalization layer to the network.
335  /// @param mean - Pre-calculated mean for each channel.
336  /// @param variance - Pre-calculated variance for each channel.
337  /// @param beta - Per-channel additive factor.
338  /// @param gamma - Per-channel multiplicative factor.
339  /// @return - Interface for configuring the layer.
340  /// @param name - Optional name for the layer.
341  virtual IConnectableLayer* AddBatchNormalizationLayer(const BatchNormalizationDescriptor& desc,
342  const ConstTensor& mean,
343  const ConstTensor& variance,
344  const ConstTensor& beta,
345  const ConstTensor& gamma,
346  const char* name = nullptr) = 0;
347 
348  /// Adds a resize bilinear layer to the network.
349  /// @param resizeDesc - Parameters for the resize operation.
350  /// @param name - Optional name for the layer.
351  /// @return - Interface for configuring the layer.
352  ARMNN_DEPRECATED_MSG("Use AddResizeLayer instead")
353  virtual IConnectableLayer* AddResizeBilinearLayer(const ResizeBilinearDescriptor& resizeDesc,
354  const char* name = nullptr) = 0;
355 
356  /// Adds a resize layer to the network.
357  /// @param resizeDescriptor - Parameters for the resize operation.
358  /// @param name - Optional name for the layer.
359  /// @return - Interface for configuring the layer.
360  virtual IConnectableLayer* AddResizeLayer(const ResizeDescriptor& resizeDescriptor,
361  const char* name = nullptr) = 0;
362 
363  /// Adds an instance normalization layer to the network.
364  /// @param desc - Parameters for the instance normalization operation.
365  /// @param name - Optional name for the layer.
366  /// @return - Interface for configuring the layer.
367  virtual IConnectableLayer* AddInstanceNormalizationLayer(const InstanceNormalizationDescriptor& desc,
368  const char* name = nullptr) = 0;
369 
370  /// Adds an L2 normalization layer to the network.
371  /// Normalization is performed along dimension 1, but requires a 4d input.
372  /// @param desc - Parameters for the L2 normalization operation.
373  /// @param name - Optional name for the layer.
374  /// @return - Interface for configuring the layer.
375  virtual IConnectableLayer* AddL2NormalizationLayer(const L2NormalizationDescriptor& desc,
376  const char* name = nullptr) = 0;
377 
378  /// Adds a log softmax layer to the network.
379  /// @param logSoftmaxDescriptor - LogSoftmaxDescriptor to configure the log softmax.
380  /// @param name - Optional name for the layer.
381  /// @return - Interface for configuring the layer.
382  virtual IConnectableLayer* AddLogSoftmaxLayer(const LogSoftmaxDescriptor& logSoftmaxDescriptor,
383  const char* name = nullptr) = 0;
384 
385  /// Adds a layer with no inputs and a single output, which always corresponds to
386  /// the passed in constant tensor.
387  /// @param input - Tensor to be provided as the only output of the layer. The layer will maintain
388  /// its own copy of the tensor data, meaning the memory referenced by @a input can
389  /// be freed or reused after this function is called.
390  /// @param name - Optional name for the layer.
391  /// @return - Interface for configuring the layer.
392  virtual IConnectableLayer* AddConstantLayer(const ConstTensor& input,
393  const char* name = nullptr) = 0;
394 
395  /// Adds a reshape layer to the network.
396  /// @param reshapeDescriptor - Parameters for the reshape operation.
397  /// @param name - Optional name for the layer.
398  /// @return - Interface for configuring the layer.
399  virtual IConnectableLayer* AddReshapeLayer(const ReshapeDescriptor& reshapeDescriptor,
400  const char* name = nullptr) = 0;
401 
402  /// Adds a space to batch layer to the network.
403  /// @param spaceToBatchNdDescriptor - Parameters for the space to batch operation.
404  /// @param name - Optional name for the layer.
405  /// @return - Interface for configuring the layer.
406  virtual IConnectableLayer* AddSpaceToBatchNdLayer(const SpaceToBatchNdDescriptor& spaceToBatchNdDescriptor,
407  const char* name = nullptr) = 0;
408 
409  /// Adds a space to depth layer to the network.
410  /// @param spaceToDepthDescriptor - Parameters for the space to depth operation.
411  /// @param name - Optional name for the layer.
412  /// @return - Interface for configuring the layer.
413  virtual IConnectableLayer* AddSpaceToDepthLayer(const SpaceToDepthDescriptor& spaceToDepthDescriptor,
414  const char* name = nullptr) = 0;
415 
416  /// Adds a floor layer to the network.
417  /// @param name - Optional name for the layer.
418  /// @return - Interface for configuring the layer.
419  virtual IConnectableLayer* AddFloorLayer(const char* name = nullptr) = 0;
420 
421  /// Adds an output layer to the network.
422  /// @param id - User generated id to uniquely identify a particular output. The same id needs to be specified
423  /// when passing the outputs to the IRuntime::EnqueueWorkload() function.
424  /// @param name - Optional name for the layer.
425  /// @return - Interface for configuring the layer.
426  virtual IConnectableLayer* AddOutputLayer(LayerBindingId id, const char* name = nullptr) = 0;
427 
428  /// Add a Lstm layer to the network
429  /// @param descriptor - Parameters for the Lstm operation
430  /// @param params - Weights and biases for the LSTM cell
431  /// @param name - Optional name for the layer
432  /// @return - Interface for configuring the layer.
433  virtual IConnectableLayer* AddLstmLayer(const LstmDescriptor& descriptor,
434  const LstmInputParams& params,
435  const char* name = nullptr) = 0;
436 
437  /// Adds a division layer to the network.
438  /// @param name - Optional name for the layer.
439  /// @return - Interface for configuring the layer.
440  virtual IConnectableLayer* AddDivisionLayer(const char* name = nullptr) = 0;
441 
442  /// Adds a subtraction layer to the network.
443  /// @param name - Optional name for the layer.
444  /// @return - Interface for configuring the layer.
445  virtual IConnectableLayer* AddSubtractionLayer(const char* name = nullptr) = 0;
446 
447  /// Add a Maximum layer to the network.
448  /// @param name - Optional name for the layer.
449  /// @ return - Interface for configuring the layer.
450  virtual IConnectableLayer* AddMaximumLayer(const char* name = nullptr) = 0;
451 
452  /// Add a Mean layer to the network.
453  /// @param meanDescriptor - Parameters for the mean operation.
454  /// @param name - Optional name for the layer.
455  /// @ return - Interface for configuring the layer.
456  virtual IConnectableLayer* AddMeanLayer(const MeanDescriptor& meanDescriptor, const char* name = nullptr) = 0;
457 
458  /// Adds a fully pad layer to the network.
459  /// @param paddings - n by 2 tensor, where n is the rank of the input tensor,
460  /// such that paddings[i,0] indicates the amount of padding to add in front of dimonsion i, and
461  /// paddings[i,1] indicates the amount of padding to add after the end of dimension i
462  /// @param name - Optional name for the layer.
463  /// @return - Interface for configuring the layer.
464  virtual IConnectableLayer* AddPadLayer(const PadDescriptor& padDescriptor,
465  const char* name = nullptr) = 0;
466 
467  /// Add a quantize layer to the network
468  ///@param name - Optional name for the layer.
469  /// @return - Interface for configuring the layer.
470  virtual IConnectableLayer* AddQuantizeLayer(const char* name = nullptr) = 0;
471 
472  /// Adds a strided slice layer to the network.
473  /// @param StridedSliceDescriptor - Parameters for the strided slice operation.
474  /// @param name - Optional name for the layer.
475  /// @return - Interface for configuring the layer.
476  virtual IConnectableLayer* AddStridedSliceLayer(const StridedSliceDescriptor& stridedSliceDescriptor,
477  const char* name = nullptr) = 0;
478 
479  /// Add a Minimum layer to the network.
480  /// @param name - Optional name for the layer.
481  /// @ return - Interface for configuring the layer.
482  virtual IConnectableLayer* AddMinimumLayer(const char* name = nullptr) = 0;
483 
484  /// Add a Greater layer to the network.
485  /// @param name - Optional name for the layer.
486  /// @ return - Interface for configuring the layer.
487  ARMNN_DEPRECATED_MSG("Use AddComparisonLayer instead")
488  virtual IConnectableLayer* AddGreaterLayer(const char* name = nullptr) = 0;
489 
490  /// Add a Equal layer to the network.
491  /// @param name - Optional name for the layer.
492  /// @ return - Interface for configuring the layer.
493  ARMNN_DEPRECATED_MSG("Use AddComparisonLayer instead")
494  virtual IConnectableLayer* AddEqualLayer(const char* name = nullptr) = 0;
495 
496  /// Add Reciprocal of square root layer to the network.
497  /// @param name - Optional name for the layer.
498  /// @ return - Interface for configuring the layer.
499  ARMNN_DEPRECATED_MSG("Use AddElementwiseUnaryLayer instead")
500  virtual IConnectableLayer* AddRsqrtLayer(const char* name = nullptr) = 0;
501 
502  /// Add Gather layer to the network.
503  /// @param name - Optional name for the layer.
504  /// @ return - Interface for configuring the layer.
505  virtual IConnectableLayer* AddGatherLayer(const char* name = nullptr) = 0;
506 
507  /// Adds a switch layer to the network.
508  /// @param name - Optional name for the layer.
509  /// @return - Interface for configuring the layer.
510  virtual IConnectableLayer* AddSwitchLayer(const char* name = nullptr) = 0;
511 
512  /// Adds a PReLU layer to the network.
513  /// @param name - Optional name for the layer.
514  /// @return - Interface for configuring the layer.
515  virtual IConnectableLayer* AddPreluLayer(const char* name = nullptr) = 0;
516 
517  /// Adds a 2D transpose convolution layer to the network.
518  /// @param descriptor - Description of the 2D transpose convolution layer.
519  /// @param weights - Tensor for the weights data.
520  /// @param biases - Optional tensor for the bias data.
521  /// @param name - Optional name for the layer.
522  /// @return - Interface for configuring the layer.
523  virtual IConnectableLayer* AddTransposeConvolution2dLayer(const TransposeConvolution2dDescriptor& descriptor,
524  const ConstTensor& weights,
525  const Optional<ConstTensor>& biases,
526  const char* name = nullptr) = 0;
527 
528  /// Adds a transpose layer to the network.
529  /// @param transposeDescriptor - TransposeDescriptor to configure the transpose.
530  /// @param name - Optional name for the layer.
531  /// @return - Interface for configuring the layer.
532  virtual IConnectableLayer* AddTransposeLayer(const TransposeDescriptor& transposeDescriptor,
533  const char* name = nullptr) = 0;
534 
535  /// Adds a stack layer to the network.
536  /// @param descriptor - Description of the stack layer.
537  /// @param name - Optional name for the layer.
538  /// @return - Interface for configuring the layer.
539  virtual IConnectableLayer* AddStackLayer(const StackDescriptor& descriptor,
540  const char* name = nullptr) = 0;
541 
542  /// Add a stand-in layer for a type unknown to the Arm NN framework.
543  /// Note: Due to the nature of this layer, no validation can be performed by the framework.
544  /// Furthermore, Any model containing this layer cannot make use of dynamic tensors since the
545  /// tensor sizes cannot be inferred.
546  /// @descriptor - Descriptor for the StandIn layer.
547  /// @return - Interface for configuring the layer.
548  virtual IConnectableLayer* AddStandInLayer(const StandInDescriptor& descriptor,
549  const char* name = nullptr) = 0;
550 
551  /// Add a QuantizedLstm layer to the network
552  /// @param params - The weights and biases for the Quantized LSTM cell
553  /// @param name - Optional name for the layer
554  /// @return - Interface for configuring the layer.
555  virtual IConnectableLayer* AddQuantizedLstmLayer(const QuantizedLstmInputParams& params,
556  const char* name = nullptr) = 0;
557 
558  /// Add a QLstm layer to the network
559  /// @param descriptor - Parameters for the QLstm operation
560  /// @param params - Weights and biases for the layer
561  /// @param name - Optional name for the layer
562  /// @return - Interface for configuring the layer.
563  virtual IConnectableLayer* AddQLstmLayer(const QLstmDescriptor& descriptor,
564  const LstmInputParams& params,
565  const char* name = nullptr) = 0;
566 
567  virtual void Accept(ILayerVisitor& visitor) const = 0;
568 
569 protected:
571 };
572 
573 using IOptimizedNetworkPtr = std::unique_ptr<IOptimizedNetwork, void(*)(IOptimizedNetwork* network)>;
574 
576 {
577 public:
578  static void Destroy(IOptimizedNetwork* network);
579 
580  virtual Status PrintGraph() = 0;
581  virtual Status SerializeToDot(std::ostream& stream) const = 0;
582 
583  virtual profiling::ProfilingGuid GetGuid() const = 0;
584 
585 protected:
587 };
588 
590 {
592  : m_ReduceFp32ToFp16(false)
593  , m_Debug(false)
594  , m_ReduceFp32ToBf16(false)
595  {}
596 
597  OptimizerOptions(bool reduceFp32ToFp16, bool debug, bool reduceFp32ToBf16 = false)
598  : m_ReduceFp32ToFp16(reduceFp32ToFp16)
599  , m_Debug(debug)
600  , m_ReduceFp32ToBf16(reduceFp32ToBf16)
601  {
602  if (m_ReduceFp32ToFp16 && m_ReduceFp32ToBf16)
603  {
604  throw InvalidArgumentException("BFloat16 and Float16 optimization cannot be enabled at the same time.");
605  }
606  }
607 
608  // Reduce Fp32 data to Fp16 for faster processing
610 
611  // Add debug data for easier troubleshooting
612  bool m_Debug;
613 
614  // Reduce Fp32 data to Bf16 for faster processing
616 };
617 
618 /// Create an optimized version of the network
619 /// @param network INetwork description of the network to be optimized.
620 /// @param backendPreferences The choice of the backend ordered by user preferences.
621 /// @param deviceSpec DeviceSpec object as queried from the runtime. See IRuntime::GetDeviceSpec()
622 /// @param messages If there are failures or warnings a string describing same will be added to the vector
623 /// @param options OptimizerOptions object with optimizer configuration options
624 /// @return An IOptimizedNetworkPtr interface to the optimized network, throws an exception derived from
625 /// armnn::Exception if process fails.
626 
627 IOptimizedNetworkPtr Optimize(const INetwork& network,
628  const std::vector<BackendId>& backendPreferences,
629  const IDeviceSpec& deviceSpec,
631  Optional<std::vector<std::string>&> messages = EmptyOptional());
632 } //namespace armnn
A ViewsDescriptor for the SplitterLayer.
Interface for a layer that is connectable to other layers via InputSlots and OutputSlots.
Definition: INetwork.hpp:61
A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
~IConnectableLayer()
Objects are not deletable via the handle.
Definition: INetwork.hpp:98
A ReshapeDescriptor for the ReshapeLayer.
A ComparisonDescriptor for the ComparisonLayer.
Definition: Descriptors.hpp:70
DataLayout::NHWC false
A Convolution2dDescriptor for the Convolution2dLayer.
const TensorInfo & GetTensorInfo(const ITensorHandle *tensorHandle)
float32 helpers
Main network class which provides the interface for building up a neural network. ...
Definition: INetwork.hpp:105
Copyright (c) 2020 ARM Limited.
A SpaceToDepthDescriptor for the SpaceToDepthLayer.
A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
int LayerBindingId
Type of identifiers for bindable layers (inputs, outputs).
Definition: Types.hpp:171
A ResizeDescriptor for the ResizeLayer.
A StackDescriptor for the StackLayer.
A PadDescriptor for the PadLayer.
An LstmDescriptor for the LstmLayer.
IOptimizedNetworkPtr Optimize(const INetwork &network, const std::vector< BackendId > &backendPreferences, const IDeviceSpec &deviceSpec, const OptimizerOptions &options=OptimizerOptions(), Optional< std::vector< std::string > &> messages=EmptyOptional())
Create an optimized version of the network.
Definition: Network.cpp:1003
An output connection slot for a layer.
Definition: INetwork.hpp:37
A L2NormalizationDescriptor for the L2NormalizationLayer.
An ArgMinMaxDescriptor for ArgMinMaxLayer.
Definition: Descriptors.hpp:51
An OriginsDescriptor for the ConcatLayer.
A FullyConnectedDescriptor for the FullyConnectedLayer.
A tensor defined by a TensorInfo (shape and data type) and an immutable backing store.
Definition: Tensor.hpp:199
Status
enumeration
Definition: Types.hpp:26
std::unique_ptr< IOptimizedNetwork, void(*)(IOptimizedNetwork *network)> IOptimizedNetworkPtr
Definition: INetwork.hpp:573
A StandInDescriptor for the StandIn layer.
A QLstmDescriptor for the QLstmLayer.
Device specific knowledge to be passed to the optimizer.
Definition: Types.hpp:161
An ActivationDescriptor for the ActivationLayer.
Definition: Descriptors.hpp:20
A SliceDescriptor for the SliceLayer.
A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
EmptyOptional is used to initialize the Optional class in case we want to have default value for an O...
Definition: Optional.hpp:32
A ElementwiseUnaryDescriptor for the ElementwiseUnaryLayer.
Definition: Descriptors.hpp:90
~IInputSlot()
Not user deletable.
Definition: INetwork.hpp:32
OptimizerOptions(bool reduceFp32ToFp16, bool debug, bool reduceFp32ToBf16=false)
Definition: INetwork.hpp:597
A MeanDescriptor for the MeanLayer.
virtual const IOutputSlot * GetConnection() const =0
A TransposeDescriptor for the TransposeLayer.
A StridedSliceDescriptor for the StridedSliceLayer.
void Connect(armnn::IConnectableLayer *from, armnn::IConnectableLayer *to, const armnn::TensorInfo &tensorInfo, unsigned int fromIndex, unsigned int toIndex)
Definition: TestUtils.cpp:12
#define ARMNN_DEPRECATED_MSG(message)
Definition: Deprecated.hpp:43
std::unique_ptr< INetwork, void(*)(INetwork *network)> INetworkPtr
Definition: INetwork.hpp:101
~IOutputSlot()
Not user deletable.
Definition: INetwork.hpp:57
A Pooling2dDescriptor for the Pooling2dLayer.
armnn::Runtime::CreationOptions::ExternalProfilingOptions options
A NormalizationDescriptor for the NormalizationLayer.
An InstanceNormalizationDescriptor for InstanceNormalizationLayer.
A ResizeBilinearDescriptor for the ResizeBilinearLayer.
A SoftmaxDescriptor for the SoftmaxLayer.
An input connection slot for a layer.
Definition: INetwork.hpp:24
A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
A BatchNormalizationDescriptor for the BatchNormalizationLayer.
A PermuteDescriptor for the PermuteLayer.
std::vector< float > anchors({ 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 0.5f, 1.0f, 1.0f, 0.5f, 10.5f, 1.0f, 1.0f, 0.5f, 10.5f, 1.0f, 1.0f, 0.5f, 100.5f, 1.0f, 1.0f })