blob: cc4fdb0564b51bfdd38fc10b267d9aad1f2e6a80 [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
Daniil Efremov02bf80d2017-11-22 00:26:51 +070072DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(concat(datasets::MediumShapes(), datasets::LargeShapes()), ScaleDataTypes),
73 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
74 datasets::BorderModes()),
75 datasets::SamplingPolicies()),
76 shape, data_type, policy, border_mode, sampling_policy)
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010077{
78 std::mt19937 generator(library->seed());
79 std::uniform_real_distribution<float> distribution_float(0.25, 2);
80 const float scale_x = distribution_float(generator);
81 const float scale_y = distribution_float(generator);
82 std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
83 uint8_t constant_border_value = distribution_u8(generator);
84
85 // Create tensors
86 CLTensor src = create_tensor<CLTensor>(shape, data_type);
87 TensorShape shape_scaled(shape);
88 shape_scaled.set(0, shape[0] * scale_x);
89 shape_scaled.set(1, shape[1] * scale_y);
90 CLTensor dst = create_tensor<CLTensor>(shape_scaled, data_type);
91
92 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
93 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
94
95 // Create and configure function
96 CLScale clscale;
Daniil Efremov02bf80d2017-11-22 00:26:51 +070097 clscale.configure(&src, &dst, policy, border_mode, constant_border_value, sampling_policy);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010098
Daniil Efremov7a49c792017-11-14 21:25:34 +070099 // Get border size depending on border mode
100 const BorderSize border_size(border_mode == BorderMode::UNDEFINED ? 0 : 1);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100101
Daniil Efremov7a49c792017-11-14 21:25:34 +0700102 // Validate valid region
Diego Lopez Recas00854292018-02-22 13:08:01 +0000103 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 +0100104 validate(dst.info()->valid_region(), dst_valid_region);
105
106 // Validate padding
107 PaddingCalculator calculator(shape_scaled.x(), 4);
108 calculator.set_border_mode(border_mode);
109
Daniil Efremov7a49c792017-11-14 21:25:34 +0700110 const PaddingSize read_padding(border_size);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100111 const PaddingSize write_padding = calculator.required_padding(PaddingCalculator::Option::EXCLUDE_BORDER);
112 validate(src.info()->padding(), read_padding);
113 validate(dst.info()->padding(), write_padding);
114}
115
116template <typename T>
117using CLScaleFixture = ScaleValidationFixture<CLTensor, CLAccessor, CLScale, T>;
118
Georgios Pinitas583137c2017-08-31 18:12:42 +0100119TEST_SUITE(Float)
120TEST_SUITE(FP32)
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700121FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)),
122 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
123 datasets::BorderModes()),
124 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100125{
126 //Create valid region
127 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000128 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 +0100129
130 // Validate output
Diego Lopez Recas00854292018-02-22 13:08:01 +0000131 validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32, tolerance_f32_absolute);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100132}
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700133FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F32)),
134 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
135 datasets::BorderModes()),
136 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100137{
138 //Create valid region
139 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000140 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 +0100141
142 // Validate output
Diego Lopez Recas00854292018-02-22 13:08:01 +0000143 validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32, tolerance_f32_absolute);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100144}
145TEST_SUITE_END()
146TEST_SUITE(FP16)
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700147FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)),
148 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
149 datasets::BorderModes()),
150 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100151{
152 //Create valid region
153 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000154 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 +0100155
156 // Validate output
157 validate(CLAccessor(_target), _reference, valid_region, tolerance_f16);
158}
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700159FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
160 DataType::F16)),
161 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
162 datasets::BorderModes()),
163 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100164{
165 //Create valid region
166 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000167 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 +0100168
169 // Validate output
170 validate(CLAccessor(_target), _reference, valid_region, tolerance_f16);
171}
172TEST_SUITE_END()
173TEST_SUITE_END()
174
175TEST_SUITE(Integer)
176TEST_SUITE(U8)
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700177FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::U8)),
178 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
179 datasets::BorderModes()),
180 datasets::SamplingPolicies()))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100181{
182 //Create valid region
183 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000184 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 +0100185
186 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100187 validate(CLAccessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100188}
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700189FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::U8)),
190 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
191 datasets::BorderModes()),
192 datasets::SamplingPolicies()))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100193{
194 //Create valid region
195 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000196 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 +0100197
198 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100199 validate(CLAccessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100200}
201TEST_SUITE_END()
Georgios Pinitas583137c2017-08-31 18:12:42 +0100202TEST_SUITE(S16)
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700203FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::S16)),
204 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
205 datasets::BorderModes()),
206 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100207{
208 //Create valid region
209 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000210 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 +0100211
212 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100213 validate(CLAccessor(_target), _reference, valid_region, tolerance_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100214}
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700215FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
216 DataType::S16)),
217 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
218 datasets::BorderModes()),
219 datasets::SamplingPolicies()))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100220{
221 //Create valid region
222 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000223 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 +0100224
225 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100226 validate(CLAccessor(_target), _reference, valid_region, tolerance_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100227}
228TEST_SUITE_END()
229TEST_SUITE_END()
230
231TEST_SUITE_END()
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100232TEST_SUITE_END()
233} // namespace validation
234} // namespace test
235} // namespace arm_compute