blob: 538449b40a321f67ce248c676ca0166df5b9d29e [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"
Michel Iwaniec5dfeae62017-11-29 10:48:23 +000028#include "arm_compute/core/QAsymm8.h"
29#include "arm_compute/core/Rounding.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"
Georgios Pinitas583137c2017-08-31 18:12:42 +010032#include "support/Half.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033
Michel Iwaniec5dfeae62017-11-29 10:48:23 +000034#include <cmath>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010035#include <cstddef>
36#include <cstdint>
37#include <string>
38#include <utility>
39
40namespace arm_compute
41{
Georgios Pinitas583137c2017-08-31 18:12:42 +010042/** 16-bit floating point type */
43using half = half_float::half;
44
Georgios Pinitas8795ffb2017-12-01 16:13:40 +000045/** Permutation vector */
46using PermutationVector = Strides;
47
Anthony Barbier6ff3b192017-09-04 18:44:23 +010048/** Image colour formats */
49enum class Format
50{
Daniil Efremov02bf80d2017-11-22 00:26:51 +070051 UNKNOWN, /**< Unknown image format */
52 U8, /**< 1 channel, 1 U8 per channel */
53 S16, /**< 1 channel, 1 S16 per channel */
54 U16, /**< 1 channel, 1 U16 per channel */
55 S32, /**< 1 channel, 1 S32 per channel */
56 U32, /**< 1 channel, 1 U32 per channel */
57 F16, /**< 1 channel, 1 F16 per channel */
58 F32, /**< 1 channel, 1 F32 per channel */
59 UV88, /**< 2 channel, 1 U8 per channel */
60 RGB888, /**< 3 channels, 1 U8 per channel */
61 RGBA8888, /**< 4 channels, 1 U8 per channel */
62 YUV444, /**< A 3 plane of 8 bit 4:4:4 sampled Y, U, V planes */
63 YUYV422, /**< A single plane of 32-bit macro pixel of Y0, U0, Y1, V0 bytes */
64 NV12, /**< A 2 plane YUV format of Luma (Y) and interleaved UV data at 4:2:0 sampling */
65 NV21, /**< A 2 plane YUV format of Luma (Y) and interleaved VU data at 4:2:0 sampling */
66 IYUV, /**< A 3 plane of 8-bit 4:2:0 sampled Y, U, V planes */
67 UYVY422 /**< A single plane of 32-bit macro pixel of U0, Y0, V0, Y1 byte */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010068};
69
70/** Available data types */
71enum class DataType
72{
73 UNKNOWN,
74 U8,
75 S8,
76 QS8,
Michel Iwaniec00633802017-10-12 14:14:15 +010077 QASYMM8,
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078 U16,
79 S16,
80 QS16,
81 U32,
82 S32,
Pablo Tellof87cc7f2017-07-26 10:28:40 +010083 QS32,
Anthony Barbier6ff3b192017-09-04 18:44:23 +010084 U64,
85 S64,
86 F16,
87 F32,
88 F64,
89 SIZET
90};
91
Daniil Efremov02bf80d2017-11-22 00:26:51 +070092/** Available Sampling Policies */
93enum class SamplingPolicy
94{
95 CENTER, /**< Samples are taken at pixel center */
96 TOP_LEFT /**< Samples are taken at pixel top left corner */
97};
98
Anthony Barbier6ff3b192017-09-04 18:44:23 +010099/** Constant value of the border pixels when using BorderMode::CONSTANT */
100constexpr uint8_t CONSTANT_BORDER_VALUE = 199;
101
102/* Constant value used to indicate a half-scale pyramid */
103constexpr float SCALE_PYRAMID_HALF = 0.5f;
104
105/* Constant value used to indicate a ORB scaled pyramid */
106constexpr float SCALE_PYRAMID_ORB = 8.408964152537146130583778358414e-01;
107
Michel Iwaniec00633802017-10-12 14:14:15 +0100108/** Quantization settings (used for QASYMM8 data type) */
109struct QuantizationInfo
110{
111 QuantizationInfo()
112 : scale(0.0f), offset(0)
113 {
114 }
115
116 QuantizationInfo(float scale, int offset)
117 : scale(scale), offset(offset)
118 {
119 }
120
Daniil Efremoveed841c2017-11-09 19:05:25 +0700121 bool operator==(const QuantizationInfo &other)
122 {
123 return scale == other.scale && offset == other.offset;
124 }
125
126 bool operator!=(const QuantizationInfo &other)
127 {
128 return !(*this == other);
129 }
130
Michel Iwaniec00633802017-10-12 14:14:15 +0100131 float scale; /**< scale */
132 int offset; /**< offset */
133
134 /** Quantizes a value using the scale/offset in this QuantizationInfo */
Michel Iwaniec5dfeae62017-11-29 10:48:23 +0000135 qasymm8_t quantize(float value, RoundingPolicy rounding_policy) const
Michel Iwaniec00633802017-10-12 14:14:15 +0100136 {
137 ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::quantize: scale == 0");
Michel Iwaniec5dfeae62017-11-29 10:48:23 +0000138 return sqcvt_qasymm8_f32(value, scale, offset, rounding_policy);
Michel Iwaniec00633802017-10-12 14:14:15 +0100139 }
140
141 /** Dequantizes a value using the scale/offset in this QuantizationInfo */
Michel Iwaniec5dfeae62017-11-29 10:48:23 +0000142 float dequantize(qasymm8_t value) const
Michel Iwaniec00633802017-10-12 14:14:15 +0100143 {
144 ARM_COMPUTE_ERROR_ON_MSG(scale == 0, "QuantizationInfo::dequantize: scale == 0");
Michel Iwaniec5dfeae62017-11-29 10:48:23 +0000145 return scvt_f32_qasymm8(value, scale, offset);
Michel Iwaniec00633802017-10-12 14:14:15 +0100146 }
147
148 /** Indicates whether this QuantizationInfo has valid settings or not */
149 bool empty() const
150 {
151 return scale == 0;
152 }
153};
154
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100155struct ValidRegion
156{
157 ValidRegion()
158 : anchor{}, shape{}
159 {
160 }
161
162 ValidRegion(const ValidRegion &) = default;
163 ValidRegion(ValidRegion &&) = default;
164 ValidRegion &operator=(const ValidRegion &) = default;
165 ValidRegion &operator=(ValidRegion &&) = default;
166 ~ValidRegion() = default;
167
168 ValidRegion(Coordinates anchor, TensorShape shape)
169 : anchor{ anchor }, shape{ shape }
170 {
171 }
172
173 /** Return the start of the valid region for the given dimension @p d */
174 int start(unsigned int d) const
175 {
176 return anchor[d];
177 }
178
179 /** Return the end of the valid region for the given dimension @p d */
180 int end(unsigned int d) const
181 {
182 return anchor[d] + shape[d];
183 }
184
185 Coordinates anchor;
186 TensorShape shape;
187};
188
189/** Methods available to handle borders */
190enum class BorderMode
191{
192 UNDEFINED, /**< Borders are left undefined */
193 CONSTANT, /**< Pixels outside the image are assumed to have a constant value */
194 REPLICATE /**< Pixels outside the image are assumed to have the same value as the closest image pixel */
195};
196
197/** Container for 2D border size */
198struct BorderSize
199{
200 /** Empty border, i.e. no border */
201 constexpr BorderSize()
202 : top{ 0 }, right{ 0 }, bottom{ 0 }, left{ 0 }
203 {
204 }
205
206 /** Border with equal size around the 2D plane */
Moritz Pflanzer7655a672017-09-23 11:57:33 +0100207 explicit constexpr BorderSize(unsigned int size)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100208 : top{ size }, right{ size }, bottom{ size }, left{ size }
209 {
210 }
211
212 /** Border with same size for top/bottom and left/right */
213 constexpr BorderSize(unsigned int top_bottom, unsigned int left_right)
214 : top{ top_bottom }, right{ left_right }, bottom{ top_bottom }, left{ left_right }
215 {
216 }
217
218 /** Border with different sizes */
219 constexpr BorderSize(unsigned int top, unsigned int right, unsigned int bottom, unsigned int left)
220 : top{ top }, right{ right }, bottom{ bottom }, left{ left }
221 {
222 }
223
224 /** Check if the entire border is zero */
225 constexpr bool empty() const
226 {
227 return top == 0 && right == 0 && bottom == 0 && left == 0;
228 }
229
230 /** Check if the border is the same size on all sides */
231 constexpr bool uniform() const
232 {
233 return top == right && top == bottom && top == left;
234 }
235
236 BorderSize &operator*=(float scale)
237 {
238 top *= scale;
239 right *= scale;
240 bottom *= scale;
241 left *= scale;
242
243 return *this;
244 }
245
246 BorderSize operator*(float scale)
247 {
248 BorderSize size = *this;
249 size *= scale;
250
251 return size;
252 }
253
254 void limit(const BorderSize &limit)
255 {
256 top = std::min(top, limit.top);
257 right = std::min(right, limit.right);
258 bottom = std::min(bottom, limit.bottom);
259 left = std::min(left, limit.left);
260 }
261
262 unsigned int top;
263 unsigned int right;
264 unsigned int bottom;
265 unsigned int left;
266};
267
268using PaddingSize = BorderSize;
269
270/** Policy to handle overflow */
271enum class ConvertPolicy
272{
273 WRAP, /**< Wrap around */
274 SATURATE /**< Saturate */
275};
276
277/** Interpolation method */
278enum class InterpolationPolicy
279{
280 NEAREST_NEIGHBOR, /**< Output values are defined to match the source pixel whose center is nearest to the sample position */
281 BILINEAR, /**< Output values are defined by bilinear interpolation between the pixels */
282 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 */
283};
284
285/** Bilinear Interpolation method used by LKTracker */
286enum class BilinearInterpolation
287{
288 BILINEAR_OLD_NEW,
289 BILINEAR_SCHARR
290};
291
292/** Threshold mode */
293enum class ThresholdType
294{
295 BINARY, /**< Threshold with one value */
296 RANGE /**< Threshold with two values*/
297};
298
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100299/** Termination criteria */
300enum class Termination
301{
302 TERM_CRITERIA_EPSILON,
303 TERM_CRITERIA_ITERATIONS,
304 TERM_CRITERIA_BOTH
305};
306
307/** Magnitude calculation type. */
308enum class MagnitudeType
309{
310 L1NORM, /**< L1 normalization type */
311 L2NORM /**< L2 normalization type */
312};
313
314/** Phase calculation type.
315 *
316 * @note When PhaseType == SIGNED, each angle is mapped to the range 0 to 255 inclusive otherwise angles between 0 and 180
317 */
318enum class PhaseType
319{
320 SIGNED, /**< Angle range: [0, 360] */
321 UNSIGNED /**< Angle range: [0, 180] */
322};
323
324/** Keypoint type */
325struct KeyPoint
326{
327 int32_t x{ 0 }; /**< X coordinates */
328 int32_t y{ 0 }; /**< Y coordinates */
329 float strength{ 0.f }; /**< Strength of the point */
330 float scale{ 0.f }; /**< Scale initialized to 0 by the corner detector */
331 float orientation{ 0.f }; /**< Orientation initialized to 0 by the corner detector */
332 int32_t tracking_status{ 0 }; /**< Status initialized to 1 by the corner detector, set to 0 when the point is lost */
333 float error{ 0.f }; /**< Tracking error initialized to 0 by the corner detector */
334};
335
336using InternalKeypoint = std::tuple<float, float, float>; /* x,y,strength */
337
338/** Rectangle type */
339struct Rectangle
340{
341 uint16_t x; /**< Top-left x coordinate */
342 uint16_t y; /**< Top-left y coordinate */
343 uint16_t width; /**< Width of the rectangle */
344 uint16_t height; /**< Height of the rectangle */
345};
346
347/** Coordinate type */
348struct Coordinates2D
349{
350 int32_t x; /**< X coordinates */
351 int32_t y; /**< Y coordinates */
352};
353
354/** Coordinate type */
355struct Coordinates3D
356{
357 uint32_t x; /**< X coordinates */
358 uint32_t y; /**< Y coordinates */
359 uint32_t z; /**< Z coordinates */
360};
361
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100362/** Region of interest */
363struct ROI
364{
365 Rectangle rect; /**< Rectangle specifying the region of interest */
366 uint16_t batch_idx; /**< The batch index of the region of interest */
367};
368
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100369/** Available channels */
370enum class Channel
371{
372 UNKNOWN, /** Unknown channel format */
373 C0, /**< First channel (used by formats with unknown channel types). */
374 C1, /**< Second channel (used by formats with unknown channel types). */
375 C2, /**< Third channel (used by formats with unknown channel types). */
376 C3, /**< Fourth channel (used by formats with unknown channel types). */
377 R, /**< Red channel. */
378 G, /**< Green channel. */
379 B, /**< Blue channel. */
380 A, /**< Alpha channel. */
381 Y, /**< Luma channel. */
382 U, /**< Cb/U channel. */
383 V /**< Cr/V/Value channel. */
384};
385
386/** Available matrix patterns */
387enum class MatrixPattern
388{
389 BOX, /**< Box pattern matrix. */
390 CROSS, /**< Cross pattern matrix. */
391 DISK, /**< Disk pattern matrix. */
392 OTHER /**< Any other matrix pattern. */
393};
394
395/** Available non linear functions. */
396enum class NonLinearFilterFunction : unsigned
397{
398 MEDIAN = 0, /**< Non linear median filter. */
399 MIN = 1, /**< Non linear erode. */
400 MAX = 2, /**< Non linear dilate. */
401};
402
Georgios Pinitasd9769582017-08-03 10:19:40 +0100403/** Available reduction operations */
404enum class ReductionOperation
405{
406 SUM_SQUARE, /**< Sum of squares */
Michalis Spyrou04f089c2017-08-08 17:42:38 +0100407 SUM, /**< Sum */
Georgios Pinitasd9769582017-08-03 10:19:40 +0100408};
409
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100410/** The normalization type used for the normalization layer */
411enum class NormType
412{
413 IN_MAP_1D, /**< Normalization applied within the same map in 1D region */
414 IN_MAP_2D, /**< Normalization applied within the same map in 2D region */
415 CROSS_MAP /**< Normalization applied cross maps */
416};
417
418/** Normalization type for Histogram of Oriented Gradients (HOG) */
419enum class HOGNormType
420{
421 L2_NORM = 1, /**< L2-norm */
422 L2HYS_NORM = 2, /**< L2-norm followed by clipping */
423 L1_NORM = 3 /**< L1 norm */
424};
425
426/** Detection window used for the object detection. The detection window keeps the following information:
427 *
428 * -# Geometry of the rectangular window (x/y of top-left corner and width/height)
429 * -# Index of the class used for evaluating which class the detection window belongs to
430 * -# Confidence value (score) obtained with the classifier
431 */
432struct DetectionWindow
433{
434 uint16_t x{ 0 }; /**< Top-left x coordinate */
435 uint16_t y{ 0 }; /**< Top-left y coordinate */
436 uint16_t width{ 0 }; /**< Width of the detection window */
437 uint16_t height{ 0 }; /**< Height of the detection window */
438 uint16_t idx_class{ 0 }; /**< Index of the class */
439 float score{ 0.f }; /**< Confidence value for the detection window */
440};
441
442/** Dimension rounding type when down-scaling on CNNs
443 * @note Used in pooling and convolution layer
444 */
445enum class DimensionRoundingType
446{
447 FLOOR, /**< Floor rounding */
448 CEIL /**< Ceil rounding */
449};
450
451/** Available pooling types */
452enum class PoolingType
453{
454 MAX, /**< Max Pooling */
Georgios Pinitascdf51452017-08-31 14:21:36 +0100455 AVG, /**< Average Pooling */
456 L2 /**< L2 Pooling */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100457};
458
459/** Padding and stride information class */
460class PadStrideInfo
461{
462public:
463 /** Constructor
464 *
465 * @param[in] stride_x (Optional) Stride, in elements, across x. Defaults to 1.
466 * @param[in] stride_y (Optional) Stride, in elements, across y. Defaults to 1.
467 * @param[in] pad_x (Optional) Padding, in elements, across x. Defaults to 0.
468 * @param[in] pad_y (Optional) Padding, in elements, across y. Defaults to 0.
469 * @param[in] round (Optional) Dimensions rounding. Defaults to @ref FLOOR.
470 */
471 PadStrideInfo(unsigned int stride_x = 1, unsigned int stride_y = 1,
472 unsigned int pad_x = 0, unsigned int pad_y = 0,
473 DimensionRoundingType round = DimensionRoundingType::FLOOR)
474 : _stride(std::make_pair(stride_x, stride_y)),
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100475 _pad_left(pad_x),
476 _pad_top(pad_y),
477 _pad_right(pad_x),
478 _pad_bottom(pad_y),
479 _round_type(round)
480 {
481 }
482 /** Constructor
483 *
484 * @param[in] stride_x Stride, in elements, across x.
485 * @param[in] stride_y Stride, in elements, across y.
486 * @param[in] pad_left Padding across x on the left, in elements.
487 * @param[in] pad_top Padding across y on the top, in elements.
488 * @param[in] pad_right Padding across x on the right, in elements.
489 * @param[in] pad_bottom Padding across y on the bottom, in elements.
490 * @param[in] round Dimensions rounding.
491 */
492 PadStrideInfo(unsigned int stride_x, unsigned int stride_y,
493 unsigned int pad_left, unsigned int pad_right,
494 unsigned int pad_top, unsigned int pad_bottom,
495 DimensionRoundingType round)
496 : _stride(std::make_pair(stride_x, stride_y)),
497 _pad_left(pad_left),
498 _pad_top(pad_top),
499 _pad_right(pad_right),
500 _pad_bottom(pad_bottom),
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100501 _round_type(round)
502 {
503 }
504 std::pair<unsigned int, unsigned int> stride() const
505 {
506 return _stride;
507 }
508 std::pair<unsigned int, unsigned int> pad() const
509 {
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100510 //this accessor should be used only when padding is symmetric
511 ARM_COMPUTE_ERROR_ON(_pad_left != _pad_right || _pad_top != _pad_bottom);
512 return std::make_pair(_pad_left, _pad_top);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100513 }
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100514
515 unsigned int pad_left() const
516 {
517 return _pad_left;
518 }
519 unsigned int pad_right() const
520 {
521 return _pad_right;
522 }
523 unsigned int pad_top() const
524 {
525 return _pad_top;
526 }
527 unsigned int pad_bottom() const
528 {
529 return _pad_bottom;
530 }
531
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100532 DimensionRoundingType round() const
533 {
534 return _round_type;
535 }
536
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100537 bool has_padding() const
538 {
539 return (_pad_left != 0 || _pad_top != 0 || _pad_right != 0 || _pad_bottom != 0);
540 }
541
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100542private:
543 std::pair<unsigned int, unsigned int> _stride;
Jaroslaw Rzepeckia1ed41f2017-10-13 11:13:58 +0100544 unsigned int _pad_left;
545 unsigned int _pad_top;
546 unsigned int _pad_right;
547 unsigned int _pad_bottom;
548
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100549 DimensionRoundingType _round_type;
550};
551
552/** Pooling Layer Information class */
553class PoolingLayerInfo
554{
555public:
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000556 /** Default Constructor */
557 PoolingLayerInfo()
558 : _pool_type(PoolingType::MAX), _pool_size(0), _pad_stride_info(PadStrideInfo()), _exclude_padding(false), _is_global_pooling(false)
559 {
560 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100561 /** Default Constructor
562 *
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000563 * @param[in] pool_type Pooling type @ref PoolingType.
564 * @param[in] pool_size Pooling size, in elements, across x and y.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100565 * @param[in] pad_stride_info (Optional) Padding and stride information @ref PadStrideInfo
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000566 * @param[in] exclude_padding (Optional) Strategy when accounting padding in calculations.
567 * True will exclude padding while false will not (Used in AVG/L2 pooling to determine the pooling area).
568 * Defaults to false;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100569 */
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000570 explicit PoolingLayerInfo(PoolingType pool_type,
571 unsigned int pool_size,
572 PadStrideInfo pad_stride_info = PadStrideInfo(),
573 bool exclude_padding = false)
574 : _pool_type(pool_type), _pool_size(pool_size), _pad_stride_info(pad_stride_info), _exclude_padding(exclude_padding), _is_global_pooling(false)
575 {
576 }
577 /** Default Constructor
578 *
579 * @note This constructor is used for global pooling
580 *
581 * @param[in] pool_type Pooling type @ref PoolingType.
582 */
583 explicit PoolingLayerInfo(PoolingType pool_type)
584 : _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 +0100585 {
586 }
587 PoolingType pool_type() const
588 {
589 return _pool_type;
590 }
591 unsigned int pool_size() const
592 {
593 return _pool_size;
594 }
595 PadStrideInfo pad_stride_info() const
596 {
597 return _pad_stride_info;
598 }
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000599 bool exclude_padding() const
600 {
601 return _exclude_padding;
602 }
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000603 bool is_global_pooling() const
604 {
605 return _is_global_pooling;
606 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100607
608private:
609 PoolingType _pool_type;
610 unsigned int _pool_size;
611 PadStrideInfo _pad_stride_info;
Georgios Pinitasadaae7e2017-10-30 15:56:32 +0000612 bool _exclude_padding;
Georgios Pinitas4c2dd542017-11-13 12:58:41 +0000613 bool _is_global_pooling;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100614};
615
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100616/** ROI Pooling Layer Information class */
617class ROIPoolingLayerInfo
618{
619public:
620 /** Default Constructor
621 *
622 * @param[in] pooled_width Pooled width of the layer.
623 * @param[in] pooled_height Pooled height of the layer.
624 * @param[in] spatial_scale Spatial scale to be applied to the ROI coordinates and dimensions.
625 */
626 ROIPoolingLayerInfo(unsigned int pooled_width, unsigned int pooled_height, float spatial_scale)
627 : _pooled_width(pooled_width), _pooled_height(pooled_height), _spatial_scale(spatial_scale)
628 {
629 }
630 unsigned int pooled_width() const
631 {
632 return _pooled_width;
633 }
634 unsigned int pooled_height() const
635 {
636 return _pooled_height;
637 }
638 float spatial_scale() const
639 {
640 return _spatial_scale;
641 }
642
643private:
644 unsigned int _pooled_width;
645 unsigned int _pooled_height;
646 float _spatial_scale;
647};
648
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100649/** Activation Layer Information class */
650class ActivationLayerInfo
651{
652public:
653 /** Available activation functions */
654 enum class ActivationFunction
655 {
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100656 LOGISTIC, /**< Logistic ( \f$ f(x) = \frac{1}{1 + e^{-x}} \f$ ) */
657 TANH, /**< Hyperbolic tangent ( \f$ f(x) = a \cdot tanh(b \cdot x) \f$ ) */
658 RELU, /**< Rectifier ( \f$ f(x) = max(0,x) \f$ ) */
659 BOUNDED_RELU, /**< Upper Bounded Rectifier ( \f$ f(x) = min(a, max(0,x)) \f$ ) */
660 LU_BOUNDED_RELU, /**< Lower and Upper Bounded Rectifier ( \f$ f(x) = min(a, max(b,x)) \f$ ) */
661 LEAKY_RELU, /**< Leaky Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
662 SOFT_RELU, /**< Soft Rectifier ( \f$ f(x)= log(1+e^x) \f$ ) */
663 ABS, /**< Absolute ( \f$ f(x)= |x| \f$ ) */
664 SQUARE, /**< Square ( \f$ f(x)= x^2 \f$ )*/
665 SQRT, /**< Square root ( \f$ f(x) = \sqrt{x} \f$ )*/
666 LINEAR /**< Linear ( \f$ f(x)= ax + b \f$ ) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100667 };
668
669 /** Default Constructor
670 *
671 * @param[in] f The activation function to use.
672 * @param[in] a (Optional) The alpha parameter used by some activation functions
Georgios Pinitas64ebe5b2017-09-01 17:44:24 +0100673 * (@ref ActivationFunction::BOUNDED_RELU, @ref ActivationFunction::LU_BOUNDED_RELU, @ref ActivationFunction::LINEAR, @ref ActivationFunction::TANH).
674 * @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 +0100675 */
676 ActivationLayerInfo(ActivationFunction f, float a = 0.0f, float b = 0.0f)
677 : _act(f), _a(a), _b(b)
678 {
679 }
680 ActivationFunction activation() const
681 {
682 return _act;
683 }
684 float a() const
685 {
686 return _a;
687 }
688 float b() const
689 {
690 return _b;
691 }
692
693private:
694 ActivationFunction _act;
695 float _a;
696 float _b;
697};
698
699/** Normalization Layer Information class */
700class NormalizationLayerInfo
701{
702public:
703 /** Default Constructor
704 *
705 * @param[in] type The normalization type. Can be @ref NormType::IN_MAP_1D, @ref NormType::IN_MAP_2D or @ref NORM_TYPE::CROSS_MAP
706 * @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 +0000707 * @param[in] alpha (Optional) Alpha parameter used by normalization equation. Defaults to 0.0001.
708 * @param[in] beta (Optional) Beta parameter used by normalization equation. Defaults to 0.5.
709 * @param[in] kappa (Optional) Kappa parameter used by [Krichevksy 2012] Across Channel Local Brightness Normalization equation.
710 * @param[in] is_scaled (Optional) Boolean that specifies if alpha will be scaled by the normalization size or not.
711 * Should be false to follow [Krichevksy 2012].
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100712 */
Georgios Pinitas41caa622017-11-16 14:37:08 +0000713 NormalizationLayerInfo(NormType type, uint32_t norm_size = 5, float alpha = 0.0001f, float beta = 0.5f, float kappa = 1.f, bool is_scaled = true)
714 : _type(type), _norm_size(norm_size), _alpha(alpha), _beta(beta), _kappa(kappa), _is_scaled(is_scaled)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100715 {
716 }
717 NormType type() const
718 {
719 return _type;
720 }
721 uint32_t norm_size() const
722 {
723 return _norm_size;
724 }
725 float alpha() const
726 {
727 return _alpha;
728 }
729 float beta() const
730 {
731 return _beta;
732 }
733 float kappa() const
734 {
735 return _kappa;
736 }
Georgios Pinitas41caa622017-11-16 14:37:08 +0000737 bool is_cross_map() const
738 {
739 return _type == NormType::CROSS_MAP;
740 }
741 bool is_in_map() const
742 {
743 return !is_cross_map();
744 }
745 /** Return the scaling factor of the normalization function.
746 *
747 * If is_scaled is set to false then [Krichevksy 2012] normalization scaling is performed,
748 * 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 +0100749 *
750 * @return The normalization scaling factor.
751 */
752 float scale_coeff() const
753 {
754 const uint32_t size = (_type == NormType::IN_MAP_2D) ? _norm_size * _norm_size : _norm_size;
Georgios Pinitas41caa622017-11-16 14:37:08 +0000755 return (_is_scaled) ? (_alpha / size) : _alpha;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100756 }
757
758private:
759 NormType _type;
760 uint32_t _norm_size;
761 float _alpha;
762 float _beta;
763 float _kappa;
Georgios Pinitas41caa622017-11-16 14:37:08 +0000764 bool _is_scaled;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100765};
766
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100767/** 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 +0100768class WeightsInfo
769{
770public:
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100771 /** Default constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100772 WeightsInfo()
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100773 : _are_reshaped(false), _kernel_width(0), _kernel_height(0), _num_kernels(0)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100774 {
775 }
776 /** Constructor
777 *
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100778 * @param[in] are_reshaped True if the weights have been reshaped
779 * @param[in] kernel_width Kernel width.
780 * @param[in] kernel_height Kernel height.
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100781 * @param[in] num_kernels Number of convolution kernels.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100782 */
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100783 WeightsInfo(bool are_reshaped, unsigned int kernel_width, unsigned int kernel_height, unsigned int num_kernels)
784 : _are_reshaped(are_reshaped), _kernel_width(kernel_width), _kernel_height(kernel_height), _num_kernels(num_kernels)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100785 {
786 }
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100787 /** Flag which specifies if the weights tensor has been reshaped.
788 *
789 * @return True if the weights tensors has been reshaped
790 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100791 bool are_reshaped() const
792 {
793 return _are_reshaped;
794 };
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100795 /** Return the number of convolution kernels
796 *
797 * @return The number of convolution kernels
798 */
799 unsigned int num_kernels() const
800 {
801 return _num_kernels;
802 };
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100803 /** Return the width and height of the kernel
804 *
805 * @return The width and height of the kernel
806 */
807 std::pair<unsigned int, unsigned int> kernel_size() const
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100808 {
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100809 return std::make_pair(_kernel_width, _kernel_height);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100810 }
811
812private:
813 const bool _are_reshaped;
Gian Marco Iodice4e288692017-06-27 11:41:59 +0100814 const unsigned int _kernel_width;
815 const unsigned int _kernel_height;
Gian Marco Iodice559d7712017-08-08 08:38:09 +0100816 const unsigned int _num_kernels;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100817};
818
Chunosov5124be52017-11-22 20:42:13 +0700819/** GEMM Information class. This class stores the necessary information to compute GEMM functions */
820class GEMMInfo
821{
822public:
823 /** Default constructor */
824 GEMMInfo()
825 : _is_a_reshaped(false), _is_b_reshaped(false), _reshape_b_only_on_first_run(false)
826 {
827 }
828 /** Constructor
829 *
830 * @param[in] is_a_reshaped True if the matrix A has been reshaped
831 * @param[in] is_b_reshaped True if the matrix B has been reshaped
832 * @param[in] reshape_b_only_on_first_run Reshape matrix B only for the first run
833 */
834 GEMMInfo(bool is_a_reshaped, bool is_b_reshaped, bool reshape_b_only_on_first_run)
835 : _is_a_reshaped(is_a_reshaped), _is_b_reshaped(is_b_reshaped), _reshape_b_only_on_first_run(reshape_b_only_on_first_run)
836 {
837 }
838 /** Flag which specifies if the matrix A has been reshaped
839 *
840 * @return True if the matrix A has been reshaped
841 */
842 bool is_a_reshaped() const
843 {
844 return _is_a_reshaped;
845 };
846 /** Flag which specifies if the matrix B has been reshaped
847 *
848 * @return True if the matrix B has been reshaped
849 */
850 bool is_b_reshaped() const
851 {
852 return _is_b_reshaped;
853 };
854 /** Flag which specifies if the reshape of matrix B should executed only for the first
855 *
856 * @note This flag could be set to TRUE when GEMM is used to accelerate convolution layer
857 *
858 * @return True if the reshaped of matrix B happens only for the first run
859 */
860 bool reshape_b_only_on_first_run() const
861 {
862 return _reshape_b_only_on_first_run;
863 };
864
865private:
866 const bool _is_a_reshaped;
867 const bool _is_b_reshaped;
868 const bool _reshape_b_only_on_first_run;
869};
870
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100871/** IO formatting information class*/
872struct IOFormatInfo
873{
874 /** Precision type used when printing floating point numbers */
875 enum class PrecisionType
876 {
877 Default, /**< Default precision to the one that the current stream has */
878 Custom, /**< Custom precision specified by the user using the precision parameter */
879 Full /**< The maximum precision of the floating point representation */
880 };
881
882 /** Specifies the area to be printed, used by Tensor objects */
883 enum class PrintRegion
884 {
885 ValidRegion, /**< Prints the valid region of the Tensor object */
886 NoPadding, /**< Prints the Tensor object without the padding */
887 Full /**< Print the tensor object including padding */
888 };
889
890 IOFormatInfo(PrintRegion print_region = PrintRegion::ValidRegion,
891 PrecisionType precision_type = PrecisionType::Default,
892 unsigned int precision = 10,
893 bool align_columns = true,
894 std::string element_delim = " ",
895 std::string row_delim = "\n")
896 : print_region(print_region),
897 precision_type(precision_type),
898 precision(precision),
899 element_delim(element_delim),
900 row_delim(row_delim),
901 align_columns(align_columns)
902 {
903 }
904
905 PrintRegion print_region;
906 PrecisionType precision_type;
907 unsigned int precision;
908 std::string element_delim;
909 std::string row_delim;
910 bool align_columns;
911};
912}
913#endif /* __ARM_COMPUTE_TYPES_H__ */