blob: d9c89f8779eb87ee9366b5fa3b4b2602618a9f69 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Mohammed Suhail Munshid538d162023-02-16 16:22:32 +00002 * Copyright (c) 2016-2023 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_TYPES_H
25#define ARM_COMPUTE_TYPES_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/Coordinates.h"
Isabella Gottardi6e464c32018-01-26 12:32:45 +000028#include "arm_compute/core/Size2D.h"
Adnan AlSinane4563a02021-09-01 15:32:03 +010029#include "arm_compute/core/Size3D.h"
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000030#include "arm_compute/core/Strides.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031#include "arm_compute/core/TensorShape.h"
SiCongLi579ca842021-10-18 09:38:33 +010032#include "arm_compute/core/experimental/IPostOp.h"
Sang-Hoon Park11fedda2020-01-15 14:44:04 +000033#include "arm_compute/core/utils/misc/Macros.h"
Georgios Pinitase8291ac2020-02-26 09:58:13 +000034#include "support/Bfloat16.h"
Georgios Pinitas583137c2017-08-31 18:12:42 +010035#include "support/Half.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036
Michel Iwaniec5dfeae62017-11-29 10:48:23 +000037#include <cmath>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038#include <cstddef>
39#include <cstdint>
Isabella Gottardia7acb3c2019-01-08 13:48:44 +000040#include <map>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041#include <string>
42#include <utility>
43
44namespace arm_compute
45{
Georgios Pinitas583137c2017-08-31 18:12:42 +010046/** 16-bit floating point type */
47using half = half_float::half;
48
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000049/** Permutation vector */
50using PermutationVector = Strides;
Georgios Pinitas77589b52018-08-21 14:41:35 +010051/** Bidirectional strides */
52using BiStrides = Coordinates;
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000053
Matthew Benthamf1aeab92023-05-30 13:35:34 +000054/** Available activation functions */
55enum class ActivationFunction
56{
57 LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */
58 TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */
59 RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */
60 BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */
61 LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */
62 LEAKY_RELU, /**< Leaky Rectifier ( \f$ f(x) = \begin{cases} \alpha x & \quad \text{if } x \text{ < 0}\\ x & \quad \text{if } x \geq \text{ 0 } \end{cases} \f$ ) */
63 SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
64 ELU, /**< Exponential Linear Unit ( \f$ f(x) = \begin{cases} \alpha (exp(x) - 1) & \quad \text{if } x \text{ < 0}\\ x & \quad \text{if } x \geq \text{ 0 } \end{cases} \f$ ) */
65 ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */
66 SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/
67 SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/
68 LINEAR, /**< Linear ( \f$ f(x)= ax + b \f$ ) */
69 IDENTITY, /**< Identity ( \f$ f(x)= x \f$ ) */
70 HARD_SWISH, /**< Hard-swish ( \f$ f(x) = (x \text{ReLU6}(x+3))/6 = x \min(\max(0,x+3),6)/6 \f$ ) */
71 SWISH, /**< Swish ( \f$ f(x) = \frac{x}{1 + e^{-ax}} = x \text{logistic}(ax) \f$ ) */
72 GELU /**< GELU ( \f$ f(x) = x * 1/2 * 1 + erf(x / \sqrt{2}) \f$ ) */
73};
74
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075/** Image colour formats */
76enum class Format
77{
Daniil Efremov02bf80d2017-11-22 00:26:51 +070078 UNKNOWN, /**< Unknown image format */
79 U8, /**< 1 channel, 1 U8 per channel */
80 S16, /**< 1 channel, 1 S16 per channel */
81 U16, /**< 1 channel, 1 U16 per channel */
82 S32, /**< 1 channel, 1 S32 per channel */
83 U32, /**< 1 channel, 1 U32 per channel */
Georgios Pinitase8291ac2020-02-26 09:58:13 +000084 BFLOAT16, /**< 16-bit brain floating-point number */
Daniil Efremov02bf80d2017-11-22 00:26:51 +070085 F16, /**< 1 channel, 1 F16 per channel */
86 F32, /**< 1 channel, 1 F32 per channel */
87 UV88, /**< 2 channel, 1 U8 per channel */
88 RGB888, /**< 3 channels, 1 U8 per channel */
89 RGBA8888, /**< 4 channels, 1 U8 per channel */
90 YUV444, /**< A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes */
91 YUYV422, /**< A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes */
92 NV12, /**< A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling */
93 NV21, /**< A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling */
94 IYUV, /**< A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes */
95 UYVY422 /**< A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096};
97
98/** Available data types */
99enum class DataType
100{
Georgios Pinitas8217c8e2019-11-11 18:24:22 +0000101 UNKNOWN, /**< Unknown data type */
102 U8, /**< unsigned 8-bit number */
103 S8, /**< signed 8-bit number */
104 QSYMM8, /**< quantized, symmetric fixed-point 8-bit number */
105 QASYMM8, /**< quantized, asymmetric fixed-point 8-bit number unsigned */
106 QASYMM8_SIGNED, /**< quantized, asymmetric fixed-point 8-bit number signed */
107 QSYMM8_PER_CHANNEL, /**< quantized, symmetric per channel fixed-point 8-bit number */
108 U16, /**< unsigned 16-bit number */
109 S16, /**< signed 16-bit number */
110 QSYMM16, /**< quantized, symmetric fixed-point 16-bit number */
111 QASYMM16, /**< quantized, asymmetric fixed-point 16-bit number */
112 U32, /**< unsigned 32-bit number */
113 S32, /**< signed 32-bit number */
114 U64, /**< unsigned 64-bit number */
115 S64, /**< signed 64-bit number */
Georgios Pinitase8291ac2020-02-26 09:58:13 +0000116 BFLOAT16, /**< 16-bit brain floating-point number */
Georgios Pinitas8217c8e2019-11-11 18:24:22 +0000117 F16, /**< 16-bit floating-point number */
118 F32, /**< 32-bit floating-point number */
119 F64, /**< 64-bit floating-point number */
120 SIZET /**< size_t */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100121};
122
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700123/** Available Sampling Policies */
124enum class SamplingPolicy
125{
126 CENTER, /**< Samples are taken at pixel center */
127 TOP_LEFT /**< Samples are taken at pixel top left corner */
128};
129
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +0000130/** [DataLayout enum definition] **/
131
Georgios Pinitas4074c992018-01-30 18:13:46 +0000132/** Supported tensor data layouts */
133enum class DataLayout
134{
Alex Gildayc357c472018-03-21 13:54:09 +0000135 UNKNOWN, /**< Unknown data layout */
136 NCHW, /**< Num samples, channels, height, width */
Adnan AlSinane4563a02021-09-01 15:32:03 +0100137 NHWC, /**< Num samples, height, width, channels */
Giorgio Arenac9fe9fc2021-10-06 12:54:29 +0100138 NCDHW, /**< Num samples, channels, depth, height, width */
Adnan AlSinane4563a02021-09-01 15:32:03 +0100139 NDHWC /**< Num samples, depth, height, width, channels */
Georgios Pinitas4074c992018-01-30 18:13:46 +0000140};
Vidhya Sudhan Loganathand646ae12018-11-19 15:18:20 +0000141/** [DataLayout enum definition] **/
Georgios Pinitas4074c992018-01-30 18:13:46 +0000142
Isabella Gottardid17a6772018-02-27 17:41:55 +0000143/** Supported tensor data layout dimensions */
144enum class DataLayoutDimension
145{
Alex Gildayc357c472018-03-21 13:54:09 +0000146 CHANNEL, /**< channel */
147 HEIGHT, /**< height */
148 WIDTH, /**< width */
Giorgio Arenac9fe9fc2021-10-06 12:54:29 +0100149 DEPTH, /**< depth */
Alex Gildayc357c472018-03-21 13:54:09 +0000150 BATCHES /**< batches */
Isabella Gottardid17a6772018-02-27 17:41:55 +0000151};
152
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000153/** Available ConvolutionMethod*/
154enum class ConvolutionMethod
155{
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000156 GEMM, /**< Convolution using GEMM */
157 GEMM_CONV2D, /**< Direct 2D GEMM convolution */
158 DIRECT, /**< Direct convolution */
Gian Marco Iodicea5cb79f2022-12-28 13:53:51 +0000159 INDIRECT, /**< Indirect convolution */
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000160 WINOGRAD, /**< Convolution using Winograd */
161 FFT /**< Convolution using FFT */
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000162};
163
Manuel Bottini05069f02019-09-26 17:18:26 +0100164/** Available DepthwiseConvolutionFunction*/
165enum class DepthwiseConvolutionFunction
166{
167 OPTIMIZED, /**< Optimized Depthwise Convolution */
168 GENERIC, /**< Generic Depthwise Convolution */
169};
170
giuros0146a49a02019-04-01 13:50:22 +0100171/** Available DeconvolutionMethod*/
172enum class DeconvolutionMethod
173{
SiCong Li4ceb4532023-03-13 15:02:23 +0000174 GEMM, /**< Deconvolution using GEMM */
175 DIRECT, /**< Direct deconvolution */
176 UPSCALE_CONV2D /**< Deconvolution with Upscaling */
giuros0146a49a02019-04-01 13:50:22 +0100177};
178
Manuel Bottini2732cca2019-05-28 11:44:41 +0100179/** Available FuseBatchNormalizationType*/
180enum class FuseBatchNormalizationType
181{
182 CONVOLUTION, /**< For Convolution weights */
183 DEPTHWISECONVOLUTION /**< For Depthwise Convolution weights*/
184};
185
Usama Arif89890c62019-03-19 10:57:05 +0000186/** Padding mode to use for PadLayer */
187enum class PaddingMode
188{
189 CONSTANT,
190 REFLECT,
191 SYMMETRIC
192};
193
Georgios Pinitas7900a9e2018-11-23 11:44:58 +0000194/** Supported comparison operations */
195enum class ComparisonOperation
196{
197 Equal, /**< Equal comparison ( \f$ x == y \f$ ) */
198 NotEqual, /**< NotEqual comparison ( \f$ x != y \f$ ) */
199 Greater, /**< Greater comparison ( \f$ x > y \f$ ) */
200 GreaterEqual, /**< Greater equal comparison ( \f$ x >= y \f$ ) */
201 Less, /**< Less comparison ( \f$ x < y \f$ ) */
202 LessEqual /**< Less equal comparison ( \f$ x <= y \f$ ) */
203};
204
Alex Gildayc357c472018-03-21 13:54:09 +0000205/** Container for valid region of a window */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100206struct ValidRegion
207{
Alex Gildayc357c472018-03-21 13:54:09 +0000208 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100209 ValidRegion()
210 : anchor{}, shape{}
211 {
212 }
213
Alex Gildayc357c472018-03-21 13:54:09 +0000214 /** Allow instances of this class to be copy constructed */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100215 ValidRegion(const ValidRegion &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000216 /** Allow instances of this class to be move constructed */
217 ValidRegion(ValidRegion &&) = default;
218 /** Allow instances of this class to be copied */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100219 ValidRegion &operator=(const ValidRegion &) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000220 /** Allow instances of this class to be moved */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100221 ValidRegion &operator=(ValidRegion &&) = default;
Alex Gildayc357c472018-03-21 13:54:09 +0000222 /** Default destructor */
223 ~ValidRegion() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100224
Alex Gildayc357c472018-03-21 13:54:09 +0000225 /** Constructor for a valid region with default number of dimensions
226 *
227 * @param[in] an_anchor Anchor for the start of the valid region.
228 * @param[in] a_shape Shape of the valid region.
229 *
230 */
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000231 ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape)
232 : anchor{ an_anchor }, shape{ a_shape }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100233 {
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000234 anchor.set_num_dimensions(std::max(anchor.num_dimensions(), shape.num_dimensions()));
235 }
236
Alex Gildayc357c472018-03-21 13:54:09 +0000237 /** Constructor for a valid region with specified number of dimensions
238 *
239 * @param[in] an_anchor Anchor for the start of the valid region.
240 * @param[in] a_shape Shape of the valid region.
241 * @param[in] num_dimensions Number of dimensions (must be >= number of dimensions of anchor and shape).
242 *
243 */
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +0000244 ValidRegion(const Coordinates &an_anchor, const TensorShape &a_shape, size_t num_dimensions)
245 : anchor{ an_anchor }, shape{ a_shape }
246 {
247 ARM_COMPUTE_ERROR_ON(num_dimensions < std::max(anchor.num_dimensions(), shape.num_dimensions()));
248 anchor.set_num_dimensions(num_dimensions);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100249 }
250
251 /** Return the start of the valid region for the given dimension @p d */
252 int start(unsigned int d) const
253 {
254 return anchor[d];
255 }
256
257 /** Return the end of the valid region for the given dimension @p d */
258 int end(unsigned int d) const
259 {
260 return anchor[d] + shape[d];
261 }
262
Diego Lopez Recas35ceeb22017-12-04 18:56:10 +0000263 /** Accessor to set the value of anchor and shape for one of the dimensions.
264 *
265 * @param[in] dimension Dimension for which the value is set.
266 * @param[in] start Value to be set in anchor for the dimension.
267 * @param[in] size Value to be set in shape for the dimension.
268 *
269 * @return *this.
270 */
271 ValidRegion &set(size_t dimension, int start, size_t size)
272 {
273 anchor.set(dimension, start);
274 shape.set(dimension, size);
275 return *this;
276 }
277
SiCong Lib63b1192022-01-28 18:24:39 +0000278 /** Check whether two valid regions are equal.
279 *
280 * @param[in] lhs LHS valid region
281 * @param[in] rhs RHS valid region
282 *
283 * @return True if the valid regions are the same.
284 */
285 inline friend bool operator==(const ValidRegion &lhs, const ValidRegion &rhs);
286
Alex Gildayc357c472018-03-21 13:54:09 +0000287 Coordinates anchor; /**< Anchor for the start of the valid region. */
288 TensorShape shape; /**< Shape of the valid region. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100289};
SiCong Lib63b1192022-01-28 18:24:39 +0000290inline bool operator==(const ValidRegion &lhs, const ValidRegion &rhs)
291{
292 return (lhs.anchor == rhs.anchor) && (lhs.shape == rhs.shape);
293}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100294
295/** Methods available to handle borders */
296enum class BorderMode
297{
298 UNDEFINED, /**< Borders are left undefined */
299 CONSTANT, /**< Pixels outside the image are assumed to have a constant value */
300 REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */
301};
302
303/** Container for 2D border size */
304struct BorderSize
305{
306 /** Empty border, i.e. no border */
Pablo Marquez Tello383de022021-03-18 11:31:13 +0000307 constexpr BorderSize() noexcept
308 : top{ 0 },
309 right{ 0 },
310 bottom{ 0 },
311 left{ 0 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100312 {
313 }
314
315 /** Border with equal size around the 2D plane */
Pablo Marquez Tello383de022021-03-18 11:31:13 +0000316 explicit constexpr BorderSize(unsigned int size) noexcept
317 : top{ size },
318 right{ size },
319 bottom{ size },
320 left{ size }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100321 {
322 }
323
324 /** Border with same size for top/bottom and left/right */
325 constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
326 : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right }
327 {
328 }
329
330 /** Border with different sizes */
331 constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
332 : top{ top }, right{ right }, bottom{ bottom }, left{ left }
333 {
334 }
335
336 /** Check if the entire border is zero */
337 constexpr bool empty() const
338 {
339 return top == 0 && right == 0 && bottom == 0 && left == 0;
340 }
341
342 /** Check if the border is the same size on all sides */
343 constexpr bool uniform() const
344 {
345 return top == right && top == bottom && top == left;
346 }
347
Alex Gildayc357c472018-03-21 13:54:09 +0000348 /** Scale this border size.
349 *
350 * @param[in] scale Scale to multiply border size by.
351 *
352 * @return *this.
353 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100354 BorderSize &operator*=(float scale)
355 {
356 top *= scale;
357 right *= scale;
358 bottom *= scale;
359 left *= scale;
360
361 return *this;
362 }
363
Alex Gildayc357c472018-03-21 13:54:09 +0000364 /** Scale a copy of this border size.
365 *
366 * @param[in] scale Scale to multiply border size by.
367 *
368 * @return a scaled copy of this.
369 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100370 BorderSize operator*(float scale)
371 {
372 BorderSize size = *this;
373 size *= scale;
374
375 return size;
376 }
377
Giorgio Arena1e2af2a2020-10-15 17:39:41 +0100378 /** Check equality with another BorderSize struct
379 *
380 * @param[in] rhs other struct to check against
381 *
382 * @return true if they are equal
383 */
SiCong Lib63b1192022-01-28 18:24:39 +0000384 bool operator==(const BorderSize &rhs) const
Giorgio Arena1e2af2a2020-10-15 17:39:41 +0100385 {
386 return (top == rhs.top) && (right == rhs.right) && (bottom == rhs.bottom) && (left == rhs.left);
387 }
388
389 /** Check non-equality with another BorderSize struct
390 *
391 * @param[in] rhs other struct to check against
392 *
393 * @return true if they are different
394 */
SiCong Lib63b1192022-01-28 18:24:39 +0000395 bool operator!=(const BorderSize &rhs) const
Giorgio Arena1e2af2a2020-10-15 17:39:41 +0100396 {
397 return !(*this == rhs);
398 }
399
Alex Gildayc357c472018-03-21 13:54:09 +0000400 /** Limit this border size.
401 *
402 * @param[in] limit Border size to limit this border size to.
403 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100404 void limit(const BorderSize &limit)
405 {
406 top = std::min(top, limit.top);
407 right = std::min(right, limit.right);
408 bottom = std::min(bottom, limit.bottom);
409 left = std::min(left, limit.left);
410 }
411
Alex Gildayc357c472018-03-21 13:54:09 +0000412 unsigned int top; /**< top of the border */
413 unsigned int right; /**< right of the border */
414 unsigned int bottom; /**< bottom of the border */
415 unsigned int left; /**< left of the border */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100416};
417
Alex Gildayc357c472018-03-21 13:54:09 +0000418/** Container for 2D padding size */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100419using PaddingSize = BorderSize;
420
SiCongLi1af54162021-10-06 15:25:57 +0100421/** Policy to handle integer overflow
422 * @note: This is ignored by floating point operations where the overflow behavior adheres to the IEEE-754 standard
423 * which states that in case of overflow ±infinity is returned for the round-to-nearest modes (and follows the
424 * rounding rules for the directed rounding modes) by default.
425 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100426enum class ConvertPolicy
427{
428 WRAP, /**< Wrap around */
429 SATURATE /**< Saturate */
430};
431
432/** Interpolation method */
433enum class InterpolationPolicy
434{
435 NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */
436 BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */
437 AREA, /**< Output values are determined by averaging the source pixels whose areas fall under the area of the destination pixel, projected onto the source image */
438};
439
440/** Bilinear Interpolation method used by LKTracker */
441enum class BilinearInterpolation
442{
Alex Gildayc357c472018-03-21 13:54:09 +0000443 BILINEAR_OLD_NEW, /**< Old-new method */
444 BILINEAR_SCHARR /**< Scharr method */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100445};
446
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100447/** Rectangle type */
448struct Rectangle
449{
450 uint16_t x; /**< Top-left x coordinate */
451 uint16_t y; /**< Top-left y coordinate */
452 uint16_t width; /**< Width of the rectangle */
453 uint16_t height; /**< Height of the rectangle */
454};
455
456/** Coordinate type */
457struct Coordinates2D
458{
459 int32_t x; /**< X coordinates */
460 int32_t y; /**< Y coordinates */
461};
462
463/** Coordinate type */
464struct Coordinates3D
465{
466 uint32_t x; /**< X coordinates */
467 uint32_t y; /**< Y coordinates */
468 uint32_t z; /**< Z coordinates */
469};
470
Giuseppe Rossinid7647d42018-07-17 18:13:13 +0100471/** Padding information as a pair of unsigned int start/end */
472using PaddingInfo = std::pair<uint32_t, uint32_t>;
473
474/** List of padding information */
475using PaddingList = std::vector<PaddingInfo>;
476
giuros013175fcf2018-11-21 09:59:17 +0000477/** Information to produce a tiled version of a Tensor */
478using Multiples = std::vector<uint32_t>;
479
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100480/** Available channels */
481enum class Channel
482{
483 UNKNOWN, /** Unknown channel format */
484 C0, /**< First channel (used by formats with unknown channel types). */
485 C1, /**< Second channel (used by formats with unknown channel types). */
486 C2, /**< Third channel (used by formats with unknown channel types). */
487 C3, /**< Fourth channel (used by formats with unknown channel types). */
488 R, /**< Red channel. */
489 G, /**< Green channel. */
490 B, /**< Blue channel. */
491 A, /**< Alpha channel. */
492 Y, /**< Luma channel. */
493 U, /**< Cb/U channel. */
494 V /**< Cr/V/Value channel. */
495};
496
Georgios Pinitasd9769582017-08-03 10:19:40 +0100497/** Available reduction operations */
498enum class ReductionOperation
499{
Michalis Spyrou7930db42018-11-22 17:36:28 +0000500 ARG_IDX_MAX, /**< Index of the max value */
Manuel Bottinib412fab2018-12-10 17:40:23 +0000501 ARG_IDX_MIN, /**< Index of the min value */
502 MEAN_SUM, /**< Mean of sum */
503 PROD, /**< Product */
504 SUM_SQUARE, /**< Sum of squares */
Usama Arifa4a08ad2019-05-20 12:38:33 +0100505 SUM, /**< Sum */
506 MIN, /**< Min */
Usama Arif28f0dd92019-05-20 13:44:34 +0100507 MAX, /**< Max */
Georgios Pinitasd9769582017-08-03 10:19:40 +0100508};
509
giuros01164a2722018-11-20 18:34:46 +0000510/** Available element-wise operations */
511enum class ArithmeticOperation
512{
513 ADD, /**< (x + y) */
514 SUB, /**< (x - y) */
515 DIV, /**< (x / y) */
516 MIN, /**< Min(x, y) */
517 MAX, /**< Max(x, y) */
518 SQUARED_DIFF, /**< (x - y)^2 */
Usama Arif81e671e2019-05-13 13:33:14 +0100519 POWER, /**< x ^ y */
giuros011e6e1b82019-05-14 16:12:53 +0100520 PRELU, /**< y*x if x < 0, x otherwise */
giuros01164a2722018-11-20 18:34:46 +0000521};
522
Michalis Spyroue9362622018-11-23 17:41:37 +0000523/** Available element wise unary operations */
524enum class ElementWiseUnary
525{
Sang-Hoon Park75eea332020-11-13 13:44:13 +0000526 RSQRT, /**< Reverse square root */
527 EXP, /**< Exponential */
528 NEG, /**< Negate */
529 LOG, /**< Natural Logarithm */
530 ABS, /**< Absolute value */
531 SIN, /**< Sine */
532 ROUND, /**< Round */
533 LOGICAL_NOT, /**< Logical Not */
Michalis Spyroue9362622018-11-23 17:41:37 +0000534};
535
Manuel Bottini63bb7ca2020-12-02 13:22:14 +0000536/** Available bitwise operations */
537enum class BitwiseOperation
538{
539 AND, /**< Bitwise AND operation */
540 NOT, /**< Bitwise NOT operation */
541 OR, /**< Bitwise OR operation */
542 XOR, /**< Bitwise XOR operation */
543};
544
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100545/** The normalization type used for the normalization layer */
546enum class NormType
547{
548 IN_MAP_1D, /**< Normalization applied within the same map in 1D region */
549 IN_MAP_2D, /**< Normalization applied within the same map in 2D region */
550 CROSS_MAP /**< Normalization applied cross maps */
551};
552
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100553/** Detection window used for the object detection. The detection window keeps the following information:
554 *
555 * -# Geometry of the rectangular window (x/y of top-left corner and width/height)
556 * -# Index of the class used for evaluating which class the detection window belongs to
557 * -# Confidence value (score) obtained with the classifier
558 */
559struct DetectionWindow
560{
561 uint16_t x{ 0 }; /**< Top-left x coordinate */
562 uint16_t y{ 0 }; /**< Top-left y coordinate */
563 uint16_t width{ 0 }; /**< Width of the detection window */
564 uint16_t height{ 0 }; /**< Height of the detection window */
565 uint16_t idx_class{ 0 }; /**< Index of the class */
566 float score{ 0.f }; /**< Confidence value for the detection window */
567};
568
569/** Dimension rounding type when down-scaling on CNNs
570 * @note Used in pooling and convolution layer
571 */
572enum class DimensionRoundingType
573{
574 FLOOR, /**< Floor rounding */
575 CEIL /**< Ceil rounding */
576};
577
578/** Available pooling types */
579enum class PoolingType
580{
581 MAX, /**< Max Pooling */
Georgios Pinitascdf51452017-08-31 14:21:36 +0100582 AVG, /**< Average Pooling */
583 L2 /**< L2 Pooling */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100584};
585
Michalis Spyrou2709d612018-09-19 09:46:47 +0100586/** Available non maxima suppression types */
587enum class NMSType
588{
589 LINEAR, /**< Linear NMS */
590 GAUSSIAN, /**< Gaussian NMS */
591 ORIGINAL /**< Original NMS */
592};
593
594/** BoxWithNonMaximaSuppressionLimit Information class */
595class BoxNMSLimitInfo final
596{
597public:
598 /** Constructor
599 *
600 * @param[in] score_thresh (Optional) Score threshold.
601 * @param[in] nms (Optional) NMS value
602 * @param[in] detections (Optional) Number of detections
603 * @param[in] soft_nms_enabled (Optional) Enable SoftNMS
604 * @param[in] soft_nms_method (Optional) Soft NMS method
605 * @param[in] soft_nms_sigma (Optional) Soft NMS sigma value
606 * @param[in] soft_nms_min_score_thres (Optional) Soft NMS minimum score threshold
Manuel Bottini5209be52019-02-13 16:34:56 +0000607 * @param[in] suppress_size (Optional) Filter out boxes based on their size. Defaults to false
608 * @param[in] min_size (Optional) Smaller boxes than min_size will be filtered out. Defaults to 1
609 * @param[in] im_width (Optional) Boxes whose centers (on the x axis) is beyond im_width will be filtered. Defaults to 1
610 * @param[in] im_height (Optional) Boxes whose centers (on the y axis) is beyond im_height will be filtered. Defaults to 1
Michalis Spyrou2709d612018-09-19 09:46:47 +0100611 */
612 BoxNMSLimitInfo(float score_thresh = 0.05f, float nms = 0.3f,
613 int detections = 100, bool soft_nms_enabled = false,
614 NMSType soft_nms_method = NMSType::LINEAR,
Manuel Bottini5209be52019-02-13 16:34:56 +0000615 float soft_nms_sigma = 0.5f, float soft_nms_min_score_thres = 0.001f, bool suppress_size = false, float min_size = 1.0f, float im_width = 1.0f, float im_height = 1.0f)
Michalis Spyrou2709d612018-09-19 09:46:47 +0100616 : _score_thresh(score_thresh), _nms(nms), _detections_per_im(detections), _soft_nms_enabled(soft_nms_enabled), _soft_nms_method(soft_nms_method), _soft_nms_sigma(soft_nms_sigma),
Manuel Bottini5209be52019-02-13 16:34:56 +0000617 _soft_nms_min_score_thres(soft_nms_min_score_thres), _suppress_size(suppress_size), _min_size(min_size), _im_width(im_width), _im_height(im_height)
Michalis Spyrou2709d612018-09-19 09:46:47 +0100618 {
619 }
620 /** Get the score threshold */
621 float score_thresh() const
622 {
623 return _score_thresh;
624 }
625 /** Get the NMS */
626 float nms() const
627 {
628 return _nms;
629 }
630 /** Get the number of detections */
631 int detections_per_im() const
632 {
633 return _detections_per_im;
634 }
635 /** Check if soft NMS is enabled */
636 bool soft_nms_enabled() const
637 {
638 return _soft_nms_enabled;
639 }
640 /** Get soft NMS method */
641 NMSType soft_nms_method() const
642 {
643 return _soft_nms_method;
644 }
645 /** Get soft NMS sigma */
646 float soft_nms_sigma() const
647 {
648 return _soft_nms_sigma;
649 }
650 /** Get soft nms min score threshold */
651 float soft_nms_min_score_thres() const
652 {
653 return _soft_nms_min_score_thres;
654 }
Manuel Bottini5209be52019-02-13 16:34:56 +0000655 /** Get if NMS will suppress boxes based on their size/position */
656 bool suppress_size() const
657 {
658 return _suppress_size;
659 }
660 /** Get size suppression threshold */
661 float min_size() const
662 {
663 return _min_size;
664 }
665 /** Get image width (NMS may suppress boxes whose center sits beyond the image width) */
666 float im_width() const
667 {
668 return _im_width;
669 }
670 /** Get image height (NMS may suppress boxes whose center sits beyond the image height) */
671 float im_height() const
672 {
673 return _im_height;
674 }
Michalis Spyrou2709d612018-09-19 09:46:47 +0100675
676private:
677 float _score_thresh;
678 float _nms;
679 int _detections_per_im;
680 bool _soft_nms_enabled;
681 NMSType _soft_nms_method;
682 float _soft_nms_sigma;
683 float _soft_nms_min_score_thres;
Manuel Bottini5209be52019-02-13 16:34:56 +0000684 bool _suppress_size;
685 float _min_size;
686 float _im_width;
687 float _im_height;
Michalis Spyrou2709d612018-09-19 09:46:47 +0100688};
689
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100690/** Padding and stride information class */
691class PadStrideInfo
692{
693public:
694 /** Constructor
695 *
696 * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1.
697 * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1.
698 * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0.
699 * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0.
ramy.elgammal@arm.coma2561f02023-06-16 20:45:48 +0100700 * @param[in] round (Optional) Dimensions rounding. Defaults to @ref DimensionRoundingType::FLOOR.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100701 */
702 PadStrideInfo(unsigned int stride_x = 1, unsigned int stride_y = 1,
703 unsigned int pad_x = 0, unsigned int pad_y = 0,
704 DimensionRoundingType round = DimensionRoundingType::FLOOR)
705 : _stride(std::make_pair(stride_x, stride_y)),
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100706 _pad_left(pad_x),
707 _pad_top(pad_y),
708 _pad_right(pad_x),
709 _pad_bottom(pad_y),
710 _round_type(round)
711 {
712 }
713 /** Constructor
714 *
715 * @param[in] stride_x Stride, in elements, across x.
716 * @param[in] stride_y Stride, in elements, across y.
717 * @param[in] pad_left Padding across x on the left, in elements.
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100718 * @param[in] pad_right Padding across x on the right, in elements.
Freddie Liardetded36632021-09-03 15:08:23 +0100719 * @param[in] pad_top Padding across y on the top, in elements.
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100720 * @param[in] pad_bottom Padding across y on the bottom, in elements.
721 * @param[in] round Dimensions rounding.
722 */
723 PadStrideInfo(unsigned int stride_x, unsigned int stride_y,
724 unsigned int pad_left, unsigned int pad_right,
725 unsigned int pad_top, unsigned int pad_bottom,
726 DimensionRoundingType round)
727 : _stride(std::make_pair(stride_x, stride_y)),
728 _pad_left(pad_left),
729 _pad_top(pad_top),
730 _pad_right(pad_right),
731 _pad_bottom(pad_bottom),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100732 _round_type(round)
733 {
734 }
Alex Gildayc357c472018-03-21 13:54:09 +0000735 /** Get the stride.
736 *
737 * @return a pair: stride x, stride y.
738 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100739 std::pair<unsigned int, unsigned int> stride() const
740 {
741 return _stride;
742 }
Alex Gildayc357c472018-03-21 13:54:09 +0000743 /** Check whether the padding is symmetric.
744 *
745 * @return True if the padding is symmetric.
746 */
Anthony Barbier21f67d62018-02-16 15:17:48 +0000747 bool padding_is_symmetric() const
748 {
749 return (_pad_left == _pad_right) && (_pad_top == _pad_bottom);
750 }
Alex Gildayc357c472018-03-21 13:54:09 +0000751 /** Get the padding.
752 *
753 * @note This should only be used when the padding is symmetric.
754 *
755 * @return a pair: padding left/right, padding top/bottom
756 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100757 std::pair<unsigned int, unsigned int> pad() const
758 {
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100759 //this accessor should be used only when padding is symmetric
Anthony Barbier21f67d62018-02-16 15:17:48 +0000760 ARM_COMPUTE_ERROR_ON(!padding_is_symmetric());
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100761 return std::make_pair(_pad_left, _pad_top);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100762 }
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100763
Alex Gildayc357c472018-03-21 13:54:09 +0000764 /** Get the left padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100765 unsigned int pad_left() const
766 {
767 return _pad_left;
768 }
Alex Gildayc357c472018-03-21 13:54:09 +0000769 /** Get the right padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100770 unsigned int pad_right() const
771 {
772 return _pad_right;
773 }
Alex Gildayc357c472018-03-21 13:54:09 +0000774 /** Get the top padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100775 unsigned int pad_top() const
776 {
777 return _pad_top;
778 }
Alex Gildayc357c472018-03-21 13:54:09 +0000779 /** Get the bottom padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100780 unsigned int pad_bottom() const
781 {
782 return _pad_bottom;
783 }
784
Alex Gildayc357c472018-03-21 13:54:09 +0000785 /** Get the rounding type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100786 DimensionRoundingType round() const
787 {
788 return _round_type;
789 }
790
Alex Gildayc357c472018-03-21 13:54:09 +0000791 /** Check whether this has any padding */
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100792 bool has_padding() const
793 {
794 return (_pad_left != 0 || _pad_top != 0 || _pad_right != 0 || _pad_bottom != 0);
795 }
796
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100797private:
798 std::pair<unsigned int, unsigned int> _stride;
Pablo Marquez Tello16789a12022-07-25 14:41:26 +0100799 unsigned int _pad_left;
800 unsigned int _pad_top;
801 unsigned int _pad_right;
802 unsigned int _pad_bottom;
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100803
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100804 DimensionRoundingType _round_type;
805};
806
SiCong Lif44bbc52022-08-29 18:25:51 +0100807/** Padding information for 2D operations like Conv2d */
808struct Padding2D
809{
810 Padding2D() = default;
811 Padding2D(size_t left, size_t right, size_t top, size_t bottom)
812 : left(left), right(right), top(top), bottom(bottom)
813 {
814 }
815 size_t left = { 0 }; /**< Padding across the width dimension on the left, in elements. */
816 size_t right = { 0 }; /**< Padding across the width dimension on the right, in elements. */
817 size_t top = { 0 }; /**< Padding across the height dimension on the top, in elements. */
818 size_t bottom = { 0 }; /**< Padding across the height dimension on the bottom, in elements. */
819};
820
Adnan AlSinane4563a02021-09-01 15:32:03 +0100821/** Padding information for 3D operations like Conv3d */
822struct Padding3D
823{
Freddie Liardetebefe522021-11-25 16:19:28 +0000824 Padding3D() noexcept
Giorgio Arenac9fe9fc2021-10-06 12:54:29 +0100825 {
826 }
827
828 Padding3D(size_t pad_x, size_t pad_y, size_t pad_z)
829 : left(pad_x), right(pad_x), top(pad_y), bottom(pad_y), front(pad_z), back(pad_z)
830 {
831 }
832
833 Padding3D(size_t left, size_t right, size_t top, size_t bottom, size_t front, size_t back)
834 : left(left), right(right), top(top), bottom(bottom), front(front), back(back)
835 {
836 }
837
Adnan AlSinane4563a02021-09-01 15:32:03 +0100838 size_t left = { 0 }; /**< Padding across the width dimenstion on the left, in elements. */
839 size_t right = { 0 }; /**< Padding across the width dimenstion on the right, in elements. */
840 size_t top = { 0 }; /**< Padding across the height dimenstion on the top, in elements. */
841 size_t bottom = { 0 }; /**< Padding across the height dimenstion on the bottom, in elements. */
842 size_t front = { 0 }; /**< Padding across the depth dimenstion on the front, in elements. */
843 size_t back = { 0 }; /**< Padding across the depth dimenstion on the back, in elements. */
844};
845
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100846/** PriorBox layer info */
847class PriorBoxLayerInfo final
848{
849public:
850 /** Default Constructor */
851 PriorBoxLayerInfo()
852 : _min_sizes(),
853 _variances(),
854 _offset(),
855 _flip(true),
856 _clip(false),
857 _max_sizes(),
858 _aspect_ratios(),
859 _img_size(),
860 _steps()
861 {
862 }
863 /** Constructor
864 *
865 * @param[in] min_sizes Min sizes vector.
Michalis Spyrou721c4cb2018-09-04 15:27:25 +0100866 * @param[in] variances Variances vector.
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100867 * @param[in] offset Offset value.
868 * @param[in] flip (Optional) Flip the aspect ratios.
869 * @param[in] clip (Optional) Clip coordinates so that they're within [0,1].
870 * @param[in] max_sizes (Optional) Max sizes vector.
871 * @param[in] aspect_ratios (Optional) Aspect ratios of the boxes.
872 * @param[in] img_size (Optional) Image size.
873 * @param[in] steps (Optional) Step values.
874 */
875 PriorBoxLayerInfo(const std::vector<float> &min_sizes, const std::vector<float> &variances, float offset, bool flip = true, bool clip = false,
Pablo Tello32521432018-11-15 14:43:10 +0000876 const std::vector<float> &max_sizes = {}, const std::vector<float> &aspect_ratios = {},
877 const Coordinates2D &img_size = Coordinates2D{ 0, 0 }, const std::array<float, 2> &steps = { { 0.f, 0.f } })
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100878 : _min_sizes(min_sizes),
879 _variances(variances),
880 _offset(offset),
881 _flip(flip),
882 _clip(clip),
883 _max_sizes(max_sizes),
Michalis Spyrou721c4cb2018-09-04 15:27:25 +0100884 _aspect_ratios(),
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100885 _img_size(img_size),
886 _steps(steps)
887 {
888 _aspect_ratios.push_back(1.);
889 for(unsigned int i = 0; i < aspect_ratios.size(); ++i)
890 {
891 float ar = aspect_ratios[i];
892 bool already_exist = false;
893 for(auto ar_new : _aspect_ratios)
894 {
895 if(fabs(ar - ar_new) < 1e-6)
896 {
897 already_exist = true;
898 break;
899 }
900 }
901 if(!already_exist)
902 {
903 _aspect_ratios.push_back(ar);
904 if(flip)
905 {
906 _aspect_ratios.push_back(1.f / ar);
907 }
908 }
909 }
910 }
911 /** Get min sizes. */
912 std::vector<float> min_sizes() const
913 {
914 return _min_sizes;
915 }
916 /** Get min variances. */
917 std::vector<float> variances() const
918 {
919 return _variances;
920 }
921 /** Get the step coordinates */
922 std::array<float, 2> steps() const
923 {
924 return _steps;
925 }
926 /** Get the image size coordinates */
927 Coordinates2D img_size() const
928 {
929 return _img_size;
930 }
931 /** Get the offset */
932 float offset() const
933 {
934 return _offset;
935 }
936 /** Get the flip value */
937 bool flip() const
938 {
939 return _flip;
940 }
941 /** Get the clip value */
942 bool clip() const
943 {
944 return _clip;
945 }
946 /** Get max sizes. */
947 std::vector<float> max_sizes() const
948 {
949 return _max_sizes;
950 }
951 /** Get aspect ratios. */
952 std::vector<float> aspect_ratios() const
953 {
954 return _aspect_ratios;
955 }
956
957private:
Pablo Marquez Tello16789a12022-07-25 14:41:26 +0100958 std::vector<float> _min_sizes;
959 std::vector<float> _variances;
960 float _offset;
961 bool _flip;
962 bool _clip;
963 std::vector<float> _max_sizes;
964 std::vector<float> _aspect_ratios;
965 Coordinates2D _img_size;
Michalis Spyrou6c7c38e2018-08-29 16:28:11 +0100966 std::array<float, 2> _steps;
967};
968
Isabella Gottardia7acb3c2019-01-08 13:48:44 +0000969// Bounding Box [xmin, ymin, xmax, ymax]
970using BBox = std::array<float, 4>;
971// LabelBBox used for map label and bounding box
972using LabelBBox = std::map<int, std::vector<BBox>>;
973
Isabella Gottardi05e56442018-11-16 11:26:52 +0000974/** Available Detection Output code types */
975enum class DetectionOutputLayerCodeType
976{
977 CORNER, /**< Use box corners */
978 CENTER_SIZE, /**< Use box centers and size */
979 CORNER_SIZE, /**< Use box centers and size */
980 TF_CENTER /**< Use box centers and size but flip x and y co-ordinates */
981};
982
983/** Detection Output layer info */
984class DetectionOutputLayerInfo final
985{
986public:
987 /** Default Constructor */
988 DetectionOutputLayerInfo()
989 : _num_classes(),
990 _share_location(),
991 _code_type(DetectionOutputLayerCodeType::CORNER),
992 _keep_top_k(),
993 _nms_threshold(),
994 _top_k(),
995 _background_label_id(),
996 _confidence_threshold(),
997 _variance_encoded_in_target(false),
998 _eta(),
999 _num_loc_classes()
1000 {
1001 _num_loc_classes = _share_location ? 1 : _num_classes;
1002 }
1003 /** Constructor
1004 *
1005 * @param[in] num_classes Number of classes to be predicted.
1006 * @param[in] share_location If true, bounding box are shared among different classes.
1007 * @param[in] code_type Type of coding method for bbox.
1008 * @param[in] keep_top_k Number of total bounding boxes to be kept per image after NMS step.
1009 * @param[in] nms_threshold Threshold to be used in NMS.
1010 * @param[in] top_k (Optional) Number of boxes per image with top confidence scores that are fed into the NMS algorithm. Default set to -1.
1011 * @param[in] background_label_id (Optional) Background label ID. If there is no background class, set it as -1.
1012 * @param[in] confidence_threshold (Optional) Only consider detections whose confidences are larger than a threshold. Default set to -FLT_MAX.
1013 * @param[in] variance_encoded_in_target (Optional) If true, variance is encoded in target. Otherwise we need to adjust the predicted offset accordingly.Default set to false.
1014 * @param[in] eta (Optional) Eta.
1015 */
1016 DetectionOutputLayerInfo(int num_classes, bool share_location, DetectionOutputLayerCodeType code_type, int keep_top_k, float nms_threshold, int top_k = -1, int background_label_id = -1,
1017 float confidence_threshold = std::numeric_limits<float>::lowest(), bool variance_encoded_in_target = false, float eta = 1)
1018 : _num_classes(num_classes),
1019 _share_location(share_location),
1020 _code_type(code_type),
1021 _keep_top_k(keep_top_k),
1022 _nms_threshold(nms_threshold),
1023 _top_k(top_k),
1024 _background_label_id(background_label_id),
1025 _confidence_threshold(confidence_threshold),
1026 _variance_encoded_in_target(variance_encoded_in_target),
1027 _eta(eta),
1028 _num_loc_classes()
1029 {
1030 _num_loc_classes = _share_location ? 1 : _num_classes;
1031 }
1032 /** Get num classes. */
1033 int num_classes() const
1034 {
1035 return _num_classes;
1036 }
1037 /** Get share location. */
1038 bool share_location() const
1039 {
1040 return _share_location;
1041 }
1042 /** Get detection output code type. */
1043 DetectionOutputLayerCodeType code_type() const
1044 {
1045 return _code_type;
1046 }
1047 /** Get if variance encoded in target. */
1048 bool variance_encoded_in_target() const
1049 {
1050 return _variance_encoded_in_target;
1051 }
1052 /** Get the number of total bounding boxes to be kept per image. */
1053 int keep_top_k() const
1054 {
1055 return _keep_top_k;
1056 }
1057 /** Get nms threshold. */
1058 float nms_threshold() const
1059 {
1060 return _nms_threshold;
1061 }
1062 /** Get eta. */
1063 float eta() const
1064 {
1065 return _eta;
1066 }
1067 /** Get background label ID. */
1068 int background_label_id() const
1069 {
1070 return _background_label_id;
1071 }
1072 /** Get confidence threshold. */
1073 float confidence_threshold() const
1074 {
1075 return _confidence_threshold;
1076 }
1077 /** Get top K. */
1078 int top_k() const
1079 {
1080 return _top_k;
1081 }
1082 /** Get number of location classes. */
1083 int num_loc_classes() const
1084 {
1085 return _num_loc_classes;
1086 }
1087
1088private:
1089 int _num_classes;
1090 bool _share_location;
1091 DetectionOutputLayerCodeType _code_type;
1092 int _keep_top_k;
1093 float _nms_threshold;
1094 int _top_k;
1095 int _background_label_id;
1096 float _confidence_threshold;
1097 bool _variance_encoded_in_target;
1098 float _eta;
1099 int _num_loc_classes;
1100};
1101
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001102/** Detection Output layer info */
1103class DetectionPostProcessLayerInfo final
1104{
1105public:
1106 /** Default Constructor */
1107 DetectionPostProcessLayerInfo()
1108 : _max_detections(),
1109 _max_classes_per_detection(),
1110 _nms_score_threshold(),
1111 _iou_threshold(),
1112 _num_classes(),
1113 _scales_values(),
1114 _use_regular_nms(),
Giuseppe Rossinid9853782019-10-25 11:11:44 +01001115 _detection_per_class(),
1116 _dequantize_scores()
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001117 {
1118 }
1119 /** Constructor
1120 *
1121 * @param[in] max_detections Number of total detection.
1122 * @param[in] max_classes_per_detection Number of total classes to be kept after NMS step. Used in the Fast Non-Max-Suppression
1123 * @param[in] nms_score_threshold Threshold to be used in NMS
1124 * @param[in] iou_threshold Threshold to be used during the intersection over union.
1125 * @param[in] num_classes Number of classes.
1126 * @param[in] scales_values Scales values used for decode center size boxes.
Giuseppe Rossinid9853782019-10-25 11:11:44 +01001127 * @param[in] use_regular_nms (Optional) Boolean to determinate if use regular or fast nms. Defaults to false.
1128 * @param[in] detection_per_class (Optional) Number of detection per class. Used in the Regular Non-Max-Suppression. Defaults to 100.
1129 * @param[in] dequantize_scores (Optional) If the scores need to be dequantized. Defaults to true.
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001130 */
1131 DetectionPostProcessLayerInfo(unsigned int max_detections, unsigned int max_classes_per_detection, float nms_score_threshold, float iou_threshold, unsigned int num_classes,
Giuseppe Rossinid9853782019-10-25 11:11:44 +01001132 std::array<float, 4> scales_values, bool use_regular_nms = false, unsigned int detection_per_class = 100, bool dequantize_scores = true)
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001133 : _max_detections(max_detections),
1134 _max_classes_per_detection(max_classes_per_detection),
1135 _nms_score_threshold(nms_score_threshold),
1136 _iou_threshold(iou_threshold),
1137 _num_classes(num_classes),
1138 _scales_values(scales_values),
1139 _use_regular_nms(use_regular_nms),
Giuseppe Rossinid9853782019-10-25 11:11:44 +01001140 _detection_per_class(detection_per_class),
1141 _dequantize_scores(dequantize_scores)
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001142 {
1143 }
1144 /** Get max detections. */
1145 unsigned int max_detections() const
1146 {
1147 return _max_detections;
1148 }
1149 /** Get max_classes per detection. Used in the Fast Non-Max-Suppression.*/
1150 unsigned int max_classes_per_detection() const
1151 {
1152 return _max_classes_per_detection;
1153 }
1154 /** Get detection per class. Used in the Regular Non-Max-Suppression */
1155 unsigned int detection_per_class() const
1156 {
1157 return _detection_per_class;
1158 }
1159 /** Get nms threshold. */
1160 float nms_score_threshold() const
1161 {
1162 return _nms_score_threshold;
1163 }
1164 /** Get intersection over union threshold. */
1165 float iou_threshold() const
1166 {
1167 return _iou_threshold;
1168 }
1169 /** Get num classes. */
1170 unsigned int num_classes() const
1171 {
1172 return _num_classes;
1173 }
1174 /** Get if use regular nms. */
1175 bool use_regular_nms() const
1176 {
1177 return _use_regular_nms;
1178 }
1179 /** Get y scale value. */
1180 float scale_value_y() const
1181 {
1182 // Saved as [y,x,h,w]
1183 return _scales_values[0];
1184 }
1185 /** Get x scale value. */
1186 float scale_value_x() const
1187 {
1188 // Saved as [y,x,h,w]
1189 return _scales_values[1];
1190 }
1191 /** Get h scale value. */
1192 float scale_value_h() const
1193 {
1194 // Saved as [y,x,h,w]
1195 return _scales_values[2];
1196 }
1197 /** Get w scale value. */
1198 float scale_value_w() const
1199 {
1200 // Saved as [y,x,h,w]
1201 return _scales_values[3];
1202 }
Giuseppe Rossinid9853782019-10-25 11:11:44 +01001203 /** Get dequantize_scores value. */
1204 bool dequantize_scores() const
1205 {
1206 return _dequantize_scores;
1207 }
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001208
1209private:
Pablo Marquez Tello16789a12022-07-25 14:41:26 +01001210 unsigned int _max_detections;
1211 unsigned int _max_classes_per_detection;
1212 float _nms_score_threshold;
1213 float _iou_threshold;
1214 unsigned int _num_classes;
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001215 std::array<float, 4> _scales_values;
Pablo Marquez Tello16789a12022-07-25 14:41:26 +01001216 bool _use_regular_nms;
1217 unsigned int _detection_per_class;
1218 bool _dequantize_scores;
Isabella Gottardia7acb3c2019-01-08 13:48:44 +00001219};
1220
Sang-Hoon Park0cb3da62020-01-15 12:39:56 +00001221/** Pooling Layer Information struct*/
1222struct PoolingLayerInfo
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001223{
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001224 /** Default Constructor */
1225 PoolingLayerInfo()
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001226 : pool_type(PoolingType::MAX),
1227 pool_size(Size2D()),
1228 data_layout(DataLayout::UNKNOWN),
1229 pad_stride_info(PadStrideInfo()),
1230 exclude_padding(false),
1231 is_global_pooling(false),
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001232 fp_mixed_precision(false),
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001233 use_inf_as_limit(true),
1234 use_kernel_indices(false)
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001235 {
1236 }
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001237 /** Constructor
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001238 *
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001239 * @param[in] pool_type Pooling type @ref PoolingType.
1240 * @param[in] pool_size Pooling size, in elements, across x and y.
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001241 * @param[in] data_layout Data layout used by the layer @ref DataLayout
1242 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
1243 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1244 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1245 * Defaults to false;
1246 * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001247 * @param[in] use_inf_as_limit (Optional) Use inf to represent the limits of datatypes range, instead of using "lowest" property of the data type.
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001248 * @param[in] use_kernel_indices (Optional) Use kernel indices instead of using source indices while computing indices tensor.
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001249 */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001250 explicit PoolingLayerInfo(PoolingType pool_type,
1251 unsigned int pool_size,
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001252 DataLayout data_layout,
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001253 PadStrideInfo pad_stride_info = PadStrideInfo(),
1254 bool exclude_padding = false,
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001255 bool fp_mixed_precision = false,
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001256 bool use_inf_as_limit = true,
1257 bool use_kernel_indices = false)
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001258 : pool_type(pool_type),
1259 pool_size(Size2D(pool_size, pool_size)),
1260 data_layout(data_layout),
1261 pad_stride_info(pad_stride_info),
1262 exclude_padding(exclude_padding),
1263 is_global_pooling(false),
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001264 fp_mixed_precision(fp_mixed_precision),
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001265 use_inf_as_limit(use_inf_as_limit),
1266 use_kernel_indices(use_kernel_indices)
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001267 {
1268 }
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001269
1270 /** Constructor
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001271 *
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001272 * @param[in] pool_type Pooling type @ref PoolingType.
1273 * @param[in] pool_size Pooling size, in elements, across x and y.
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001274 * @param[in] data_layout Data layout used by the layer @ref DataLayout
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001275 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
1276 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1277 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1278 * Defaults to false;
1279 * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001280 * @param[in] use_inf_as_limit (Optional) Use inf to represent the limits of datatypes range, instead of using "lowest" property of the data type.
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001281 * @param[in] use_kernel_indices (Optional) Use kernel indices instead of using source indices while computing indices tensor.
Isabella Gottardi6e464c32018-01-26 12:32:45 +00001282 */
1283 explicit PoolingLayerInfo(PoolingType pool_type,
1284 Size2D pool_size,
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001285 DataLayout data_layout,
Sang-Hoon Park2aa7fd02019-09-18 13:39:00 +01001286 PadStrideInfo pad_stride_info = PadStrideInfo(),
1287 bool exclude_padding = false,
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001288 bool fp_mixed_precision = false,
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001289 bool use_inf_as_limit = true,
1290 bool use_kernel_indices = false)
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001291 : pool_type(pool_type),
1292 pool_size(pool_size),
1293 data_layout(data_layout),
1294 pad_stride_info(pad_stride_info),
1295 exclude_padding(exclude_padding),
1296 is_global_pooling(false),
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001297 fp_mixed_precision(fp_mixed_precision),
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001298 use_inf_as_limit(use_inf_as_limit),
1299 use_kernel_indices(use_kernel_indices)
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001300 {
1301 }
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001302
1303 /** Constructor
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001304 *
1305 * @note This constructor is used for global pooling
1306 *
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001307 * @param[in] pool_type Pooling type @ref PoolingType.
1308 * @param[in] data_layout Data layout used by the layer @ref DataLayout
Georgios Pinitas4c2dd542017-11-13 12:58:41 +00001309 */
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001310 explicit PoolingLayerInfo(PoolingType pool_type, DataLayout data_layout)
1311 : pool_type(pool_type),
1312 pool_size(Size2D()),
1313 data_layout(data_layout),
1314 pad_stride_info(PadStrideInfo(1, 1, 0, 0)),
1315 exclude_padding(false),
1316 is_global_pooling(true),
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001317 fp_mixed_precision(false),
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001318 use_inf_as_limit(true),
1319 use_kernel_indices(false)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001320 {
1321 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001322
Sang-Hoon Park0cb3da62020-01-15 12:39:56 +00001323 PoolingType pool_type;
1324 Size2D pool_size;
Sang-Hoon Park11fedda2020-01-15 14:44:04 +00001325 DataLayout data_layout;
Sang-Hoon Park0cb3da62020-01-15 12:39:56 +00001326 PadStrideInfo pad_stride_info;
1327 bool exclude_padding;
1328 bool is_global_pooling;
1329 bool fp_mixed_precision;
Adnan AlSinan227db8d2023-02-14 14:24:09 +00001330 bool use_inf_as_limit;
Adnan AlSinanbbf2e742023-02-22 12:15:14 +00001331 bool use_kernel_indices;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001332};
1333
ramelg0137515692022-02-26 22:06:20 +00001334/** Pooling Layer Information struct*/
1335struct Pooling3dLayerInfo
1336{
1337 /** Default Constructor */
Michalis Spyrou50e48aa2022-04-21 16:42:56 +01001338 Pooling3dLayerInfo() noexcept
ramelg0137515692022-02-26 22:06:20 +00001339 : pool_type(PoolingType::MAX),
1340 pool_size(Size3D()),
1341 stride(Size3D()),
1342 padding(Padding3D()),
1343 exclude_padding(false),
1344 is_global_pooling(false),
1345 fp_mixed_precision(false),
1346 round_type(DimensionRoundingType::FLOOR)
1347 {
1348 }
1349 /** Constructor
1350 *
1351 * @param[in] pool_type Pooling type @ref PoolingType.
1352 * @param[in] pool_size Pooling size, in elements, across x, y and z.
1353 * @param[in] stride (Optional) stride information @ref Size3D
1354 * @param[in] padding (Optional) padding information @ref Padding3D
1355 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1356 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1357 * Defaults to false;
1358 * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
ramy.elgammal@arm.coma2561f02023-06-16 20:45:48 +01001359 * @param[in] round_type (Optional) Dimensions rounding. Defaults to @ref DimensionRoundingType::FLOOR
ramelg0137515692022-02-26 22:06:20 +00001360 */
1361 explicit Pooling3dLayerInfo(PoolingType pool_type,
1362 unsigned int pool_size,
1363 Size3D stride = Size3D(1U, 1U, 1U),
1364 Padding3D padding = Padding3D(),
1365 bool exclude_padding = false,
1366 bool fp_mixed_precision = false,
1367 DimensionRoundingType round_type = DimensionRoundingType::FLOOR)
1368 : pool_type(pool_type),
1369 pool_size(Size3D(pool_size, pool_size, pool_size)),
1370 stride(stride),
1371 padding(padding),
1372 exclude_padding(exclude_padding),
1373 is_global_pooling(false),
1374 fp_mixed_precision(fp_mixed_precision),
1375 round_type(round_type)
1376 {
1377 }
1378
1379 /** Constructor
1380 *
1381 * @param[in] pool_type Pooling type @ref PoolingType.
1382 * @param[in] pool_size Pooling size, in elements, across x, y and z.
1383 * @param[in] stride (Optional) stride information @ref Size3D
1384 * @param[in] padding (Optional) padding information @ref Padding3D
1385 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
1386 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
1387 * Defaults to false;
1388 * @param[in] fp_mixed_precision (Optional) Use wider accumulators (32 bit instead of 16 for FP16) to improve accuracy.
ramy.elgammal@arm.coma2561f02023-06-16 20:45:48 +01001389 * @param[in] round_type (Optional) Dimensions rounding. Defaults to @ref DimensionRoundingType::FLOOR
ramelg0137515692022-02-26 22:06:20 +00001390 */
1391 explicit Pooling3dLayerInfo(PoolingType pool_type,
1392 Size3D pool_size,
1393 Size3D stride = Size3D(1U, 1U, 1U),
1394 Padding3D padding = Padding3D(),
1395 bool exclude_padding = false,
1396 bool fp_mixed_precision = false,
1397 DimensionRoundingType round_type = DimensionRoundingType::FLOOR)
1398 : pool_type(pool_type),
1399 pool_size(pool_size),
1400 stride(stride),
1401 padding(padding),
1402 exclude_padding(exclude_padding),
1403 is_global_pooling(false),
1404 fp_mixed_precision(fp_mixed_precision),
1405 round_type(round_type)
1406 {
1407 }
1408
1409 /** Constructor
1410 *
1411 * @note This constructor is used for global pooling
1412 *
1413 * @param[in] pool_type Pooling type @ref PoolingType.
1414 */
1415 explicit Pooling3dLayerInfo(PoolingType pool_type)
1416 : pool_type(pool_type),
1417 pool_size(Size3D()),
1418 stride(Size3D(1U, 1U, 1U)),
1419 padding(Padding3D(0, 0, 0)),
1420 exclude_padding(false),
1421 is_global_pooling(true),
1422 fp_mixed_precision(false),
1423 round_type(DimensionRoundingType::FLOOR)
1424 {
1425 }
1426
1427 PoolingType pool_type;
1428 Size3D pool_size;
1429 Size3D stride;
1430 Padding3D padding;
1431 bool exclude_padding;
1432 bool is_global_pooling;
1433 bool fp_mixed_precision;
1434 DimensionRoundingType round_type;
1435};
1436
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001437/** ROI Pooling Layer Information class */
giuros0118870812018-09-13 09:31:40 +01001438class ROIPoolingLayerInfo final
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001439{
1440public:
giuros0118870812018-09-13 09:31:40 +01001441 /** Constructor
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001442 *
giuros0118870812018-09-13 09:31:40 +01001443 * @param[in] pooled_width Pooled width of the layer.
1444 * @param[in] pooled_height Pooled height of the layer.
1445 * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
1446 * @param[in] sampling_ratio Number of samples to include in each pooling region (if set to zero, a ceil(roi_dims/pooling_dims))
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001447 */
giuros0118870812018-09-13 09:31:40 +01001448 ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale, unsigned int sampling_ratio = 0)
1449 : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale), _sampling_ratio(sampling_ratio)
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001450 {
1451 }
Alex Gildayc357c472018-03-21 13:54:09 +00001452 /** Get the pooled width of the layer */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001453 unsigned int pooled_width() const
1454 {
1455 return _pooled_width;
1456 }
Alex Gildayc357c472018-03-21 13:54:09 +00001457 /** Get the pooled height of the layer */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001458 unsigned int pooled_height() const
1459 {
1460 return _pooled_height;
1461 }
Alex Gildayc357c472018-03-21 13:54:09 +00001462 /** Get the spatial scale */
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001463 float spatial_scale() const
1464 {
1465 return _spatial_scale;
1466 }
giuros0118870812018-09-13 09:31:40 +01001467 /** Get sampling ratio */
1468 unsigned int sampling_ratio() const
1469 {
1470 return _sampling_ratio;
1471 }
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001472
1473private:
1474 unsigned int _pooled_width;
1475 unsigned int _pooled_height;
1476 float _spatial_scale;
giuros0118870812018-09-13 09:31:40 +01001477 unsigned int _sampling_ratio;
Georgios Pinitas7b7858d2017-06-21 16:44:24 +01001478};
1479
Manuel Bottini5209be52019-02-13 16:34:56 +00001480/** Generate Proposals Information class */
1481class GenerateProposalsInfo
1482{
1483public:
1484 /** Constructor
1485 *
1486 * @param[in] im_width Width of the original image
1487 * @param[in] im_height Height of the original image
1488 * @param[in] im_scale Scale applied to the original image
1489 * @param[in] spatial_scale (Optional)Scale applied to the feature map. Defaults to 1.0
1490 * @param[in] pre_nms_topN (Optional)Number of the best scores to be selected from the transformations. Defaults to 6000.
1491 * @param[in] post_nms_topN (Optional)Number of the best scores to be selected from the NMS operation. Defaults to 300.
1492 * @param[in] nms_thres (Optional)NMS overlap threshold. Defaults to 0.7.
1493 * @param[in] min_size (Optional)Size used to validate the anchors produced. Defaults to 16.
1494 * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region of interest). Defaults to 4.
1495 */
1496 GenerateProposalsInfo(float im_width, float im_height, float im_scale, float spatial_scale = 1.0, int pre_nms_topN = 6000, int post_nms_topN = 300, float nms_thres = 0.7, float min_size = 16.0,
1497 size_t values_per_roi = 4)
1498 : _im_height(im_height), _im_width(im_width), _im_scale(im_scale), _spatial_scale(spatial_scale), _pre_nms_topN(pre_nms_topN), _post_nms_topN(post_nms_topN), _nms_thres(nms_thres),
1499 _min_size(min_size), _values_per_roi(values_per_roi)
1500 {
1501 }
1502
1503 /* Get the original height */
1504 float im_height() const
1505 {
1506 return _im_height;
1507 }
1508 /* Get the original width */
1509 float im_width() const
1510 {
1511 return _im_width;
1512 }
1513 /* Get the image scale */
1514 float im_scale() const
1515 {
1516 return _im_scale;
1517 }
1518 /* Get the value of how many best scores to select (before NMS) */
1519 int pre_nms_topN() const
1520 {
1521 return _pre_nms_topN;
1522 }
1523 /* Get the value of how many best scores to select (after NMS) */
1524 int post_nms_topN() const
1525 {
1526 return _post_nms_topN;
1527 }
1528 /* Get the NMS overlap threshold */
1529 float nms_thres() const
1530 {
1531 return _nms_thres;
1532 }
1533 /* Get the minimal size */
1534 float min_size() const
1535 {
1536 return _min_size;
1537 }
1538 /* Get the spatial scale to be applied to the feature maps */
1539 float spatial_scale() const
1540 {
1541 return _spatial_scale;
1542 }
1543 /* Get the values used to represent a ROI(Region of interest)*/
1544 size_t values_per_roi() const
1545 {
1546 return _values_per_roi;
1547 }
1548
1549private:
1550 float _im_height;
1551 float _im_width;
1552 float _im_scale;
1553 float _spatial_scale;
1554 int _pre_nms_topN;
1555 int _post_nms_topN;
1556 float _nms_thres;
1557 float _min_size;
1558 size_t _values_per_roi;
1559};
1560
1561/** ComputeAnchors information class */
1562class ComputeAnchorsInfo
1563{
1564public:
1565 /** Constructor
1566 *
1567 * @param[in] feat_width Feature map width
1568 * @param[in] feat_height Feature map height
1569 * @param[in] spatial_scale Feature map scale
1570 * @param[in] values_per_roi (Optional)Values used to represent a ROI(Region Of Interest). Defaults to 4
1571 */
1572 ComputeAnchorsInfo(float feat_width, float feat_height, float spatial_scale, size_t values_per_roi = 4)
1573 : _feat_height(feat_height),
1574 _feat_width(feat_width),
1575 _spatial_scale(spatial_scale),
1576 _values_per_roi(values_per_roi)
1577 {
1578 }
1579
1580 /* Get the height of the feature map */
1581 float feat_height() const
1582 {
1583 return _feat_height;
1584 }
1585
1586 /* Get the width of the feature map */
1587 float feat_width() const
1588 {
1589 return _feat_width;
1590 }
1591
1592 /* Get the scale of the feature map */
1593 float spatial_scale() const
1594 {
1595 return _spatial_scale;
1596 }
1597
1598 /* Get the values used to represent a ROI(Region Of Interest)*/
1599 size_t values_per_roi() const
1600 {
1601 return _values_per_roi;
1602 }
1603
1604private:
1605 float _feat_height;
1606 float _feat_width;
1607 float _spatial_scale;
1608 size_t _values_per_roi;
1609};
1610
giuros01c04a0e82018-10-03 12:44:35 +01001611/** Bounding Box Transform information class */
giuros01d696cb62018-11-16 10:39:59 +00001612class BoundingBoxTransformInfo final
giuros01c04a0e82018-10-03 12:44:35 +01001613{
1614public:
1615 /** Constructor
1616 *
giuros01d696cb62018-11-16 10:39:59 +00001617 * @param[in] img_width Width of the original image
1618 * @param[in] img_height Height, of the original image
1619 * @param[in] scale Scale of the original image
1620 * @param[in] apply_scale (Optional)Re-apply scaling after transforming the boxes. Defaults to false
1621 * @param[in] weights (Optional)Weights [wx, wy, ww, wh] for the deltas. Defaults to all ones
1622 * @param[in] correct_transform_coords (Optional)Correct bounding box transform coordinates. Defaults to false
1623 * @param[in] bbox_xform_clip (Optional)Minimum bounding box width and height after bounding box transformation in log-space. Defaults to log(1000/16)
giuros01c04a0e82018-10-03 12:44:35 +01001624 */
giuros01d696cb62018-11-16 10:39:59 +00001625 BoundingBoxTransformInfo(float img_width, float img_height, float scale, bool apply_scale = false, const std::array<float, 4> weights = { { 1.f, 1.f, 1.f, 1.f } }, bool correct_transform_coords =
1626 false,
1627 float bbox_xform_clip =
1628 4.135166556742356f)
1629 : _img_width(img_width), _img_height(img_height), _scale(scale), _apply_scale(apply_scale), _correct_transform_coords(correct_transform_coords), _weights(weights), _bbox_xform_clip(bbox_xform_clip)
giuros01c04a0e82018-10-03 12:44:35 +01001630 {
1631 }
1632
1633 std::array<float, 4> weights() const
1634 {
1635 return _weights;
1636 }
1637
1638 float bbox_xform_clip() const
1639 {
1640 return _bbox_xform_clip;
1641 }
1642
1643 float img_height() const
1644 {
1645 return _img_height;
1646 }
1647
1648 float img_width() const
1649 {
1650 return _img_width;
1651 }
1652
1653 float scale() const
1654 {
1655 return _scale;
1656 }
1657
1658 bool apply_scale() const
1659 {
1660 return _apply_scale;
1661 }
1662
giuros01d696cb62018-11-16 10:39:59 +00001663 bool correct_transform_coords() const
1664 {
1665 return _correct_transform_coords;
1666 }
1667
giuros01c04a0e82018-10-03 12:44:35 +01001668private:
Pablo Marquez Tello16789a12022-07-25 14:41:26 +01001669 float _img_width;
1670 float _img_height;
1671 float _scale;
1672 bool _apply_scale;
1673 bool _correct_transform_coords;
giuros01c04a0e82018-10-03 12:44:35 +01001674 std::array<float, 4> _weights;
Pablo Marquez Tello16789a12022-07-25 14:41:26 +01001675 float _bbox_xform_clip;
giuros01c04a0e82018-10-03 12:44:35 +01001676};
1677
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001678/** Normalization Layer Information class */
1679class NormalizationLayerInfo
1680{
1681public:
1682 /** Default Constructor
1683 *
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +00001684 * @param[in] type The normalization type. Can be @ref NormType::IN_MAP_1D, @ref NormType::IN_MAP_2D or @ref NormType::CROSS_MAP
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001685 * @param[in] norm_size The normalization size is the number of elements to normalize across. Defaults to 5.
Georgios Pinitas41caa622017-11-16 14:37:08 +00001686 * @param[in] alpha (Optional) Alpha parameter used by normalization equation. Defaults to 0.0001.
1687 * @param[in] beta (Optional) Beta parameter used by normalization equation. Defaults to 0.5.
1688 * @param[in] kappa (Optional) Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
1689 * @param[in] is_scaled (Optional) Boolean that specifies if alpha will be scaled by the normalization size or not.
1690 * Should be false to follow [Krichevksy 2012].
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001691 */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001692 NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f, bool is_scaled = true)
1693 : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa), _is_scaled(is_scaled)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001694 {
1695 }
Alex Gildayc357c472018-03-21 13:54:09 +00001696 /** Get the normalization type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001697 NormType type() const
1698 {
1699 return _type;
1700 }
Alex Gildayc357c472018-03-21 13:54:09 +00001701 /** Get the normalization size */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001702 uint32_t norm_size() const
1703 {
1704 return _norm_size;
1705 }
Alex Gildayc357c472018-03-21 13:54:09 +00001706 /** Get the alpha value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001707 float alpha() const
1708 {
1709 return _alpha;
1710 }
Alex Gildayc357c472018-03-21 13:54:09 +00001711 /** Get the beta value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001712 float beta() const
1713 {
1714 return _beta;
1715 }
Alex Gildayc357c472018-03-21 13:54:09 +00001716 /** Get the kappa value */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001717 float kappa() const
1718 {
1719 return _kappa;
1720 }
Michele Di Giorgio9d3a8312018-11-20 12:31:24 +00001721 /** Get the is_scaled value */
1722 bool is_scaled() const
1723 {
1724 return _is_scaled;
1725 }
Alex Gildayc357c472018-03-21 13:54:09 +00001726 /** Check if normalization is cross map */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001727 bool is_cross_map() const
1728 {
1729 return _type == NormType::CROSS_MAP;
1730 }
Alex Gildayc357c472018-03-21 13:54:09 +00001731 /** Check if normalization is not cross map */
Georgios Pinitas41caa622017-11-16 14:37:08 +00001732 bool is_in_map() const
1733 {
1734 return !is_cross_map();
1735 }
1736 /** Return the scaling factor of the normalization function.
1737 *
1738 * If is_scaled is set to false then [Krichevksy 2012] normalization scaling is performed,
1739 * where alpha is returned plainly, else alpha is scaled by the total number of elements used for the normalization.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001740 *
1741 * @return The normalization scaling factor.
1742 */
1743 float scale_coeff() const
1744 {
1745 const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
Georgios Pinitas41caa622017-11-16 14:37:08 +00001746 return (_is_scaled) ? (_alpha / size) : _alpha;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001747 }
1748
1749private:
1750 NormType _type;
1751 uint32_t _norm_size;
1752 float _alpha;
1753 float _beta;
1754 float _kappa;
Georgios Pinitas41caa622017-11-16 14:37:08 +00001755 bool _is_scaled;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001756};
1757
thecha012bfadd92020-08-12 17:25:51 +01001758class StridedSliceLayerInfo
1759{
1760public:
1761 /** Default Constructor
1762 *
1763 * @param[in] begin_mask (Optional) If the ith bit of begin_mask is set, starts[i] is ignored and the fullest possible range in that dimension is used instead.
1764 * @param[in] end_mask (Optional) If the ith bit of end_mask is set, ends[i] is ignored and the fullest possible range in that dimension is used instead.
1765 * @param[in] shrink_axis_mask (Optional) If the ith bit of shrink_axis_mask is set, it implies that the ith specification shrinks the dimensionality by 1.
1766 */
1767 StridedSliceLayerInfo(int32_t begin_mask = 0, int32_t end_mask = 0, int32_t shrink_axis_mask = 0)
1768 : _begin_mask(begin_mask), _end_mask(end_mask), _shrink_axis_mask(shrink_axis_mask)
1769 {
1770 }
1771
1772 /* Get the begin mask value */
1773 int32_t begin_mask() const
1774 {
1775 return _begin_mask;
1776 }
1777
1778 /* Get the end mask value */
1779 int32_t end_mask() const
1780 {
1781 return _end_mask;
1782 }
1783
1784 /* Get the shrink axis mask value */
1785 int32_t shrink_axis_mask() const
1786 {
1787 return _shrink_axis_mask;
1788 }
1789
1790private:
1791 int32_t _begin_mask;
1792 int32_t _end_mask;
1793 int32_t _shrink_axis_mask;
1794};
1795
Ramy Elgammal91780022022-07-20 14:57:37 +01001796/** Memory layouts for the weights tensor.
1797 *
1798 * * UNSPECIFIED is used to select kernels that do not run in
1799 * variable weights mode.
1800 *
1801 * * ANY is used to query the kernel database to retrieve any of the
1802 * kernels that runs in variable weights mode. Once a kernel is
1803 * found, the specific format expected by the kernel can be
1804 * retrieved by the user for reordering the weights tensor
1805 * accordingly.
1806 *
1807 * The other values OHWIo{interleave_by}i{block_by} describe the
1808 * memory layout of a 4D tensor with layout OHWI that has been
1809 * transformed into a 4D tensor with dimensions O'HWI' where:
1810 *
1811 * O' = first multiple of {interleave_by} s.t. O<=O'
1812 * I' = first multiple of {block_by} s.t. I<=I'
1813 *
1814 * The total size of the dst tensor is O' x H x W x I'
1815 *
1816 * The access function of the tensor with layout
1817 * OHWIo{interleave_by}i{block_by} and size O'HWI' is a 6-parameter
1818 * access function, where the 6 parameters are computed as follows:
1819 *
1820 * x5 = floor(o/{interleave_by}) RANGE [0, O'/{interleave_by} -1] SIZE: O'/{interleave_by}
1821 *
1822 * x4 = h RANGE [0, H-1] SIZE: H
1823 * x3 = w RANGE [0, W-1] SIZE: W
1824 * x2 = floor(i/{block_by}) RANGE [0, I'/{block_by} -1] SIZE: I'/{block_by}
1825 * x1 = o%{interleave_by} RANGE [0, {interleave_by} -1] SIZE: {interleave_by}
1826 * x0 = i%{block_by} RANGE [0, {block_by} -1] SIZE: {block_by}
1827 * TOTAL SIZE: O' * H * W * I'
1828 *
1829 * 4D 6D
1830 * ----------------- -----------------------------------
1831 * value(o, h, w, i) = x5 * H * W * I' * {interleave_by}
1832 * + x4 * W * I' * {interleave_by}
1833 * + x3 * I' * {interleave_by}
1834 * + x2 * {interleave_by} * {block_by}
1835 * + x1 * {block_by}
1836 * + x0
1837 *
1838 * Notice that in arm_gemm the 4D tensor of dimension O'HWI' created
1839 * for the OHWIo{interleave_by}i{block_by} format is in reality seen
1840 * as a 2D tensor, where the number of rows is O'/{interleave_by}
1841 * and the number of columns is {interleave_by} * H * W * I'.
1842 *
1843 * The postfix *_bf16 is for the memory layout needed for the
1844 * fast-mode kernels, in which the weights are passed in bfloat16
1845 * format.
1846 */
1847enum class WeightFormat
1848{
1849 UNSPECIFIED = 0x1,
1850 ANY = 0x2,
1851 OHWI = 0x100100,
1852 OHWIo2 = 0x100200,
1853 OHWIo4 = 0x100400,
1854 OHWIo8 = 0x100800,
1855 OHWIo16 = 0x101000,
1856 OHWIo32 = 0x102000,
1857 OHWIo64 = 0x104000,
1858 OHWIo128 = 0x108000,
1859 OHWIo4i2 = 0x200400,
1860 OHWIo4i2_bf16 = 0x200410,
1861 OHWIo8i2 = 0x200800,
1862 OHWIo8i2_bf16 = 0x200810,
1863 OHWIo16i2 = 0x201000,
1864 OHWIo16i2_bf16 = 0x201010,
1865 OHWIo32i2 = 0x202000,
1866 OHWIo32i2_bf16 = 0x202010,
1867 OHWIo64i2 = 0x204000,
1868 OHWIo64i2_bf16 = 0x204010,
1869 OHWIo4i4 = 0x400400,
1870 OHWIo4i4_bf16 = 0x400410,
1871 OHWIo8i4 = 0x400800,
1872 OHWIo8i4_bf16 = 0x400810,
1873 OHWIo16i4 = 0x401000,
1874 OHWIo16i4_bf16 = 0x401010,
1875 OHWIo32i4 = 0x402000,
1876 OHWIo32i4_bf16 = 0x402010,
1877 OHWIo64i4 = 0x404000,
1878 OHWIo64i4_bf16 = 0x404010,
1879 OHWIo2i8 = 0x800200,
1880 OHWIo4i8 = 0x800400,
1881 OHWIo8i8 = 0x800800,
1882 OHWIo16i8 = 0x801000,
1883 OHWIo32i8 = 0x802000,
1884 OHWIo64i8 = 0x804000
1885};
1886// OHWIo<interleave_by>i<block_by>
1887inline int interleave_by(const WeightFormat wf)
1888{
Pablo Marquez Tello93581a52022-07-21 13:55:27 +01001889 return (static_cast<int>(wf) >> 8) & 0xFFF;
Ramy Elgammal91780022022-07-20 14:57:37 +01001890}
1891inline int block_by(const WeightFormat wf)
1892{
Pablo Marquez Tello93581a52022-07-21 13:55:27 +01001893 return (static_cast<int>(wf) >> 20) & 0xF;
Ramy Elgammal91780022022-07-20 14:57:37 +01001894}
Pablo Marquez Tello93581a52022-07-21 13:55:27 +01001895inline bool is_fixed_format(const WeightFormat &wf)
Ramy Elgammal91780022022-07-20 14:57:37 +01001896{
1897 return wf != WeightFormat::UNSPECIFIED && wf != WeightFormat::ANY;
1898}
Pablo Marquez Tello93581a52022-07-21 13:55:27 +01001899inline bool is_fixed_format_fast_math(const WeightFormat &wf)
1900{
1901 return (static_cast<int>(wf) >> 4) & 0x1;
1902}
Ramy Elgammal91780022022-07-20 14:57:37 +01001903
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001904/** Convolution Layer Weights Information class. This class stores the necessary information to compute convolution layer when the weights are already reshaped */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001905class WeightsInfo
1906{
1907public:
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001908 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001909 WeightsInfo()
Ramy Elgammal91780022022-07-20 14:57:37 +01001910 : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0), _retain_internal_weights(false), _weight_format(arm_compute::WeightFormat::UNSPECIFIED)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001911 {
1912 }
1913 /** Constructor
1914 *
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001915 * @param[in] are_reshaped True if the weights have been reshaped
1916 * @param[in] kernel_width Kernel width.
1917 * @param[in] kernel_height Kernel height.
1918 * @param[in] num_kernels Number of convolution kernels.
1919 * @param[in] retain_internal_weights (Optional) True if internal reshaped weights must be retained. Used for reconfiguration purposes. Default is false.
Ramy Elgammal91780022022-07-20 14:57:37 +01001920 * @param[in] weight_format (Optional) arm_gemm:WeightFormat enumeration requested by the user. Default is arm_compute::WeightFormat::UNSPECIFIED.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001921 */
Francesco Petrogalli553f6952022-06-30 10:22:01 +00001922 WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels, bool retain_internal_weights = false,
Ramy Elgammal91780022022-07-20 14:57:37 +01001923 arm_compute::WeightFormat weight_format = arm_compute::WeightFormat::UNSPECIFIED)
Francesco Petrogalli553f6952022-06-30 10:22:01 +00001924 : _are_reshaped(are_reshaped), _kernel_width(kernel_width), _kernel_height(kernel_height), _num_kernels(num_kernels), _retain_internal_weights(retain_internal_weights), _weight_format(weight_format)
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001925 {
1926 }
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001927 /** Flag which specifies if the weights tensor has been reshaped.
1928 *
1929 * @return True if the weights tensors has been reshaped
1930 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001931 bool are_reshaped() const
1932 {
1933 return _are_reshaped;
1934 };
Gian Marco Iodice559d7712017-08-08 08:38:09 +01001935 /** Return the number of convolution kernels
1936 *
1937 * @return The number of convolution kernels
1938 */
1939 unsigned int num_kernels() const
1940 {
1941 return _num_kernels;
1942 };
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001943 /** Return the width and height of the kernel
1944 *
1945 * @return The width and height of the kernel
1946 */
1947 std::pair<unsigned int, unsigned int> kernel_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001948 {
Gian Marco Iodice4e288692017-06-27 11:41:59 +01001949 return std::make_pair(_kernel_width, _kernel_height);
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001950 }
Michele Di Giorgiob62280a2018-05-31 17:31:05 +01001951 bool retain_internal_weights() const
1952 {
1953 return _retain_internal_weights;
1954 }
Ramy Elgammal91780022022-07-20 14:57:37 +01001955 arm_compute::WeightFormat weight_format() const
Francesco Petrogalli553f6952022-06-30 10:22:01 +00001956 {
1957 return _weight_format;
1958 }
Milos Puzovic13b623e2022-07-27 17:53:21 +00001959 void set_weight_format(arm_compute::WeightFormat weight_format)
1960 {
1961 _weight_format = weight_format;
1962 }
1963
Francesco Petrogalli553f6952022-06-30 10:22:01 +00001964 unsigned int kernel_width() const
1965 {
1966 return _kernel_width;
1967 }
1968 unsigned int kernel_height() const
1969 {
1970 return _kernel_height;
1971 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001972
1973private:
Ramy Elgammal91780022022-07-20 14:57:37 +01001974 bool _are_reshaped;
1975 unsigned int _kernel_width;
1976 unsigned int _kernel_height;
1977 unsigned int _num_kernels;
1978 bool _retain_internal_weights;
1979 arm_compute::WeightFormat _weight_format;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001980};
1981
Gian Marco36a0a462018-01-12 10:21:40 +00001982/** GEMM reshape information class. This class stores the necessary information about matrix A and matrix B reshape.
1983 *
Michele Di Giorgio93b75e02021-06-21 12:00:43 +01001984 * The matrix A can only be reshaped through @ref opencl::kernels::ClGemmReshapeLhsMatrixKernel or @ref cpu::kernels::CpuGemmInterleave4x4Kernel
Georgios Pinitas856f66e2021-04-22 21:13:21 +01001985 * Note: Optionally just for @ref opencl::kernels::ClGemmReshapeLhsMatrixKernel is it possible to set mult_interleave4x4_height, the multiplication factor for the height of the 4x4 interleaved block
Gian Marco36a0a462018-01-12 10:21:40 +00001986 *
Michele Di Giorgio93b75e02021-06-21 12:00:43 +01001987 * The matrix B can only be reshaped through @ref opencl::kernels::ClGemmReshapeRhsMatrixKernel or @ref cpu::kernels::CpuGemmTranspose1xWKernel
Georgios Pinitas856f66e2021-04-22 21:13:21 +01001988 * Note: Optionally just for @ref opencl::kernels::ClGemmReshapeRhsMatrixKernel is it possible to set mult_transpose1xW_width, the multiplication factor for the width of the 1xW transposed block
Gian Marco36a0a462018-01-12 10:21:40 +00001989 *
1990 */
1991class GEMMReshapeInfo final
1992{
1993public:
1994 /** Default constructor */
1995 GEMMReshapeInfo()
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01001996 : _m(1), _n(1), _k(1), _mult_transpose1xW_width(1), _mult_interleave4x4_height(1), _depth_output_gemm3d(0), _reinterpret_input_as_3d(false), _broadcast_bias(false)
Gian Marco36a0a462018-01-12 10:21:40 +00001997 {
1998 }
1999 /** Constructor
2000 *
2001 * @param[in] m Number of matrix A rows
2002 * @param[in] n Number of matrix B columns
2003 * @param[in] k Number of matrix A columns or matrix B rows
2004 * @param[in] mult_transpose1xW_width (Optional) Multiplication factor for the width of the 1xW transposed block
2005 * @param[in] mult_interleave4x4_height (Optional) Multiplication factor for the height of the 4x4 interleaved block
Gian Marco Iodice3139f032018-11-05 14:26:32 +00002006 * @param[in] depth_output_gemm3d (Optional) Depth (third dimension) of the output tensor to be used with the GEMM3D kernel.
2007 * If 0 the output will not be reinterpreted as 3D. Default 0
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01002008 * @param[in] reinterpret_input_as_3d (Optional) Reinterpret the input as 3D tensor. (i.e. this flag should be set to true when GEMM is used
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01002009 * to perform 1x1 convolutions with the NHWC data layout)
2010 * @param[in] broadcast_bias (Optional) Broadcast the shape of the bias tensor from a vector to a matrix.
Gian Marco36a0a462018-01-12 10:21:40 +00002011 */
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01002012 GEMMReshapeInfo(int m, int n, int k, int mult_transpose1xW_width = 1, int mult_interleave4x4_height = 1, int depth_output_gemm3d = 0, bool reinterpret_input_as_3d = false, bool broadcast_bias = false)
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01002013 : _m(m), _n(n), _k(k), _mult_transpose1xW_width(mult_transpose1xW_width), _mult_interleave4x4_height(mult_interleave4x4_height), _depth_output_gemm3d(depth_output_gemm3d),
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01002014 _reinterpret_input_as_3d(reinterpret_input_as_3d), _broadcast_bias(broadcast_bias)
Gian Marco36a0a462018-01-12 10:21:40 +00002015 {
2016 }
2017 /** Number of matrix A rows
2018 *
2019 * @return the number of matrix A rows
2020 */
2021 int m() const
2022 {
2023 return _m;
2024 }
2025 /** Number of matrix B columns
2026 *
2027 * @return the number of matrix B columns
2028 */
2029 int n() const
2030 {
2031 return _n;
2032 }
2033 /** Number of matrix A columns or matrix B rows
2034 *
2035 * @return the number of matrix A columns or matrix B rows
2036 */
2037 int k() const
2038 {
2039 return _k;
2040 }
2041 /** Multiplication factor for the width of the 1xW transposed block
2042 *
2043 * @return the multiplication factor for the width of the 1xW transposed block
2044 */
2045 int mult_transpose1xW_width() const
2046 {
2047 return _mult_transpose1xW_width;
2048 }
2049 /** Multiplication factor for the height of the 4x4 interleaved block
2050 *
2051 * @return the multiplication factor for the height of the 4x4 interleaved block
2052 */
2053 int mult_interleave4x4_height() const
2054 {
2055 return _mult_interleave4x4_height;
2056 }
Isabella Gottardi8e74f442018-03-01 16:42:00 +00002057 /** Depth (third dimension) of the output tensor to be used with the GEMM3D kernel
2058 *
2059 * @note GEMM3D kernel is used when the output has to be reinterpret as 3D tensor. In that case:
2060 * m = depth_output_gemm3d * output_height
2061 *
2062 * @return the depth of the output tensor to be used with the GEMM3D kernel
2063 */
2064 int depth_output_gemm3d() const
2065 {
2066 return _depth_output_gemm3d;
2067 }
Gian Marco Iodice68a3f562018-07-26 11:44:03 +01002068 /** Flag which specifies if the input tensor has to be reinterpreted as 3D
2069 *
2070 * @return True if the input tensor has to be reinterpreted as 3D tensor
2071 */
2072 bool reinterpret_input_as_3d() const
2073 {
2074 return _reinterpret_input_as_3d;
2075 };
Georgios Pinitasb0f342e2019-05-21 13:32:43 +01002076 /** Flag which specifies whether to broadcast the shape of the bias tensor.
2077 *
2078 * @return True if the shape of the bias tensor is to be broadcasted.
2079 */
2080 bool broadcast_bias() const
2081 {
2082 return _broadcast_bias;
2083 };
Gian Marco36a0a462018-01-12 10:21:40 +00002084
2085private:
SiCong Liebd8fb42020-08-18 11:03:14 +01002086 int _m;
2087 int _n;
2088 int _k;
2089 int _mult_transpose1xW_width;
2090 int _mult_interleave4x4_height;
2091 int _depth_output_gemm3d;
2092 bool _reinterpret_input_as_3d;
2093 bool _broadcast_bias;
Gian Marco36a0a462018-01-12 10:21:40 +00002094};
2095
Gian Marco Iodice4b908652018-10-18 10:21:02 +01002096/** GEMMLowp output stage type */
2097enum class GEMMLowpOutputStageType
2098{
Manuel Bottini959c26d2019-12-02 16:22:35 +00002099 NONE, /**< No quantization */
2100 QUANTIZE_DOWN, /**< Quantize using an integer multiplication */
2101 QUANTIZE_DOWN_FIXEDPOINT, /**< Quantize using a fixed point multiplication */
2102 QUANTIZE_DOWN_FLOAT /**< Quantize using a floating point multiplication */
Gian Marco Iodice4b908652018-10-18 10:21:02 +01002103};
2104
2105/** GEMMLowp output stage info */
2106struct GEMMLowpOutputStageInfo
2107{
Giorgio Arena1856ff72020-02-07 13:46:45 +00002108 GEMMLowpOutputStageType type{ GEMMLowpOutputStageType::NONE }; /**< GEMMLowp output stage type */
2109 int32_t gemmlowp_offset{ 0 }; /**< GEMMLowp output stage offset used for quantizing to QASYMM8 */
2110 int32_t gemmlowp_multiplier{ 0 }; /**< GEMMLowp output stage multiplier used for quantizing to QASYMM8 */
2111 int32_t gemmlowp_shift{ 0 }; /**< GEMMLowp output stage shift used for quantizing to uint8 */
2112 int32_t gemmlowp_min_bound{ std::numeric_limits<int32_t>::lowest() }; /**< GEMMLowp min value used to saturate down the output result before converting back to QASYMM8 */
2113 int32_t gemmlowp_max_bound{ std::numeric_limits<int32_t>::max() }; /**< GEMMLowp max value used to saturate down the output result before converting back to QASYMM8 */
2114 std::vector<int32_t> gemmlowp_multipliers{}; /**< GEMMLowp output stage multiplier used for quantizing to QASYMM8 */
2115 std::vector<int32_t> gemmlowp_shifts{}; /**< GEMMLowp output stage multiplier used for quantizing to QASYMM8 */
Sheri Zhang1b14c752020-03-09 14:29:52 +00002116 float gemmlowp_real_multiplier{ 0 }; /**< GEMMLowp output stage real multiplier used for quantizing to QASYMM8 */
Giorgio Arena1856ff72020-02-07 13:46:45 +00002117 bool is_quantized_per_channel{ false }; /**< GEMMLowp quantized per-channel flag */
2118 DataType output_data_type{ DataType::UNKNOWN }; /**< Output tensor data type to use if the output is not initialized */
Gian Marco Iodice4b908652018-10-18 10:21:02 +01002119};
2120
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +00002121/** GEMM LHS (Left Hand Side) matrix information */
2122struct GEMMLHSMatrixInfo
2123{
morgolockaba2f912020-05-05 16:28:19 +01002124 GEMMLHSMatrixInfo() = default;
2125 GEMMLHSMatrixInfo(unsigned int m, unsigned int k, unsigned int v, bool trans, bool inter)
2126 : m0(m), k0(k), v0(v), transpose(trans), interleave(inter)
2127 {
2128 }
Gian Marco Iodice5ba5e092018-12-06 17:13:09 +00002129 unsigned int m0{ 1 }; /**< Number of rows processed by the matrix multiplication */
2130 unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
2131 unsigned int v0{ 1 }; /**< Number of vertical blocks of size (m0xk0) stored on the same output row */
2132 bool transpose{ true }; /**< True if the (m0xk0) block has to be transposed before been stored */
2133 bool interleave{ true }; /**< True if the v0 (m0xk0) blocks have to be interleaved in the output row */
2134};
2135
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +00002136/** GEMM RHS (Right Hand Side) matrix information */
2137struct GEMMRHSMatrixInfo
2138{
morgolockaba2f912020-05-05 16:28:19 +01002139 GEMMRHSMatrixInfo() = default;
Gian Marco Iodicee3a849a2020-06-10 17:59:30 +01002140 GEMMRHSMatrixInfo(unsigned int n, unsigned int k, unsigned int h, bool trans, bool inter, bool export_to_cl_img)
2141 : n0(n), k0(k), h0(h), transpose(trans), interleave(inter), export_to_cl_image(export_to_cl_img)
morgolockaba2f912020-05-05 16:28:19 +01002142 {
2143 }
Gian Marco Iodicedd717c32020-05-28 10:22:03 +01002144 unsigned int n0{ 1 }; /**< Number of columns processed by the matrix multiplication */
2145 unsigned int k0{ 1 }; /**< Number of partial accumulations performed by the matrix multiplication */
2146 unsigned int h0{ 1 }; /**< Number of horizontal blocks of size (k0xn0) stored on the same output row */
2147 bool transpose{ true }; /**< True if the (k0xn0) block has to be transposed before been stored */
2148 bool interleave{ true }; /**< True if the h0 (k0xn0) blocks have to be interleaved in the output row */
2149 bool export_to_cl_image{ false }; /**< True if the reshaped rhs has to be exported to cl_image. n0 must be equal to 4 */
Gian Marco Iodice3b0a2652018-12-07 11:18:09 +00002150};
2151
SiCongLi579ca842021-10-18 09:38:33 +01002152class ITensorInfo;
Chunosov5124be52017-11-22 20:42:13 +07002153
Gian Marco Iodice247f52c2018-03-22 11:24:56 +00002154/** Winograd information */
2155struct WinogradInfo
2156{
2157 /** Default constructor
2158 *
2159 * @param[in] output_tile_sz Width and height of the output tile
2160 * @param[in] kernel_sz Width and height of the kernel
2161 * @param[in] input_dims Width and height of the input tensor before the convolution is applied
2162 * @param[in] conv_info Convolution info (Pads, strides)
2163 * @param[in] data_layout Data layout to use for the output tensor once the convolution has been applied
2164 */
2165 WinogradInfo(Size2D output_tile_sz, Size2D kernel_sz, Size2D input_dims, PadStrideInfo conv_info, DataLayout data_layout)
2166 : output_tile_size(output_tile_sz), kernel_size(kernel_sz), input_dimensions(input_dims), convolution_info(conv_info), output_data_layout(data_layout)
2167 {
2168 }
2169
2170 Size2D output_tile_size{}; /**< Width and height of the output tile */
2171 Size2D kernel_size{}; /**< Width and height of the kernel*/
2172 Size2D input_dimensions{}; /**< Width and height of the input tensor before the convolution is applied */
2173 PadStrideInfo convolution_info{}; /**< Convolution info (Pads, strides,...) */
2174 DataLayout output_data_layout{ DataLayout::NCHW }; /**< Data layout to use for the output tensor once the convolution has been applied (NCHW or NHWC) */
2175};
2176
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002177/** IO formatting information class*/
2178struct IOFormatInfo
2179{
2180 /** Precision type used when printing floating point numbers */
2181 enum class PrecisionType
2182 {
2183 Default, /**< Default precision to the one that the current stream has */
2184 Custom, /**< Custom precision specified by the user using the precision parameter */
2185 Full /**< The maximum precision of the floating point representation */
2186 };
2187
2188 /** Specifies the area to be printed, used by Tensor objects */
2189 enum class PrintRegion
2190 {
2191 ValidRegion, /**< Prints the valid region of the Tensor object */
2192 NoPadding, /**< Prints the Tensor object without the padding */
2193 Full /**< Print the tensor object including padding */
2194 };
2195
Alex Gildayc357c472018-03-21 13:54:09 +00002196 /** Construct a set of IO formatting information.
2197 *
2198 * @param[in] print_region Area to be printed. Used by Tensor objects. Default: ValidRegion.
2199 * @param[in] precision_type Precision type for floating point numbers. Default: stream default.
2200 * @param[in] precision Precision value for float point numbers. Default: 10.
2201 * @param[in] align_columns Whether to align columns when printed. Default: true.
2202 * @param[in] element_delim Delimeter between elements. Default: " ".
2203 * @param[in] row_delim Delimenter between rows. Default: "\n".
2204 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002205 IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion,
2206 PrecisionType precision_type = PrecisionType::Default,
2207 unsigned int precision = 10,
2208 bool align_columns = true,
2209 std::string element_delim = " ",
2210 std::string row_delim = "\n")
2211 : print_region(print_region),
2212 precision_type(precision_type),
2213 precision(precision),
2214 element_delim(element_delim),
2215 row_delim(row_delim),
2216 align_columns(align_columns)
2217 {
2218 }
2219
Alex Gildayc357c472018-03-21 13:54:09 +00002220 /** Area to be printed by Tensor objects */
2221 PrintRegion print_region;
2222 /** Floating point precision type */
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002223 PrecisionType precision_type;
Alex Gildayc357c472018-03-21 13:54:09 +00002224 /** Floating point precision */
2225 unsigned int precision;
2226 /** Element delimeter */
2227 std::string element_delim;
2228 /** Row delimeter */
2229 std::string row_delim;
2230 /** Align columns */
2231 bool align_columns;
Anthony Barbier6ff3b192017-09-04 18:44:23 +01002232};
Mohammed Suhail Munshid538d162023-02-16 16:22:32 +00002233
SiCong Li4ceb4532023-03-13 15:02:23 +00002234/** Class for holding information related to cropping */
2235using CropInfo = Padding2D;
Georgios Pinitasd8734b52017-12-22 15:27:52 +00002236} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +00002237#endif /* ARM_COMPUTE_TYPES_H */