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