blob: 06a38c41f2087a1102a39a7c0b32b91806dc9de4 [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 Arenaf7959862017-06-13 15:19:51 +010040 /** Compute reference mean and standard deviation.
41 *
42 * @param[in] shape Shape of the input tensors.
43 *
44 * @return Computed mean and standard deviation.
45 */
46 static std::pair<float, float> compute_reference_mean_and_standard_deviation(const TensorShape &shape);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010047 /** Compute reference integral image.
48 *
49 * @param[in] shape Shape of the input and output tensors.
50 *
51 * @return Computed raw tensor.
52 */
53 static RawTensor compute_reference_integral_image(const TensorShape &shape);
54 /** Compute reference absolute difference.
55 *
56 * @param[in] shape Shape of the input and output tensors.
57 * @param[in] dt_in0 Data type of first input tensor.
58 * @param[in] dt_in1 Data type of second input tensor.
59 * @param[in] dt_out Data type of the output tensor.
60 *
61 * @return Computed raw tensor.
62 */
63 static RawTensor compute_reference_absolute_difference(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out);
64 /** Compute reference accumulate.
65 *
66 * @param[in] shape Shape of the input and output tensors.
67 *
68 * @return Computed raw tensor.
69 */
70 static RawTensor compute_reference_accumulate(const TensorShape &shape);
71 /** Compute reference accumulate.
72 *
73 * @param[in] shape Shape of the input and output tensors.
74 * @param[in] shift A uint32_t value within the range of [0, 15]
75 *
76 * @return Computed raw tensor.
77 */
78 static RawTensor compute_reference_accumulate_squared(const TensorShape &shape, uint32_t shift);
79 /** Compute reference accumulate.
80 *
81 * @param[in] shape Shape of the input and output tensors.
82 * @param[in] alpha A float value within the range of [0, 1]
83 *
84 * @return Computed raw tensor.
85 */
86 static RawTensor compute_reference_accumulate_weighted(const TensorShape &shape, float alpha);
87 /** Compute reference arithmetic addition.
88 *
89 * @param[in] shape Shape of the input and output tensors.
90 * @param[in] dt_in0 Data type of first input tensor.
91 * @param[in] dt_in1 Data type of second input tensor.
92 * @param[in] dt_out Data type of the output tensor.
93 * @param[in] convert_policy Overflow policy of the operation.
94 *
95 * @return Computed raw tensor.
96 */
97 static RawTensor compute_reference_arithmetic_addition(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy convert_policy);
98 /** Compute reference arithmetic subtraction.
99 *
100 * @param[in] shape Shape of the input and output tensors.
101 * @param[in] dt_in0 Data type of first input tensor.
102 * @param[in] dt_in1 Data type of second input tensor.
103 * @param[in] dt_out Data type of the output tensor.
104 * @param[in] convert_policy Overflow policy of the operation.
105 *
106 * @return Computed raw tensor.
107 */
108 static RawTensor compute_reference_arithmetic_subtraction(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy convert_policy);
109 /** Compute reference bitwise and.
110 *
111 * @param[in] shape Shape of the input and output tensors.
112 *
113 * @return Computed raw tensor.
114 */
115 static RawTensor compute_reference_bitwise_and(const TensorShape &shape);
116 /** Compute reference bitwise or.
117 *
118 * @param[in] shape Shape of the input and output tensors.
119 *
120 * @return Computed raw tensor.
121 */
122 static RawTensor compute_reference_bitwise_or(const TensorShape &shape);
123 /** Compute reference bitwise xor.
124 *
125 * @param[in] shape Shape of the input and output tensors.
126 *
127 * @return Computed raw tensor.
128 */
129 static RawTensor compute_reference_bitwise_xor(const TensorShape &shape);
130 /** Compute reference bitwise not.
131 *
132 * @param[in] shape Shape of the input and output tensors.
133 *
134 * @return Computed raw tensor.
135 */
136 static RawTensor compute_reference_bitwise_not(const TensorShape &shape);
137 /** Compute reference 3-by-3 box filter.
138 *
139 * @param[in] shape Shape of the input and output tensors.
140 *
141 * @return Computed raw tensor.
142 */
143 static RawTensor compute_reference_box3x3(const TensorShape &shape);
144 /** Compute reference depth convert.
145 *
146 * @param[in] shape Shape of the input and output tensors.
147 * @param[in] dt_in Data type of input tensor.
148 * @param[in] dt_out Data type of the output tensor.
149 * @param[in] policy Overflow policy of the operation.
150 * @param[in] shift Value for down/up conversions. Must be 0 <= shift < 8.
151 * @param[in] fixed_point_position Fixed point position.
152 *
153 * @return Computed raw tensor.
154 */
155 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);
156 /** Compute matrix multiply function.
157 *
158 * @param[in] src_shape1 First input tensor shape
159 * @param[in] src_shape2 Second input tensor shape
160 * @param[in] src_shape3 Third input tensor shape
161 * @param[out] dst_shape Output tensor.
162 * @param[in] alpha Weight of the matrix product
163 * @param[in] beta Weight of the third matrix
164 * @param[in] dt Tensor's data type
165 * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers
166 *
167 * @return Computed output tensor.
168 */
169 static RawTensor compute_reference_gemm(const TensorShape &src_shape1, const TensorShape &src_shape2, const TensorShape &src_shape3,
170 const TensorShape &dst_shape, float alpha, float beta, DataType dt, int fixed_point_position = 0);
171 /** Compute reference pixel-wise multiplication
172 *
173 * @param[in] shape Shape of the input and output tensors.
174 * @param[in] dt_in0 Data type of first input tensor.
175 * @param[in] dt_in1 Data type of second input tensor.
176 * @param[in] dt_out Data type of the output tensor.
177 * @param[in] scale Non-negative scale.
178 * @param[in] convert_policy Overflow policy of the operation.
179 * @param[in] rounding_policy Rounding policy of the operation.
180 *
181 * @return Computed raw tensor.
182 */
183 static RawTensor compute_reference_pixel_wise_multiplication(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, float scale, ConvertPolicy convert_policy,
184 RoundingPolicy rounding_policy);
185 /** Compute reference pixel-wise multiplication.
186 *
187 * @param[in] shape Shape of the input and output tensors.
188 * @param[in] dt_in0 Data type of first input tensor.
189 * @param[in] dt_in1 Data type of second input tensor.
190 * @param[in] dt_out Data type of the output tensor.
191 * @param[in] scale Scale to apply after multiplication. Must be positive.
192 * @param[in] fixed_point_position Fixed point position that expresses the number of bits for the fractional part of the number.
193 * @param[in] convert_policy Overflow policy of the operation.
194 * @param[in] rounding_policy Rounding policy of the operation.
195 *
196 * @return Computed raw tensor.
197 */
198 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,
199 ConvertPolicy convert_policy, RoundingPolicy rounding_policy);
200 /** Compute reference threshold.
201 *
202 * @param[in] shape Shape of the input and output tensors.
203 * @param[in] threshold Threshold. When the threshold type is RANGE, this is used as the lower threshold.
204 * @param[in] false_value value to set when the condition is not respected.
205 * @param[in] true_value value to set when the condition is respected.
206 * @param[in] type Thresholding type. Either RANGE or BINARY.
207 * @param[in] upper Upper threshold. Only used when the thresholding type is RANGE.
208 *
209 * @return Computed raw tensor.
210 */
211 static RawTensor compute_reference_threshold(const TensorShape &shape, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper);
212 /** Compute reference activation layer.
213 *
214 * @param[in] shape Shape of the input and output tensors.
215 * @param[in] dt Data type of the tensors.
216 * @param[in] act_info Activation layer information.
217 * @param[in] fixed_point_position (Optional)Number of bits for the fractional part of fixed point numbers.
218 *
219 * @return Computed raw tensor.
220 */
221 static RawTensor compute_reference_activation_layer(const TensorShape &shape, DataType dt, ActivationLayerInfo act_info, int fixed_point_position = 0);
222 /** Compute reference batch normalization layer.
223 *
224 * @param[in] shape0 Shape of the input and output tensors.
225 * @param[in] shape1 Shape of the vector tensors.
226 * @param[in] dt Data type of all input and output tensors.
227 * @param[in] epsilon Small value to avoid division with zero.
228 * @param[in] fixed_point_position Fixed point position.
229 *
230 * @return Computed raw tensor.
231 */
232 static RawTensor compute_reference_batch_normalization_layer(const TensorShape &shape0, const TensorShape &shape1, DataType dt, float epsilon, int fixed_point_position = 0);
233 /** Compute reference pixel-wise multiplication
234 *
235 * @param[in] input_shape Shape for the input tensor
236 * @param[in] weights_shape Shape for the weights tensor
237 * @param[in] bias_shape Shape for the bias tensor
238 * @param[in] output_shape Shape for the output tensor
239 * @param[in] dt Data type to use
240 * @param[in] conv_info Pads and strides information for the convolution layer
241 * @param[in] fixed_point_position Number of bits for the fractional part of the fixed point numbers
242 *
243 * @return Computed raw tensor.
244 */
245 static RawTensor compute_reference_convolution_layer(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, DataType dt,
246 const PadStrideInfo &conv_info, int fixed_point_position);
247 /** Compute reference for fully connected layer function
248 *
249 * @param[in] input_shape Shape for the input tensor
250 * @param[in] weights_shape Shape for the weights tensor
251 * @param[in] bias_shape Shape for the bias tensor
252 * @param[in] output_shape Shape for the output tensor
253 * @param[in] dt Data type to use
254 * @param[in] transpose_weights Transpose the weights if true
255 * @param[in] fixed_point_position Number of bits for the fractional part of the fixed point numbers
256 *
257 * @return Computed raw tensor.
258 */
259 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,
260 bool transpose_weights, int fixed_point_position);
261 /** Compute reference normalization layer.
262 *
263 * @param[in] shape Shape of the input and output tensors.
264 * @param[in] dt Data type of input and output tensors.
265 * @param[in] norm_info Normalization Layer information.
266 * @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).
267 *
268 * @return Computed raw tensor.
269 */
270 static RawTensor compute_reference_normalization_layer(const TensorShape &shape, DataType dt, NormalizationLayerInfo norm_info, int fixed_point_position = 0);
271 /** Compute reference pooling layer.
272 *
273 * @param[in] shape_in Shape of the input tensor.
274 * @param[in] shape_out Shape of the output tensor.
275 * @param[in] dt Data type of input and output tensors.
276 * @param[in] pool_info Pooling Layer information.
277 * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers.
278 *
279 * @return Computed raw tensor.
280 */
281 static RawTensor compute_reference_pooling_layer(const TensorShape &shape_in, const TensorShape &shape_out, DataType dt, PoolingLayerInfo pool_info, int fixed_point_position = 0);
282 /** Compute reference softmax layer.
283 *
284 * @param[in] shape Shape of the input and output tensors.
285 * @param[in] dt Data type of input and output tensors.
286 * @param[in] fixed_point_position (Optional) Number of bits for the fractional part of the fixed point numbers
287 *
288 * @return Computed raw tensor.
289 */
290 static RawTensor compute_reference_softmax_layer(const TensorShape &shape, DataType dt, int fixed_point_position = 0);
291 /** Compute reference fixed point operation.
292 *
293 * @param[in] shape Shape of the input and output tensors.
294 * @param[in] dt_in Data type of the input tensor.
295 * @param[in] dt_out Data type of the output tensor.
296 * @param[in] op Fixed point operation to perform.
297 * @param[in] fixed_point_position Number of bits for the fractional part of the fixed point numbers
298 *
299 * @return Computed raw tensor.
300 */
301 static RawTensor compute_reference_fixed_point_operation(const TensorShape &shape, DataType dt_in, DataType dt_out, FixedPointOp op, int fixed_point_position);
302
303protected:
304 Reference() = default;
305 ~Reference() = default;
306};
307} // namespace validation
308} // namespace test
309} // namespace arm_compute
310#endif