blob: 288dc0e3f7ca93485a718bd5088850b6ae81d600 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 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_TEST_REFERENCE_REFERENCE_H__
25#define __ARM_COMPUTE_TEST_REFERENCE_REFERENCE_H__
26
27#include "RawTensor.h"
28#include "Types.h"
Giorgio Arena2ca209e2017-06-13 15:49:37 +010029#include "arm_compute/runtime/Array.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030
Isabella Gottardib797fa22017-06-23 15:02:11 +010031#include <map>
Georgios Pinitasd4f8c272017-06-30 16:16:19 +010032#include <vector>
33
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034namespace arm_compute
35{
36namespace test
37{
38namespace validation
39{
40/** Interface for reference implementations. */
41class Reference
42{
43public:
Giorgio Arena50f9fd72017-06-19 17:05:30 +010044 /** Compute reference sobel 3x3.
45 *
46 * @param[in] shape Shape of the input and output tensors.
47 * @param[in] border_mode Border mode to use for input tensor
48 * @param[in] constant_border_value Constant value to use if @p border_mode is constant
49 *
50 * @return Computed raw tensors along x and y axis.
51 */
52 static std::pair<RawTensor, RawTensor> compute_reference_sobel_3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value);
53 /** Compute reference sobel 5x5.
54 *
55 * @param[in] shape Shape of the input and output tensors.
56 * @param[in] border_mode Border mode to use for input tensor
57 * @param[in] constant_border_value Constant value to use if @p border_mode is constant
58 *
59 * @return Computed raw tensors along x and y axis.
60 */
61 static std::pair<RawTensor, RawTensor> compute_reference_sobel_5x5(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value);
Giorgio Arenafc2817d2017-06-27 17:26:37 +010062 /** Compute reference Harris corners.
63 *
64 * @param[in] shape Shape of input tensor
65 * @param[in] threshold Minimum threshold with which to eliminate Harris Corner scores (computed using the normalized Sobel kernel).
66 * @param[in] min_dist Radial Euclidean distance for the euclidean distance stage
67 * @param[in] sensitivity Sensitivity threshold k from the Harris-Stephens equation
68 * @param[in] gradient_size The gradient window size to use on the input. The implementation supports 3, 5, and 7
69 * @param[in] block_size The block window size used to compute the Harris Corner score. The implementation supports 3, 5, and 7.
70 * @param[in] border_mode Border mode to use
71 * @param[in] constant_border_value Constant value to use for borders if border_mode is set to CONSTANT.
72 *
73 * @return Computed corners' keypoints.
74 */
75 static KeyPointArray compute_reference_harris_corners(const TensorShape &shape, float threshold, float min_dist, float sensitivity,
76 int32_t gradient_size, int32_t block_size, BorderMode border_mode, uint8_t constant_border_value);
Giorgio Arena2ca209e2017-06-13 15:49:37 +010077 /** Compute min max location.
78 *
79 * @param[in] shape Shape of the input tensors.
80 * @param[in] dt_in Data type of input tensor.
81 * @param[out] min Minimum value of tensor
82 * @param[out] max Maximum value of tensor
83 * @param[out] min_loc Array with locations of minimum values
84 * @param[out] max_loc Array with locations of maximum values
85 * @param[out] min_count Number of minimum values found
86 * @param[out] max_count Number of maximum values found
87 *
88 * @return Computed minimum, maximum values and their locations.
89 */
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010090 static void compute_reference_min_max_location(const TensorShape &shape, DataType dt_in, void *min, void *max, IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &max_loc,
Giorgio Arena935deee2017-06-14 13:40:36 +010091 uint32_t &min_count,
Giorgio Arena2ca209e2017-06-13 15:49:37 +010092 uint32_t &max_count);
Giorgio Arenaf7959862017-06-13 15:19:51 +010093 /** Compute reference mean and standard deviation.
94 *
95 * @param[in] shape Shape of the input tensors.
96 *
97 * @return Computed mean and standard deviation.
98 */
99 static std::pair<float, float> compute_reference_mean_and_standard_deviation(const TensorShape &shape);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100 /** Compute reference integral image.
101 *
102 * @param[in] shape Shape of the input and output tensors.
103 *
104 * @return Computed raw tensor.
105 */
106 static RawTensor compute_reference_integral_image(const TensorShape &shape);
107 /** Compute reference absolute difference.
108 *
109 * @param[in] shape Shape of the input and output tensors.
110 * @param[in] dt_in0 Data type of first input tensor.
111 * @param[in] dt_in1 Data type of second input tensor.
112 * @param[in] dt_out Data type of the output tensor.
113 *
114 * @return Computed raw tensor.
115 */
116 static RawTensor compute_reference_absolute_difference(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out);
117 /** Compute reference accumulate.
118 *
119 * @param[in] shape Shape of the input and output tensors.
120 *
121 * @return Computed raw tensor.
122 */
123 static RawTensor compute_reference_accumulate(const TensorShape &shape);
124 /** Compute reference accumulate.
125 *
126 * @param[in] shape Shape of the input and output tensors.
127 * @param[in] shift A uint32_t value within the range of [0, 15]
128 *
129 * @return Computed raw tensor.
130 */
131 static RawTensor compute_reference_accumulate_squared(const TensorShape &shape, uint32_t shift);
132 /** Compute reference accumulate.
133 *
134 * @param[in] shape Shape of the input and output tensors.
135 * @param[in] alpha A float value within the range of [0, 1]
136 *
137 * @return Computed raw tensor.
138 */
139 static RawTensor compute_reference_accumulate_weighted(const TensorShape &shape, float alpha);
140 /** Compute reference arithmetic addition.
141 *
Michele Di Giorgio81f0d152017-07-11 15:00:52 +0100142 * @param[in] shape Shape of the input and output tensors.
143 * @param[in] dt_in0 Data type of first input tensor.
144 * @param[in] dt_in1 Data type of second input tensor.
145 * @param[in] dt_out Data type of the output tensor.
146 * @param[in] convert_policy Overflow policy of the operation.
147 * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100148 *
149 * @return Computed raw tensor.
150 */
Michele Di Giorgio81f0d152017-07-11 15:00:52 +0100151 static RawTensor compute_reference_arithmetic_addition(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy convert_policy, int fixed_point_position = 0);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100152 /** Compute reference arithmetic subtraction.
153 *
Michele Di Giorgio81f0d152017-07-11 15:00:52 +0100154 * @param[in] shape Shape of the input and output tensors.
155 * @param[in] dt_in0 Data type of first input tensor.
156 * @param[in] dt_in1 Data type of second input tensor.
157 * @param[in] dt_out Data type of the output tensor.
158 * @param[in] convert_policy Overflow policy of the operation.
159 * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100160 *
161 * @return Computed raw tensor.
162 */
Michele Di Giorgio81f0d152017-07-11 15:00:52 +0100163 static RawTensor compute_reference_arithmetic_subtraction(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy convert_policy, int fixed_point_position = 0);
SiCong Libacaf9a2017-06-19 13:41:45 +0100164 /** Compute reference box3x3 filter.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100165 *
SiCong Libacaf9a2017-06-19 13:41:45 +0100166 * @param[in] shape Shape of the input and output tensors.
167 * @param[in] border_mode BorderMode used by the input tensor.
168 * @param[in] constant_border_value Constant to use if @p border_mode == CONSTANT.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100169 *
170 * @return Computed raw tensor.
171 */
SiCong Libacaf9a2017-06-19 13:41:45 +0100172 static RawTensor compute_reference_box3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100173 /** Compute reference depth convert.
174 *
Georgios Pinitase2229412017-07-12 12:30:40 +0100175 * @param[in] shape Shape of the input and output tensors.
176 * @param[in] dt_in Data type of input tensor.
177 * @param[in] dt_out Data type of the output tensor.
178 * @param[in] policy Overflow policy of the operation.
179 * @param[in] shift Value for down/up conversions. Must be 0 <= shift < 8.
180 * @param[in] fixed_point_position_in (Optional) Fixed point position for the input tensor.
181 * @param[in] fixed_point_position_out (Optional) Fixed point position for the output tensor.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100182 *
183 * @return Computed raw tensor.
184 */
Georgios Pinitase2229412017-07-12 12:30:40 +0100185 static RawTensor compute_reference_depth_convert(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy,
186 uint32_t shift, uint32_t fixed_point_position_in = 0, uint32_t fixed_point_position_out = 0);
SiCong Li5a536642017-06-19 14:47:05 +0100187 /** Compute reference gaussian3x3 filter.
188 *
189 * @param[in] shape Shape of the input and output tensors.
190 * @param[in] border_mode BorderMode used by the input tensor
191 * @param[in] constant_border_value Constant to use if @p border_mode == CONSTANT
192 *
193 * @return Computed raw tensor.
194 */
195 static RawTensor compute_reference_gaussian3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value);
SiCong Li3eb263e2017-06-19 15:31:43 +0100196 /** Compute reference gaussian5x5 filter.
197 *
198 * @param[in] shape Shape of the input and output tensors.
199 * @param[in] border_mode BorderMode used by the input tensor.
200 * @param[in] constant_border_value Constant to use if @p border_mode == CONSTANT.
201 *
202 * @return Computed raw tensor.
203 */
204 static RawTensor compute_reference_gaussian5x5(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value);
Isabella Gottardi3b77e9d2017-06-22 11:05:41 +0100205 /** Compute reference non linear filter function
206 *
207 * @param[in] shape Shape of the input and output tensors.Data type supported: U8
208 * @param[in] function Non linear function to perform
209 * @param[in] mask_size Mask size. Supported sizes: 3, 5
210 * @param[in] pattern Matrix pattern
211 * @param[in] mask The given mask. Will be used only if pattern is specified to PATTERN_OTHER
212 * @param[in] border_mode Strategy to use for borders.
213 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT.
214 *
215 * @return Computed raw tensor.
216 */
217 static RawTensor compute_reference_non_linear_filter(const TensorShape &shape, NonLinearFilterFunction function, unsigned int mask_size,
218 MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, uint8_t constant_border_value = 0);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100219 /** Compute reference pixel-wise multiplication
220 *
221 * @param[in] shape Shape of the input and output tensors.
222 * @param[in] dt_in0 Data type of first input tensor.
223 * @param[in] dt_in1 Data type of second input tensor.
224 * @param[in] dt_out Data type of the output tensor.
225 * @param[in] scale Non-negative scale.
226 * @param[in] convert_policy Overflow policy of the operation.
227 * @param[in] rounding_policy Rounding policy of the operation.
228 *
229 * @return Computed raw tensor.
230 */
231 static RawTensor compute_reference_pixel_wise_multiplication(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, float scale, ConvertPolicy convert_policy,
232 RoundingPolicy rounding_policy);
233 /** Compute reference pixel-wise multiplication.
234 *
235 * @param[in] shape Shape of the input and output tensors.
236 * @param[in] dt_in0 Data type of first input tensor.
237 * @param[in] dt_in1 Data type of second input tensor.
238 * @param[in] dt_out Data type of the output tensor.
239 * @param[in] scale Scale to apply after multiplication. Must be positive.
240 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number.
241 * @param[in] convert_policy Overflow policy of the operation.
242 * @param[in] rounding_policy Rounding policy of the operation.
243 *
244 * @return Computed raw tensor.
245 */
246 static RawTensor compute_reference_fixed_point_pixel_wise_multiplication(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, float scale, int fixed_point_position,
247 ConvertPolicy convert_policy, RoundingPolicy rounding_policy);
Isabella Gottardib797fa22017-06-23 15:02:11 +0100248 /** Compute reference Table Lookup.
249 *
250 * @param[in] shape Shape of the input and output tensors.
251 * @param[in] dt_inout Data type of input/output tensor.
252 * @param[in] lut Input lookup table.
253 *
254 * @return Computed raw tensor.
255 */
256 template <typename T>
257 static RawTensor compute_reference_table_lookup(const TensorShape &shape, DataType dt_inout, std::map<T, T> &lut);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100258 /** Compute reference threshold.
259 *
260 * @param[in] shape Shape of the input and output tensors.
261 * @param[in] threshold Threshold. When the threshold type is RANGE, this is used as the lower threshold.
262 * @param[in] false_value value to set when the condition is not respected.
263 * @param[in] true_value value to set when the condition is respected.
264 * @param[in] type Thresholding type. Either RANGE or BINARY.
265 * @param[in] upper Upper threshold. Only used when the thresholding type is RANGE.
266 *
267 * @return Computed raw tensor.
268 */
269 static RawTensor compute_reference_threshold(const TensorShape &shape, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper);
Isabella Gottardi62031532017-07-04 11:21:28 +0100270
271 /** Compute reference Warp Perspective.
272 *
273 * @param[in] shape Shape of the input and output tensors.
274 * @param[out] valid_mask Valid mask tensor.
275 * @param[in] matrix The perspective matrix. Must be 3x3 of type float.
276 * @param[in] policy The interpolation type.
277 * @param[in] border_mode Strategy to use for borders.
278 * @param[in] constant_border_value Constant value to use for borders if border_mode is set to CONSTANT.
279 *
280 * @return Computed raw tensor.
281 */
282 static RawTensor compute_reference_warp_perspective(const TensorShape &shape, RawTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode,
283 uint8_t constant_border_value);
284
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100285 /** Compute reference batch normalization layer.
286 *
287 * @param[in] shape0 Shape of the input and output tensors.
288 * @param[in] shape1 Shape of the vector tensors.
289 * @param[in] dt Data type of all input and output tensors.
290 * @param[in] epsilon Small value to avoid division with zero.
291 * @param[in] fixed_point_position Fixed point position.
292 *
293 * @return Computed raw tensor.
294 */
295 static RawTensor compute_reference_batch_normalization_layer(const TensorShape &shape0, const TensorShape &shape1, DataType dt, float epsilon, int fixed_point_position = 0);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100296 /** Compute reference pooling layer.
297 *
298 * @param[in] shape_in Shape of the input tensor.
299 * @param[in] shape_out Shape of the output tensor.
300 * @param[in] dt Data type of input and output tensors.
301 * @param[in] pool_info Pooling Layer information.
302 * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers.
303 *
304 * @return Computed raw tensor.
305 */
306 static RawTensor compute_reference_pooling_layer(const TensorShape &shape_in, const TensorShape &shape_out, DataType dt, PoolingLayerInfo pool_info, int fixed_point_position = 0);
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100307 /** Compute reference roi pooling layer.
308 *
309 * @param[in] shape Shape of the input tensor.
310 * @param[in] dt Data type of input and output tensors.
311 * @param[in] rois Region of interest vector.
312 * @param[in] pool_info ROI Pooling Layer information.
313 */
314 static RawTensor compute_reference_roi_pooling_layer(const TensorShape &shape, DataType dt, const std::vector<ROI> &rois, const ROIPoolingLayerInfo &pool_info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100315 /** Compute reference fixed point operation.
316 *
317 * @param[in] shape Shape of the input and output tensors.
318 * @param[in] dt_in Data type of the input tensor.
319 * @param[in] dt_out Data type of the output tensor.
320 * @param[in] op Fixed point operation to perform.
321 * @param[in] fixed_point_position Number of bits for the fractional part of the fixed point numbers
322 *
323 * @return Computed raw tensor.
324 */
325 static RawTensor compute_reference_fixed_point_operation(const TensorShape &shape, DataType dt_in, DataType dt_out, FixedPointOp op, int fixed_point_position);
326
327protected:
328 Reference() = default;
329 ~Reference() = default;
330};
331} // namespace validation
332} // namespace test
333} // namespace arm_compute
Anthony Barbierac69aa12017-07-03 17:39:37 +0100334#endif /* __ARM_COMPUTE_TEST_REFERENCE_REFERENCE_H__ */