blob: 9ab169b251f27d3e9ff9e8abdcadd0dc46cc7161 [file] [log] [blame]
Isabella Gottardi1fab09f2017-07-13 15:55:57 +01001/*
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +00002 * Copyright (c) 2017-2020 ARM Limited.
Isabella Gottardi1fab09f2017-07-13 15:55:57 +01003 *
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 "arm_compute/core/Helpers.h"
25#include "arm_compute/core/Types.h"
26#include "arm_compute/runtime/NEON/functions/NEScale.h"
27#include "arm_compute/runtime/Tensor.h"
28#include "arm_compute/runtime/TensorAllocator.h"
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010029#include "tests/NEON/Accessor.h"
30#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010031#include "tests/datasets/BorderModeDataset.h"
32#include "tests/datasets/InterpolationPolicyDataset.h"
Daniil Efremov02bf80d2017-11-22 00:26:51 +070033#include "tests/datasets/SamplingPolicyDataset.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010034#include "tests/datasets/ShapeDatasets.h"
35#include "tests/framework/Asserts.h"
36#include "tests/framework/Macros.h"
37#include "tests/framework/datasets/Datasets.h"
38#include "tests/validation/Helpers.h"
39#include "tests/validation/Validation.h"
40#include "tests/validation/fixtures/ScaleFixture.h"
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010041
42namespace arm_compute
43{
44namespace test
45{
46namespace validation
47{
Isabella Gottardi732f3682017-09-05 14:10:12 +010048namespace
49{
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +010050using test::datasets::ShapeDataset;
51
52/** Class to generate boundary values for the given template parameters
53 * including shapes with large differences between width and height
54 */
55template <uint32_t channel, uint32_t batch, uint32_t element_per_vector, uint32_t vector_size>
56class ScaleShapesBaseDataSet : public ShapeDataset
57{
58 static constexpr auto boundary_minus_one = element_per_vector * vector_size - 1;
59 static constexpr auto boundary_plus_one = element_per_vector * vector_size + 1;
60 static constexpr auto small_size = 3;
61
62public:
63 // These tensor shapes are NCHW layout, fixture will convert to NHWC.
64 ScaleShapesBaseDataSet()
65 : ShapeDataset("Shape",
66 {
67 TensorShape{ small_size, boundary_minus_one, channel, batch },
68 TensorShape{ small_size, boundary_plus_one, channel, batch },
69 TensorShape{ boundary_minus_one, small_size, channel, batch },
70 TensorShape{ boundary_plus_one, small_size, channel, batch },
71 TensorShape{ boundary_minus_one, boundary_plus_one, channel, batch },
72 TensorShape{ boundary_plus_one, boundary_minus_one, channel, batch },
73 })
74 {
75 }
76};
77
78/** For the single vector, only larger value (+1) than boundary
79 * since smaller value (-1) could cause some invalid shapes like
80 * - invalid zero size
81 * - size 1 which isn't compatible with scale with aligned corners.
82 */
83template <uint32_t channel, uint32_t batch, uint32_t element_per_vector>
84class ScaleShapesBaseDataSet<channel, batch, element_per_vector, 1> : public ShapeDataset
85{
86 static constexpr auto small_size = 3;
87 static constexpr auto boundary_plus_one = element_per_vector + 1;
88
89public:
90 // These tensor shapes are NCHW layout, fixture will convert to NHWC.
91 ScaleShapesBaseDataSet()
92 : ShapeDataset("Shape",
93 {
94 TensorShape{ small_size, boundary_plus_one, channel, batch },
95 TensorShape{ boundary_plus_one, small_size, channel, batch },
96 })
97 {
98 }
99};
100
101/** For the shapes smaller than one vector, only pre-defined tiny shapes
102 * are tested (3x2, 2x3) as smaller shapes are more likely to cause
103 * issues and easier to debug.
104 */
105template <uint32_t channel, uint32_t batch, uint32_t element_per_vector>
106class ScaleShapesBaseDataSet<channel, batch, element_per_vector, 0> : public ShapeDataset
107{
108 static constexpr auto small_size = 3;
109 static constexpr auto zero_vector_boundary_value = 2;
110
111public:
112 // These tensor shapes are NCHW layout, fixture will convert to NHWC.
113 ScaleShapesBaseDataSet()
114 : ShapeDataset("Shape",
115 {
116 TensorShape{ small_size, zero_vector_boundary_value, channel, batch },
117 TensorShape{ zero_vector_boundary_value, small_size, channel, batch },
118 })
119 {
120 }
121};
122
123/** Generated shaeps
124 * - 2D shapes with 0, 1, 2 vector iterations
125 * - 3D shapes with 0, 1 vector iterations
126 * - 4D shapes with 0 vector iterations
127 */
128#define SCALE_SHAPE_DATASET(element_per_vector) \
129 concat(concat(concat(concat(concat(ScaleShapesBaseDataSet<1, 1, (element_per_vector), 0>(), \
130 ScaleShapesBaseDataSet<1, 1, (element_per_vector), 1>()), \
131 ScaleShapesBaseDataSet<1, 1, (element_per_vector), 2>()), \
132 ScaleShapesBaseDataSet<3, 3, (element_per_vector), 0>()), \
133 ScaleShapesBaseDataSet<3, 3, (element_per_vector), 1>()), \
134 ScaleShapesBaseDataSet<3, 7, (element_per_vector), 0>())
135
136/** We consider vector size in byte 64 since the maximum size of
137 * a vector used by @ref ScaleKernelInfo is currently 64-byte (float32x4x4).
138 * There are possibility to reduce test time further by using
139 * smaller vector sizes for different data types where applicable.
140 */
141constexpr uint32_t vector_byte = 64;
142
143template <typename T>
144constexpr uint32_t num_elements_per_vector()
145{
146 return vector_byte / sizeof(T);
147}
148
Georgios Pinitas583137c2017-08-31 18:12:42 +0100149/** Scale data types */
150const auto ScaleDataTypes = framework::dataset::make("DataType",
151{
152 DataType::U8,
153 DataType::S16,
154 DataType::F32,
155});
156
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100157/** Interpolation policy test set */
158const auto InterpolationPolicySet = framework::dataset::make("InterpolationPolicy",
159{
160 InterpolationPolicy::NEAREST_NEIGHBOR,
161 InterpolationPolicy::BILINEAR,
162});
163
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100164/** Scale data types */
165const auto ScaleDataLayouts = framework::dataset::make("DataLayout",
166{
167 DataLayout::NCHW,
168 DataLayout::NHWC,
169});
170
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100171/** Sampling policy data set */
172const auto SamplingPolicySet = framework::dataset::make("SamplingPolicy",
173{
174 SamplingPolicy::TOP_LEFT,
175 SamplingPolicy::CENTER,
176});
177
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +0000178/** Align corners */
179const auto AlignCorners = framework::dataset::make("AlignCorners",
180{
181 false,
182 true,
183});
184
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100185/** Generating dataset for non-quantized data tyeps with the given shapes */
186#define ASSEMBLE_DATASET(shape) \
187 combine(combine(combine(combine(combine((shape), ScaleDataLayouts), \
188 InterpolationPolicySet), \
189 datasets::BorderModes()), \
190 SamplingPolicySet), \
191 AlignCorners)
192
193/** Quantization information data set */
194const auto QuantizationInfoSet = framework::dataset::make("QuantizationInfo",
195{
196 QuantizationInfo(0.5f, -10),
197});
198
199/** Generating dataset for quantized data tyeps with the given shapes */
200#define ASSEMBLE_QUANTIZED_DATASET(shape) \
201 combine(combine(combine(combine(combine(combine(shape, \
202 QuantizationInfoSet), \
203 ScaleDataLayouts), \
204 InterpolationPolicySet), \
205 datasets::BorderModes()), \
206 SamplingPolicySet), \
207 AlignCorners)
208
Georgios Pinitas583137c2017-08-31 18:12:42 +0100209/** Tolerance */
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100210constexpr AbsoluteTolerance<uint8_t> tolerance_u8(1);
211constexpr AbsoluteTolerance<int16_t> tolerance_s16(1);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100212RelativeTolerance<float> tolerance_f32(0.01);
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000213#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
214RelativeTolerance<half> tolerance_f16(half(0.1));
215#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100216
217constexpr float tolerance_num_s16 = 0.01f;
218constexpr float tolerance_num_f32 = 0.01f;
Isabella Gottardi732f3682017-09-05 14:10:12 +0100219} // namespace
220
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100221TEST_SUITE(NEON)
222TEST_SUITE(Scale)
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100223TEST_SUITE(Validate)
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100224
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100225/** Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros
226 * we use to check the validity of given arguments in @ref NEScale
227 * and subsequent call to @ref NEScaleKernel.
228 * Since this is using validate() of @ref NEScale, which pre-adjust
229 * arguments for @ref NEScaleKernel, the following conditions in
230 * the kernel are not currently tested.
231 * - The same input and output
232 * - Data type of offset, dx and dy
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100233 * This suite also tests two different validate() APIs - one is
234 * using @ref ScaleKernelInfo and the other one is more verbose
235 * one calls the other one - in the same test case. Even though
236 * there are possibility that it makes debugging for regression
237 * harder, belows are reasons of this test case implementation.
238 * - The more verbose one is just a wrapper function calls
239 * the other one without any additional logic. So we are
240 * safe to merge two tests into one.
241 * - A large amount of code duplication is test suite can be prevented.
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100242 */
243
244const auto input_shape = TensorShape{ 2, 3, 3, 2 };
245const auto output_shape = TensorShape{ 4, 6, 3, 2 };
246
247constexpr auto default_data_type = DataType::U8;
248constexpr auto default_data_layout = DataLayout::NHWC;
249constexpr auto default_interpolation_policy = InterpolationPolicy::NEAREST_NEIGHBOR;
250constexpr auto default_border_mode = BorderMode::UNDEFINED;
251constexpr auto default_sampling_policy = SamplingPolicy::CENTER;
252constexpr bool default_use_padding = false;
253
254TEST_CASE(NullPtr, framework::DatasetMode::ALL)
Georgios Pinitas20b43132018-05-14 16:05:23 +0100255{
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100256 const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout };
257 const auto output = TensorInfo{ output_shape, 1, default_data_type, default_data_layout };
258 Status result{};
Georgios Pinitas20b43132018-05-14 16:05:23 +0100259
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100260 // nullptr is given as input
261 result = NEScale::validate(nullptr, &output, default_interpolation_policy, default_border_mode);
262 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
263
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100264 result = NEScale::validate(nullptr, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode });
265 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
266
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100267 // nullptr is given as output
268 result = NEScale::validate(&input, nullptr, default_interpolation_policy, default_border_mode);
269 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100270
271 result = NEScale::validate(&input, nullptr, ScaleKernelInfo{ default_interpolation_policy, default_border_mode });
272 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100273}
274
275TEST_CASE(SupportDataType, framework::DatasetMode::ALL)
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100276{
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100277 const std::map<DataType, bool> supported_data_types =
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100278 {
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100279 { DataType::U8, true },
280 { DataType::S8, false },
281 { DataType::QSYMM8, false },
282 { DataType::QASYMM8, true },
283 { DataType::QASYMM8_SIGNED, true },
284 { DataType::QSYMM8_PER_CHANNEL, false },
285 { DataType::U16, false },
286 { DataType::S16, true },
287 { DataType::QSYMM16, false },
288 { DataType::QASYMM16, false },
289 { DataType::U32, false },
290 { DataType::S32, false },
291 { DataType::U64, false },
292 { DataType::S64, false },
293 { DataType::BFLOAT16, false },
294#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
295 { DataType::F16, true },
296#else // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
297 { DataType::F16, false },
298#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
299 { DataType::F32, true },
300 { DataType::F64, false },
301 { DataType::SIZET, false },
302 };
303 Status result{};
304 for(auto &kv : supported_data_types)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100305 {
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100306 const auto input = TensorInfo{ input_shape, 1, kv.first, default_data_layout };
307 const auto output = TensorInfo{ output_shape, 1, kv.first, default_data_layout };
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100308
309 result = NEScale::validate(&input, &output, default_interpolation_policy, default_border_mode);
310 ARM_COMPUTE_EXPECT(bool(result) == kv.second, framework::LogLevel::ERRORS);
311
312 result = NEScale::validate(&input, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode });
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100313 ARM_COMPUTE_EXPECT(bool(result) == kv.second, framework::LogLevel::ERRORS);
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100314 }
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100315}
316
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100317TEST_CASE(MissmatchingDataType, framework::DatasetMode::ALL)
318{
319 constexpr auto non_default_data_type = DataType::F32;
320
321 const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout };
322 const auto output = TensorInfo{ output_shape, 1, non_default_data_type, default_data_layout };
323 Status result{};
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100324
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100325 result = NEScale::validate(&input, &output, default_interpolation_policy, default_border_mode);
326 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100327
328 result = NEScale::validate(&input, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode });
329 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100330}
331
332TEST_CASE(UsePadding, framework::DatasetMode::ALL)
333{
334 const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout };
335 const auto output = TensorInfo{ output_shape, 1, default_data_type, default_data_layout };
336 Status result{};
337
338 // When use padding is false, border mode should be constant
339 constexpr auto border_mode = BorderMode::UNDEFINED;
340 constexpr bool use_padding = false;
341
342 result = NEScale::validate(&input, &output, default_interpolation_policy, border_mode, PixelValue(), default_sampling_policy, use_padding);
343 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100344
345 result = NEScale::validate(&input, &output, ScaleKernelInfo{ default_interpolation_policy, border_mode, PixelValue(), default_sampling_policy, use_padding });
346 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100347}
348
349TEST_CASE(AreaWithNHWC, framework::DatasetMode::ALL)
350{
351 // InterpolationPolicy::AREA is not supported for NHWC
352 constexpr auto interpolation_policy = InterpolationPolicy::AREA;
353 constexpr auto data_layout = DataLayout::NHWC;
354
355 const auto input = TensorInfo{ input_shape, 1, default_data_type, data_layout };
356 const auto output = TensorInfo{ output_shape, 1, default_data_type, data_layout };
357 Status result{};
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100358
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100359 result = NEScale::validate(&input, &output, interpolation_policy, default_border_mode);
360 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100361
362 result = NEScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode });
363 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100364}
365
366TEST_CASE(AreaWithNonU8, framework::DatasetMode::ALL)
367{
368 // InterpolationPolicy::AREA only supports U8
369 constexpr auto interpolation_policy = InterpolationPolicy::AREA;
370 constexpr auto data_type = DataType::F32;
371 constexpr auto data_layout = DataLayout::NCHW;
372
373 const auto input = TensorInfo{ input_shape, 1, data_type, data_layout };
374 const auto output = TensorInfo{ output_shape, 1, data_type, data_layout };
375 Status result{};
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100376
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100377 result = NEScale::validate(&input, &output, interpolation_policy, default_border_mode);
378 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100379
380 result = NEScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode });
381 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100382}
383
384TEST_CASE(InvalidAlignedCornerOutput, framework::DatasetMode::ALL)
385{
386 // Bilinear with aligned corners require at least 2x2 output to prevent overflow.
387 // Also, aligned corners require sampling policy to be TOP_LEFT.
388 constexpr auto interpolation_policy = InterpolationPolicy::BILINEAR;
389 constexpr bool align_corners = true;
390 constexpr auto sampling_policy = SamplingPolicy::TOP_LEFT;
391 const auto invalid_output_shape = TensorShape{ 1, 1, 3, 2 };
392
393 const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout };
394 const auto output = TensorInfo{ invalid_output_shape, 1, default_data_type, default_data_layout };
395 Status result{};
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100396
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100397 result = NEScale::validate(&input, &output, interpolation_policy, default_border_mode, PixelValue(), sampling_policy, default_use_padding, align_corners);
398 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100399
Sang-Hoon Parkc2617982020-05-20 22:13:47 +0100400 result = NEScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode, PixelValue(), sampling_policy, default_use_padding, align_corners });
401 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
402}
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100403TEST_SUITE_END() // Validate
404
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100405template <typename T>
406using NEScaleFixture = ScaleValidationFixture<Tensor, Accessor, NEScale, T>;
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000407template <typename T>
408using NEScaleQuantizedFixture = ScaleValidationQuantizedFixture<Tensor, Accessor, NEScale, T>;
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100409
Georgios Pinitas583137c2017-08-31 18:12:42 +0100410TEST_SUITE(Float)
411TEST_SUITE(FP32)
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100412const auto f32_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<float>())), framework::dataset::make("DataType", DataType::F32));
413FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<float>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f32_shape))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100414{
415 //Create valid region
416 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000417 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
Georgios Pinitas583137c2017-08-31 18:12:42 +0100418
419 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100420 validate(Accessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100421}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000422TEST_SUITE_END() // FP32
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000423#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
424TEST_SUITE(FP16)
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100425const auto f16_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<half>())), framework::dataset::make("DataType", DataType::F16));
426FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<half>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f16_shape))
Georgios Pinitasc47ef202018-11-16 18:19:43 +0000427{
428 //Create valid region
429 TensorInfo src_info(_shape, 1, _data_type);
430 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
431
432 // Validate output
433 validate(Accessor(_target), _reference, valid_region, tolerance_f16);
434}
435TEST_SUITE_END() // FP16
436#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000437TEST_SUITE_END() // Float
Georgios Pinitas583137c2017-08-31 18:12:42 +0100438
439TEST_SUITE(Integer)
440TEST_SUITE(U8)
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100441const auto u8_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<uint8_t>())), framework::dataset::make("DataType", DataType::U8));
442FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(u8_shape))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100443{
444 //Create valid region
445 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000446 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100447
448 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100449 validate(Accessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100450}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000451TEST_SUITE_END() // U8
Georgios Pinitas583137c2017-08-31 18:12:42 +0100452TEST_SUITE(S16)
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100453const auto s16_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<int16_t>())), framework::dataset::make("DataType", DataType::S16));
454FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<int16_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(s16_shape))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100455{
456 //Create valid region
457 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000458 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
Georgios Pinitas583137c2017-08-31 18:12:42 +0100459
460 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100461 validate(Accessor(_target), _reference, valid_region, tolerance_s16, tolerance_num_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100462}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000463TEST_SUITE_END() // S16
464TEST_SUITE_END() // Integer
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100465
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000466TEST_SUITE(Quantized)
467TEST_SUITE(QASYMM8)
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100468const auto qasymm8_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<uint8_t>())), framework::dataset::make("DataType", DataType::QASYMM8));
469FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_shape))
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000470{
471 //Create valid region
472 TensorInfo src_info(_shape, 1, _data_type);
473 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
474
475 // Validate output
476 validate(Accessor(_target), _reference, valid_region, tolerance_u8);
477}
478TEST_SUITE_END() // QASYMM8
Sheri Zhang359c48e2020-04-30 22:53:39 +0100479TEST_SUITE(QASYMM8_SIGNED)
Sang-Hoon Parkc72dabc2020-05-27 13:03:18 +0100480const auto qasymm8_signed_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<int8_t>())), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED));
481FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleQuantizedFixture<int8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_signed_shape))
Sheri Zhang359c48e2020-04-30 22:53:39 +0100482{
483 //Create valid region
484 TensorInfo src_info(_shape, 1, _data_type);
485 ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
486
487 // Validate output
488 validate(Accessor(_target), _reference, valid_region, tolerance_u8);
489}
490TEST_SUITE_END() // QASYMM8_SIGNED
Vidhya Sudhan Loganathan3ac2f3a2019-01-17 15:16:19 +0000491TEST_SUITE_END() // Quantized
492
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000493TEST_SUITE_END() // Scale
494TEST_SUITE_END() // NEON
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100495} // namespace validation
496} // namespace test
497} // namespace arm_compute