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