blob: 523b49deb777842e57789676404ce5aa7b5410bf [file] [log] [blame]
Isabella Gottardi1fab09f2017-07-13 15:55:57 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * 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/CL/functions/CLScale.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/CL/CLAccessor.h"
30#include "tests/PaddingCalculator.h"
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +010031#include "tests/datasets/ScaleValidationDataset.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010032#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010034#include "tests/validation/Helpers.h"
35#include "tests/validation/Validation.h"
36#include "tests/validation/fixtures/ScaleFixture.h"
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010037
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +010046using datasets::ScaleShapesBaseDataSet;
47using datasets::ScaleInterpolationPolicySet;
48using datasets::ScaleDataLayouts;
49using datasets::ScaleSamplingPolicySet;
50using datasets::ScaleAlignCornersSamplingPolicySet;
51
52/** We consider vector size in byte 16 since the maximum size of
53 * a vector used by @ref CLScaleKernel is currently 16-byte (float4).
54 */
55constexpr uint32_t vector_byte = 16;
56
57template <typename T>
58constexpr uint32_t num_elements_per_vector()
59{
60 return vector_byte / sizeof(T);
61}
62
Georgios Pinitas583137c2017-08-31 18:12:42 +010063/** CNN data types */
64const auto ScaleDataTypes = framework::dataset::make("DataType",
65{
66 DataType::U8,
67 DataType::S16,
68 DataType::F16,
69 DataType::F32,
70});
71
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +010072/** Quantization information data set */
73const auto QuantizationInfoSet = framework::dataset::make("QuantizationInfo",
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +000074{
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +010075 QuantizationInfo(0.5f, -1),
76});
Sang-Hoon Parkbb123bd2020-01-03 10:57:30 +000077
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010078/** Tolerance */
Manuel Bottini8481d832019-12-10 15:28:40 +000079constexpr AbsoluteTolerance<uint8_t> tolerance_q8(1);
80constexpr AbsoluteTolerance<int8_t> tolerance_qs8(1);
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +010081constexpr AbsoluteTolerance<int16_t> tolerance_s16(1);
Diego Lopez Recas00854292018-02-22 13:08:01 +000082constexpr float tolerance_f32_absolute(0.001f);
83
84RelativeTolerance<float> tolerance_f32(0.05);
85RelativeTolerance<half> tolerance_f16(half(0.1));
Moritz Pflanzerff1c3602017-09-22 12:41:25 +010086
87constexpr float tolerance_num_f32(0.01f);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010088} // namespace
89
90TEST_SUITE(CL)
91TEST_SUITE(Scale)
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +010092TEST_SUITE(Validate)
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010093
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +010094const auto default_input_shape = TensorShape{ 2, 3, 3, 2 };
95const auto default_output_shape = TensorShape{ 4, 6, 3, 2 };
Isabella Gottardi553b9992018-09-03 12:17:47 +010096
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +010097constexpr auto default_data_type = DataType::U8;
98constexpr auto default_data_layout = DataLayout::NHWC;
99constexpr auto default_interpolation_policy = InterpolationPolicy::NEAREST_NEIGHBOR;
100constexpr auto default_border_mode = BorderMode::UNDEFINED;
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100101constexpr bool default_use_padding = false;
102
103TEST_CASE(NullPtr, framework::DatasetMode::ALL)
Isabella Gottardi553b9992018-09-03 12:17:47 +0100104{
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100105 const auto input = TensorInfo{ default_input_shape, 1, default_data_type, default_data_layout };
106 const auto output = TensorInfo{ default_output_shape, 1, default_data_type, default_data_layout };
107 Status result{};
108
109 // nullptr is given as input
110 result = CLScale::validate(nullptr, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode });
111 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
112
113 // nullptr is given as output
114 result = CLScale::validate(&input, nullptr, ScaleKernelInfo{ default_interpolation_policy, default_border_mode });
115 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
Isabella Gottardi553b9992018-09-03 12:17:47 +0100116}
117
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100118TEST_CASE(SupportDataType, framework::DatasetMode::ALL)
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100119{
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100120 const std::map<DataType, bool> supported_data_types =
121 {
122 { DataType::U8, true },
123 { DataType::S8, false },
124 { DataType::QSYMM8, false },
125 { DataType::QASYMM8, true },
126 { DataType::QASYMM8_SIGNED, true },
127 { DataType::QSYMM8_PER_CHANNEL, false },
128 { DataType::U16, false },
129 { DataType::S16, true },
130 { DataType::QSYMM16, false },
131 { DataType::QASYMM16, false },
132 { DataType::U32, false },
133 { DataType::S32, false },
134 { DataType::U64, false },
135 { DataType::S64, false },
136 { DataType::BFLOAT16, false },
137 { DataType::F16, true },
138 { DataType::F32, true },
139 { DataType::F64, false },
140 { DataType::SIZET, false },
141 };
142 Status result{};
143 for(auto &kv : supported_data_types)
144 {
145 const auto input = TensorInfo{ default_input_shape, 1, kv.first, default_data_layout };
146 const auto output = TensorInfo{ default_output_shape, 1, kv.first, default_data_layout };
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100147
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100148 result = CLScale::validate(&input, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode });
149 ARM_COMPUTE_EXPECT(bool(result) == kv.second, framework::LogLevel::ERRORS);
150 }
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100151}
152
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100153TEST_CASE(SameInputOutput, framework::DatasetMode::ALL)
154{
155 const auto input = TensorInfo{ default_input_shape, 1, default_data_type, default_data_layout };
156 Status result{};
157
158 result = CLScale::validate(&input, &input, ScaleKernelInfo{ default_interpolation_policy, default_border_mode });
159 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
160}
161
162TEST_CASE(MissmatchingDataType, framework::DatasetMode::ALL)
163{
164 constexpr auto non_default_data_type = DataType::F32;
165
166 const auto input = TensorInfo{ default_input_shape, 1, default_data_type, default_data_layout };
167 const auto output = TensorInfo{ default_output_shape, 1, non_default_data_type, default_data_layout };
168 Status result{};
169
170 result = CLScale::validate(&input, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode });
171 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
172}
173
174TEST_CASE(AlignedCornerNotSupported, framework::DatasetMode::ALL)
175{
176 // Aligned corners require sampling policy to be TOP_LEFT.
177 constexpr auto interpolation_policy = InterpolationPolicy::BILINEAR;
178 constexpr bool align_corners = true;
179 constexpr auto sampling_policy = SamplingPolicy::CENTER;
180
181 const auto input = TensorInfo{ default_input_shape, 1, default_data_type, default_data_layout };
182 const auto output = TensorInfo{ default_output_shape, 1, default_data_type, default_data_layout };
183 Status result{};
184
185 result = CLScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode, PixelValue(), sampling_policy, default_use_padding, align_corners });
186 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
187}
188
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100189TEST_CASE(WindowShrink, framework::DatasetMode::ALL)
190{
191 const auto input = TensorInfo{ TensorShape(37U, 37U, 2U), 1, DataType::F32 };
192 const auto output = TensorInfo{ TensorShape(39U, 55U, 2U), 1, DataType::F32 };
193 Status result{};
194
195 result = CLScale::validate(&input.clone()->set_is_resizable(false), &output.clone()->set_is_resizable(false), ScaleKernelInfo{ default_interpolation_policy, default_border_mode });
196 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
197}
198
199TEST_CASE(IncorrectScaleFactor, framework::DatasetMode::ALL)
200{
201 const auto input = TensorInfo{ TensorShape(28U, 33U, 2U), 1, DataType::F32 };
202 const auto output = TensorInfo{ TensorShape(26U, 21U, 2U), 1, DataType::F32 };
203 constexpr auto interpolation_policy = InterpolationPolicy::AREA;
204 Status result{};
205
206 result = CLScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode });
207 ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS);
208}
209TEST_SUITE_END() // Validate
210
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100211template <typename T>
212using CLScaleFixture = ScaleValidationFixture<CLTensor, CLAccessor, CLScale, T>;
213
Georgios Pinitas583137c2017-08-31 18:12:42 +0100214TEST_SUITE(Float)
215TEST_SUITE(FP32)
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100216const auto f32_shape = combine((SCALE_PRECOMMIT_SHAPE_DATASET(num_elements_per_vector<float>())), framework::dataset::make("DataType", DataType::F32));
217FIXTURE_DATA_TEST_CASE(Run, CLScaleFixture<float>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f32_shape, ScaleSamplingPolicySet))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100218{
219 //Create valid region
220 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000221 const 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 +0100222
223 // Validate output
Diego Lopez Recas00854292018-02-22 13:08:01 +0000224 validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32, tolerance_f32_absolute);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100225}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100226FIXTURE_DATA_TEST_CASE(RunAlignCorners, CLScaleFixture<float>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f32_shape, ScaleAlignCornersSamplingPolicySet))
Sang-Hoon Parkf025a772020-05-26 11:11:32 +0100227{
228 //Create valid region
229 TensorInfo src_info(_shape, 1, _data_type);
230 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
231
232 // Validate output
233 validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32, tolerance_f32_absolute);
234}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100235const auto f32_nightly_shape = combine((SCALE_NIGHTLY_SHAPE_DATASET(num_elements_per_vector<float>())), framework::dataset::make("DataType", DataType::F32));
236FIXTURE_DATA_TEST_CASE(RunNightly, CLScaleFixture<float>, framework::DatasetMode::NIGHTLY, ASSEMBLE_DATASET(f32_nightly_shape, ScaleSamplingPolicySet))
Sang-Hoon Parkf025a772020-05-26 11:11:32 +0100237{
238 //Create valid region
239 TensorInfo src_info(_shape, 1, _data_type);
240 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
241
242 // Validate output
243 validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32, tolerance_f32_absolute);
244}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100245FIXTURE_DATA_TEST_CASE(RunNightlyAlignCorners, CLScaleFixture<float>, framework::DatasetMode::NIGHTLY, ASSEMBLE_DATASET(f32_nightly_shape, ScaleAlignCornersSamplingPolicySet))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100246{
247 //Create valid region
248 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000249 const 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 +0100250
251 // Validate output
Diego Lopez Recas00854292018-02-22 13:08:01 +0000252 validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32, tolerance_f32_absolute);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100253}
Michalis Spyrou17220e22018-09-12 13:35:38 +0100254TEST_SUITE_END() // FP32
Georgios Pinitas583137c2017-08-31 18:12:42 +0100255TEST_SUITE(FP16)
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100256const auto f16_shape = combine((SCALE_PRECOMMIT_SHAPE_DATASET(num_elements_per_vector<half>())), framework::dataset::make("DataType", DataType::F16));
257FIXTURE_DATA_TEST_CASE(Run, CLScaleFixture<half>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f16_shape, ScaleSamplingPolicySet))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100258{
259 //Create valid region
260 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000261 const 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 +0100262
263 // Validate output
264 validate(CLAccessor(_target), _reference, valid_region, tolerance_f16);
265}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100266FIXTURE_DATA_TEST_CASE(RunAlignCorners, CLScaleFixture<half>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f16_shape, ScaleAlignCornersSamplingPolicySet))
Sang-Hoon Parkf025a772020-05-26 11:11:32 +0100267{
268 //Create valid region
269 TensorInfo src_info(_shape, 1, _data_type);
270 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
271
272 // Validate output
273 validate(CLAccessor(_target), _reference, valid_region, tolerance_f16);
274}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100275const auto f16_nightly_shape = combine((SCALE_NIGHTLY_SHAPE_DATASET(num_elements_per_vector<half>())), framework::dataset::make("DataType", DataType::F16));
276FIXTURE_DATA_TEST_CASE(RunNightly, CLScaleFixture<half>, framework::DatasetMode::NIGHTLY, ASSEMBLE_DATASET(f16_nightly_shape, ScaleSamplingPolicySet))
Sang-Hoon Parkf025a772020-05-26 11:11:32 +0100277{
278 //Create valid region
279 TensorInfo src_info(_shape, 1, _data_type);
280 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
281
282 // Validate output
283 validate(CLAccessor(_target), _reference, valid_region, tolerance_f16);
284}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100285FIXTURE_DATA_TEST_CASE(RunNightlyAlignCorners, CLScaleFixture<half>, framework::DatasetMode::NIGHTLY, ASSEMBLE_DATASET(f16_nightly_shape, ScaleAlignCornersSamplingPolicySet))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100286{
287 //Create valid region
288 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000289 const 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 +0100290
291 // Validate output
292 validate(CLAccessor(_target), _reference, valid_region, tolerance_f16);
293}
Michalis Spyrou17220e22018-09-12 13:35:38 +0100294TEST_SUITE_END() // FP16
295TEST_SUITE_END() // Float
Georgios Pinitas583137c2017-08-31 18:12:42 +0100296
297TEST_SUITE(Integer)
298TEST_SUITE(U8)
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100299const auto u8_shape = combine((SCALE_PRECOMMIT_SHAPE_DATASET(num_elements_per_vector<uint8_t>())), framework::dataset::make("DataType", DataType::U8));
300FIXTURE_DATA_TEST_CASE(Run, CLScaleFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(u8_shape, ScaleSamplingPolicySet))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100301{
302 //Create valid region
303 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000304 const 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 +0100305
306 // Validate output
Manuel Bottini8481d832019-12-10 15:28:40 +0000307 validate(CLAccessor(_target), _reference, valid_region, tolerance_q8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100308}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100309FIXTURE_DATA_TEST_CASE(RunAlignCorners, CLScaleFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(u8_shape, ScaleAlignCornersSamplingPolicySet))
Sang-Hoon Parkf025a772020-05-26 11:11:32 +0100310{
311 //Create valid region
312 TensorInfo src_info(_shape, 1, _data_type);
313 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
314
315 // Validate output
316 validate(CLAccessor(_target), _reference, valid_region, tolerance_q8);
317}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100318const auto u8_nightly_shape = combine((SCALE_NIGHTLY_SHAPE_DATASET(num_elements_per_vector<uint8_t>())), framework::dataset::make("DataType", DataType::U8));
319FIXTURE_DATA_TEST_CASE(RunNightly, CLScaleFixture<uint8_t>, framework::DatasetMode::NIGHTLY, ASSEMBLE_DATASET(u8_nightly_shape, ScaleSamplingPolicySet))
Sang-Hoon Parkf025a772020-05-26 11:11:32 +0100320{
321 //Create valid region
322 TensorInfo src_info(_shape, 1, _data_type);
323 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
324
325 // Validate output
326 validate(CLAccessor(_target), _reference, valid_region, tolerance_q8);
327}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100328FIXTURE_DATA_TEST_CASE(RunNightlyAlignCorners, CLScaleFixture<uint8_t>, framework::DatasetMode::NIGHTLY, ASSEMBLE_DATASET(u8_nightly_shape, ScaleAlignCornersSamplingPolicySet))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100329{
330 //Create valid region
331 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000332 const 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 +0100333
334 // Validate output
Manuel Bottini8481d832019-12-10 15:28:40 +0000335 validate(CLAccessor(_target), _reference, valid_region, tolerance_q8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100336}
Michalis Spyrou17220e22018-09-12 13:35:38 +0100337TEST_SUITE_END() // U8
Georgios Pinitas583137c2017-08-31 18:12:42 +0100338TEST_SUITE(S16)
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100339const auto s16_shape = combine((SCALE_PRECOMMIT_SHAPE_DATASET(num_elements_per_vector<int16_t>())), framework::dataset::make("DataType", DataType::S16));
340FIXTURE_DATA_TEST_CASE(Run, CLScaleFixture<int16_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(s16_shape, ScaleSamplingPolicySet))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100341{
342 //Create valid region
343 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000344 const 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 +0100345
346 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100347 validate(CLAccessor(_target), _reference, valid_region, tolerance_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100348}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100349FIXTURE_DATA_TEST_CASE(RunAlignCorners, CLScaleFixture<int16_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(s16_shape, ScaleAlignCornersSamplingPolicySet))
Sang-Hoon Parkf025a772020-05-26 11:11:32 +0100350{
351 //Create valid region
352 TensorInfo src_info(_shape, 1, _data_type);
353 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
354
355 // Validate output
356 validate(CLAccessor(_target), _reference, valid_region, tolerance_s16);
357}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100358const auto s16_nightly_shape = combine((SCALE_NIGHTLY_SHAPE_DATASET(num_elements_per_vector<int16_t>())), framework::dataset::make("DataType", DataType::S16));
359FIXTURE_DATA_TEST_CASE(RunNightly, CLScaleFixture<int16_t>, framework::DatasetMode::NIGHTLY, ASSEMBLE_DATASET(s16_nightly_shape, ScaleSamplingPolicySet))
Sang-Hoon Parkf025a772020-05-26 11:11:32 +0100360{
361 //Create valid region
362 TensorInfo src_info(_shape, 1, _data_type);
363 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
364
365 // Validate output
366 validate(CLAccessor(_target), _reference, valid_region, tolerance_s16);
367}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100368FIXTURE_DATA_TEST_CASE(RunNightlyAlignCorners, CLScaleFixture<int16_t>, framework::DatasetMode::NIGHTLY, ASSEMBLE_DATASET(s16_nightly_shape, ScaleAlignCornersSamplingPolicySet))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100369{
370 //Create valid region
371 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000372 const 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 +0100373
374 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100375 validate(CLAccessor(_target), _reference, valid_region, tolerance_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100376}
Michalis Spyrou17220e22018-09-12 13:35:38 +0100377TEST_SUITE_END() // S16
378TEST_SUITE_END() // Integer
Georgios Pinitas583137c2017-08-31 18:12:42 +0100379
Michalis Spyrou17220e22018-09-12 13:35:38 +0100380template <typename T>
381using CLScaleQuantizedFixture = ScaleValidationQuantizedFixture<CLTensor, CLAccessor, CLScale, T>;
382TEST_SUITE(Quantized)
383TEST_SUITE(QASYMM8)
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100384const auto qasymm8_shape = combine((SCALE_PRECOMMIT_SHAPE_DATASET(num_elements_per_vector<uint8_t>())), framework::dataset::make("DataType", DataType::QASYMM8));
385FIXTURE_DATA_TEST_CASE(Run, CLScaleQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_shape, ScaleSamplingPolicySet, QuantizationInfoSet))
Michalis Spyrou17220e22018-09-12 13:35:38 +0100386{
387 //Create valid region
388 TensorInfo src_info(_shape, 1, _data_type);
389 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
390
391 // Validate output
Manuel Bottini8481d832019-12-10 15:28:40 +0000392 validate(CLAccessor(_target), _reference, valid_region, tolerance_q8);
Michalis Spyrou17220e22018-09-12 13:35:38 +0100393}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100394FIXTURE_DATA_TEST_CASE(RunAlignCorners, CLScaleQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_shape, ScaleAlignCornersSamplingPolicySet,
395 QuantizationInfoSet))
Sang-Hoon Parkf025a772020-05-26 11:11:32 +0100396{
397 //Create valid region
398 TensorInfo src_info(_shape, 1, _data_type);
399 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
400
401 // Validate output
402 validate(CLAccessor(_target), _reference, valid_region, tolerance_q8);
403}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100404const auto qasymm8_nightly_shape = combine((SCALE_NIGHTLY_SHAPE_DATASET(num_elements_per_vector<uint8_t>())), framework::dataset::make("DataType", DataType::QASYMM8));
405FIXTURE_DATA_TEST_CASE(RunNightly, CLScaleQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, ASSEMBLE_QUANTIZED_DATASET(qasymm8_nightly_shape, ScaleSamplingPolicySet, QuantizationInfoSet))
Sang-Hoon Parkf025a772020-05-26 11:11:32 +0100406{
407 //Create valid region
408 TensorInfo src_info(_shape, 1, _data_type);
409 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
410
411 // Validate output
412 validate(CLAccessor(_target), _reference, valid_region, tolerance_q8);
413}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100414FIXTURE_DATA_TEST_CASE(RunNightlyAlignCorners, CLScaleQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY, ASSEMBLE_QUANTIZED_DATASET(qasymm8_nightly_shape, ScaleAlignCornersSamplingPolicySet,
415 QuantizationInfoSet))
Michalis Spyrou17220e22018-09-12 13:35:38 +0100416{
417 //Create valid region
418 TensorInfo src_info(_shape, 1, _data_type);
419 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
420
421 // Validate output
Manuel Bottini8481d832019-12-10 15:28:40 +0000422 validate(CLAccessor(_target), _reference, valid_region, tolerance_q8);
Michalis Spyrou17220e22018-09-12 13:35:38 +0100423}
424TEST_SUITE_END() // QASYMM8
Manuel Bottini8481d832019-12-10 15:28:40 +0000425TEST_SUITE(QASYMM8_SIGNED)
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100426const auto qasymm8_signed_shape = combine((SCALE_PRECOMMIT_SHAPE_DATASET(num_elements_per_vector<int8_t>())), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED));
427FIXTURE_DATA_TEST_CASE(Run, CLScaleQuantizedFixture<int8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_signed_shape, ScaleSamplingPolicySet, QuantizationInfoSet))
Manuel Bottini8481d832019-12-10 15:28:40 +0000428{
429 //Create valid region
430 TensorInfo src_info(_shape, 1, _data_type);
431 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
432
433 // Validate output
434 validate(CLAccessor(_target), _reference, valid_region, tolerance_qs8);
435}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100436FIXTURE_DATA_TEST_CASE(RunAlignCorners, CLScaleQuantizedFixture<int8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_signed_shape, ScaleAlignCornersSamplingPolicySet,
437 QuantizationInfoSet))
Sang-Hoon Parkf025a772020-05-26 11:11:32 +0100438{
439 //Create valid region
440 TensorInfo src_info(_shape, 1, _data_type);
441 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
442
443 // Validate output
444 validate(CLAccessor(_target), _reference, valid_region, tolerance_qs8);
445}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100446const auto qasymm8_signed_nightly_shape = combine((SCALE_NIGHTLY_SHAPE_DATASET(num_elements_per_vector<int8_t>())), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED));
447FIXTURE_DATA_TEST_CASE(RunNightly, CLScaleQuantizedFixture<int8_t>, framework::DatasetMode::NIGHTLY, ASSEMBLE_QUANTIZED_DATASET(qasymm8_signed_nightly_shape, ScaleSamplingPolicySet,
448 QuantizationInfoSet))
Sang-Hoon Parkf025a772020-05-26 11:11:32 +0100449{
450 //Create valid region
451 TensorInfo src_info(_shape, 1, _data_type);
452 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
453
454 // Validate output
455 validate(CLAccessor(_target), _reference, valid_region, tolerance_qs8);
456}
Sang-Hoon Park27a9e4f2020-06-08 19:21:34 +0100457FIXTURE_DATA_TEST_CASE(RunNightlyAlignCorners, CLScaleQuantizedFixture<int8_t>, framework::DatasetMode::NIGHTLY, ASSEMBLE_QUANTIZED_DATASET(qasymm8_signed_nightly_shape,
458 ScaleAlignCornersSamplingPolicySet,
459 QuantizationInfoSet))
Manuel Bottini8481d832019-12-10 15:28:40 +0000460{
461 //Create valid region
462 TensorInfo src_info(_shape, 1, _data_type);
463 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED));
464
465 // Validate output
466 validate(CLAccessor(_target), _reference, valid_region, tolerance_qs8);
467}
468TEST_SUITE_END() // QASYMM8_SIGNED
Michalis Spyrou17220e22018-09-12 13:35:38 +0100469TEST_SUITE_END() // Quantized
470
471TEST_SUITE_END() // Scale
472TEST_SUITE_END() // CL
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100473} // namespace validation
474} // namespace test
475} // namespace arm_compute