blob: beaec143ef0b6fe9c2de94d2db9cb69d3eb286d9 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 ARM Limited.
3 *
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 */
24#ifndef __ARM_COMPUTE_TYPES_H__
25#define __ARM_COMPUTE_TYPES_H__
26
27#include "arm_compute/core/Coordinates.h"
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000028#include "arm_compute/core/Strides.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010029#include "arm_compute/core/TensorShape.h"
Georgios Pinitas583137c2017-08-31 18:12:42 +010030#include "support/Half.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031
32#include <cstddef>
33#include <cstdint>
34#include <string>
35#include <utility>
36
37namespace arm_compute
38{
Georgios Pinitas583137c2017-08-31 18:12:42 +010039/** 16-bit floating point type */
40using half = half_float::half;
41
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000042/** Permutation vector */
43using PermutationVector = Strides;
44
Anthony Barbier6ff3b192017-09-04 18:44:23 +010045/** Image colour formats */
46enum class Format
47{
Daniil Efremov02bf80d2017-11-22 00:26:51 +070048 UNKNOWN, /**< Unknown image format */
49 U8, /**< 1 channel, 1 U8 per channel */
50 S16, /**< 1 channel, 1 S16 per channel */
51 U16, /**< 1 channel, 1 U16 per channel */
52 S32, /**< 1 channel, 1 S32 per channel */
53 U32, /**< 1 channel, 1 U32 per channel */
54 F16, /**< 1 channel, 1 F16 per channel */
55 F32, /**< 1 channel, 1 F32 per channel */
56 UV88, /**< 2 channel, 1 U8 per channel */
57 RGB888, /**< 3 channels, 1 U8 per channel */
58 RGBA8888, /**< 4 channels, 1 U8 per channel */
59 YUV444, /**< A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes */
60 YUYV422, /**< A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes */
61 NV12, /**< A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling */
62 NV21, /**< A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling */
63 IYUV, /**< A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes */
64 UYVY422 /**< A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010065};
66
67/** Available data types */
68enum class DataType
69{
70 UNKNOWN,
71 U8,
72 S8,
73 QS8,
Michel Iwaniec00633802017-10-12 14:14:15 +010074 QASYMM8,
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075 U16,
76 S16,
77 QS16,
78 U32,
79 S32,
Pablo Tellof87cc7f2017-07-26 10:28:40 +010080 QS32,
Anthony Barbier6ff3b192017-09-04 18:44:23 +010081 U64,
82 S64,
83 F16,
84 F32,
85 F64,
86 SIZET
87};
88
Daniil Efremov02bf80d2017-11-22 00:26:51 +070089/** Available Sampling Policies */
90enum class SamplingPolicy
91{
92 CENTER, /**< Samples are taken at pixel center */
93 TOP_LEFT /**< Samples are taken at pixel top left corner */
94};
95
Anthony Barbier6ff3b192017-09-04 18:44:23 +010096/** Constant value of the border pixels when using BorderMode::CONSTANT */
97constexpr uint8_t CONSTANT_BORDER_VALUE = 199;
98
99/* Constant value used to indicate a half-scale pyramid */
100constexpr float SCALE_PYRAMID_HALF = 0.5f;
101
102/* Constant value used to indicate a ORB scaled pyramid */
103constexpr float SCALE_PYRAMID_ORB = 8.408964152537146130583778358414e-01;
104
Jaroslaw Rzepecki0a878ae2017-11-22 17:16:39 +0000105/** Rounding method */
106enum class RoundingPolicy
107{
108 TO_ZERO, /**< Truncates the least significand values that are lost in operations. */
109 TO_NEAREST_UP, /**< Rounds to nearest value; half rounds away from zero */
110 TO_NEAREST_EVEN, /**< Rounds to nearest value; half rounds to nearest even */
111};
112
113//forward declare round function
114int round(float, RoundingPolicy);
115
Michel Iwaniec00633802017-10-12 14:14:15 +0100116/** Quantization settings (used for QASYMM8 data type) */
117struct QuantizationInfo
118{
119 QuantizationInfo()
120 : scale(0.0f), offset(0)
121 {
122 }
123
124 QuantizationInfo(float scale, int offset)
125 : scale(scale), offset(offset)
126 {
127 }
128
Daniil Efremoveed841c2017-11-09 19:05:25 +0700129 bool operator==(const QuantizationInfo &other)
130 {
131 return scale == other.scale && offset == other.offset;
132 }
133
134 bool operator!=(const QuantizationInfo &other)
135 {
136 return !(*this == other);
137 }
138
Michel Iwaniec00633802017-10-12 14:14:15 +0100139 float scale; /**< scale */
140 int offset; /**< offset */
141
142 /** Quantizes a value using the scale/offset in this QuantizationInfo */
Jaroslaw Rzepecki0a878ae2017-11-22 17:16:39 +0000143 uint8_t quantize(float value, RoundingPolicy rounding_policy) const
Michel Iwaniec00633802017-10-12 14:14:15 +0100144 {
145 ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::quantize: scale == 0");
Jaroslaw Rzepecki0a878ae2017-11-22 17:16:39 +0000146 int quantized = arm_compute::round(value / scale, rounding_policy) + offset;
Michel Iwaniec00633802017-10-12 14:14:15 +0100147 quantized = std::max(0, std::min(quantized, 255));
148 return quantized;
149 }
150
151 /** Dequantizes a value using the scale/offset in this QuantizationInfo */
152 float dequantize(uint8_t value) const
153 {
154 ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::dequantize: scale == 0");
Anton Lokhmotovaf6204c2017-11-08 09:34:19 +0000155 float dequantized = (static_cast<int>(value) - offset) * scale;
Michel Iwaniec00633802017-10-12 14:14:15 +0100156 return dequantized;
157 }
158
159 /** Indicates whether this QuantizationInfo has valid settings or not */
160 bool empty() const
161 {
162 return scale == 0;
163 }
164};
165
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100166struct ValidRegion
167{
168 ValidRegion()
169 : anchor{}, shape{}
170 {
171 }
172
173 ValidRegion(const ValidRegion &) = default;
174 ValidRegion(ValidRegion &&) = default;
175 ValidRegion &operator=(const ValidRegion &) = default;
176 ValidRegion &operator=(ValidRegion &&) = default;
177 ~ValidRegion() = default;
178
179 ValidRegion(Coordinates anchor, TensorShape shape)
180 : anchor{ anchor }, shape{ shape }
181 {
182 }
183
184 /** Return the start of the valid region for the given dimension @p d */
185 int start(unsigned int d) const
186 {
187 return anchor[d];
188 }
189
190 /** Return the end of the valid region for the given dimension @p d */
191 int end(unsigned int d) const
192 {
193 return anchor[d] + shape[d];
194 }
195
196 Coordinates anchor;
197 TensorShape shape;
198};
199
200/** Methods available to handle borders */
201enum class BorderMode
202{
203 UNDEFINED, /**< Borders are left undefined */
204 CONSTANT, /**< Pixels outside the image are assumed to have a constant value */
205 REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */
206};
207
208/** Container for 2D border size */
209struct BorderSize
210{
211 /** Empty border, i.e. no border */
212 constexpr BorderSize()
213 : top{ 0 }, right{ 0 }, bottom{ 0 }, left{ 0 }
214 {
215 }
216
217 /** Border with equal size around the 2D plane */
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100218 explicit constexpr BorderSize(unsigned int size)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100219 : top{ size }, right{ size }, bottom{ size }, left{ size }
220 {
221 }
222
223 /** Border with same size for top/bottom and left/right */
224 constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
225 : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right }
226 {
227 }
228
229 /** Border with different sizes */
230 constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
231 : top{ top }, right{ right }, bottom{ bottom }, left{ left }
232 {
233 }
234
235 /** Check if the entire border is zero */
236 constexpr bool empty() const
237 {
238 return top == 0 && right == 0 && bottom == 0 && left == 0;
239 }
240
241 /** Check if the border is the same size on all sides */
242 constexpr bool uniform() const
243 {
244 return top == right && top == bottom && top == left;
245 }
246
247 BorderSize &operator*=(float scale)
248 {
249 top *= scale;
250 right *= scale;
251 bottom *= scale;
252 left *= scale;
253
254 return *this;
255 }
256
257 BorderSize operator*(float scale)
258 {
259 BorderSize size = *this;
260 size *= scale;
261
262 return size;
263 }
264
265 void limit(const BorderSize &limit)
266 {
267 top = std::min(top, limit.top);
268 right = std::min(right, limit.right);
269 bottom = std::min(bottom, limit.bottom);
270 left = std::min(left, limit.left);
271 }
272
273 unsigned int top;
274 unsigned int right;
275 unsigned int bottom;
276 unsigned int left;
277};
278
279using PaddingSize = BorderSize;
280
281/** Policy to handle overflow */
282enum class ConvertPolicy
283{
284 WRAP, /**< Wrap around */
285 SATURATE /**< Saturate */
286};
287
288/** Interpolation method */
289enum class InterpolationPolicy
290{
291 NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */
292 BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */
293 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 */
294};
295
296/** Bilinear Interpolation method used by LKTracker */
297enum class BilinearInterpolation
298{
299 BILINEAR_OLD_NEW,
300 BILINEAR_SCHARR
301};
302
303/** Threshold mode */
304enum class ThresholdType
305{
306 BINARY, /**< Threshold with one value */
307 RANGE /**< Threshold with two values*/
308};
309
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100310/** Termination criteria */
311enum class Termination
312{
313 TERM_CRITERIA_EPSILON,
314 TERM_CRITERIA_ITERATIONS,
315 TERM_CRITERIA_BOTH
316};
317
318/** Magnitude calculation type. */
319enum class MagnitudeType
320{
321 L1NORM, /**< L1 normalization type */
322 L2NORM /**< L2 normalization type */
323};
324
325/** Phase calculation type.
326 *
327 * @note When PhaseType == SIGNED, each angle is mapped to the range 0 to 255 inclusive otherwise angles between 0 and 180
328 */
329enum class PhaseType
330{
331 SIGNED, /**< Angle range: [0, 360] */
332 UNSIGNED /**< Angle range: [0, 180] */
333};
334
335/** Keypoint type */
336struct KeyPoint
337{
338 int32_t x{ 0 }; /**< X coordinates */
339 int32_t y{ 0 }; /**< Y coordinates */
340 float strength{ 0.f }; /**< Strength of the point */
341 float scale{ 0.f }; /**< Scale initialized to 0 by the corner detector */
342 float orientation{ 0.f }; /**< Orientation initialized to 0 by the corner detector */
343 int32_t tracking_status{ 0 }; /**< Status initialized to 1 by the corner detector, set to 0 when the point is lost */
344 float error{ 0.f }; /**< Tracking error initialized to 0 by the corner detector */
345};
346
347using InternalKeypoint = std::tuple<float, float, float>; /* x,y,strength */
348
349/** Rectangle type */
350struct Rectangle
351{
352 uint16_t x; /**< Top-left x coordinate */
353 uint16_t y; /**< Top-left y coordinate */
354 uint16_t width; /**< Width of the rectangle */
355 uint16_t height; /**< Height of the rectangle */
356};
357
358/** Coordinate type */
359struct Coordinates2D
360{
361 int32_t x; /**< X coordinates */
362 int32_t y; /**< Y coordinates */
363};
364
365/** Coordinate type */
366struct Coordinates3D
367{
368 uint32_t x; /**< X coordinates */
369 uint32_t y; /**< Y coordinates */
370 uint32_t z; /**< Z coordinates */
371};
372
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100373/** Region of interest */
374struct ROI
375{
376 Rectangle rect; /**< Rectangle specifying the region of interest */
377 uint16_t batch_idx; /**< The batch index of the region of interest */
378};
379
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100380/** Available channels */
381enum class Channel
382{
383 UNKNOWN, /** Unknown channel format */
384 C0, /**< First channel (used by formats with unknown channel types). */
385 C1, /**< Second channel (used by formats with unknown channel types). */
386 C2, /**< Third channel (used by formats with unknown channel types). */
387 C3, /**< Fourth channel (used by formats with unknown channel types). */
388 R, /**< Red channel. */
389 G, /**< Green channel. */
390 B, /**< Blue channel. */
391 A, /**< Alpha channel. */
392 Y, /**< Luma channel. */
393 U, /**< Cb/U channel. */
394 V /**< Cr/V/Value channel. */
395};
396
397/** Available matrix patterns */
398enum class MatrixPattern
399{
400 BOX, /**< Box pattern matrix. */
401 CROSS, /**< Cross pattern matrix. */
402 DISK, /**< Disk pattern matrix. */
403 OTHER /**< Any other matrix pattern. */
404};
405
406/** Available non linear functions. */
407enum class NonLinearFilterFunction : unsigned
408{
409 MEDIAN = 0, /**< Non linear median filter. */
410 MIN = 1, /**< Non linear erode. */
411 MAX = 2, /**< Non linear dilate. */
412};
413
Georgios Pinitasd9769582017-08-03 10:19:40 +0100414/** Available reduction operations */
415enum class ReductionOperation
416{
417 SUM_SQUARE, /**< Sum of squares */
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100418 SUM, /**< Sum */
Georgios Pinitasd9769582017-08-03 10:19:40 +0100419};
420
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100421/** The normalization type used for the normalization layer */
422enum class NormType
423{
424 IN_MAP_1D, /**< Normalization applied within the same map in 1D region */
425 IN_MAP_2D, /**< Normalization applied within the same map in 2D region */
426 CROSS_MAP /**< Normalization applied cross maps */
427};
428
429/** Normalization type for Histogram of Oriented Gradients (HOG) */
430enum class HOGNormType
431{
432 L2_NORM = 1, /**< L2-norm */
433 L2HYS_NORM = 2, /**< L2-norm followed by clipping */
434 L1_NORM = 3 /**< L1 norm */
435};
436
437/** Detection window used for the object detection. The detection window keeps the following information:
438 *
439 * -# Geometry of the rectangular window (x/y of top-left corner and width/height)
440 * -# Index of the class used for evaluating which class the detection window belongs to
441 * -# Confidence value (score) obtained with the classifier
442 */
443struct DetectionWindow
444{
445 uint16_t x{ 0 }; /**< Top-left x coordinate */
446 uint16_t y{ 0 }; /**< Top-left y coordinate */
447 uint16_t width{ 0 }; /**< Width of the detection window */
448 uint16_t height{ 0 }; /**< Height of the detection window */
449 uint16_t idx_class{ 0 }; /**< Index of the class */
450 float score{ 0.f }; /**< Confidence value for the detection window */
451};
452
453/** Dimension rounding type when down-scaling on CNNs
454 * @note Used in pooling and convolution layer
455 */
456enum class DimensionRoundingType
457{
458 FLOOR, /**< Floor rounding */
459 CEIL /**< Ceil rounding */
460};
461
462/** Available pooling types */
463enum class PoolingType
464{
465 MAX, /**< Max Pooling */
Georgios Pinitascdf51452017-08-31 14:21:36 +0100466 AVG, /**< Average Pooling */
467 L2 /**< L2 Pooling */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100468};
469
470/** Padding and stride information class */
471class PadStrideInfo
472{
473public:
474 /** Constructor
475 *
476 * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1.
477 * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1.
478 * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0.
479 * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0.
480 * @param[in] round (Optional) Dimensions rounding. Defaults to @ref FLOOR.
481 */
482 PadStrideInfo(unsigned int stride_x = 1, unsigned int stride_y = 1,
483 unsigned int pad_x = 0, unsigned int pad_y = 0,
484 DimensionRoundingType round = DimensionRoundingType::FLOOR)
485 : _stride(std::make_pair(stride_x, stride_y)),
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100486 _pad_left(pad_x),
487 _pad_top(pad_y),
488 _pad_right(pad_x),
489 _pad_bottom(pad_y),
490 _round_type(round)
491 {
492 }
493 /** Constructor
494 *
495 * @param[in] stride_x Stride, in elements, across x.
496 * @param[in] stride_y Stride, in elements, across y.
497 * @param[in] pad_left Padding across x on the left, in elements.
498 * @param[in] pad_top Padding across y on the top, in elements.
499 * @param[in] pad_right Padding across x on the right, in elements.
500 * @param[in] pad_bottom Padding across y on the bottom, in elements.
501 * @param[in] round Dimensions rounding.
502 */
503 PadStrideInfo(unsigned int stride_x, unsigned int stride_y,
504 unsigned int pad_left, unsigned int pad_right,
505 unsigned int pad_top, unsigned int pad_bottom,
506 DimensionRoundingType round)
507 : _stride(std::make_pair(stride_x, stride_y)),
508 _pad_left(pad_left),
509 _pad_top(pad_top),
510 _pad_right(pad_right),
511 _pad_bottom(pad_bottom),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100512 _round_type(round)
513 {
514 }
515 std::pair<unsigned int, unsigned int> stride() const
516 {
517 return _stride;
518 }
519 std::pair<unsigned int, unsigned int> pad() const
520 {
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100521 //this accessor should be used only when padding is symmetric
522 ARM_COMPUTE_ERROR_ON(_pad_left != _pad_right || _pad_top != _pad_bottom);
523 return std::make_pair(_pad_left, _pad_top);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100524 }
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100525
526 unsigned int pad_left() const
527 {
528 return _pad_left;
529 }
530 unsigned int pad_right() const
531 {
532 return _pad_right;
533 }
534 unsigned int pad_top() const
535 {
536 return _pad_top;
537 }
538 unsigned int pad_bottom() const
539 {
540 return _pad_bottom;
541 }
542
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100543 DimensionRoundingType round() const
544 {
545 return _round_type;
546 }
547
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100548 bool has_padding() const
549 {
550 return (_pad_left != 0 || _pad_top != 0 || _pad_right != 0 || _pad_bottom != 0);
551 }
552
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100553private:
554 std::pair<unsigned int, unsigned int> _stride;
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100555 unsigned int _pad_left;
556 unsigned int _pad_top;
557 unsigned int _pad_right;
558 unsigned int _pad_bottom;
559
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100560 DimensionRoundingType _round_type;
561};
562
563/** Pooling Layer Information class */
564class PoolingLayerInfo
565{
566public:
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000567 /** Default Constructor */
568 PoolingLayerInfo()
569 : _pool_type(PoolingType::MAX), _pool_size(0), _pad_stride_info(PadStrideInfo()), _exclude_padding(false), _is_global_pooling(false)
570 {
571 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100572 /** Default Constructor
573 *
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000574 * @param[in] pool_type Pooling type @ref PoolingType.
575 * @param[in] pool_size Pooling size, in elements, across x and y.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100576 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000577 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
578 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
579 * Defaults to false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100580 */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000581 explicit PoolingLayerInfo(PoolingType pool_type,
582 unsigned int pool_size,
583 PadStrideInfo pad_stride_info = PadStrideInfo(),
584 bool exclude_padding = false)
585 : _pool_type(pool_type), _pool_size(pool_size), _pad_stride_info(pad_stride_info), _exclude_padding(exclude_padding), _is_global_pooling(false)
586 {
587 }
588 /** Default Constructor
589 *
590 * @note This constructor is used for global pooling
591 *
592 * @param[in] pool_type Pooling type @ref PoolingType.
593 */
594 explicit PoolingLayerInfo(PoolingType pool_type)
595 : _pool_type(pool_type), _pool_size(0), _pad_stride_info(PadStrideInfo(1, 1, 0, 0)), _exclude_padding(false), _is_global_pooling(true)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100596 {
597 }
598 PoolingType pool_type() const
599 {
600 return _pool_type;
601 }
602 unsigned int pool_size() const
603 {
604 return _pool_size;
605 }
606 PadStrideInfo pad_stride_info() const
607 {
608 return _pad_stride_info;
609 }
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000610 bool exclude_padding() const
611 {
612 return _exclude_padding;
613 }
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000614 bool is_global_pooling() const
615 {
616 return _is_global_pooling;
617 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100618
619private:
620 PoolingType _pool_type;
621 unsigned int _pool_size;
622 PadStrideInfo _pad_stride_info;
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000623 bool _exclude_padding;
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000624 bool _is_global_pooling;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100625};
626
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100627/** ROI Pooling Layer Information class */
628class ROIPoolingLayerInfo
629{
630public:
631 /** Default Constructor
632 *
633 * @param[in] pooled_width Pooled width of the layer.
634 * @param[in] pooled_height Pooled height of the layer.
635 * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
636 */
637 ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale)
638 : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale)
639 {
640 }
641 unsigned int pooled_width() const
642 {
643 return _pooled_width;
644 }
645 unsigned int pooled_height() const
646 {
647 return _pooled_height;
648 }
649 float spatial_scale() const
650 {
651 return _spatial_scale;
652 }
653
654private:
655 unsigned int _pooled_width;
656 unsigned int _pooled_height;
657 float _spatial_scale;
658};
659
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100660/** Activation Layer Information class */
661class ActivationLayerInfo
662{
663public:
664 /** Available activation functions */
665 enum class ActivationFunction
666 {
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100667 LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */
668 TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */
669 RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */
670 BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */
671 LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */
672 LEAKY_RELU, /**< Leaky Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
673 SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
674 ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */
675 SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/
676 SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/
677 LINEAR /**< Linear ( \f$ f(x)= ax + b \f$ ) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100678 };
679
680 /** Default Constructor
681 *
682 * @param[in] f The activation function to use.
683 * @param[in] a (Optional) The alpha parameter used by some activation functions
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100684 * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH).
685 * @param[in] b (Optional) The beta parameter used by some activation functions (@ref ActivationFunction::LINEAR, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::TANH).
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100686 */
687 ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f)
688 : _act(f), _a(a), _b(b)
689 {
690 }
691 ActivationFunction activation() const
692 {
693 return _act;
694 }
695 float a() const
696 {
697 return _a;
698 }
699 float b() const
700 {
701 return _b;
702 }
703
704private:
705 ActivationFunction _act;
706 float _a;
707 float _b;
708};
709
710/** Normalization Layer Information class */
711class NormalizationLayerInfo
712{
713public:
714 /** Default Constructor
715 *
716 * @param[in] type The normalization type. Can be @ref NormType::IN_MAP_1D, @ref NormType::IN_MAP_2D or @ref NORM_TYPE::CROSS_MAP
717 * @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 +0000718 * @param[in] alpha (Optional) Alpha parameter used by normalization equation. Defaults to 0.0001.
719 * @param[in] beta (Optional) Beta parameter used by normalization equation. Defaults to 0.5.
720 * @param[in] kappa (Optional) Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
721 * @param[in] is_scaled (Optional) Boolean that specifies if alpha will be scaled by the normalization size or not.
722 * Should be false to follow [Krichevksy 2012].
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100723 */
Georgios Pinitas41caa622017-11-16 14:37:08 +0000724 NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f, bool is_scaled = true)
725 : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa), _is_scaled(is_scaled)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100726 {
727 }
728 NormType type() const
729 {
730 return _type;
731 }
732 uint32_t norm_size() const
733 {
734 return _norm_size;
735 }
736 float alpha() const
737 {
738 return _alpha;
739 }
740 float beta() const
741 {
742 return _beta;
743 }
744 float kappa() const
745 {
746 return _kappa;
747 }
Georgios Pinitas41caa622017-11-16 14:37:08 +0000748 bool is_cross_map() const
749 {
750 return _type == NormType::CROSS_MAP;
751 }
752 bool is_in_map() const
753 {
754 return !is_cross_map();
755 }
756 /** Return the scaling factor of the normalization function.
757 *
758 * If is_scaled is set to false then [Krichevksy 2012] normalization scaling is performed,
759 * 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 +0100760 *
761 * @return The normalization scaling factor.
762 */
763 float scale_coeff() const
764 {
765 const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
Georgios Pinitas41caa622017-11-16 14:37:08 +0000766 return (_is_scaled) ? (_alpha / size) : _alpha;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100767 }
768
769private:
770 NormType _type;
771 uint32_t _norm_size;
772 float _alpha;
773 float _beta;
774 float _kappa;
Georgios Pinitas41caa622017-11-16 14:37:08 +0000775 bool _is_scaled;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100776};
777
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100778/** 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 +0100779class WeightsInfo
780{
781public:
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100782 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100783 WeightsInfo()
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100784 : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100785 {
786 }
787 /** Constructor
788 *
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100789 * @param[in] are_reshaped True if the weights have been reshaped
790 * @param[in] kernel_width Kernel width.
791 * @param[in] kernel_height Kernel height.
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100792 * @param[in] num_kernels Number of convolution kernels.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100793 */
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100794 WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels)
795 : _are_reshaped(are_reshaped), _kernel_width(kernel_width), _kernel_height(kernel_height), _num_kernels(num_kernels)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100796 {
797 }
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100798 /** Flag which specifies if the weights tensor has been reshaped.
799 *
800 * @return True if the weights tensors has been reshaped
801 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100802 bool are_reshaped() const
803 {
804 return _are_reshaped;
805 };
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100806 /** Return the number of convolution kernels
807 *
808 * @return The number of convolution kernels
809 */
810 unsigned int num_kernels() const
811 {
812 return _num_kernels;
813 };
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100814 /** Return the width and height of the kernel
815 *
816 * @return The width and height of the kernel
817 */
818 std::pair<unsigned int, unsigned int> kernel_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100819 {
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100820 return std::make_pair(_kernel_width, _kernel_height);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100821 }
822
823private:
824 const bool _are_reshaped;
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100825 const unsigned int _kernel_width;
826 const unsigned int _kernel_height;
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100827 const unsigned int _num_kernels;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100828};
829
Chunosov5124be52017-11-22 20:42:13 +0700830/** GEMM Information class. This class stores the necessary information to compute GEMM functions */
831class GEMMInfo
832{
833public:
834 /** Default constructor */
835 GEMMInfo()
836 : _is_a_reshaped(false), _is_b_reshaped(false), _reshape_b_only_on_first_run(false)
837 {
838 }
839 /** Constructor
840 *
841 * @param[in] is_a_reshaped True if the matrix A has been reshaped
842 * @param[in] is_b_reshaped True if the matrix B has been reshaped
843 * @param[in] reshape_b_only_on_first_run Reshape matrix B only for the first run
844 */
845 GEMMInfo(bool is_a_reshaped, bool is_b_reshaped, bool reshape_b_only_on_first_run)
846 : _is_a_reshaped(is_a_reshaped), _is_b_reshaped(is_b_reshaped), _reshape_b_only_on_first_run(reshape_b_only_on_first_run)
847 {
848 }
849 /** Flag which specifies if the matrix A has been reshaped
850 *
851 * @return True if the matrix A has been reshaped
852 */
853 bool is_a_reshaped() const
854 {
855 return _is_a_reshaped;
856 };
857 /** Flag which specifies if the matrix B has been reshaped
858 *
859 * @return True if the matrix B has been reshaped
860 */
861 bool is_b_reshaped() const
862 {
863 return _is_b_reshaped;
864 };
865 /** Flag which specifies if the reshape of matrix B should executed only for the first
866 *
867 * @note This flag could be set to TRUE when GEMM is used to accelerate convolution layer
868 *
869 * @return True if the reshaped of matrix B happens only for the first run
870 */
871 bool reshape_b_only_on_first_run() const
872 {
873 return _reshape_b_only_on_first_run;
874 };
875
876private:
877 const bool _is_a_reshaped;
878 const bool _is_b_reshaped;
879 const bool _reshape_b_only_on_first_run;
880};
881
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100882/** IO formatting information class*/
883struct IOFormatInfo
884{
885 /** Precision type used when printing floating point numbers */
886 enum class PrecisionType
887 {
888 Default, /**< Default precision to the one that the current stream has */
889 Custom, /**< Custom precision specified by the user using the precision parameter */
890 Full /**< The maximum precision of the floating point representation */
891 };
892
893 /** Specifies the area to be printed, used by Tensor objects */
894 enum class PrintRegion
895 {
896 ValidRegion, /**< Prints the valid region of the Tensor object */
897 NoPadding, /**< Prints the Tensor object without the padding */
898 Full /**< Print the tensor object including padding */
899 };
900
901 IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion,
902 PrecisionType precision_type = PrecisionType::Default,
903 unsigned int precision = 10,
904 bool align_columns = true,
905 std::string element_delim = " ",
906 std::string row_delim = "\n")
907 : print_region(print_region),
908 precision_type(precision_type),
909 precision(precision),
910 element_delim(element_delim),
911 row_delim(row_delim),
912 align_columns(align_columns)
913 {
914 }
915
916 PrintRegion print_region;
917 PrecisionType precision_type;
918 unsigned int precision;
919 std::string element_delim;
920 std::string row_delim;
921 bool align_columns;
922};
923}
924#endif /* __ARM_COMPUTE_TYPES_H__ */