IVGCVSW-3722 Add front end support for ArgMinMax
[platform/upstream/armnn.git] / include / armnn / Descriptors.hpp
1 //
2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 #pragma once
6
7 #include "Deprecated.hpp"
8 #include "DescriptorsFwd.hpp"
9
10 #include <cstdint>
11 #include <initializer_list>
12
13 #include "Tensor.hpp"
14 #include "Types.hpp"
15
16 namespace armnn
17 {
18
19 /// An ActivationDescriptor for the ActivationLayer.
20 struct ActivationDescriptor
21 {
22     ActivationDescriptor() : m_Function(ActivationFunction::Sigmoid), m_A(0), m_B(0) {}
23
24     /// @brief The activation function to use
25     /// (Sigmoid, TanH, Linear, ReLu, BoundedReLu, SoftReLu, LeakyReLu, Abs, Sqrt, Square).
26     ActivationFunction m_Function;
27     /// Alpha upper bound value used by the activation functions. (BoundedReLu, Linear, TanH).
28     float              m_A;
29     /// Beta lower bound value used by the activation functions. (BoundedReLu, Linear, TanH).
30     float              m_B;
31 };
32
33 /// An ArgMinMaxDescriptor for ArgMinMaxLayer
34 struct ArgMinMaxDescriptor
35 {
36     ArgMinMaxDescriptor()
37     : m_Axis(-1) {}
38
39     int m_Axis;
40 };
41
42 /// A PermuteDescriptor for the PermuteLayer.
43 struct PermuteDescriptor
44 {
45     PermuteDescriptor()
46         : m_DimMappings{}
47     {
48     }
49     PermuteDescriptor(const PermutationVector& dimMappings)
50         : m_DimMappings(dimMappings)
51     {
52     }
53     /// @brief Indicates how to translate tensor elements from a given source into the target destination, when
54     /// source and target potentially have different memory layouts e.g. {0U, 3U, 1U, 2U}.
55     PermutationVector m_DimMappings;
56 };
57
58 /// A SoftmaxDescriptor for the SoftmaxLayer.
59 struct SoftmaxDescriptor
60 {
61     SoftmaxDescriptor()
62     : m_Beta(1.0f)
63     , m_Axis(-1)
64     {}
65
66     /// Exponentiation value.
67     float m_Beta;
68     /// Scalar, defaulted to the last index (-1), specifying the dimension the activation will be performed on.
69     int m_Axis;
70 };
71
72 /// @brief An OriginsDescriptor for the ConcatLayer.
73 /// Descriptor to configure the concatenation process. Number of views must be equal to the number of inputs, and
74 /// their order must match - e.g. first view corresponds to the first input, second view to the second input, etc.
75 struct OriginsDescriptor
76 {
77     OriginsDescriptor();
78     OriginsDescriptor(uint32_t numViews, uint32_t numDimensions = 4);
79     OriginsDescriptor(const OriginsDescriptor& other);
80     OriginsDescriptor(OriginsDescriptor&& other);
81
82     ~OriginsDescriptor();
83
84     OriginsDescriptor& operator=(OriginsDescriptor rhs);
85
86     /// @Brief Set the view origin coordinates. The arguments are: view, dimension, value.
87     /// If the view is greater than or equal to GetNumViews(), then the view argument is out of range.
88     /// If the coord is greater than or equal to GetNumDimensions(), then the coord argument is out of range.
89     Status SetViewOriginCoord(uint32_t view, uint32_t coord, uint32_t value);
90     /// Get the number of views.
91     uint32_t GetNumViews() const;
92     /// Get the number of dimensions.
93     uint32_t GetNumDimensions() const;
94     /// Return the view origin at the int value idx.
95     const uint32_t* GetViewOrigin(uint32_t idx) const;
96     /// @brief Reorders the viewOrigins in accordance with the indices presented in newOrdering array.
97     /// The number of views must match number of elements in the new ordering array.
98     void ReorderOrigins(unsigned int*  newOrdering, unsigned int numNewOrdering);
99     /// Swap the ViewsDescriptor values first and second.
100     friend void swap(OriginsDescriptor& first, OriginsDescriptor& second);
101     /// Set the concatenation axis value.
102     void SetConcatAxis(unsigned int concatAxis);
103     /// Get the concatenation axis value.
104     unsigned int GetConcatAxis() const;
105
106 private:
107     unsigned int m_ConcatAxis;
108     uint32_t     m_NumViews;
109     uint32_t     m_NumDimensions;
110     uint32_t**   m_ViewOrigins;
111 };
112
113 /// @brief A ViewsDescriptor for the SplitterLayer.
114 /// Descriptor to configure the splitting process. Number of Views must be equal to the number of outputs, and
115 /// their order must match - e.g. first view corresponds to the first output, second view to the second output, etc.
116 struct ViewsDescriptor
117 {
118     ViewsDescriptor(uint32_t numViews, uint32_t numDimensions = 4);
119     ViewsDescriptor(const ViewsDescriptor& other);
120     ViewsDescriptor();
121     ViewsDescriptor(ViewsDescriptor&& other);
122
123     ~ViewsDescriptor();
124
125     ViewsDescriptor& operator=(ViewsDescriptor rhs);
126     /// @Brief Set the view origin coordinates. The arguments are: view, dimension, value.
127     /// If the view is greater than or equal to GetNumViews(), then the view argument is out of range.
128     /// If the coord is greater than or equal to GetNumDimensions(), then the coord argument is out of range.
129     Status SetViewOriginCoord(uint32_t view, uint32_t coord, uint32_t value);
130     /// @brief Set the size of the views. The arguments are: view, dimension, value.
131     /// If the view is greater than or equal to GetNumViews(), then the view argument is out of range.
132     /// If the coord is greater than or equal to GetNumDimensions(), then the coord argument is out of range.
133     Status SetViewSize(uint32_t view, uint32_t coord, uint32_t value);
134
135     /// Get the number of views.
136     uint32_t GetNumViews() const;
137     /// Get the number of dimensions.
138     uint32_t GetNumDimensions() const;
139     /// Get the view origin at the int value idx.
140     const uint32_t* GetViewOrigin(uint32_t idx) const;
141     /// Get the view sizes at the int value idx.
142     const uint32_t* GetViewSizes(uint32_t idx) const;
143     /// Get the View Origins
144     const OriginsDescriptor& GetOrigins() const;
145
146     /// Swap the ViewsDescriptor value first and second.
147     friend void swap(ViewsDescriptor& first, ViewsDescriptor& second);
148 private:
149     OriginsDescriptor m_Origins;
150     uint32_t**        m_ViewSizes;
151 };
152
153 template <typename TensorShapeIt>
154 ARMNN_DEPRECATED_MSG("Use CreateDescriptorForConcatenation instead")
155 OriginsDescriptor CreateMergerDescriptorForConcatenation(TensorShapeIt first,
156                                                          TensorShapeIt last,
157                                                          unsigned int concatenationDimension)
158 {
159     return CreateDescriptorForConcatenation(first, last, concatenationDimension);
160 }
161
162 /// @brief Convenience template to create an OriginsDescriptor to use when creating a ConcatLayer for performing
163 /// concatenation of a number of input tensors.
164 template <typename TensorShapeIt>
165 OriginsDescriptor CreateDescriptorForConcatenation(TensorShapeIt first,
166                                                    TensorShapeIt last,
167                                                    unsigned int concatenationDimension)
168 {
169     auto numInputs = std::distance(first, last);
170
171     if (numInputs < 2)
172     {
173         throw InvalidArgumentException("Concatenation requires at least 2 inputs");
174     }
175
176     const auto& firstInputShape = *first;
177
178     const unsigned int numDimensions = firstInputShape.GetNumDimensions();
179     for (auto it = first + 1; it != last; ++it)
180     {
181         if (it->GetNumDimensions() != numDimensions)
182         {
183             throw InvalidArgumentException("All inputs to concatenation must have the same number of dimensions");
184         }
185     }
186
187     if (concatenationDimension >= numDimensions)
188     {
189         throw InvalidArgumentException("concatenationDimension must be between 0 and the number of dimensions.");
190     }
191
192     for (auto it = first; it != last; ++it)
193     {
194         for (unsigned int d = 0; d < numDimensions; ++d)
195         {
196             const bool dimSizeOk = (d == concatenationDimension) || (firstInputShape[d] == (*it)[d]);
197             if (!dimSizeOk)
198             {
199                 throw InvalidArgumentException("All inputs to concatenation must be the same size along all dimensions "
200                     " except the concatenation dimension");
201             }
202         }
203     }
204
205     OriginsDescriptor viewsDescriptor(static_cast<uint32_t>(numInputs), numDimensions);
206     viewsDescriptor.SetConcatAxis(concatenationDimension);
207
208     uint32_t viewIndex = 0u;
209     uint32_t coordAlongConcatDim = 0u;
210     for (auto it = first; it != last; ++it)
211     {
212         const auto& inputShape = *it;
213
214         for (unsigned int i = 0; i < concatenationDimension; ++i)
215         {
216             viewsDescriptor.SetViewOriginCoord(viewIndex, i, 0);
217         }
218
219         viewsDescriptor.SetViewOriginCoord(viewIndex, concatenationDimension, coordAlongConcatDim);
220         unsigned int dimSize = inputShape[concatenationDimension];
221         coordAlongConcatDim += dimSize;
222
223
224         for (unsigned int i = concatenationDimension + 1; i < numDimensions; ++i)
225         {
226             viewsDescriptor.SetViewOriginCoord(viewIndex, i, 0);
227         }
228
229         ++viewIndex;
230     }
231
232     return viewsDescriptor;
233 }
234
235 /// A Pooling2dDescriptor for the Pooling2dLayer.
236 struct Pooling2dDescriptor
237 {
238     Pooling2dDescriptor()
239     : m_PoolType(PoolingAlgorithm::Max)
240     , m_PadLeft(0)
241     , m_PadRight(0)
242     , m_PadTop(0)
243     , m_PadBottom(0)
244     , m_PoolWidth(0)
245     , m_PoolHeight(0)
246     , m_StrideX(0)
247     , m_StrideY(0)
248     , m_OutputShapeRounding(OutputShapeRounding::Floor)
249     , m_PaddingMethod(PaddingMethod::Exclude)
250     , m_DataLayout(DataLayout::NCHW)
251     {}
252
253     /// The pooling algorithm to use (Max. Average, L2).
254     PoolingAlgorithm    m_PoolType;
255     /// Padding left value in the width dimension.
256     uint32_t            m_PadLeft;
257     /// Padding right value in the width dimension.
258     uint32_t            m_PadRight;
259     /// Padding top value in the height dimension.
260     uint32_t            m_PadTop;
261     /// Padding bottom value in the height dimension.
262     uint32_t            m_PadBottom;
263     /// Pooling width value.
264     uint32_t            m_PoolWidth;
265     /// Pooling height value.
266     uint32_t            m_PoolHeight;
267     /// Stride value when proceeding through input for the width dimension.
268     uint32_t            m_StrideX;
269     /// Stride value when proceeding through input for the height dimension.
270     uint32_t            m_StrideY;
271     /// The rounding method for the output shape. (Floor, Ceiling).
272     OutputShapeRounding m_OutputShapeRounding;
273     /// The padding method to be used. (Exclude, IgnoreValue).
274     PaddingMethod       m_PaddingMethod;
275     /// The data layout to be used (NCHW, NHWC).
276     DataLayout   m_DataLayout;
277 };
278
279 /// A FullyConnectedDescriptor for the FullyConnectedLayer.
280 struct FullyConnectedDescriptor
281 {
282     FullyConnectedDescriptor()
283     : m_BiasEnabled(false)
284     , m_TransposeWeightMatrix(false)
285     {}
286
287     /// Enable/disable bias.
288     bool m_BiasEnabled;
289     /// Enable/disable transpose weight matrix.
290     bool m_TransposeWeightMatrix;
291 };
292
293 /// A Convolution2dDescriptor for the Convolution2dLayer.
294 struct Convolution2dDescriptor
295 {
296     Convolution2dDescriptor()
297     : m_PadLeft(0)
298     , m_PadRight(0)
299     , m_PadTop(0)
300     , m_PadBottom(0)
301     , m_StrideX(0)
302     , m_StrideY(0)
303     , m_DilationX(1)
304     , m_DilationY(1)
305     , m_BiasEnabled(false)
306     , m_DataLayout(DataLayout::NCHW)
307     {}
308
309     /// Padding left value in the width dimension.
310     uint32_t             m_PadLeft;
311     /// Padding right value in the width dimension.
312     uint32_t             m_PadRight;
313     /// Padding top value in the height dimension.
314     uint32_t             m_PadTop;
315     /// Padding bottom value in the height dimension.
316     uint32_t             m_PadBottom;
317     /// Stride value when proceeding through input for the width dimension.
318     uint32_t             m_StrideX;
319     /// Stride value when proceeding through input for the height dimension.
320     uint32_t             m_StrideY;
321     /// Dilation along x axis
322     uint32_t             m_DilationX;
323     /// Dilation along y axis
324     uint32_t             m_DilationY;
325     /// Enable/disable bias.
326     bool                 m_BiasEnabled;
327     /// The data layout to be used (NCHW, NHWC).
328     DataLayout           m_DataLayout;
329 };
330
331 /// A DepthwiseConvolution2dDescriptor for the DepthwiseConvolution2dLayer.
332 struct DepthwiseConvolution2dDescriptor
333 {
334     DepthwiseConvolution2dDescriptor()
335     :   m_PadLeft(0)
336     ,   m_PadRight(0)
337     ,   m_PadTop(0)
338     ,   m_PadBottom(0)
339     ,   m_StrideX(0)
340     ,   m_StrideY(0)
341     ,   m_DilationX(1)
342     ,   m_DilationY(1)
343     ,   m_BiasEnabled(false)
344     ,   m_DataLayout(DataLayout::NCHW)
345     {}
346
347     /// Padding left value in the width dimension.
348     uint32_t   m_PadLeft;
349     /// Padding right value in the width dimension.
350     uint32_t   m_PadRight;
351     /// Padding top value in the height dimension.
352     uint32_t   m_PadTop;
353     /// Padding bottom value in the height dimension.
354     uint32_t   m_PadBottom;
355     /// Stride value when proceeding through input for the width dimension.
356     uint32_t   m_StrideX;
357     /// Stride value when proceeding through input for the height dimension.
358     uint32_t   m_StrideY;
359     /// Dilation factor value for width dimension.
360     uint32_t   m_DilationX;
361     /// Dilation factor value for height dimension.
362     uint32_t   m_DilationY;
363     /// Enable/disable bias.
364     bool       m_BiasEnabled;
365     /// The data layout to be used (NCHW, NHWC).
366     DataLayout m_DataLayout;
367 };
368
369 struct DetectionPostProcessDescriptor
370 {
371     DetectionPostProcessDescriptor()
372     : m_MaxDetections(0)
373     , m_MaxClassesPerDetection(1)
374     , m_DetectionsPerClass(1)
375     , m_NmsScoreThreshold(0)
376     , m_NmsIouThreshold(0)
377     , m_NumClasses(0)
378     , m_UseRegularNms(false)
379     , m_ScaleX(0)
380     , m_ScaleY(0)
381     , m_ScaleW(0)
382     , m_ScaleH(0)
383     {}
384
385     /// Maximum numbers of detections.
386     uint32_t m_MaxDetections;
387     /// Maximum numbers of classes per detection, used in Fast NMS.
388     uint32_t m_MaxClassesPerDetection;
389     /// Detections per classes, used in Regular NMS.
390     uint32_t m_DetectionsPerClass;
391     /// NMS score threshold.
392     float m_NmsScoreThreshold;
393     /// Intersection over union threshold.
394     float m_NmsIouThreshold;
395     /// Number of classes.
396     uint32_t m_NumClasses;
397     /// Use Regular NMS.
398     bool m_UseRegularNms;
399     /// Center size encoding scale x.
400     float m_ScaleX;
401     /// Center size encoding scale y.
402     float m_ScaleY;
403     /// Center size encoding scale weight.
404     float m_ScaleW;
405     /// Center size encoding scale height.
406     float m_ScaleH;
407 };
408
409 /// A NormalizationDescriptor for the NormalizationLayer.
410 struct NormalizationDescriptor
411 {
412     NormalizationDescriptor()
413     : m_NormChannelType(NormalizationAlgorithmChannel::Across)
414     , m_NormMethodType(NormalizationAlgorithmMethod::LocalBrightness)
415     , m_NormSize(0)
416     , m_Alpha(0.f)
417     , m_Beta(0.f)
418     , m_K(0.f)
419     , m_DataLayout(DataLayout::NCHW)
420     {}
421
422     /// Normalization channel algorithm to use (Across, Within).
423     NormalizationAlgorithmChannel m_NormChannelType;
424     /// Normalization method algorithm to use (LocalBrightness, LocalContrast).
425     NormalizationAlgorithmMethod  m_NormMethodType;
426     /// Depth radius value.
427     uint32_t                      m_NormSize;
428     /// Alpha value for the normalization equation.
429     float                         m_Alpha;
430     /// Beta value for the normalization equation.
431     float                         m_Beta;
432     /// Kappa value used for the across channel normalization equation.
433     float                         m_K;
434     /// The data layout to be used (NCHW, NHWC).
435     DataLayout                    m_DataLayout;
436 };
437
438 /// A L2NormalizationDescriptor for the L2NormalizationLayer.
439 struct L2NormalizationDescriptor
440 {
441     L2NormalizationDescriptor()
442     : m_Eps(1e-12f)
443     , m_DataLayout(DataLayout::NCHW)
444     {}
445
446     /// Used to avoid dividing by zero.
447     float m_Eps;
448     /// The data layout to be used (NCHW, NHWC).
449     DataLayout m_DataLayout;
450 };
451
452 /// A BatchNormalizationDescriptor for the BatchNormalizationLayer.
453 struct BatchNormalizationDescriptor
454 {
455     BatchNormalizationDescriptor()
456     : m_Eps(0.0001f)
457     , m_DataLayout(DataLayout::NCHW)
458     {}
459
460     /// Value to add to the variance. Used to avoid dividing by zero.
461     float m_Eps;
462     /// The data layout to be used (NCHW, NHWC).
463     DataLayout m_DataLayout;
464 };
465
466 /// A BatchToSpaceNdDescriptor for the BatchToSpaceNdLayer.
467 struct BatchToSpaceNdDescriptor
468 {
469     BatchToSpaceNdDescriptor()
470         : m_BlockShape({1, 1})
471         , m_Crops({{0, 0}, {0, 0}})
472         , m_DataLayout(DataLayout::NCHW)
473     {}
474
475     BatchToSpaceNdDescriptor(std::vector<unsigned int> blockShape,
476                              std::vector<std::pair<unsigned int, unsigned int>> crops)
477         : m_BlockShape(blockShape)
478         , m_Crops(crops)
479         , m_DataLayout(DataLayout::NCHW)
480     {}
481
482     /// Block shape values.
483     std::vector<unsigned int> m_BlockShape;
484     /// The values to crop from the input dimension.
485     std::vector<std::pair<unsigned int, unsigned int>> m_Crops;
486     /// The data layout to be used (NCHW, NHWC).
487     DataLayout m_DataLayout;
488 };
489
490 /// A FakeQuantizationDescriptor for the FakeQuantizationLayer.
491 struct FakeQuantizationDescriptor
492 {
493     FakeQuantizationDescriptor()
494     : m_Min(-6.0f)
495     , m_Max(6.0f)
496     {}
497
498     /// Minimum value.
499     float m_Min;
500     /// Maximum value.
501     float m_Max;
502 };
503
504 /// A ResizeBilinearDescriptor for the ResizeBilinearLayer.
505 struct ResizeBilinearDescriptor
506 {
507     ResizeBilinearDescriptor()
508     : m_TargetWidth(0)
509     , m_TargetHeight(0)
510     , m_DataLayout(DataLayout::NCHW)
511     {}
512
513     /// Target width value.
514     uint32_t          m_TargetWidth;
515     /// Target height value.
516     uint32_t          m_TargetHeight;
517     /// The data layout to be used (NCHW, NHWC).
518     DataLayout m_DataLayout;
519 };
520
521 /// A ResizeDescriptor for the ResizeLayer.
522 struct ResizeDescriptor
523 {
524     ResizeDescriptor()
525             : m_TargetWidth(0)
526             , m_TargetHeight(0)
527             , m_Method(ResizeMethod::NearestNeighbor)
528             , m_DataLayout(DataLayout::NCHW)
529     {}
530
531     /// Target width value.
532     uint32_t m_TargetWidth;
533     /// Target height value.
534     uint32_t m_TargetHeight;
535     /// The Interpolation method to use
536     /// (Bilinear, NearestNeighbor).
537     ResizeMethod m_Method;
538     /// The data layout to be used (NCHW, NHWC).
539     DataLayout m_DataLayout;
540 };
541
542
543 /// A ReshapeDescriptor for the ReshapeLayer.
544 struct ReshapeDescriptor
545 {
546     ReshapeDescriptor()
547     : m_TargetShape()
548     {}
549
550     ReshapeDescriptor(const TensorShape& shape)
551     : m_TargetShape(shape)
552     {}
553
554     /// Target shape value.
555     TensorShape m_TargetShape;
556 };
557
558 /// A SpaceToBatchNdDescriptor for the SpaceToBatchNdLayer.
559 struct SpaceToBatchNdDescriptor
560 {
561     SpaceToBatchNdDescriptor()
562     : m_BlockShape({1, 1})
563     , m_PadList({{0, 0}, {0, 0}})
564     , m_DataLayout(DataLayout::NCHW)
565     {}
566
567     SpaceToBatchNdDescriptor(const std::vector<unsigned int>& blockShape,
568                              const std::vector<std::pair<unsigned int, unsigned int>>& padList)
569     : m_BlockShape(blockShape)
570     , m_PadList(padList)
571     , m_DataLayout(DataLayout::NCHW)
572     {}
573
574     /// Block shape value.
575     std::vector<unsigned int> m_BlockShape;
576     /// @brief Specifies the padding values for the input dimension:
577     /// heightPad{top, bottom} widthPad{left, right}.
578     std::vector<std::pair<unsigned int, unsigned int>> m_PadList;
579     /// The data layout to be used (NCHW, NHWC).
580     DataLayout m_DataLayout;
581 };
582
583 /// A SpaceToDepthDescriptor for the SpaceToDepthLayer
584 struct SpaceToDepthDescriptor
585 {
586     SpaceToDepthDescriptor()
587     : m_BlockSize(1u)
588     , m_DataLayout(DataLayout::NHWC)
589     {}
590
591     /// Scalar specifying the input block size. It must be >= 1
592     unsigned int m_BlockSize;
593     /// The data layout to be used (NCHW, NHWC).
594     DataLayout m_DataLayout;
595 };
596
597 /// An LstmDescriptor for the LstmLayer.
598 struct LstmDescriptor
599 {
600     LstmDescriptor()
601     : m_ActivationFunc(1) // 0: None, 1: Relu, 3: Relu6, 4: Tanh, 6: Sigmoid
602     , m_ClippingThresCell(0.0)
603     , m_ClippingThresProj(0.0)
604     , m_CifgEnabled(true)
605     , m_PeepholeEnabled(false)
606     , m_ProjectionEnabled(false)
607     , m_LayerNormEnabled(false)
608     {}
609
610     /// @brief The activation function to use.
611     /// 0: None, 1: Relu, 3: Relu6, 4: Tanh, 6: Sigmoid.
612     uint32_t m_ActivationFunc;
613     /// Clipping threshold value for the cell state.
614     float m_ClippingThresCell;
615     /// Clipping threshold value for the projection.
616     float m_ClippingThresProj;
617     /// Enable/disable cifg (coupled input & forget gate).
618     bool m_CifgEnabled;
619     /// Enable/disable peephole.
620     bool m_PeepholeEnabled;
621     /// Enable/disable the projection layer.
622     bool m_ProjectionEnabled;
623     /// Enable/disable layer normalization
624     bool m_LayerNormEnabled;
625 };
626
627 /// A MeanDescriptor for the MeanLayer.
628 struct MeanDescriptor
629 {
630     MeanDescriptor()
631     : m_Axis()
632     , m_KeepDims(false)
633     {}
634
635     MeanDescriptor(const std::vector<unsigned int>& axis, bool keepDims)
636     : m_Axis(axis)
637     , m_KeepDims(keepDims)
638     {}
639
640     /// Values for the dimensions to reduce.
641     std::vector<unsigned int> m_Axis;
642     /// Enable/disable keep dimensions. If true, then the reduced dimensions that are of length 1 are kept.
643     bool m_KeepDims;
644 };
645
646 /// A PadDescriptor for the PadLayer.
647 struct PadDescriptor
648 {
649     PadDescriptor() : m_PadValue(0)
650     {}
651
652     PadDescriptor(const std::vector<std::pair<unsigned int, unsigned int>>& padList, const float& padValue = 0)
653     : m_PadList(padList), m_PadValue(padValue)
654     {}
655
656     /// @brief Specifies the padding for input dimension.
657     /// First is the number of values to add before the tensor in the dimension.
658     /// Second is the number of values to add after the tensor in the dimension.
659     /// The number of pairs should match the number of dimensions in the input tensor.
660     std::vector<std::pair<unsigned int, unsigned int>> m_PadList;
661
662     /// Optional value to use for padding, defaults to 0
663     float m_PadValue;
664 };
665
666 /// A StackDescriptor for the StackLayer.
667 struct StackDescriptor
668 {
669     StackDescriptor()
670     : m_Axis(0)
671     , m_NumInputs(0)
672     , m_InputShape()
673     {}
674
675     StackDescriptor(uint32_t axis, uint32_t numInputs, const TensorShape& inputShape)
676     : m_Axis(axis)
677     , m_NumInputs(numInputs)
678     , m_InputShape(inputShape)
679     {}
680
681     /// 0-based axis along which to stack the input tensors.
682     uint32_t m_Axis;
683     /// Number of input tensors.
684     uint32_t m_NumInputs;
685     /// Required shape of all input tensors.
686     TensorShape m_InputShape;
687 };
688
689 /// A StridedSliceDescriptor for the StridedSliceLayer.
690 struct StridedSliceDescriptor
691 {
692     StridedSliceDescriptor(const std::vector<int>& begin,
693                            const std::vector<int>& end,
694                            const std::vector<int>& stride)
695     : m_Begin(begin)
696     , m_End(end)
697     , m_Stride(stride)
698     , m_BeginMask(0)
699     , m_EndMask(0)
700     , m_ShrinkAxisMask(0)
701     , m_EllipsisMask(0)
702     , m_NewAxisMask(0)
703     , m_DataLayout(DataLayout::NCHW)
704     {}
705
706     StridedSliceDescriptor()
707     : StridedSliceDescriptor({}, {}, {})
708     {}
709
710     int GetStartForAxis(const TensorShape& inputShape, unsigned int axis) const;
711     int GetStopForAxis(const TensorShape& inputShape,
712                        unsigned int axis,
713                        int startForAxis) const;
714
715     /// Begin values for the input that will be sliced.
716     std::vector<int> m_Begin;
717     /// End values for the input that will be sliced.
718     std::vector<int> m_End;
719     /// Stride values for the input that will be sliced.
720     std::vector<int> m_Stride;
721
722     /// @brief Begin mask value. If set, then the begin is disregarded and the fullest
723     /// range is used for the dimension.
724     int32_t m_BeginMask;
725     /// @brief End mask value. If set, then the end is disregarded and the fullest range
726     /// is used for the dimension.
727     int32_t m_EndMask;
728     /// Shrink axis mask value. If set, the nth specification shrinks the dimensionality by 1.
729     int32_t m_ShrinkAxisMask;
730     /// Ellipsis mask value.
731     int32_t m_EllipsisMask;
732     /// @brief New axis mask value. If set, the begin, end and stride is disregarded and
733     /// a new 1 dimension is inserted to this location of the output tensor.
734     int32_t m_NewAxisMask;
735
736     /// The data layout to be used (NCHW, NHWC).
737     DataLayout m_DataLayout;
738 };
739
740 /// A PreCompiledDescriptor for the PreCompiledLayer.
741 struct PreCompiledDescriptor
742 {
743     PreCompiledDescriptor(unsigned int numInputSlots = 1u, unsigned int numOutputSlots = 1u)
744         : m_NumInputSlots(numInputSlots), m_NumOutputSlots(numOutputSlots)
745     {}
746
747     ~PreCompiledDescriptor() = default;
748
749     unsigned int m_NumInputSlots;
750     unsigned int m_NumOutputSlots;
751 };
752
753 /// A TransposeConvolution2dDescriptor for the TransposeConvolution2dLayer.
754 struct TransposeConvolution2dDescriptor
755 {
756     TransposeConvolution2dDescriptor() :
757         m_PadLeft(0),
758         m_PadRight(0),
759         m_PadTop(0),
760         m_PadBottom(0),
761         m_StrideX(0),
762         m_StrideY(0),
763         m_BiasEnabled(false),
764         m_DataLayout(DataLayout::NCHW)
765     {}
766
767     /// Padding left value in the width dimension.
768     uint32_t   m_PadLeft;
769     /// Padding right value in the width dimension.
770     uint32_t   m_PadRight;
771     /// Padding top value in the height dimension.
772     uint32_t   m_PadTop;
773     /// Padding bottom value in the height dimension.
774     uint32_t   m_PadBottom;
775     /// Stride value when proceeding through input for the width dimension.
776     uint32_t   m_StrideX;
777     /// Stride value when proceeding through input for the height dimension.
778     uint32_t   m_StrideY;
779     /// Enable/disable bias.
780     bool       m_BiasEnabled;
781     /// The data layout to be used (NCHW, NHWC).
782     DataLayout m_DataLayout;
783 };
784
785 } // namespace armnn