blob: 92d4f96c6ab8bf88fdbe771ca6939e58b620db43 [file] [log] [blame]
Isabella Gottardi1fab09f2017-07-13 15:55:57 +01001/*
Diego Lopez Recasff860cf2018-02-22 13:08:01 +00002 * Copyright (c) 2017-2018 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"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010031#include "tests/datasets/BorderModeDataset.h"
Daniil Efremov02bf80d2017-11-22 00:26:51 +070032#include "tests/datasets/SamplingPolicyDataset.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010033#include "tests/datasets/ShapeDatasets.h"
34#include "tests/framework/Asserts.h"
35#include "tests/framework/Macros.h"
36#include "tests/framework/datasets/Datasets.h"
37#include "tests/validation/Helpers.h"
38#include "tests/validation/Validation.h"
39#include "tests/validation/fixtures/ScaleFixture.h"
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010040
41namespace arm_compute
42{
43namespace test
44{
45namespace validation
46{
47namespace
48{
Georgios Pinitas583137c2017-08-31 18:12:42 +010049/** CNN data types */
50const auto ScaleDataTypes = framework::dataset::make("DataType",
51{
52 DataType::U8,
53 DataType::S16,
54 DataType::F16,
55 DataType::F32,
56});
57
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010058/** Tolerance */
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +010059constexpr AbsoluteTolerance<uint8_t> tolerance_u8(1);
60constexpr AbsoluteTolerance<int16_t> tolerance_s16(1);
Diego Lopez Recas00854292018-02-22 13:08:01 +000061constexpr float tolerance_f32_absolute(0.001f);
62
63RelativeTolerance<float> tolerance_f32(0.05);
64RelativeTolerance<half> tolerance_f16(half(0.1));
Moritz Pflanzerff1c3602017-09-22 12:41:25 +010065
66constexpr float tolerance_num_f32(0.01f);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010067} // namespace
68
69TEST_SUITE(CL)
70TEST_SUITE(Scale)
71
Isabella Gottardi553b9992018-09-03 12:17:47 +010072// *INDENT-OFF*
73// clang-format off
74
75DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
76 framework::dataset::make("InputInfo",{ TensorInfo(TensorShape(28U, 32U, 2U), 1, DataType::F16),
77 TensorInfo(TensorShape(28U, 32U, 2U), 1, DataType::F32),
78 TensorInfo(TensorShape(36U, 36U, 2U, 4U), 1, DataType::U8),
79 TensorInfo(TensorShape(40U, 35U, 2U, 4U), 1, DataType::S16),
80 TensorInfo(TensorShape(37U, 37U, 2U), 1, DataType::F32), // window shrink
81 TensorInfo(TensorShape(128U, 64U, 1U, 3U), 1, DataType::QASYMM8), // not supported
82 TensorInfo(TensorShape(37U, 37U, 3U, 4U), 1, DataType::F32), // mismatching datatype
83 TensorInfo(TensorShape(28U, 33U, 2U), 1, DataType::F32), // policy area, scale factor not correct
84 }),
85 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 68U, 2U), 1, DataType::F16),
86 TensorInfo(TensorShape(40U, 56U, 2U), 1, DataType::F32),
87 TensorInfo(TensorShape(40U, 76U, 2U, 4U), 1, DataType::U8),
88 TensorInfo(TensorShape(28U, 32U, 2U, 4U), 1, DataType::S16),
89 TensorInfo(TensorShape(39U, 55U, 2U), 1, DataType::F32), // window shrink
90 TensorInfo(TensorShape(137U, 134U, 1U, 3U), 1, DataType::QASYMM8), // not supported
91 TensorInfo(TensorShape(39U, 77U, 3U, 4U), 1, DataType::F16), // mismatching datatype
92 TensorInfo(TensorShape(26U, 21U, 2U), 1, DataType::F32), // policy area, scale factor not correct
93 })),
94 framework::dataset::make("Policy",{ InterpolationPolicy::BILINEAR,
95 InterpolationPolicy::BILINEAR,
96 InterpolationPolicy::NEAREST_NEIGHBOR,
97 InterpolationPolicy::NEAREST_NEIGHBOR,
98 InterpolationPolicy::NEAREST_NEIGHBOR,
99 InterpolationPolicy::BILINEAR,
100 InterpolationPolicy::BILINEAR,
101 InterpolationPolicy::AREA,
102 })),
103 framework::dataset::make("BorderMode",{ BorderMode::UNDEFINED,
104 BorderMode::UNDEFINED,
105 BorderMode::UNDEFINED,
106 BorderMode::UNDEFINED,
107 BorderMode::UNDEFINED,
108 BorderMode::UNDEFINED,
109 BorderMode::UNDEFINED,
110 BorderMode::UNDEFINED,
111 })),
112 framework::dataset::make("Expected", { true, true, true, true, false, false, false, false })),
113input_info, output_info, policy, border_mode, expected)
114{
115 Status status = CLScale::validate(&input_info.clone()->set_is_resizable(false),
116 &output_info.clone()->set_is_resizable(false), policy, border_mode);
117 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
118}
119
120// clang-format on
121// *INDENT-ON*
122
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700123DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(concat(datasets::MediumShapes(), datasets::LargeShapes()), ScaleDataTypes),
124 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
125 datasets::BorderModes()),
126 datasets::SamplingPolicies()),
127 shape, data_type, policy, border_mode, sampling_policy)
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100128{
129 std::mt19937 generator(library->seed());
130 std::uniform_real_distribution<float> distribution_float(0.25, 2);
131 const float scale_x = distribution_float(generator);
132 const float scale_y = distribution_float(generator);
133 std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
134 uint8_t constant_border_value = distribution_u8(generator);
135
136 // Create tensors
137 CLTensor src = create_tensor<CLTensor>(shape, data_type);
138 TensorShape shape_scaled(shape);
139 shape_scaled.set(0, shape[0] * scale_x);
140 shape_scaled.set(1, shape[1] * scale_y);
141 CLTensor dst = create_tensor<CLTensor>(shape_scaled, data_type);
142
143 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
144 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
145
146 // Create and configure function
147 CLScale clscale;
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700148 clscale.configure(&src, &dst, policy, border_mode, constant_border_value, sampling_policy);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100149
Daniil Efremov7a49c792017-11-14 21:25:34 +0700150 // Get border size depending on border mode
151 const BorderSize border_size(border_mode == BorderMode::UNDEFINED ? 0 : 1);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100152
Daniil Efremov7a49c792017-11-14 21:25:34 +0700153 // Validate valid region
Diego Lopez Recas00854292018-02-22 13:08:01 +0000154 const ValidRegion dst_valid_region = calculate_valid_region_scale(*(src.info()), shape_scaled, policy, sampling_policy, (border_mode == BorderMode::UNDEFINED));
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100155 validate(dst.info()->valid_region(), dst_valid_region);
156
157 // Validate padding
158 PaddingCalculator calculator(shape_scaled.x(), 4);
159 calculator.set_border_mode(border_mode);
160
Daniil Efremov7a49c792017-11-14 21:25:34 +0700161 const PaddingSize read_padding(border_size);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100162 const PaddingSize write_padding = calculator.required_padding(PaddingCalculator::Option::EXCLUDE_BORDER);
163 validate(src.info()->padding(), read_padding);
164 validate(dst.info()->padding(), write_padding);
165}
166
167template <typename T>
168using CLScaleFixture = ScaleValidationFixture<CLTensor, CLAccessor, CLScale, T>;
169
Georgios Pinitas583137c2017-08-31 18:12:42 +0100170TEST_SUITE(Float)
171TEST_SUITE(FP32)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100172FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
173 DataType::F32)),
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100174 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700175 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
176 datasets::BorderModes()),
177 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100178{
179 //Create valid region
180 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000181 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 +0100182
183 // Validate output
Diego Lopez Recas00854292018-02-22 13:08:01 +0000184 validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32, tolerance_f32_absolute);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100185}
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100186FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
187 DataType::F32)),
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100188 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700189 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
190 datasets::BorderModes()),
191 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100192{
193 //Create valid region
194 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000195 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 +0100196
197 // Validate output
Diego Lopez Recas00854292018-02-22 13:08:01 +0000198 validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32, tolerance_f32_absolute);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100199}
200TEST_SUITE_END()
201TEST_SUITE(FP16)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100202FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
203 DataType::F16)),
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100204 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700205 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
206 datasets::BorderModes()),
207 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100208{
209 //Create valid region
210 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000211 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 +0100212
213 // Validate output
214 validate(CLAccessor(_target), _reference, valid_region, tolerance_f16);
215}
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100216FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700217 DataType::F16)),
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100218 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700219 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
220 datasets::BorderModes()),
221 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100222{
223 //Create valid region
224 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000225 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 +0100226
227 // Validate output
228 validate(CLAccessor(_target), _reference, valid_region, tolerance_f16);
229}
230TEST_SUITE_END()
231TEST_SUITE_END()
232
233TEST_SUITE(Integer)
234TEST_SUITE(U8)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100235FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
236 DataType::U8)),
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100237 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700238 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
239 datasets::BorderModes()),
240 datasets::SamplingPolicies()))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100241{
242 //Create valid region
243 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000244 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 +0100245
246 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100247 validate(CLAccessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100248}
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100249FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
250 DataType::U8)),
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100251 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700252 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
253 datasets::BorderModes()),
254 datasets::SamplingPolicies()))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100255{
256 //Create valid region
257 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000258 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 +0100259
260 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100261 validate(CLAccessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100262}
263TEST_SUITE_END()
Georgios Pinitas583137c2017-08-31 18:12:42 +0100264TEST_SUITE(S16)
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100265FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
266 DataType::S16)),
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100267 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700268 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
269 datasets::BorderModes()),
270 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100271{
272 //Create valid region
273 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000274 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 +0100275
276 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100277 validate(CLAccessor(_target), _reference, valid_region, tolerance_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100278}
Georgios Pinitas393fa4c2018-05-08 15:54:53 +0100279FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700280 DataType::S16)),
Michalis Spyrou46da23f2018-04-10 13:41:30 +0100281 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700282 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
283 datasets::BorderModes()),
284 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100285{
286 //Create valid region
287 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000288 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 +0100289
290 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100291 validate(CLAccessor(_target), _reference, valid_region, tolerance_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100292}
293TEST_SUITE_END()
294TEST_SUITE_END()
295
296TEST_SUITE_END()
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100297TEST_SUITE_END()
298} // namespace validation
299} // namespace test
300} // namespace arm_compute