blob: 3aca1eaaaee26a94d6975ba35f2852e6a98ec412 [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"
29
Georgios Pinitasd4f8c272017-06-30 16:16:19 +010030#include <vector>
31
Anthony Barbier6ff3b192017-09-04 18:44:23 +010032namespace arm_compute
33{
34namespace test
35{
36namespace validation
37{
38/** Interface for reference implementations. */
39class Reference
40{
41public:
Giorgio Arena50f9fd72017-06-19 17:05:30 +010042 /** Compute reference sobel 3x3.
43 *
44 * @param[in] shape Shape of the input and output tensors.
45 * @param[in] border_mode Border mode to use for input tensor
46 * @param[in] constant_border_value Constant value to use if @p border_mode is constant
47 *
48 * @return Computed raw tensors along x and y axis.
49 */
50 static std::pair<RawTensor, RawTensor> compute_reference_sobel_3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value);
51 /** Compute reference sobel 5x5.
52 *
53 * @param[in] shape Shape of the input and output tensors.
54 * @param[in] border_mode Border mode to use for input tensor
55 * @param[in] constant_border_value Constant value to use if @p border_mode is constant
56 *
57 * @return Computed raw tensors along x and y axis.
58 */
59 static std::pair<RawTensor, RawTensor> compute_reference_sobel_5x5(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value);
Giorgio Arenaf7959862017-06-13 15:19:51 +010060 /** Compute reference mean and standard deviation.
61 *
62 * @param[in] shape Shape of the input tensors.
63 *
64 * @return Computed mean and standard deviation.
65 */
66 static std::pair<float, float> compute_reference_mean_and_standard_deviation(const TensorShape &shape);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010067 /** Compute reference integral image.
68 *
69 * @param[in] shape Shape of the input and output tensors.
70 *
71 * @return Computed raw tensor.
72 */
73 static RawTensor compute_reference_integral_image(const TensorShape &shape);
74 /** Compute reference absolute difference.
75 *
76 * @param[in] shape Shape of the input and output tensors.
77 * @param[in] dt_in0 Data type of first input tensor.
78 * @param[in] dt_in1 Data type of second input tensor.
79 * @param[in] dt_out Data type of the output tensor.
80 *
81 * @return Computed raw tensor.
82 */
83 static RawTensor compute_reference_absolute_difference(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out);
84 /** Compute reference accumulate.
85 *
86 * @param[in] shape Shape of the input and output tensors.
87 *
88 * @return Computed raw tensor.
89 */
90 static RawTensor compute_reference_accumulate(const TensorShape &shape);
91 /** Compute reference accumulate.
92 *
93 * @param[in] shape Shape of the input and output tensors.
94 * @param[in] shift A uint32_t value within the range of [0, 15]
95 *
96 * @return Computed raw tensor.
97 */
98 static RawTensor compute_reference_accumulate_squared(const TensorShape &shape, uint32_t shift);
99 /** Compute reference accumulate.
100 *
101 * @param[in] shape Shape of the input and output tensors.
102 * @param[in] alpha A float value within the range of [0, 1]
103 *
104 * @return Computed raw tensor.
105 */
106 static RawTensor compute_reference_accumulate_weighted(const TensorShape &shape, float alpha);
107 /** Compute reference arithmetic addition.
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 * @param[in] convert_policy Overflow policy of the operation.
114 *
115 * @return Computed raw tensor.
116 */
117 static RawTensor compute_reference_arithmetic_addition(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy convert_policy);
118 /** Compute reference arithmetic subtraction.
119 *
120 * @param[in] shape Shape of the input and output tensors.
121 * @param[in] dt_in0 Data type of first input tensor.
122 * @param[in] dt_in1 Data type of second input tensor.
123 * @param[in] dt_out Data type of the output tensor.
124 * @param[in] convert_policy Overflow policy of the operation.
125 *
126 * @return Computed raw tensor.
127 */
128 static RawTensor compute_reference_arithmetic_subtraction(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy convert_policy);
129 /** Compute reference bitwise and.
130 *
131 * @param[in] shape Shape of the input and output tensors.
132 *
133 * @return Computed raw tensor.
134 */
135 static RawTensor compute_reference_bitwise_and(const TensorShape &shape);
136 /** Compute reference bitwise or.
137 *
138 * @param[in] shape Shape of the input and output tensors.
139 *
140 * @return Computed raw tensor.
141 */
142 static RawTensor compute_reference_bitwise_or(const TensorShape &shape);
143 /** Compute reference bitwise xor.
144 *
145 * @param[in] shape Shape of the input and output tensors.
146 *
147 * @return Computed raw tensor.
148 */
149 static RawTensor compute_reference_bitwise_xor(const TensorShape &shape);
150 /** Compute reference bitwise not.
151 *
152 * @param[in] shape Shape of the input and output tensors.
153 *
154 * @return Computed raw tensor.
155 */
156 static RawTensor compute_reference_bitwise_not(const TensorShape &shape);
SiCong Libacaf9a2017-06-19 13:41:45 +0100157 /** Compute reference box3x3 filter.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100158 *
SiCong Libacaf9a2017-06-19 13:41:45 +0100159 * @param[in] shape Shape of the input and output tensors.
160 * @param[in] border_mode BorderMode used by the input tensor.
161 * @param[in] constant_border_value Constant to use if @p border_mode == CONSTANT.
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100162 *
163 * @return Computed raw tensor.
164 */
SiCong Libacaf9a2017-06-19 13:41:45 +0100165 static RawTensor compute_reference_box3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100166 /** Compute reference depth convert.
167 *
168 * @param[in] shape Shape of the input and output tensors.
169 * @param[in] dt_in Data type of input tensor.
170 * @param[in] dt_out Data type of the output tensor.
171 * @param[in] policy Overflow policy of the operation.
172 * @param[in] shift Value for down/up conversions. Must be 0 <= shift < 8.
173 * @param[in] fixed_point_position Fixed point position.
174 *
175 * @return Computed raw tensor.
176 */
177 static RawTensor compute_reference_depth_convert(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift, uint32_t fixed_point_position);
SiCong Li5a536642017-06-19 14:47:05 +0100178 /** Compute reference gaussian3x3 filter.
179 *
180 * @param[in] shape Shape of the input and output tensors.
181 * @param[in] border_mode BorderMode used by the input tensor
182 * @param[in] constant_border_value Constant to use if @p border_mode == CONSTANT
183 *
184 * @return Computed raw tensor.
185 */
186 static RawTensor compute_reference_gaussian3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value);
SiCong Li3eb263e2017-06-19 15:31:43 +0100187 /** Compute reference gaussian5x5 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_gaussian5x5(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100196 /** Compute matrix multiply function.
197 *
198 * @param[in] src_shape1 First input tensor shape
199 * @param[in] src_shape2 Second input tensor shape
200 * @param[in] src_shape3 Third input tensor shape
201 * @param[out] dst_shape Output tensor.
202 * @param[in] alpha Weight of the matrix product
203 * @param[in] beta Weight of the third matrix
204 * @param[in] dt Tensor's data type
205 * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers
206 *
207 * @return Computed output tensor.
208 */
209 static RawTensor compute_reference_gemm(const TensorShape &src_shape1, const TensorShape &src_shape2, const TensorShape &src_shape3,
210 const TensorShape &dst_shape, float alpha, float beta, DataType dt, int fixed_point_position = 0);
Isabella Gottardi3b77e9d2017-06-22 11:05:41 +0100211 /** Compute reference non linear filter function
212 *
213 * @param[in] shape Shape of the input and output tensors.Data type supported: U8
214 * @param[in] function Non linear function to perform
215 * @param[in] mask_size Mask size. Supported sizes: 3, 5
216 * @param[in] pattern Matrix pattern
217 * @param[in] mask The given mask. Will be used only if pattern is specified to PATTERN_OTHER
218 * @param[in] border_mode Strategy to use for borders.
219 * @param[in] constant_border_value (Optional) Constant value to use for borders if border_mode is set to CONSTANT.
220 *
221 * @return Computed raw tensor.
222 */
223 static RawTensor compute_reference_non_linear_filter(const TensorShape &shape, NonLinearFilterFunction function, unsigned int mask_size,
224 MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, uint8_t constant_border_value = 0);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100225 /** Compute reference pixel-wise multiplication
226 *
227 * @param[in] shape Shape of the input and output tensors.
228 * @param[in] dt_in0 Data type of first input tensor.
229 * @param[in] dt_in1 Data type of second input tensor.
230 * @param[in] dt_out Data type of the output tensor.
231 * @param[in] scale Non-negative scale.
232 * @param[in] convert_policy Overflow policy of the operation.
233 * @param[in] rounding_policy Rounding policy of the operation.
234 *
235 * @return Computed raw tensor.
236 */
237 static RawTensor compute_reference_pixel_wise_multiplication(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, float scale, ConvertPolicy convert_policy,
238 RoundingPolicy rounding_policy);
239 /** Compute reference pixel-wise multiplication.
240 *
241 * @param[in] shape Shape of the input and output tensors.
242 * @param[in] dt_in0 Data type of first input tensor.
243 * @param[in] dt_in1 Data type of second input tensor.
244 * @param[in] dt_out Data type of the output tensor.
245 * @param[in] scale Scale to apply after multiplication. Must be positive.
246 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number.
247 * @param[in] convert_policy Overflow policy of the operation.
248 * @param[in] rounding_policy Rounding policy of the operation.
249 *
250 * @return Computed raw tensor.
251 */
252 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,
253 ConvertPolicy convert_policy, RoundingPolicy rounding_policy);
254 /** Compute reference threshold.
255 *
256 * @param[in] shape Shape of the input and output tensors.
257 * @param[in] threshold Threshold. When the threshold type is RANGE, this is used as the lower threshold.
258 * @param[in] false_value value to set when the condition is not respected.
259 * @param[in] true_value value to set when the condition is respected.
260 * @param[in] type Thresholding type. Either RANGE or BINARY.
261 * @param[in] upper Upper threshold. Only used when the thresholding type is RANGE.
262 *
263 * @return Computed raw tensor.
264 */
265 static RawTensor compute_reference_threshold(const TensorShape &shape, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper);
266 /** Compute reference activation layer.
267 *
268 * @param[in] shape Shape of the input and output tensors.
269 * @param[in] dt Data type of the tensors.
270 * @param[in] act_info Activation layer information.
271 * @param[in] fixed_point_position (Optional)Number of bits for the fractional part of fixed point numbers.
272 *
273 * @return Computed raw tensor.
274 */
275 static RawTensor compute_reference_activation_layer(const TensorShape &shape, DataType dt, ActivationLayerInfo act_info, int fixed_point_position = 0);
276 /** Compute reference batch normalization layer.
277 *
278 * @param[in] shape0 Shape of the input and output tensors.
279 * @param[in] shape1 Shape of the vector tensors.
280 * @param[in] dt Data type of all input and output tensors.
281 * @param[in] epsilon Small value to avoid division with zero.
282 * @param[in] fixed_point_position Fixed point position.
283 *
284 * @return Computed raw tensor.
285 */
286 static RawTensor compute_reference_batch_normalization_layer(const TensorShape &shape0, const TensorShape &shape1, DataType dt, float epsilon, int fixed_point_position = 0);
287 /** Compute reference pixel-wise multiplication
288 *
289 * @param[in] input_shape Shape for the input tensor
290 * @param[in] weights_shape Shape for the weights tensor
291 * @param[in] bias_shape Shape for the bias tensor
292 * @param[in] output_shape Shape for the output tensor
293 * @param[in] dt Data type to use
294 * @param[in] conv_info Pads and strides information for the convolution layer
295 * @param[in] fixed_point_position Number of bits for the fractional part of the fixed point numbers
296 *
297 * @return Computed raw tensor.
298 */
299 static RawTensor compute_reference_convolution_layer(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, DataType dt,
300 const PadStrideInfo &conv_info, int fixed_point_position);
301 /** Compute reference for fully connected layer function
302 *
303 * @param[in] input_shape Shape for the input tensor
304 * @param[in] weights_shape Shape for the weights tensor
305 * @param[in] bias_shape Shape for the bias tensor
306 * @param[in] output_shape Shape for the output tensor
307 * @param[in] dt Data type to use
308 * @param[in] transpose_weights Transpose the weights if true
309 * @param[in] fixed_point_position Number of bits for the fractional part of the fixed point numbers
310 *
311 * @return Computed raw tensor.
312 */
313 static RawTensor compute_reference_fully_connected_layer(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, DataType dt,
314 bool transpose_weights, int fixed_point_position);
315 /** Compute reference normalization layer.
316 *
317 * @param[in] shape Shape of the input and output tensors.
318 * @param[in] dt Data type of input and output tensors.
319 * @param[in] norm_info Normalization Layer information.
320 * @param[in] fixed_point_position (Optional) Fixed point position that expresses the number of bits for the fractional part of the number when the tensor's data type is QS8 or QS16 (default = 0).
321 *
322 * @return Computed raw tensor.
323 */
324 static RawTensor compute_reference_normalization_layer(const TensorShape &shape, DataType dt, NormalizationLayerInfo norm_info, int fixed_point_position = 0);
325 /** Compute reference pooling layer.
326 *
327 * @param[in] shape_in Shape of the input tensor.
328 * @param[in] shape_out Shape of the output tensor.
329 * @param[in] dt Data type of input and output tensors.
330 * @param[in] pool_info Pooling Layer information.
331 * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers.
332 *
333 * @return Computed raw tensor.
334 */
335 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 +0100336 /** Compute reference roi pooling layer.
337 *
338 * @param[in] shape Shape of the input tensor.
339 * @param[in] dt Data type of input and output tensors.
340 * @param[in] rois Region of interest vector.
341 * @param[in] pool_info ROI Pooling Layer information.
342 */
343 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 +0100344 /** Compute reference softmax layer.
345 *
346 * @param[in] shape Shape of the input and output tensors.
347 * @param[in] dt Data type of input and output tensors.
348 * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers
349 *
350 * @return Computed raw tensor.
351 */
352 static RawTensor compute_reference_softmax_layer(const TensorShape &shape, DataType dt, int fixed_point_position = 0);
353 /** Compute reference fixed point operation.
354 *
355 * @param[in] shape Shape of the input and output tensors.
356 * @param[in] dt_in Data type of the input tensor.
357 * @param[in] dt_out Data type of the output tensor.
358 * @param[in] op Fixed point operation to perform.
359 * @param[in] fixed_point_position Number of bits for the fractional part of the fixed point numbers
360 *
361 * @return Computed raw tensor.
362 */
363 static RawTensor compute_reference_fixed_point_operation(const TensorShape &shape, DataType dt_in, DataType dt_out, FixedPointOp op, int fixed_point_position);
364
365protected:
366 Reference() = default;
367 ~Reference() = default;
368};
369} // namespace validation
370} // namespace test
371} // namespace arm_compute
372#endif