Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 1 | /* |
Diego Lopez Recas | ff860cf | 2018-02-22 13:08:01 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 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/NEON/functions/NEScale.h" |
| 27 | #include "arm_compute/runtime/Tensor.h" |
| 28 | #include "arm_compute/runtime/TensorAllocator.h" |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 29 | #include "tests/NEON/Accessor.h" |
| 30 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 31 | #include "tests/datasets/BorderModeDataset.h" |
| 32 | #include "tests/datasets/InterpolationPolicyDataset.h" |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 33 | #include "tests/datasets/SamplingPolicyDataset.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 34 | #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 Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 41 | |
| 42 | namespace arm_compute |
| 43 | { |
| 44 | namespace test |
| 45 | { |
| 46 | namespace validation |
| 47 | { |
Isabella Gottardi | 732f368 | 2017-09-05 14:10:12 +0100 | [diff] [blame] | 48 | namespace |
| 49 | { |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 50 | /** Scale data types */ |
| 51 | const auto ScaleDataTypes = framework::dataset::make("DataType", |
| 52 | { |
| 53 | DataType::U8, |
| 54 | DataType::S16, |
| 55 | DataType::F32, |
| 56 | }); |
| 57 | |
| 58 | /** Tolerance */ |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 59 | constexpr AbsoluteTolerance<uint8_t> tolerance_u8(1); |
| 60 | constexpr AbsoluteTolerance<int16_t> tolerance_s16(1); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 61 | RelativeTolerance<float> tolerance_f32(0.01); |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 62 | |
| 63 | constexpr float tolerance_num_s16 = 0.01f; |
| 64 | constexpr float tolerance_num_f32 = 0.01f; |
Isabella Gottardi | 732f368 | 2017-09-05 14:10:12 +0100 | [diff] [blame] | 65 | } // namespace |
| 66 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 67 | TEST_SUITE(NEON) |
| 68 | TEST_SUITE(Scale) |
| 69 | |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 70 | DATA_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 Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 75 | { |
| 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 Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 99 | nescale.configure(&src, &dst, policy, border_mode, constant_border_value, sampling_policy); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 100 | |
| 101 | // Validate valid region |
Georgios Pinitas | 6727f12 | 2018-03-13 10:29:13 +0000 | [diff] [blame] | 102 | const ValidRegion dst_valid_region = calculate_valid_region_scale(*(src.info()), shape_scaled, policy, BorderSize(1), (border_mode == BorderMode::UNDEFINED)); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 103 | |
| 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 | |
| 116 | template <typename T> |
| 117 | using NEScaleFixture = ScaleValidationFixture<Tensor, Accessor, NEScale, T>; |
| 118 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 119 | TEST_SUITE(Float) |
| 120 | TEST_SUITE(FP32) |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 121 | FIXTURE_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 Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 126 | { |
| 127 | //Create valid region |
| 128 | TensorInfo src_info(_shape, 1, _data_type); |
Georgios Pinitas | 6727f12 | 2018-03-13 10:29:13 +0000 | [diff] [blame] | 129 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 130 | |
| 131 | // Validate output |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 132 | validate(Accessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 133 | } |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 134 | FIXTURE_DATA_TEST_CASE(RunLarge, NEScaleFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 135 | DataType::F32)), |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 136 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 137 | datasets::BorderModes()), |
| 138 | framework::dataset::make("SamplingPolicy", { SamplingPolicy::CENTER }))) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 139 | { |
| 140 | //Create valid region |
| 141 | TensorInfo src_info(_shape, 1, _data_type); |
Georgios Pinitas | 6727f12 | 2018-03-13 10:29:13 +0000 | [diff] [blame] | 142 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 143 | |
| 144 | // Validate output |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 145 | validate(Accessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 146 | } |
| 147 | TEST_SUITE_END() |
| 148 | TEST_SUITE_END() |
| 149 | |
| 150 | TEST_SUITE(Integer) |
| 151 | TEST_SUITE(U8) |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 152 | FIXTURE_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 Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 157 | { |
| 158 | //Create valid region |
| 159 | TensorInfo src_info(_shape, 1, _data_type); |
Georgios Pinitas | 6727f12 | 2018-03-13 10:29:13 +0000 | [diff] [blame] | 160 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 161 | |
| 162 | // Validate output |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 163 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 164 | } |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 165 | FIXTURE_DATA_TEST_CASE(RunLarge, NEScaleFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 166 | DataType::U8)), |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 167 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 168 | datasets::BorderModes()), |
| 169 | framework::dataset::make("SamplingPolicy", { SamplingPolicy::CENTER }))) |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 170 | { |
| 171 | //Create valid region |
| 172 | TensorInfo src_info(_shape, 1, _data_type); |
Georgios Pinitas | 6727f12 | 2018-03-13 10:29:13 +0000 | [diff] [blame] | 173 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 174 | |
| 175 | // Validate output |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 176 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 177 | } |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 178 | TEST_SUITE_END() |
| 179 | TEST_SUITE(S16) |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 180 | FIXTURE_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 Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 185 | { |
| 186 | //Create valid region |
| 187 | TensorInfo src_info(_shape, 1, _data_type); |
Georgios Pinitas | 6727f12 | 2018-03-13 10:29:13 +0000 | [diff] [blame] | 188 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 189 | |
| 190 | // Validate output |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 191 | validate(Accessor(_target), _reference, valid_region, tolerance_s16, tolerance_num_s16); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 192 | } |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 193 | FIXTURE_DATA_TEST_CASE(RunLarge, NEScaleFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType", |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 194 | DataType::S16)), |
Daniil Efremov | 02bf80d | 2017-11-22 00:26:51 +0700 | [diff] [blame] | 195 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::NEAREST_NEIGHBOR, InterpolationPolicy::BILINEAR })), |
| 196 | datasets::BorderModes()), |
| 197 | framework::dataset::make("SamplingPolicy", { SamplingPolicy::CENTER }))) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 198 | { |
| 199 | //Create valid region |
| 200 | TensorInfo src_info(_shape, 1, _data_type); |
Georgios Pinitas | 6727f12 | 2018-03-13 10:29:13 +0000 | [diff] [blame] | 201 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, BorderSize(1), (_border_mode == BorderMode::UNDEFINED)); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 202 | |
| 203 | // Validate output |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 204 | validate(Accessor(_target), _reference, valid_region, tolerance_s16, tolerance_num_s16); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 205 | } |
| 206 | TEST_SUITE_END() |
| 207 | TEST_SUITE_END() |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 208 | |
| 209 | TEST_SUITE_END() |
| 210 | TEST_SUITE_END() |
| 211 | } // namespace validation |
| 212 | } // namespace test |
| 213 | } // namespace arm_compute |