blob: be6ddba6335cbf204d544039ea91e0716d7705d2 [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
26#include "Globals.h"
27#include "Helpers.h"
28#include "ReferenceCPP.h"
29#include "TensorLibrary.h"
30#include "validation/Helpers.h"
31
32#include <random>
33
34using namespace arm_compute::test;
35
36namespace arm_compute
37{
38namespace test
39{
40namespace validation
41{
Giorgio Arena50f9fd72017-06-19 17:05:30 +010042std::pair<RawTensor, RawTensor> Reference::compute_reference_sobel_3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value)
43{
44 // Create reference
45 RawTensor ref_src = library->get(shape, Format::U8);
46 RawTensor ref_dst_x = library->get(shape, Format::S16);
47 RawTensor ref_dst_y = library->get(shape, Format::S16);
48
49 // Fill reference
50 library->fill_tensor_uniform(ref_src, 0);
51
52 // Compute reference
53 ReferenceCPP::sobel_3x3(ref_src, ref_dst_x, ref_dst_y, border_mode, constant_border_value);
54
55 return std::make_pair(ref_dst_x, ref_dst_y);
56}
57std::pair<RawTensor, RawTensor> Reference::compute_reference_sobel_5x5(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value)
58{
59 // Create reference
60 RawTensor ref_src = library->get(shape, Format::U8);
61 RawTensor ref_dst_x = library->get(shape, Format::S16);
62 RawTensor ref_dst_y = library->get(shape, Format::S16);
63
64 // Fill reference
65 library->fill_tensor_uniform(ref_src, 0);
66
67 // Compute reference
68 ReferenceCPP::sobel_5x5(ref_src, ref_dst_x, ref_dst_y, border_mode, constant_border_value);
69
70 return std::make_pair(ref_dst_x, ref_dst_y);
71}
Giorgio Arenaf7959862017-06-13 15:19:51 +010072std::pair<float, float> Reference::compute_reference_mean_and_standard_deviation(const TensorShape &shape)
73{
74 // Create reference
75 RawTensor ref_src = library->get(shape, DataType::U8);
76
77 // Create output variables
78 float mean;
79 float std_dev;
80
81 // Fill reference
82 library->fill_tensor_uniform(ref_src, 0);
83
84 // Compute reference
85 ReferenceCPP::mean_and_standard_deviation(ref_src, mean, std_dev);
86
87 return std::make_pair(mean, std_dev);
88}
Anthony Barbier6ff3b192017-09-04 18:44:23 +010089RawTensor Reference::compute_reference_integral_image(const TensorShape &shape)
90{
91 // Create reference
92 RawTensor ref_src = library->get(shape, DataType::U8);
93 RawTensor ref_dst = library->get(shape, DataType::U32);
94
95 // Fill reference
96 library->fill_tensor_uniform(ref_src, 0);
97
98 // Compute reference
99 ReferenceCPP::integral_image(ref_src, ref_dst);
100
101 return ref_dst;
102}
103RawTensor Reference::compute_reference_absolute_difference(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out)
104{
105 // Create reference
106 RawTensor ref_src1 = library->get(shape, dt_in0);
107 RawTensor ref_src2 = library->get(shape, dt_in1);
108 RawTensor ref_dst = library->get(shape, dt_out);
109
110 // Fill reference
111 library->fill_tensor_uniform(ref_src1, 0);
112 library->fill_tensor_uniform(ref_src2, 1);
113
114 // Compute reference
115 ReferenceCPP::absolute_difference(ref_src1, ref_src2, ref_dst);
116
117 return ref_dst;
118}
119
120RawTensor Reference::compute_reference_accumulate(const TensorShape &shape)
121{
122 // Create reference
123 RawTensor ref_src = library->get(shape, DataType::U8);
124 RawTensor ref_dst = library->get(shape, DataType::S16);
125
126 // Fill reference
127 library->fill_tensor_uniform(ref_src, 0);
128 library->fill_tensor_uniform(ref_dst, 1);
129
130 // Compute reference
131 ReferenceCPP::accumulate(ref_src, ref_dst);
132
133 return ref_dst;
134}
135
136RawTensor Reference::compute_reference_accumulate_squared(const TensorShape &shape, uint32_t shift)
137{
138 // Create reference
139 RawTensor ref_src = library->get(shape, DataType::U8);
140 RawTensor ref_dst = library->get(shape, DataType::S16);
141
142 // Fill reference
143 // ref_dst tensor filled with non-negative values
144 library->fill_tensor_uniform(ref_src, 0);
145 library->fill_tensor_uniform(ref_dst, 1, static_cast<int16_t>(0), std::numeric_limits<int16_t>::max());
146
147 // Compute reference
148 ReferenceCPP::accumulate_squared(ref_src, ref_dst, shift);
149
150 return ref_dst;
151}
152
153RawTensor Reference::compute_reference_accumulate_weighted(const TensorShape &shape, float alpha)
154{
155 // Create reference
156 RawTensor ref_src = library->get(shape, DataType::U8);
157 RawTensor ref_dst = library->get(shape, DataType::U8);
158
159 // Fill reference
160 library->fill_tensor_uniform(ref_src, 0);
161 library->fill_tensor_uniform(ref_dst, 1);
162
163 // Compute reference
164 ReferenceCPP::accumulate_weighted(ref_src, ref_dst, alpha);
165
166 return ref_dst;
167}
168
169RawTensor Reference::compute_reference_arithmetic_addition(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy convert_policy)
170{
171 // Create reference
172 RawTensor ref_src1 = library->get(shape, dt_in0);
173 RawTensor ref_src2 = library->get(shape, dt_in1);
174 RawTensor ref_dst = library->get(shape, dt_out);
175
176 // Fill reference
177 library->fill_tensor_uniform(ref_src1, 0);
178 library->fill_tensor_uniform(ref_src2, 1);
179
180 // Compute reference
181 ReferenceCPP::arithmetic_addition(ref_src1, ref_src2, ref_dst, convert_policy);
182
183 return ref_dst;
184}
185
186RawTensor Reference::compute_reference_arithmetic_subtraction(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, ConvertPolicy convert_policy)
187{
188 // Create reference
189 RawTensor ref_src1 = library->get(shape, dt_in0);
190 RawTensor ref_src2 = library->get(shape, dt_in1);
191 RawTensor ref_dst = library->get(shape, dt_out);
192
193 // Fill reference
194 library->fill_tensor_uniform(ref_src1, 0);
195 library->fill_tensor_uniform(ref_src2, 1);
196
197 // Compute reference
198 ReferenceCPP::arithmetic_subtraction(ref_src1, ref_src2, ref_dst, convert_policy);
199
200 return ref_dst;
201}
202
203RawTensor Reference::compute_reference_bitwise_and(const TensorShape &shape)
204{
205 // Create reference
206 RawTensor ref_src1 = library->get(shape, DataType::U8);
207 RawTensor ref_src2 = library->get(shape, DataType::U8);
208 RawTensor ref_dst = library->get(shape, DataType::U8);
209
210 // Fill reference
211 library->fill_tensor_uniform(ref_src1, 0);
212 library->fill_tensor_uniform(ref_src2, 1);
213
214 // Compute reference
215 ReferenceCPP::bitwise_and(ref_src1, ref_src2, ref_dst);
216
217 return ref_dst;
218}
219
220RawTensor Reference::compute_reference_bitwise_or(const TensorShape &shape)
221{
222 // Create reference
223 RawTensor ref_src1 = library->get(shape, DataType::U8);
224 RawTensor ref_src2 = library->get(shape, DataType::U8);
225 RawTensor ref_dst = library->get(shape, DataType::U8);
226
227 // Fill reference
228 library->fill_tensor_uniform(ref_src1, 0);
229 library->fill_tensor_uniform(ref_src2, 1);
230
231 // Compute reference
232 ReferenceCPP::bitwise_or(ref_src1, ref_src2, ref_dst);
233
234 return ref_dst;
235}
236
237RawTensor Reference::compute_reference_bitwise_xor(const TensorShape &shape)
238{
239 // Create reference
240 RawTensor ref_src1 = library->get(shape, DataType::U8);
241 RawTensor ref_src2 = library->get(shape, DataType::U8);
242 RawTensor ref_dst = library->get(shape, DataType::U8);
243
244 // Fill reference
245 library->fill_tensor_uniform(ref_src1, 0);
246 library->fill_tensor_uniform(ref_src2, 1);
247
248 // Compute reference
249 ReferenceCPP::bitwise_xor(ref_src1, ref_src2, ref_dst);
250
251 return ref_dst;
252}
253
254RawTensor Reference::compute_reference_bitwise_not(const TensorShape &shape)
255{
256 // Create reference
257 RawTensor ref_src = library->get(shape, DataType::U8);
258 RawTensor ref_dst = library->get(shape, DataType::U8);
259
260 // Fill reference
261 library->fill_tensor_uniform(ref_src, 0);
262
263 // Compute reference
264 ReferenceCPP::bitwise_not(ref_src, ref_dst);
265
266 return ref_dst;
267}
268
SiCong Libacaf9a2017-06-19 13:41:45 +0100269RawTensor Reference::compute_reference_box3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value)
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100270{
271 // Create reference
272 RawTensor ref_src = library->get(shape, DataType::U8);
273 RawTensor ref_dst = library->get(shape, DataType::U8);
274
275 // Fill reference
276 library->fill_tensor_uniform(ref_src, 0);
277
278 // Compute reference
SiCong Libacaf9a2017-06-19 13:41:45 +0100279 ReferenceCPP::box3x3(ref_src, ref_dst, border_mode, constant_border_value);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100280
281 return ref_dst;
282}
283
284RawTensor Reference::compute_reference_depth_convert(const TensorShape &shape, DataType dt_in, DataType dt_out, ConvertPolicy policy, uint32_t shift, uint32_t fixed_point_position)
285{
286 RawTensor ref_src = library->get(shape, dt_in, 1, fixed_point_position);
287 RawTensor ref_dst = library->get(shape, dt_out, 1, fixed_point_position);
288
289 // Fill reference
290 library->fill_tensor_uniform(ref_src, 0);
291
292 // Compute reference
293 ReferenceCPP::depth_convert(ref_src, ref_dst, policy, shift);
294
295 return ref_dst;
296}
297
SiCong Li5a536642017-06-19 14:47:05 +0100298RawTensor Reference::compute_reference_gaussian3x3(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value)
299{
300 // Create reference
301 RawTensor ref_src = library->get(shape, DataType::U8);
302 RawTensor ref_dst = library->get(shape, DataType::U8);
303
304 // Fill reference
305 library->fill_tensor_uniform(ref_src, 0);
306
307 // Compute reference
308 ReferenceCPP::gaussian3x3(ref_src, ref_dst, border_mode, constant_border_value);
309
310 return ref_dst;
311}
312
SiCong Li3eb263e2017-06-19 15:31:43 +0100313RawTensor Reference::compute_reference_gaussian5x5(const TensorShape &shape, BorderMode border_mode, uint8_t constant_border_value)
314{
315 // Create reference
316 RawTensor ref_src = library->get(shape, DataType::U8);
317 RawTensor ref_dst = library->get(shape, DataType::U8);
318
319 // Fill reference
320 library->fill_tensor_uniform(ref_src, 0);
321
322 // Compute reference
323 ReferenceCPP::gaussian5x5(ref_src, ref_dst, border_mode, constant_border_value);
324
325 return ref_dst;
326}
327
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100328RawTensor Reference::compute_reference_gemm(const TensorShape &src_shape1, const TensorShape &src_shape2, const TensorShape &src_shape3,
329 const TensorShape &dst_shape, float alpha, float beta, DataType dt, int fixed_point_position)
330{
331 RawTensor src1 = library->get(src_shape1, dt, 1, fixed_point_position);
332 RawTensor src2 = library->get(src_shape2, dt, 1, fixed_point_position);
333 RawTensor src3 = library->get(src_shape3, dt, 1, fixed_point_position);
334 RawTensor dst = library->get(dst_shape, dt, 1, fixed_point_position);
335
336 // Fill reference
337 if(dt == DataType::F32)
338 {
339 std::uniform_real_distribution<> distribution(-1.0f, 1.0f);
340 library->fill(src1, distribution, 0);
341 library->fill(src2, distribution, 1);
342 library->fill(src3, distribution, 2);
343 }
344 else
345 {
346 library->fill_tensor_uniform(src1, 0);
347 library->fill_tensor_uniform(src2, 1);
348 library->fill_tensor_uniform(src3, 2);
349 }
350
351 // Compute reference
352 ReferenceCPP::gemm(src1, src2, src3, dst, alpha, beta);
353
354 return dst;
355}
356
Isabella Gottardi3b77e9d2017-06-22 11:05:41 +0100357RawTensor Reference::compute_reference_non_linear_filter(const TensorShape &shape, NonLinearFilterFunction function, unsigned int mask_size,
358 MatrixPattern pattern, const uint8_t *mask, BorderMode border_mode, uint8_t constant_border_value)
359{
360 // Create reference
361 RawTensor ref_src = library->get(shape, DataType::U8);
362 RawTensor ref_dst = library->get(shape, DataType::U8);
363
364 // Fill reference
365 library->fill_tensor_uniform(ref_src, 0);
366
367 // Compute reference
368 ReferenceCPP::non_linear_filter(ref_src, ref_dst, function, mask_size, pattern, mask, border_mode, constant_border_value);
369
370 return ref_dst;
371}
372
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100373RawTensor Reference::compute_reference_pixel_wise_multiplication(const TensorShape &shape, DataType dt_in0, DataType dt_in1, DataType dt_out, float scale, ConvertPolicy convert_policy,
374 RoundingPolicy rounding_policy)
375{
376 // Create reference
377 RawTensor ref_src1 = library->get(shape, dt_in0);
378 RawTensor ref_src2 = library->get(shape, dt_in1);
379 RawTensor ref_dst = library->get(shape, dt_out);
380
381 // Fill reference
382 library->fill_tensor_uniform(ref_src1, 0);
383 library->fill_tensor_uniform(ref_src2, 1);
384
385 // Compute reference
386 ReferenceCPP::pixel_wise_multiplication(ref_src1, ref_src2, ref_dst, scale, convert_policy, rounding_policy);
387
388 return ref_dst;
389}
390
391RawTensor 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,
392 ConvertPolicy convert_policy, RoundingPolicy rounding_policy)
393{
394 // Create reference
395 RawTensor ref_src1 = library->get(shape, dt_in0, 1, fixed_point_position);
396 RawTensor ref_src2 = library->get(shape, dt_in1, 1, fixed_point_position);
397 RawTensor ref_dst = library->get(shape, dt_out, 1, fixed_point_position);
398
399 // Fill reference
400 library->fill_tensor_uniform(ref_src1, 0);
401 library->fill_tensor_uniform(ref_src2, 1);
402
403 // Compute reference
404 ReferenceCPP::fixed_point_pixel_wise_multiplication(ref_src1, ref_src2, ref_dst, scale, convert_policy, rounding_policy);
405
406 return ref_dst;
407}
408
409RawTensor Reference::compute_reference_threshold(const TensorShape &shape, uint8_t threshold, uint8_t false_value, uint8_t true_value, ThresholdType type, uint8_t upper)
410{
411 // Create reference
412 RawTensor ref_src1 = library->get(shape, DataType::U8);
413 RawTensor ref_dst = library->get(shape, DataType::U8);
414
415 // Fill reference
416 library->fill_tensor_uniform(ref_src1, 0);
417
418 // Compute reference
419 ReferenceCPP::threshold(ref_src1, ref_dst, threshold, false_value, true_value, type, upper);
420
421 return ref_dst;
422}
423
424RawTensor Reference::compute_reference_activation_layer(const TensorShape &shape, DataType dt, ActivationLayerInfo act_info, int fixed_point_position)
425{
426 // Create reference
427 RawTensor ref_src = library->get(shape, dt, 1, fixed_point_position);
428 RawTensor ref_dst = library->get(shape, dt, 1, fixed_point_position);
429
430 // Fill reference
431 if(dt == DataType::F32)
432 {
433 float min_bound = 0;
434 float max_bound = 0;
435 std::tie(min_bound, max_bound) = get_activation_layer_test_bounds<float>(act_info.activation());
436 std::uniform_real_distribution<> distribution(min_bound, max_bound);
437 library->fill(ref_src, distribution, 0);
438 }
439 else
440 {
441 int min_bound = 0;
442 int max_bound = 0;
443 std::tie(min_bound, max_bound) = get_activation_layer_test_bounds<int8_t>(act_info.activation(), fixed_point_position);
444 std::uniform_int_distribution<> distribution(min_bound, max_bound);
445 library->fill(ref_src, distribution, 0);
446 }
447
448 // Compute reference
449 ReferenceCPP::activation_layer(ref_src, ref_dst, act_info);
450
451 return ref_dst;
452}
453
454RawTensor Reference::compute_reference_batch_normalization_layer(const TensorShape &shape0, const TensorShape &shape1, DataType dt, float epsilon, int fixed_point_position)
455{
456 // Create reference
457 RawTensor ref_src = library->get(shape0, dt, 1, fixed_point_position);
458 RawTensor ref_dst = library->get(shape0, dt, 1, fixed_point_position);
459 RawTensor ref_mean = library->get(shape1, dt, 1, fixed_point_position);
460 RawTensor ref_var = library->get(shape1, dt, 1, fixed_point_position);
461 RawTensor ref_beta = library->get(shape1, dt, 1, fixed_point_position);
462 RawTensor ref_gamma = library->get(shape1, dt, 1, fixed_point_position);
463
464 // Fill tensors with values from -1 to 1.
465 if(dt == DataType::F32)
466 {
467 float min_bound = 0.f;
468 float max_bound = 0.f;
469 std::tie(min_bound, max_bound) = get_batchnormalization_layer_test_bounds<float>();
470 std::uniform_real_distribution<> distribution(min_bound, max_bound);
471 std::uniform_real_distribution<> distribution_var(0, max_bound);
472 library->fill(ref_src, distribution, 0);
473 library->fill(ref_mean, distribution, 1);
474 library->fill(ref_var, distribution_var, 0);
475 library->fill(ref_beta, distribution, 3);
476 library->fill(ref_gamma, distribution, 4);
477 }
478 else
479 {
480 int min_bound = 0;
481 int max_bound = 0;
482 std::tie(min_bound, max_bound) = get_batchnormalization_layer_test_bounds<int8_t>(fixed_point_position);
483 std::uniform_int_distribution<> distribution(min_bound, max_bound);
484 std::uniform_int_distribution<> distribution_var(0, max_bound);
485 library->fill(ref_src, distribution, 0);
486 library->fill(ref_mean, distribution, 1);
487 library->fill(ref_var, distribution_var, 0);
488 library->fill(ref_beta, distribution, 3);
489 library->fill(ref_gamma, distribution, 4);
490 }
491
492 // Compute reference
493 ReferenceCPP::batch_normalization_layer(ref_src, ref_dst, ref_mean, ref_var, ref_beta, ref_gamma, epsilon, fixed_point_position);
494
495 return ref_dst;
496}
497
498RawTensor Reference::compute_reference_convolution_layer(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape, DataType dt,
499 const PadStrideInfo &conv_info, int fixed_point_position)
500{
501 // Create reference
502 RawTensor ref_src = library->get(input_shape, dt, 1, fixed_point_position);
503 RawTensor ref_weights = library->get(weights_shape, dt, 1, fixed_point_position);
504 RawTensor ref_bias = library->get(bias_shape, dt, 1, fixed_point_position);
505 RawTensor ref_dst = library->get(output_shape, dt, 1, fixed_point_position);
506
507 // Fill reference
508 if(dt == DataType::F32)
509 {
510 std::uniform_real_distribution<> distribution(-1.0f, 1.0f);
511 library->fill(ref_src, distribution, 0);
512 library->fill(ref_weights, distribution, 1);
513 library->fill(ref_bias, distribution, 2);
514 }
515 else
516 {
517 library->fill_tensor_uniform(ref_src, 0);
518 library->fill_tensor_uniform(ref_weights, 1);
519 library->fill_tensor_uniform(ref_bias, 2);
520 }
521
522 // Compute reference
523 ReferenceCPP::convolution_layer(ref_src, ref_weights, ref_bias, ref_dst, conv_info);
524
525 return ref_dst;
526}
527
528RawTensor Reference::compute_reference_fully_connected_layer(const TensorShape &input_shape, const TensorShape &weights_shape, const TensorShape &bias_shape, const TensorShape &output_shape,
529 DataType dt, bool transpose_weights, int fixed_point_position)
530{
531 // Create reference
532 RawTensor ref_src = library->get(input_shape, dt, 1, fixed_point_position);
533 RawTensor ref_bias = library->get(bias_shape, dt, 1, fixed_point_position);
534 RawTensor ref_dst = library->get(output_shape, dt, 1, fixed_point_position);
535
536 // Swap the first and second dimension of weights' shape if transpose_weights is true
537 TensorShape ws = weights_shape;
538 if(transpose_weights)
539 {
540 const size_t dimx = ws.x();
541 ws.set(0, ws.y());
542 ws.set(1, dimx);
543 }
544
545 RawTensor ref_weights = library->get(ws, dt, 1, fixed_point_position);
546
547 // Fill reference
548 if(dt == DataType::F32)
549 {
550 std::uniform_real_distribution<> distribution(-1.0f, 1.0f);
551 library->fill(ref_src, distribution, 0);
552 library->fill(ref_weights, distribution, 1);
553 library->fill(ref_bias, distribution, 2);
554 }
555 else
556 {
557 library->fill_tensor_uniform(ref_src, 0);
558 library->fill_tensor_uniform(ref_weights, 1);
559 library->fill_tensor_uniform(ref_bias, 2);
560 }
561
562 // Compute reference
563 ReferenceCPP::fully_connected_layer(ref_src, ref_weights, ref_bias, ref_dst);
564
565 return ref_dst;
566}
567
568RawTensor Reference::compute_reference_normalization_layer(const TensorShape &shape, DataType dt, NormalizationLayerInfo norm_info, int fixed_point_position)
569{
570 // Create reference
571 RawTensor ref_src = library->get(shape, dt, 1, fixed_point_position);
572 RawTensor ref_dst = library->get(shape, dt, 1, fixed_point_position);
573
574 // Fill reference
575 if(dt == DataType::QS8)
576 {
577 const int8_t one_fixed_point = 1 << fixed_point_position;
578 const int8_t minus_one_fixed_point = -one_fixed_point;
579 library->fill_tensor_uniform(ref_src, 0, minus_one_fixed_point, one_fixed_point);
580 }
581 else
582 {
583 library->fill_tensor_uniform(ref_src, 0);
584 }
585
586 // Compute reference
587 ReferenceCPP::normalization_layer(ref_src, ref_dst, norm_info);
588
589 return ref_dst;
590}
591
592RawTensor Reference::compute_reference_pooling_layer(const TensorShape &shape_in, const TensorShape &shape_out, DataType dt, PoolingLayerInfo pool_info, int fixed_point_position)
593{
594 // Create reference
595 RawTensor ref_src = library->get(shape_in, dt, 1, fixed_point_position);
596 RawTensor ref_dst = library->get(shape_out, dt, 1, fixed_point_position);
597
598 // Fill reference
599 int min = 0;
600 int max = 0;
601 switch(dt)
602 {
603 case DataType::F32:
604 min = -1;
605 max = 1;
606 break;
607 case DataType::QS8:
608 min = -(1 << fixed_point_position);
609 max = (1 << fixed_point_position);
610 break;
611 default:
612 ARM_COMPUTE_ERROR("DataType not supported.");
613 }
614 std::uniform_real_distribution<> distribution(min, max);
615 library->fill(ref_src, distribution, 0.0);
616
617 // Compute reference
618 ReferenceCPP::pooling_layer(ref_src, ref_dst, pool_info, fixed_point_position);
619
620 return ref_dst;
621}
622
623RawTensor Reference::compute_reference_softmax_layer(const TensorShape &shape, DataType dt, int fixed_point_position)
624{
625 // Create reference
626 RawTensor ref_src = library->get(shape, dt, 1, fixed_point_position);
627 RawTensor ref_dst = library->get(shape, dt, 1, fixed_point_position);
628
629 // Fill reference
630 if(arm_compute::is_data_type_float(dt))
631 {
Georgios Pinitase5f8fd62017-06-23 18:03:44 +0100632 std::uniform_real_distribution<> distribution(-1000.f, 1000.f);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100633 library->fill(ref_src, distribution, 0);
634 }
635 else
636 {
637 int one_fixed = 1 << fixed_point_position;
638 std::uniform_int_distribution<> distribution(-one_fixed, one_fixed);
639 library->fill(ref_src, distribution, 0);
640 }
641
642 // Compute reference
643 ReferenceCPP::softmax_layer(ref_src, ref_dst);
644
645 return ref_dst;
646}
647
648RawTensor Reference::compute_reference_fixed_point_operation(const TensorShape &shape, DataType dt_in, DataType dt_out, FixedPointOp op, int fixed_point_position)
649{
650 // Create reference
651 RawTensor ref_src = library->get(shape, dt_in, 1, fixed_point_position);
652 RawTensor ref_dst = library->get(shape, dt_out, 1, fixed_point_position);
653
654 // Fill reference
655 int min = 0;
656 int max = 0;
657 switch(op)
658 {
659 case(FixedPointOp::INV_SQRT):
660 min = 32;
661 max = 127;
662 break;
663 case(FixedPointOp::LOG):
664 min = (1 << (fixed_point_position - 1));
665 max = 63;
666 break;
667 case(FixedPointOp::EXP):
668 min = 1;
669 max = (1 << (fixed_point_position - 1));
670 break;
671 case(FixedPointOp::RECIPROCAL):
672 min = 15;
673 max = 100;
674 break;
675 default:
676 ARM_COMPUTE_ERROR("Fixed point operation not supported");
677 }
678 std::uniform_int_distribution<> distribution(min, max);
679 library->fill(ref_src, distribution, 0);
680
681 // Compute reference
682 ReferenceCPP::fixed_point_operation(ref_src, ref_dst, op);
683
684 return ref_dst;
685}
686
687} // namespace validation
688} // namespace test
689} // namespace arm_compute