blob: f43f2aeeb938f92d2ed8cad1c8f81ff6e6b6a55d [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"
32#include "tests/datasets/ShapeDatasets.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/framework/datasets/Datasets.h"
36#include "tests/validation/Helpers.h"
37#include "tests/validation/Validation.h"
38#include "tests/validation/fixtures/ScaleFixture.h"
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010039
40namespace arm_compute
41{
42namespace test
43{
44namespace validation
45{
46namespace
47{
Georgios Pinitas583137c2017-08-31 18:12:42 +010048/** CNN data types */
49const auto ScaleDataTypes = framework::dataset::make("DataType",
50{
51 DataType::U8,
52 DataType::S16,
53 DataType::F16,
54 DataType::F32,
55});
56
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010057/** Tolerance */
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +010058constexpr AbsoluteTolerance<uint8_t> tolerance_u8(1);
59constexpr AbsoluteTolerance<int16_t> tolerance_s16(1);
steniu01f81652d2017-09-11 15:29:12 +010060RelativeTolerance<float> tolerance_f32(0.05);
Georgios Pinitas583137c2017-08-31 18:12:42 +010061RelativeTolerance<half> tolerance_f16(half(0.1));
Moritz Pflanzerff1c3602017-09-22 12:41:25 +010062
63constexpr float tolerance_num_f32(0.01f);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010064} // namespace
65
66TEST_SUITE(CL)
67TEST_SUITE(Scale)
68
steniu01f81652d2017-09-11 15:29:12 +010069DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::MediumShapes(), datasets::LargeShapes()), ScaleDataTypes),
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010070 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
71 datasets::BorderModes()),
72 shape, data_type, policy, border_mode)
73{
74 std::mt19937 generator(library->seed());
75 std::uniform_real_distribution<float> distribution_float(0.25, 2);
76 const float scale_x = distribution_float(generator);
77 const float scale_y = distribution_float(generator);
78 std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
79 uint8_t constant_border_value = distribution_u8(generator);
80
81 // Create tensors
82 CLTensor src = create_tensor<CLTensor>(shape, data_type);
83 TensorShape shape_scaled(shape);
84 shape_scaled.set(0, shape[0] * scale_x);
85 shape_scaled.set(1, shape[1] * scale_y);
86 CLTensor dst = create_tensor<CLTensor>(shape_scaled, data_type);
87
88 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
89 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
90
91 // Create and configure function
92 CLScale clscale;
93 clscale.configure(&src, &dst, policy, border_mode, constant_border_value);
94
95 // Validate valid region
96 const ValidRegion dst_valid_region = calculate_valid_region_scale(*(src.info()), shape_scaled, policy, BorderSize(1), (border_mode == BorderMode::UNDEFINED));
97
98 validate(dst.info()->valid_region(), dst_valid_region);
99
100 // Validate padding
101 PaddingCalculator calculator(shape_scaled.x(), 4);
102 calculator.set_border_mode(border_mode);
103
104 const PaddingSize read_padding(1);
105 const PaddingSize write_padding = calculator.required_padding(PaddingCalculator::Option::EXCLUDE_BORDER);
106 validate(src.info()->padding(), read_padding);
107 validate(dst.info()->padding(), write_padding);
108}
109
110template <typename T>
111using CLScaleFixture = ScaleValidationFixture<CLTensor, CLAccessor, CLScale, T>;
112
Georgios Pinitas583137c2017-08-31 18:12:42 +0100113TEST_SUITE(Float)
114TEST_SUITE(FP32)
115FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)),
116 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
117 datasets::BorderModes()))
118{
119 //Create valid region
120 TensorInfo src_info(_shape, 1, _data_type);
121 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
122
123 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100124 validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100125}
126FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::F32)),
127 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
128 datasets::BorderModes()))
129{
130 //Create valid region
131 TensorInfo src_info(_shape, 1, _data_type);
132 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
133
134 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100135 validate(CLAccessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100136}
137TEST_SUITE_END()
138TEST_SUITE(FP16)
139FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)),
140 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
141 datasets::BorderModes()))
142{
143 //Create valid region
144 TensorInfo src_info(_shape, 1, _data_type);
145 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
146
147 // Validate output
148 validate(CLAccessor(_target), _reference, valid_region, tolerance_f16);
149}
150FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
151 DataType::F16)),
152 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
153 datasets::BorderModes()))
154{
155 //Create valid region
156 TensorInfo src_info(_shape, 1, _data_type);
157 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
158
159 // Validate output
160 validate(CLAccessor(_target), _reference, valid_region, tolerance_f16);
161}
162TEST_SUITE_END()
163TEST_SUITE_END()
164
165TEST_SUITE(Integer)
166TEST_SUITE(U8)
167FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::U8)),
168 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
169 datasets::BorderModes()))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100170{
171 //Create valid region
172 TensorInfo src_info(_shape, 1, _data_type);
173 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
174
175 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100176 validate(CLAccessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100177}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100178FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::U8)),
179 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
180 datasets::BorderModes()))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100181{
182 //Create valid region
183 TensorInfo src_info(_shape, 1, _data_type);
184 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
185
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}
189TEST_SUITE_END()
Georgios Pinitas583137c2017-08-31 18:12:42 +0100190TEST_SUITE(S16)
191FIXTURE_DATA_TEST_CASE(RunSmall, CLScaleFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::S16)),
192 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
193 datasets::BorderModes()))
194{
195 //Create valid region
196 TensorInfo src_info(_shape, 1, _data_type);
197 const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED));
198
199 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100200 validate(CLAccessor(_target), _reference, valid_region, tolerance_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100201}
202FIXTURE_DATA_TEST_CASE(RunLarge, CLScaleFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", DataType::S16)),
203 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
204 datasets::BorderModes()))
205{
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}
213TEST_SUITE_END()
214TEST_SUITE_END()
215
216TEST_SUITE_END()
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100217TEST_SUITE_END()
218} // namespace validation
219} // namespace test
220} // namespace arm_compute