blob: 5f76a0ca06a94156e8b42be4488f065e30369b8d [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/NEON/functions/NEScale.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/NEON/Accessor.h"
30#include "tests/PaddingCalculator.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010031#include "tests/datasets/BorderModeDataset.h"
32#include "tests/datasets/InterpolationPolicyDataset.h"
Daniil Efremov02bf80d2017-11-22 00:26:51 +070033#include "tests/datasets/SamplingPolicyDataset.h"
Moritz Pflanzera09de0c2017-09-01 20:41:12 +010034#include "tests/datasets/ShapeDatasets.h"
35#include "tests/framework/Asserts.h"
36#include "tests/framework/Macros.h"
37#include "tests/framework/datasets/Datasets.h"
38#include "tests/validation/Helpers.h"
39#include "tests/validation/Validation.h"
40#include "tests/validation/fixtures/ScaleFixture.h"
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010041
42namespace arm_compute
43{
44namespace test
45{
46namespace validation
47{
Isabella Gottardi732f3682017-09-05 14:10:12 +010048namespace
49{
Georgios Pinitas583137c2017-08-31 18:12:42 +010050/** Scale data types */
51const auto ScaleDataTypes = framework::dataset::make("DataType",
52{
53 DataType::U8,
54 DataType::S16,
55 DataType::F32,
56});
57
58/** Tolerance */
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +010059constexpr AbsoluteTolerance<uint8_t> tolerance_u8(1);
60constexpr AbsoluteTolerance<int16_t> tolerance_s16(1);
Georgios Pinitas583137c2017-08-31 18:12:42 +010061RelativeTolerance<float> tolerance_f32(0.01);
Moritz Pflanzerff1c3602017-09-22 12:41:25 +010062
63constexpr float tolerance_num_s16 = 0.01f;
64constexpr float tolerance_num_f32 = 0.01f;
Isabella Gottardi732f3682017-09-05 14:10:12 +010065} // namespace
66
Isabella Gottardi1fab09f2017-07-13 15:55:57 +010067TEST_SUITE(NEON)
68TEST_SUITE(Scale)
69
Daniil Efremov02bf80d2017-11-22 00:26:51 +070070DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), ScaleDataTypes),
71 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
72 datasets::BorderModes()),
73 framework::dataset::make("SamplingPolicy", { SamplingPolicy::CENTER })),
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 uint8_t constant_border_value = 0;
81 if(border_mode == BorderMode::CONSTANT)
82 {
83 std::uniform_int_distribution<uint8_t> distribution_u8(0, 255);
84 constant_border_value = distribution_u8(generator);
85 }
86
87 // Create tensors
88 Tensor src = create_tensor<Tensor>(shape, data_type);
89 TensorShape shape_scaled(shape);
90 shape_scaled.set(0, shape[0] * scale_x);
91 shape_scaled.set(1, shape[1] * scale_y);
92 Tensor dst = create_tensor<Tensor>(shape_scaled, data_type);
93
94 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
95 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
96
97 // Create and configure function
98 NEScale nescale;
Daniil Efremov02bf80d2017-11-22 00:26:51 +070099 nescale.configure(&src, &dst, policy, border_mode, constant_border_value, sampling_policy);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100100
101 // Validate valid region
Diego Lopez Recas00854292018-02-22 13:08:01 +0000102 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 +0100103
104 validate(dst.info()->valid_region(), dst_valid_region);
105
106 // Validate padding
107 PaddingCalculator calculator(shape_scaled.x(), 16);
108 calculator.set_border_mode(border_mode);
109
110 const PaddingSize read_padding(1);
111 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 NEScaleFixture = ScaleValidationFixture<Tensor, Accessor, NEScale, 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, NEScaleFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
122 DataType::F32)),
123 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
124 datasets::BorderModes()),
125 framework::dataset::make("SamplingPolicy", { SamplingPolicy::CENTER })))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100126{
127 //Create valid region
128 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000129 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 +0100130
131 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100132 validate(Accessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100133}
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700134FIXTURE_DATA_TEST_CASE(RunLarge, NEScaleFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
Georgios Pinitas583137c2017-08-31 18:12:42 +0100135 DataType::F32)),
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700136 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
137 datasets::BorderModes()),
138 framework::dataset::make("SamplingPolicy", { SamplingPolicy::CENTER })))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100139{
140 //Create valid region
141 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000142 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 +0100143
144 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100145 validate(Accessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100146}
147TEST_SUITE_END()
148TEST_SUITE_END()
149
150TEST_SUITE(Integer)
151TEST_SUITE(U8)
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700152FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<uint8_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
153 DataType::U8)),
154 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
155 datasets::BorderModes()),
156 framework::dataset::make("SamplingPolicy", { SamplingPolicy::CENTER })))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100157{
158 //Create valid region
159 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000160 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 +0100161
162 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100163 validate(Accessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100164}
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700165FIXTURE_DATA_TEST_CASE(RunLarge, NEScaleFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100166 DataType::U8)),
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700167 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
168 datasets::BorderModes()),
169 framework::dataset::make("SamplingPolicy", { SamplingPolicy::CENTER })))
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100170{
171 //Create valid region
172 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000173 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 +0100174
175 // Validate output
Georgios Pinitas99d4f4a2017-09-19 16:51:42 +0100176 validate(Accessor(_target), _reference, valid_region, tolerance_u8);
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100177}
Georgios Pinitas583137c2017-08-31 18:12:42 +0100178TEST_SUITE_END()
179TEST_SUITE(S16)
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700180FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
181 DataType::S16)),
182 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
183 datasets::BorderModes()),
184 framework::dataset::make("SamplingPolicy", { SamplingPolicy::CENTER })))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100185{
186 //Create valid region
187 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000188 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 +0100189
190 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100191 validate(Accessor(_target), _reference, valid_region, tolerance_s16, tolerance_num_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100192}
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700193FIXTURE_DATA_TEST_CASE(RunLarge, NEScaleFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
Georgios Pinitas583137c2017-08-31 18:12:42 +0100194 DataType::S16)),
Daniil Efremov02bf80d2017-11-22 00:26:51 +0700195 framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })),
196 datasets::BorderModes()),
197 framework::dataset::make("SamplingPolicy", { SamplingPolicy::CENTER })))
Georgios Pinitas583137c2017-08-31 18:12:42 +0100198{
199 //Create valid region
200 TensorInfo src_info(_shape, 1, _data_type);
Diego Lopez Recas00854292018-02-22 13:08:01 +0000201 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 +0100202
203 // Validate output
Moritz Pflanzerff1c3602017-09-22 12:41:25 +0100204 validate(Accessor(_target), _reference, valid_region, tolerance_s16, tolerance_num_s16);
Georgios Pinitas583137c2017-08-31 18:12:42 +0100205}
206TEST_SUITE_END()
207TEST_SUITE_END()
Isabella Gottardi1fab09f2017-07-13 15:55:57 +0100208
209TEST_SUITE_END()
210TEST_SUITE_END()
211} // namespace validation
212} // namespace test
213} // namespace arm_compute