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