blob: aeda33b7c69a5f5139d834179abb939a7977e866 [file] [log] [blame]
Isabella Gottardi1fab09f2017-07-13 15:55:57 +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 "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);
steniu01f81652d2017-09-11 15:29:12 +010061RelativeTolerance<float> tolerance_f32(0.05);
Georgios Pinitas583137c2017-08-31 18:12:42 +010062RelativeTolerance<half> tolerance_f16(half(0.1));
Moritz Pflanzerff1c3602017-09-22 12:41:25 +010063
64constexpr float tolerance_num_f32(0.01f);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010065} // namespace
66
67TEST_SUITE(CL)
68TEST_SUITE(Scale)
69
Daniil Efremov02bf80d2017-11-22 00:26:51 +070070DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(concat(datasets::MediumShapes(), datasets::LargeShapes()), ScaleDataTypes),
71 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
72 datasets::BorderModes()),
73 datasets::SamplingPolicies()),
74 shape, data_type, policy, border_mode, sampling_policy)
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010075{
76 std::mt19937 generator(library->seed());
77 std::uniform_real_distribution<float> distribution_float(0.25, 2);
78 const float scale_x = distribution_float(generator);
79 const float scale_y = distribution_float(generator);
80 std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
81 uint8_t constant_border_value = distribution_u8(generator);
82
83 // Create tensors
84 CLTensor src = create_tensor<CLTensor>(shape, data_type);
85 TensorShape shape_scaled(shape);
86 shape_scaled.set(0, shape[0] * scale_x);
87 shape_scaled.set(1, shape[1] * scale_y);
88 CLTensor dst = create_tensor<CLTensor>(shape_scaled, data_type);
89
90 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
91 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
92
93 // Create and configure function
94 CLScale clscale;
Daniil Efremov02bf80d2017-11-22 00:26:51 +070095 clscale.configure(&src, &dst, policy, border_mode, constant_border_value, sampling_policy);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010096
Daniil Efremov7a49c792017-11-14 21:25:34 +070097 // Get border size depending on border mode
98 const BorderSize border_size(border_mode == BorderMode::UNDEFINED ? 0 : 1);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010099
Daniil Efremov7a49c792017-11-14 21:25:34 +0700100 // Validate valid region
101 const ValidRegion dst_valid_region = calculate_valid_region_scale(*(src.info()), shape_scaled, policy, border_size, (border_mode == BorderMode::UNDEFINED));
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100102 validate(dst.info()->valid_region(), dst_valid_region);
103
104 // Validate padding
105 PaddingCalculator calculator(shape_scaled.x(), 4);
106 calculator.set_border_mode(border_mode);
107
Daniil Efremov7a49c792017-11-14 21:25:34 +0700108 const PaddingSize read_padding(border_size);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100109 const PaddingSize write_padding = calculator.required_padding(PaddingCalculator::Option::EXCLUDE_BORDER);
110 validate(src.info()->padding(), read_padding);
111 validate(dst.info()->padding(), write_padding);
112}
113
114template <typename T>
115using CLScaleFixture = ScaleValidationFixture<CLTensor, CLAccessor, CLScale, T>;
116
Georgios Pinitas583137c2017-08-31 18:12:42 +0100117TEST_SUITE(Float)
118TEST_SUITE(FP32)
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700119FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)),
120 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
121 datasets::BorderModes()),
122 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100123{
124 //Create valid region
125 TensorInfo src_info(_shape, 1, _data_type);
126 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
127
128 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100129 validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100130}
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700131FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F32)),
132 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
133 datasets::BorderModes()),
134 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100135{
136 //Create valid region
137 TensorInfo src_info(_shape, 1, _data_type);
138 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
139
140 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100141 validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100142}
143TEST_SUITE_END()
144TEST_SUITE(FP16)
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700145FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)),
146 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
147 datasets::BorderModes()),
148 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100149{
150 //Create valid region
151 TensorInfo src_info(_shape, 1, _data_type);
152 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
153
154 // Validate output
155 validate(CLAccessor(_target), _reference, valid_region, tolerance_f16);
156}
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700157FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
158 DataType::F16)),
159 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
160 datasets::BorderModes()),
161 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100162{
163 //Create valid region
164 TensorInfo src_info(_shape, 1, _data_type);
165 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
166
167 // Validate output
168 validate(CLAccessor(_target), _reference, valid_region, tolerance_f16);
169}
170TEST_SUITE_END()
171TEST_SUITE_END()
172
173TEST_SUITE(Integer)
174TEST_SUITE(U8)
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700175FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::U8)),
176 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
177 datasets::BorderModes()),
178 datasets::SamplingPolicies()))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100179{
180 //Create valid region
181 TensorInfo src_info(_shape, 1, _data_type);
182 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
183
184 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100185 validate(CLAccessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100186}
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700187FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::U8)),
188 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
189 datasets::BorderModes()),
190 datasets::SamplingPolicies()))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100191{
192 //Create valid region
193 TensorInfo src_info(_shape, 1, _data_type);
194 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
195
196 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100197 validate(CLAccessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100198}
199TEST_SUITE_END()
Georgios Pinitas583137c2017-08-31 18:12:42 +0100200TEST_SUITE(S16)
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700201FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::S16)),
202 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
203 datasets::BorderModes()),
204 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100205{
206 //Create valid region
207 TensorInfo src_info(_shape, 1, _data_type);
208 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
209
210 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100211 validate(CLAccessor(_target), _reference, valid_region, tolerance_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100212}
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700213FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
214 DataType::S16)),
215 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
216 datasets::BorderModes()),
217 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100218{
219 //Create valid region
220 TensorInfo src_info(_shape, 1, _data_type);
221 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
222
223 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100224 validate(CLAccessor(_target), _reference, valid_region, tolerance_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100225}
226TEST_SUITE_END()
227TEST_SUITE_END()
228
229TEST_SUITE_END()
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100230TEST_SUITE_END()
231} // namespace validation
232} // namespace test
233} // namespace arm_compute