blob: 0fca661dc44f76c19ed202f1c4c523d9289cee85 [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#include "Reference.h"
25
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010026#include "AssetsLibrary.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010027#include "Globals.h"
28#include "Helpers.h"
29#include "ReferenceCPP.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030#include "validation/Helpers.h"
31
32#include <random>
Georgios Pinitas7b7858d2017-06-21 16:44:24 +010033#include <vector>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034
35using namespace arm_compute::test;
36
Isabella Gottardib797fa22017-06-23 15:02:11 +010037#ifndef DOXYGEN_SKIP_THIS
Anthony Barbier6ff3b192017-09-04 18:44:23 +010038namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
Giorgio Arena50f9fd72017-06-19 17:05:30 +010044std::pair<RawTensor, RawTensor> Reference::compute_reference_sobel_3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value)
45{
46 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010047 RawTensor ref_src(shape, Format::U8);
48 RawTensor ref_dst_x(shape, Format::S16);
49 RawTensor ref_dst_y(shape, Format::S16);
Giorgio Arena50f9fd72017-06-19 17:05:30 +010050
51 // Fill reference
52 library->fill_tensor_uniform(ref_src, 0);
53
54 // Compute reference
55 ReferenceCPP::sobel_3x3(ref_src, ref_dst_x, ref_dst_y, border_mode, constant_border_value);
56
57 return std::make_pair(ref_dst_x, ref_dst_y);
58}
59std::pair<RawTensor, RawTensor> Reference::compute_reference_sobel_5x5(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value)
60{
61 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010062 RawTensor ref_src(shape, Format::U8);
63 RawTensor ref_dst_x(shape, Format::S16);
64 RawTensor ref_dst_y(shape, Format::S16);
Giorgio Arena50f9fd72017-06-19 17:05:30 +010065
66 // Fill reference
67 library->fill_tensor_uniform(ref_src, 0);
68
69 // Compute reference
70 ReferenceCPP::sobel_5x5(ref_src, ref_dst_x, ref_dst_y, border_mode, constant_border_value);
71
72 return std::make_pair(ref_dst_x, ref_dst_y);
73}
Michele Di Giorgioef4b4ae2017-07-04 17:19:43 +010074void Reference::compute_reference_min_max_location(const TensorShape &shape, DataType dt_in, void *min, void *max, IArray<Coordinates2D> &min_loc, IArray<Coordinates2D> &max_loc,
Giorgio Arena2ca209e2017-06-13 15:49:37 +010075 uint32_t &min_count, uint32_t &max_count)
76{
77 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010078 RawTensor ref_src(shape, dt_in);
Giorgio Arena2ca209e2017-06-13 15:49:37 +010079
80 // Fill reference
81 library->fill_tensor_uniform(ref_src, 0);
82
83 // Compute reference
84 ReferenceCPP::min_max_location(ref_src, min, max, min_loc, max_loc, min_count, max_count);
85}
Giorgio Arenaf7959862017-06-13 15:19:51 +010086std::pair<float, float> Reference::compute_reference_mean_and_standard_deviation(const TensorShape &shape)
87{
88 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +010089 RawTensor ref_src(shape, DataType::U8);
Giorgio Arenaf7959862017-06-13 15:19:51 +010090
91 // Create output variables
92 float mean;
93 float std_dev;
94
95 // Fill reference
96 library->fill_tensor_uniform(ref_src, 0);
97
98 // Compute reference
99 ReferenceCPP::mean_and_standard_deviation(ref_src, mean, std_dev);
100
101 return std::make_pair(mean, std_dev);
102}
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100103RawTensor Reference::compute_reference_integral_image(const TensorShape &shape)
104{
105 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100106 RawTensor ref_src(shape, DataType::U8);
107 RawTensor ref_dst(shape, DataType::U32);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100108
109 // Fill reference
110 library->fill_tensor_uniform(ref_src, 0);
111
112 // Compute reference
113 ReferenceCPP::integral_image(ref_src, ref_dst);
114
115 return ref_dst;
116}
117RawTensor Reference::compute_reference_absolute_difference(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out)
118{
119 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100120 RawTensor ref_src1(shape, dt_in0);
121 RawTensor ref_src2(shape, dt_in1);
122 RawTensor ref_dst(shape, dt_out);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100123
124 // Fill reference
125 library->fill_tensor_uniform(ref_src1, 0);
126 library->fill_tensor_uniform(ref_src2, 1);
127
128 // Compute reference
129 ReferenceCPP::absolute_difference(ref_src1, ref_src2, ref_dst);
130
131 return ref_dst;
132}
133
134RawTensor Reference::compute_reference_accumulate(const TensorShape &shape)
135{
136 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100137 RawTensor ref_src(shape, DataType::U8);
138 RawTensor ref_dst(shape, DataType::S16);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100139
140 // Fill reference
141 library->fill_tensor_uniform(ref_src, 0);
142 library->fill_tensor_uniform(ref_dst, 1);
143
144 // Compute reference
145 ReferenceCPP::accumulate(ref_src, ref_dst);
146
147 return ref_dst;
148}
149
150RawTensor Reference::compute_reference_accumulate_squared(const TensorShape &shape, uint32_t shift)
151{
152 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100153 RawTensor ref_src(shape, DataType::U8);
154 RawTensor ref_dst(shape, DataType::S16);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100155
156 // Fill reference
157 // ref_dst tensor filled with non-negative values
158 library->fill_tensor_uniform(ref_src, 0);
159 library->fill_tensor_uniform(ref_dst, 1, static_cast<int16_t>(0), std::numeric_limits<int16_t>::max());
160
161 // Compute reference
162 ReferenceCPP::accumulate_squared(ref_src, ref_dst, shift);
163
164 return ref_dst;
165}
166
167RawTensor Reference::compute_reference_accumulate_weighted(const TensorShape &shape, float alpha)
168{
169 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100170 RawTensor ref_src(shape, DataType::U8);
171 RawTensor ref_dst(shape, DataType::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100172
173 // Fill reference
174 library->fill_tensor_uniform(ref_src, 0);
175 library->fill_tensor_uniform(ref_dst, 1);
176
177 // Compute reference
178 ReferenceCPP::accumulate_weighted(ref_src, ref_dst, alpha);
179
180 return ref_dst;
181}
182
Michele Di Giorgio81f0d152017-07-11 15:00:52 +0100183RawTensor Reference::compute_reference_arithmetic_addition(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy convert_policy, int fixed_point_position)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100184{
185 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100186 RawTensor ref_src1(shape, dt_in0, 1, fixed_point_position);
187 RawTensor ref_src2(shape, dt_in1, 1, fixed_point_position);
188 RawTensor ref_dst(shape, dt_out, 1, fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100189
190 // Fill reference
191 library->fill_tensor_uniform(ref_src1, 0);
192 library->fill_tensor_uniform(ref_src2, 1);
193
194 // Compute reference
195 ReferenceCPP::arithmetic_addition(ref_src1, ref_src2, ref_dst, convert_policy);
196
197 return ref_dst;
198}
199
Michele Di Giorgio81f0d152017-07-11 15:00:52 +0100200RawTensor Reference::compute_reference_arithmetic_subtraction(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy convert_policy, int fixed_point_position)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100201{
202 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100203 RawTensor ref_src1(shape, dt_in0, 1, fixed_point_position);
204 RawTensor ref_src2(shape, dt_in1, 1, fixed_point_position);
205 RawTensor ref_dst(shape, dt_out, 1, fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100206
207 // Fill reference
208 library->fill_tensor_uniform(ref_src1, 0);
209 library->fill_tensor_uniform(ref_src2, 1);
210
211 // Compute reference
212 ReferenceCPP::arithmetic_subtraction(ref_src1, ref_src2, ref_dst, convert_policy);
213
214 return ref_dst;
215}
216
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100217RawTensor Reference::compute_reference_bitwise_xor(const TensorShape &shape)
218{
219 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100220 RawTensor ref_src1(shape, DataType::U8);
221 RawTensor ref_src2(shape, DataType::U8);
222 RawTensor ref_dst(shape, DataType::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100223
224 // Fill reference
225 library->fill_tensor_uniform(ref_src1, 0);
226 library->fill_tensor_uniform(ref_src2, 1);
227
228 // Compute reference
229 ReferenceCPP::bitwise_xor(ref_src1, ref_src2, ref_dst);
230
231 return ref_dst;
232}
233
234RawTensor Reference::compute_reference_bitwise_not(const TensorShape &shape)
235{
236 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100237 RawTensor ref_src(shape, DataType::U8);
238 RawTensor ref_dst(shape, DataType::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100239
240 // Fill reference
241 library->fill_tensor_uniform(ref_src, 0);
242
243 // Compute reference
244 ReferenceCPP::bitwise_not(ref_src, ref_dst);
245
246 return ref_dst;
247}
248
SiCong Libacaf9a2017-06-19 13:41:45 +0100249RawTensor Reference::compute_reference_box3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100250{
251 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100252 RawTensor ref_src(shape, DataType::U8);
253 RawTensor ref_dst(shape, DataType::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100254
255 // Fill reference
256 library->fill_tensor_uniform(ref_src, 0);
257
258 // Compute reference
SiCong Libacaf9a2017-06-19 13:41:45 +0100259 ReferenceCPP::box3x3(ref_src, ref_dst, border_mode, constant_border_value);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100260
261 return ref_dst;
262}
263
Georgios Pinitase2229412017-07-12 12:30:40 +0100264RawTensor Reference::compute_reference_depth_convert(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy,
265 uint32_t shift, uint32_t fixed_point_position_in, uint32_t fixed_point_position_out)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100266{
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100267 RawTensor ref_src(shape, dt_in, 1, fixed_point_position_in);
268 RawTensor ref_dst(shape, dt_out, 1, fixed_point_position_out);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100269
270 // Fill reference
271 library->fill_tensor_uniform(ref_src, 0);
272
273 // Compute reference
274 ReferenceCPP::depth_convert(ref_src, ref_dst, policy, shift);
275
276 return ref_dst;
277}
278
SiCong Li5a536642017-06-19 14:47:05 +0100279RawTensor Reference::compute_reference_gaussian3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value)
280{
281 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100282 RawTensor ref_src(shape, DataType::U8);
283 RawTensor ref_dst(shape, DataType::U8);
SiCong Li5a536642017-06-19 14:47:05 +0100284
285 // Fill reference
286 library->fill_tensor_uniform(ref_src, 0);
287
288 // Compute reference
289 ReferenceCPP::gaussian3x3(ref_src, ref_dst, border_mode, constant_border_value);
290
291 return ref_dst;
292}
293
SiCong Li3eb263e2017-06-19 15:31:43 +0100294RawTensor Reference::compute_reference_gaussian5x5(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value)
295{
296 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100297 RawTensor ref_src(shape, DataType::U8);
298 RawTensor ref_dst(shape, DataType::U8);
SiCong Li3eb263e2017-06-19 15:31:43 +0100299
300 // Fill reference
301 library->fill_tensor_uniform(ref_src, 0);
302
303 // Compute reference
304 ReferenceCPP::gaussian5x5(ref_src, ref_dst, border_mode, constant_border_value);
305
306 return ref_dst;
307}
308
Isabella Gottardi3b77e9d2017-06-22 11:05:41 +0100309RawTensor Reference::compute_reference_non_linear_filter(const TensorShape &shape, NonLinearFilterFunction function, unsigned int mask_size,
310 MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, uint8_t constant_border_value)
311{
312 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100313 RawTensor ref_src(shape, DataType::U8);
314 RawTensor ref_dst(shape, DataType::U8);
Isabella Gottardi3b77e9d2017-06-22 11:05:41 +0100315
316 // Fill reference
317 library->fill_tensor_uniform(ref_src, 0);
318
319 // Compute reference
320 ReferenceCPP::non_linear_filter(ref_src, ref_dst, function, mask_size, pattern, mask, border_mode, constant_border_value);
321
322 return ref_dst;
323}
324
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100325RawTensor Reference::compute_reference_pixel_wise_multiplication(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, float scale, ConvertPolicy convert_policy,
326 RoundingPolicy rounding_policy)
327{
328 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100329 RawTensor ref_src1(shape, dt_in0);
330 RawTensor ref_src2(shape, dt_in1);
331 RawTensor ref_dst(shape, dt_out);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100332
333 // Fill reference
334 library->fill_tensor_uniform(ref_src1, 0);
335 library->fill_tensor_uniform(ref_src2, 1);
336
337 // Compute reference
338 ReferenceCPP::pixel_wise_multiplication(ref_src1, ref_src2, ref_dst, scale, convert_policy, rounding_policy);
339
340 return ref_dst;
341}
342
343RawTensor Reference::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,
344 ConvertPolicy convert_policy, RoundingPolicy rounding_policy)
345{
346 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100347 RawTensor ref_src1(shape, dt_in0, 1, fixed_point_position);
348 RawTensor ref_src2(shape, dt_in1, 1, fixed_point_position);
349 RawTensor ref_dst(shape, dt_out, 1, fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100350
351 // Fill reference
352 library->fill_tensor_uniform(ref_src1, 0);
353 library->fill_tensor_uniform(ref_src2, 1);
354
355 // Compute reference
356 ReferenceCPP::fixed_point_pixel_wise_multiplication(ref_src1, ref_src2, ref_dst, scale, convert_policy, rounding_policy);
357
358 return ref_dst;
359}
360
Isabella Gottardib797fa22017-06-23 15:02:11 +0100361template <typename T>
362RawTensor Reference::compute_reference_table_lookup(const TensorShape &shape, DataType dt_inout, std::map<T, T> &lut)
363{
364 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100365 RawTensor ref_src(shape, dt_inout);
366 RawTensor ref_dst(shape, dt_inout);
Isabella Gottardib797fa22017-06-23 15:02:11 +0100367 // Fill reference
368 library->fill_tensor_uniform(ref_src, 0);
369
370 // Compute reference
371 ReferenceCPP::table_lookup(ref_src, ref_dst, lut);
372
373 return ref_dst;
374}
375template RawTensor arm_compute::test::validation::Reference::compute_reference_table_lookup<uint8_t>(const TensorShape &shape, DataType dt_inout, std::map<uint8_t, uint8_t> &lut);
376template RawTensor arm_compute::test::validation::Reference::compute_reference_table_lookup<int16_t>(const TensorShape &shape, DataType dt_inout, std::map<int16_t, int16_t> &lut);
377
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100378RawTensor Reference::compute_reference_threshold(const TensorShape &shape, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper)
379{
380 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100381 RawTensor ref_src(shape, DataType::U8);
382 RawTensor ref_dst(shape, DataType::U8);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100383
384 // Fill reference
Isabella Gottardib797fa22017-06-23 15:02:11 +0100385 library->fill_tensor_uniform(ref_src, 0);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100386
387 // Compute reference
Isabella Gottardib797fa22017-06-23 15:02:11 +0100388 ReferenceCPP::threshold(ref_src, ref_dst, threshold, false_value, true_value, type, upper);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100389
390 return ref_dst;
391}
392
Isabella Gottardi62031532017-07-04 11:21:28 +0100393RawTensor Reference::compute_reference_warp_perspective(const TensorShape &shape, RawTensor &valid_mask, const float *matrix, InterpolationPolicy policy, BorderMode border_mode,
394 uint8_t constant_border_value)
395{
396 // Create reference
397 RawTensor ref_src(shape, DataType::U8);
398 RawTensor ref_dst(shape, DataType::U8);
399
400 // Fill reference
401 library->fill_tensor_uniform(ref_src, 0);
402
403 // Compute reference
404 ReferenceCPP::warp_perspective(ref_src, ref_dst, valid_mask, matrix, policy, border_mode, constant_border_value);
405
406 return ref_dst;
407}
408
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100409RawTensor Reference::compute_reference_batch_normalization_layer(const TensorShape &shape0, const TensorShape &shape1, DataType dt, float epsilon, int fixed_point_position)
410{
411 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100412 RawTensor ref_src(shape0, dt, 1, fixed_point_position);
413 RawTensor ref_dst(shape0, dt, 1, fixed_point_position);
414 RawTensor ref_mean(shape1, dt, 1, fixed_point_position);
415 RawTensor ref_var(shape1, dt, 1, fixed_point_position);
416 RawTensor ref_beta(shape1, dt, 1, fixed_point_position);
417 RawTensor ref_gamma(shape1, dt, 1, fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100418
Pablo Tello8fda1cb2017-07-05 15:20:38 +0100419 // Fill tensors
420 switch(dt)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100421 {
Pablo Tello8fda1cb2017-07-05 15:20:38 +0100422 case DataType::QS8:
Michalis Spyrou172e5702017-06-26 14:18:47 +0100423 {
Pablo Tello8fda1cb2017-07-05 15:20:38 +0100424 const std::pair<int8_t, int8_t> bounds = get_batchnormalization_layer_test_bounds<int8_t>(fixed_point_position);
425 std::uniform_int_distribution<> distribution(bounds.first, bounds.second);
426 std::uniform_int_distribution<> distribution_var(0, bounds.second);
427 fill_tensors(distribution, { 0, 1, 3, 4 }, &ref_src, &ref_mean, &ref_beta, &ref_gamma);
428 fill_tensors(distribution_var, { 0 }, &ref_var);
429 break;
Michalis Spyrou172e5702017-06-26 14:18:47 +0100430 }
Pablo Tello8fda1cb2017-07-05 15:20:38 +0100431 case DataType::QS16:
Michalis Spyrou172e5702017-06-26 14:18:47 +0100432 {
Pablo Tello8fda1cb2017-07-05 15:20:38 +0100433 const std::pair<int16_t, int16_t> bounds = get_batchnormalization_layer_test_bounds<int16_t>(fixed_point_position);
434 std::uniform_int_distribution<> distribution(bounds.first, bounds.second);
435 std::uniform_int_distribution<> distribution_var(0, bounds.second);
436 fill_tensors(distribution, { 0, 1, 3, 4 }, &ref_src, &ref_mean, &ref_beta, &ref_gamma);
437 fill_tensors(distribution_var, { 0 }, &ref_var);
438 break;
Michalis Spyrou172e5702017-06-26 14:18:47 +0100439 }
Pablo Tello8fda1cb2017-07-05 15:20:38 +0100440 case DataType::F16:
441 {
442 const std::pair<half_float::half, half_float::half> bounds = get_batchnormalization_layer_test_bounds<half_float::half>();
443 std::uniform_real_distribution<> distribution(bounds.first, bounds.second);
444 std::uniform_real_distribution<> distribution_var(0, bounds.second);
445 fill_tensors(distribution, { 0, 1, 3, 4 }, &ref_src, &ref_mean, &ref_beta, &ref_gamma);
446 fill_tensors(distribution_var, { 0 }, &ref_var);
447 break;
448 }
449 case DataType::F32:
450 {
451 const std::pair<float, float> bounds = get_batchnormalization_layer_test_bounds<float>();
452 std::uniform_real_distribution<> distribution(bounds.first, bounds.second);
453 std::uniform_real_distribution<> distribution_var(0, bounds.second);
454 fill_tensors(distribution, { 0, 1, 3, 4 }, &ref_src, &ref_mean, &ref_beta, &ref_gamma);
455 fill_tensors(distribution_var, { 0 }, &ref_var);
456 break;
457 }
458 default:
459 {
460 ARM_COMPUTE_ERROR("Not supported");
461 break;
462 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100463 }
464
465 // Compute reference
466 ReferenceCPP::batch_normalization_layer(ref_src, ref_dst, ref_mean, ref_var, ref_beta, ref_gamma, epsilon, fixed_point_position);
467
468 return ref_dst;
469}
470
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100471RawTensor Reference::compute_reference_fully_connected_layer(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape,
472 DataType dt, bool transpose_weights, int fixed_point_position)
473{
474 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100475 RawTensor ref_src(input_shape, dt, 1, fixed_point_position);
476 RawTensor ref_bias(bias_shape, dt, 1, fixed_point_position);
477 RawTensor ref_dst(output_shape, dt, 1, fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100478
479 // Swap the first and second dimension of weights' shape if transpose_weights is true
480 TensorShape ws = weights_shape;
481 if(transpose_weights)
482 {
483 const size_t dimx = ws.x();
484 ws.set(0, ws.y());
485 ws.set(1, dimx);
486 }
487
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100488 RawTensor ref_weights(ws, dt, 1, fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100489
490 // Fill reference
Pablo Tellodcdc85e2017-06-28 10:05:29 +0100491 if(dt == DataType::F16 || dt == DataType::F32)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100492 {
493 std::uniform_real_distribution<> distribution(-1.0f, 1.0f);
494 library->fill(ref_src, distribution, 0);
495 library->fill(ref_weights, distribution, 1);
496 library->fill(ref_bias, distribution, 2);
497 }
498 else
499 {
500 library->fill_tensor_uniform(ref_src, 0);
501 library->fill_tensor_uniform(ref_weights, 1);
502 library->fill_tensor_uniform(ref_bias, 2);
503 }
504
505 // Compute reference
506 ReferenceCPP::fully_connected_layer(ref_src, ref_weights, ref_bias, ref_dst);
507
508 return ref_dst;
509}
510
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100511RawTensor Reference::compute_reference_pooling_layer(const TensorShape &shape_in, const TensorShape &shape_out, DataType dt, PoolingLayerInfo pool_info, int fixed_point_position)
512{
513 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100514 RawTensor ref_src(shape_in, dt, 1, fixed_point_position);
515 RawTensor ref_dst(shape_out, dt, 1, fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100516
517 // Fill reference
518 int min = 0;
519 int max = 0;
520 switch(dt)
521 {
522 case DataType::F32:
Pablo Tello0c34fe22017-06-26 17:17:42 +0100523 case DataType::F16:
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100524 min = -1;
525 max = 1;
526 break;
527 case DataType::QS8:
528 min = -(1 << fixed_point_position);
529 max = (1 << fixed_point_position);
530 break;
531 default:
532 ARM_COMPUTE_ERROR("DataType not supported.");
533 }
534 std::uniform_real_distribution<> distribution(min, max);
535 library->fill(ref_src, distribution, 0.0);
536
537 // Compute reference
538 ReferenceCPP::pooling_layer(ref_src, ref_dst, pool_info, fixed_point_position);
539
540 return ref_dst;
541}
542
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100543RawTensor Reference::compute_reference_roi_pooling_layer(const TensorShape &shape, DataType dt, const std::vector<ROI> &rois, const ROIPoolingLayerInfo &pool_info)
544{
545 TensorShape shape_dst;
546 shape_dst.set(0, pool_info.pooled_width());
547 shape_dst.set(1, pool_info.pooled_height());
548 shape_dst.set(2, shape.z());
549 shape_dst.set(3, rois.size());
550
551 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100552 RawTensor ref_src(shape, dt);
553 RawTensor ref_dst(shape_dst, dt);
Georgios Pinitas7b7858d2017-06-21 16:44:24 +0100554
555 // Fill reference
556 std::uniform_real_distribution<> distribution(-1, 1);
557 library->fill(ref_src, distribution, 0.0);
558
559 // Compute reference
560 ReferenceCPP::roi_pooling_layer(ref_src, ref_dst, rois, pool_info);
561
562 return ref_dst;
563}
564
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100565RawTensor Reference::compute_reference_fixed_point_operation(const TensorShape &shape, DataType dt_in, DataType dt_out, FixedPointOp op, int fixed_point_position)
566{
567 // Create reference
Moritz Pflanzerfb5aabb2017-07-18 14:39:55 +0100568 RawTensor ref_src(shape, dt_in, 1, fixed_point_position);
569 RawTensor ref_dst(shape, dt_out, 1, fixed_point_position);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100570
571 // Fill reference
572 int min = 0;
573 int max = 0;
574 switch(op)
575 {
576 case(FixedPointOp::INV_SQRT):
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100577 min = 1;
578 max = (dt_in == DataType::QS8) ? 0x7F : 0x7FFF;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100579 break;
580 case(FixedPointOp::LOG):
581 min = (1 << (fixed_point_position - 1));
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100582 max = (dt_in == DataType::QS8) ? 0x3F : 0x3FFF;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100583 break;
584 case(FixedPointOp::EXP):
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100585 min = -(1 << (fixed_point_position - 1));
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100586 max = (1 << (fixed_point_position - 1));
587 break;
588 case(FixedPointOp::RECIPROCAL):
589 min = 15;
Michalis Spyrou0a8334c2017-06-14 18:00:05 +0100590 max = (dt_in == DataType::QS8) ? 0x7F : 0x7FFF;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100591 break;
592 default:
593 ARM_COMPUTE_ERROR("Fixed point operation not supported");
594 }
595 std::uniform_int_distribution<> distribution(min, max);
596 library->fill(ref_src, distribution, 0);
597
598 // Compute reference
599 ReferenceCPP::fixed_point_operation(ref_src, ref_dst, op);
600
601 return ref_dst;
602}
603
604} // namespace validation
605} // namespace test
606} // namespace arm_compute
Isabella Gottardib797fa22017-06-23 15:02:11 +0100607#endif /* DOXYGEN_SKIP_THIS */