Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 1 | /* |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 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 | { |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 50 | using test::datasets::ShapeDataset; |
| 51 | |
| 52 | /** Class to generate boundary values for the given template parameters |
| 53 | * including shapes with large differences between width and height |
| 54 | */ |
| 55 | template <uint32_t channel, uint32_t batch, uint32_t element_per_vector, uint32_t vector_size> |
| 56 | class ScaleShapesBaseDataSet : public ShapeDataset |
| 57 | { |
| 58 | static constexpr auto boundary_minus_one = element_per_vector * vector_size - 1; |
| 59 | static constexpr auto boundary_plus_one = element_per_vector * vector_size + 1; |
| 60 | static constexpr auto small_size = 3; |
| 61 | |
| 62 | public: |
| 63 | // These tensor shapes are NCHW layout, fixture will convert to NHWC. |
| 64 | ScaleShapesBaseDataSet() |
| 65 | : ShapeDataset("Shape", |
| 66 | { |
| 67 | TensorShape{ small_size, boundary_minus_one, channel, batch }, |
| 68 | TensorShape{ small_size, boundary_plus_one, channel, batch }, |
| 69 | TensorShape{ boundary_minus_one, small_size, channel, batch }, |
| 70 | TensorShape{ boundary_plus_one, small_size, channel, batch }, |
| 71 | TensorShape{ boundary_minus_one, boundary_plus_one, channel, batch }, |
| 72 | TensorShape{ boundary_plus_one, boundary_minus_one, channel, batch }, |
| 73 | }) |
| 74 | { |
| 75 | } |
| 76 | }; |
| 77 | |
| 78 | /** For the single vector, only larger value (+1) than boundary |
| 79 | * since smaller value (-1) could cause some invalid shapes like |
| 80 | * - invalid zero size |
| 81 | * - size 1 which isn't compatible with scale with aligned corners. |
| 82 | */ |
| 83 | template <uint32_t channel, uint32_t batch, uint32_t element_per_vector> |
| 84 | class ScaleShapesBaseDataSet<channel, batch, element_per_vector, 1> : public ShapeDataset |
| 85 | { |
| 86 | static constexpr auto small_size = 3; |
| 87 | static constexpr auto boundary_plus_one = element_per_vector + 1; |
| 88 | |
| 89 | public: |
| 90 | // These tensor shapes are NCHW layout, fixture will convert to NHWC. |
| 91 | ScaleShapesBaseDataSet() |
| 92 | : ShapeDataset("Shape", |
| 93 | { |
| 94 | TensorShape{ small_size, boundary_plus_one, channel, batch }, |
| 95 | TensorShape{ boundary_plus_one, small_size, channel, batch }, |
| 96 | }) |
| 97 | { |
| 98 | } |
| 99 | }; |
| 100 | |
| 101 | /** For the shapes smaller than one vector, only pre-defined tiny shapes |
| 102 | * are tested (3x2, 2x3) as smaller shapes are more likely to cause |
| 103 | * issues and easier to debug. |
| 104 | */ |
| 105 | template <uint32_t channel, uint32_t batch, uint32_t element_per_vector> |
| 106 | class ScaleShapesBaseDataSet<channel, batch, element_per_vector, 0> : public ShapeDataset |
| 107 | { |
| 108 | static constexpr auto small_size = 3; |
| 109 | static constexpr auto zero_vector_boundary_value = 2; |
| 110 | |
| 111 | public: |
| 112 | // These tensor shapes are NCHW layout, fixture will convert to NHWC. |
| 113 | ScaleShapesBaseDataSet() |
| 114 | : ShapeDataset("Shape", |
| 115 | { |
| 116 | TensorShape{ small_size, zero_vector_boundary_value, channel, batch }, |
| 117 | TensorShape{ zero_vector_boundary_value, small_size, channel, batch }, |
| 118 | }) |
| 119 | { |
| 120 | } |
| 121 | }; |
| 122 | |
| 123 | /** Generated shaeps |
| 124 | * - 2D shapes with 0, 1, 2 vector iterations |
| 125 | * - 3D shapes with 0, 1 vector iterations |
| 126 | * - 4D shapes with 0 vector iterations |
| 127 | */ |
| 128 | #define SCALE_SHAPE_DATASET(element_per_vector) \ |
| 129 | concat(concat(concat(concat(concat(ScaleShapesBaseDataSet<1, 1, (element_per_vector), 0>(), \ |
| 130 | ScaleShapesBaseDataSet<1, 1, (element_per_vector), 1>()), \ |
| 131 | ScaleShapesBaseDataSet<1, 1, (element_per_vector), 2>()), \ |
| 132 | ScaleShapesBaseDataSet<3, 3, (element_per_vector), 0>()), \ |
| 133 | ScaleShapesBaseDataSet<3, 3, (element_per_vector), 1>()), \ |
| 134 | ScaleShapesBaseDataSet<3, 7, (element_per_vector), 0>()) |
| 135 | |
| 136 | /** We consider vector size in byte 64 since the maximum size of |
| 137 | * a vector used by @ref ScaleKernelInfo is currently 64-byte (float32x4x4). |
| 138 | * There are possibility to reduce test time further by using |
| 139 | * smaller vector sizes for different data types where applicable. |
| 140 | */ |
| 141 | constexpr uint32_t vector_byte = 64; |
| 142 | |
| 143 | template <typename T> |
| 144 | constexpr uint32_t num_elements_per_vector() |
| 145 | { |
| 146 | return vector_byte / sizeof(T); |
| 147 | } |
| 148 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 149 | /** Scale data types */ |
| 150 | const auto ScaleDataTypes = framework::dataset::make("DataType", |
| 151 | { |
| 152 | DataType::U8, |
| 153 | DataType::S16, |
| 154 | DataType::F32, |
| 155 | }); |
| 156 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 157 | /** Interpolation policy test set */ |
| 158 | const auto InterpolationPolicySet = framework::dataset::make("InterpolationPolicy", |
| 159 | { |
| 160 | InterpolationPolicy::NEAREST_NEIGHBOR, |
| 161 | InterpolationPolicy::BILINEAR, |
| 162 | }); |
| 163 | |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 164 | /** Scale data types */ |
| 165 | const auto ScaleDataLayouts = framework::dataset::make("DataLayout", |
| 166 | { |
| 167 | DataLayout::NCHW, |
| 168 | DataLayout::NHWC, |
| 169 | }); |
| 170 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 171 | /** Sampling policy data set */ |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame^] | 172 | const auto SamplingPolicySet = combine(datasets::SamplingPolicies(), |
| 173 | framework::dataset::make("AlignCorners", { false })); |
| 174 | |
| 175 | /** Sampling policy data set for Aligned Corners which only allows TOP_LEFT poicy.*/ |
| 176 | const auto AlignCornersSamplingPolicySet = combine(framework::dataset::make("SamplingPolicy", |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 177 | { |
| 178 | SamplingPolicy::TOP_LEFT, |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame^] | 179 | }), |
| 180 | framework::dataset::make("AlignCorners", { true })); |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 181 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 182 | /** Generating dataset for non-quantized data tyeps with the given shapes */ |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame^] | 183 | #define ASSEMBLE_DATASET(shape, samping_policy_set) \ |
| 184 | combine(combine(combine(combine((shape), ScaleDataLayouts), \ |
| 185 | InterpolationPolicySet), \ |
| 186 | datasets::BorderModes()), \ |
| 187 | samping_policy_set) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 188 | |
| 189 | /** Quantization information data set */ |
| 190 | const auto QuantizationInfoSet = framework::dataset::make("QuantizationInfo", |
| 191 | { |
| 192 | QuantizationInfo(0.5f, -10), |
| 193 | }); |
| 194 | |
| 195 | /** Generating dataset for quantized data tyeps with the given shapes */ |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame^] | 196 | #define ASSEMBLE_QUANTIZED_DATASET(shape, sampling_policy_set) \ |
| 197 | combine(combine(combine(combine(combine(shape, \ |
| 198 | QuantizationInfoSet), \ |
| 199 | ScaleDataLayouts), \ |
| 200 | InterpolationPolicySet), \ |
| 201 | datasets::BorderModes()), \ |
| 202 | sampling_policy_set) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 203 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 204 | /** Tolerance */ |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 205 | constexpr AbsoluteTolerance<uint8_t> tolerance_u8(1); |
| 206 | constexpr AbsoluteTolerance<int16_t> tolerance_s16(1); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 207 | RelativeTolerance<float> tolerance_f32(0.01); |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 208 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 209 | RelativeTolerance<half> tolerance_f16(half(0.1)); |
| 210 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 211 | |
| 212 | constexpr float tolerance_num_s16 = 0.01f; |
| 213 | constexpr float tolerance_num_f32 = 0.01f; |
Isabella Gottardi | 732f368 | 2017-09-05 14:10:12 +0100 | [diff] [blame] | 214 | } // namespace |
| 215 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 216 | TEST_SUITE(NEON) |
| 217 | TEST_SUITE(Scale) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 218 | TEST_SUITE(Validate) |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 219 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 220 | /** Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros |
| 221 | * we use to check the validity of given arguments in @ref NEScale |
| 222 | * and subsequent call to @ref NEScaleKernel. |
| 223 | * Since this is using validate() of @ref NEScale, which pre-adjust |
| 224 | * arguments for @ref NEScaleKernel, the following conditions in |
| 225 | * the kernel are not currently tested. |
| 226 | * - The same input and output |
| 227 | * - Data type of offset, dx and dy |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 228 | * This suite also tests two different validate() APIs - one is |
| 229 | * using @ref ScaleKernelInfo and the other one is more verbose |
| 230 | * one calls the other one - in the same test case. Even though |
| 231 | * there are possibility that it makes debugging for regression |
| 232 | * harder, belows are reasons of this test case implementation. |
| 233 | * - The more verbose one is just a wrapper function calls |
| 234 | * the other one without any additional logic. So we are |
| 235 | * safe to merge two tests into one. |
| 236 | * - A large amount of code duplication is test suite can be prevented. |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 237 | */ |
| 238 | |
| 239 | const auto input_shape = TensorShape{ 2, 3, 3, 2 }; |
| 240 | const auto output_shape = TensorShape{ 4, 6, 3, 2 }; |
| 241 | |
| 242 | constexpr auto default_data_type = DataType::U8; |
| 243 | constexpr auto default_data_layout = DataLayout::NHWC; |
| 244 | constexpr auto default_interpolation_policy = InterpolationPolicy::NEAREST_NEIGHBOR; |
| 245 | constexpr auto default_border_mode = BorderMode::UNDEFINED; |
| 246 | constexpr auto default_sampling_policy = SamplingPolicy::CENTER; |
| 247 | constexpr bool default_use_padding = false; |
| 248 | |
| 249 | TEST_CASE(NullPtr, framework::DatasetMode::ALL) |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 250 | { |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 251 | const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout }; |
| 252 | const auto output = TensorInfo{ output_shape, 1, default_data_type, default_data_layout }; |
| 253 | Status result{}; |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 254 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 255 | // nullptr is given as input |
| 256 | result = NEScale::validate(nullptr, &output, default_interpolation_policy, default_border_mode); |
| 257 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
| 258 | |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 259 | result = NEScale::validate(nullptr, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode }); |
| 260 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
| 261 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 262 | // nullptr is given as output |
| 263 | result = NEScale::validate(&input, nullptr, default_interpolation_policy, default_border_mode); |
| 264 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 265 | |
| 266 | result = NEScale::validate(&input, nullptr, ScaleKernelInfo{ default_interpolation_policy, default_border_mode }); |
| 267 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | TEST_CASE(SupportDataType, framework::DatasetMode::ALL) |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 271 | { |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 272 | const std::map<DataType, bool> supported_data_types = |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 273 | { |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 274 | { DataType::U8, true }, |
| 275 | { DataType::S8, false }, |
| 276 | { DataType::QSYMM8, false }, |
| 277 | { DataType::QASYMM8, true }, |
| 278 | { DataType::QASYMM8_SIGNED, true }, |
| 279 | { DataType::QSYMM8_PER_CHANNEL, false }, |
| 280 | { DataType::U16, false }, |
| 281 | { DataType::S16, true }, |
| 282 | { DataType::QSYMM16, false }, |
| 283 | { DataType::QASYMM16, false }, |
| 284 | { DataType::U32, false }, |
| 285 | { DataType::S32, false }, |
| 286 | { DataType::U64, false }, |
| 287 | { DataType::S64, false }, |
| 288 | { DataType::BFLOAT16, false }, |
| 289 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 290 | { DataType::F16, true }, |
| 291 | #else // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 292 | { DataType::F16, false }, |
| 293 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 294 | { DataType::F32, true }, |
| 295 | { DataType::F64, false }, |
| 296 | { DataType::SIZET, false }, |
| 297 | }; |
| 298 | Status result{}; |
| 299 | for(auto &kv : supported_data_types) |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 300 | { |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 301 | const auto input = TensorInfo{ input_shape, 1, kv.first, default_data_layout }; |
| 302 | const auto output = TensorInfo{ output_shape, 1, kv.first, default_data_layout }; |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 303 | |
| 304 | result = NEScale::validate(&input, &output, default_interpolation_policy, default_border_mode); |
| 305 | ARM_COMPUTE_EXPECT(bool(result) == kv.second, framework::LogLevel::ERRORS); |
| 306 | |
| 307 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode }); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 308 | ARM_COMPUTE_EXPECT(bool(result) == kv.second, framework::LogLevel::ERRORS); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 309 | } |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 310 | } |
| 311 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 312 | TEST_CASE(MissmatchingDataType, framework::DatasetMode::ALL) |
| 313 | { |
| 314 | constexpr auto non_default_data_type = DataType::F32; |
| 315 | |
| 316 | const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout }; |
| 317 | const auto output = TensorInfo{ output_shape, 1, non_default_data_type, default_data_layout }; |
| 318 | Status result{}; |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 319 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 320 | result = NEScale::validate(&input, &output, default_interpolation_policy, default_border_mode); |
| 321 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 322 | |
| 323 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode }); |
| 324 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | TEST_CASE(UsePadding, framework::DatasetMode::ALL) |
| 328 | { |
| 329 | const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout }; |
| 330 | const auto output = TensorInfo{ output_shape, 1, default_data_type, default_data_layout }; |
| 331 | Status result{}; |
| 332 | |
| 333 | // When use padding is false, border mode should be constant |
| 334 | constexpr auto border_mode = BorderMode::UNDEFINED; |
| 335 | constexpr bool use_padding = false; |
| 336 | |
| 337 | result = NEScale::validate(&input, &output, default_interpolation_policy, border_mode, PixelValue(), default_sampling_policy, use_padding); |
| 338 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 339 | |
| 340 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ default_interpolation_policy, border_mode, PixelValue(), default_sampling_policy, use_padding }); |
| 341 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | TEST_CASE(AreaWithNHWC, framework::DatasetMode::ALL) |
| 345 | { |
| 346 | // InterpolationPolicy::AREA is not supported for NHWC |
| 347 | constexpr auto interpolation_policy = InterpolationPolicy::AREA; |
| 348 | constexpr auto data_layout = DataLayout::NHWC; |
| 349 | |
| 350 | const auto input = TensorInfo{ input_shape, 1, default_data_type, data_layout }; |
| 351 | const auto output = TensorInfo{ output_shape, 1, default_data_type, data_layout }; |
| 352 | Status result{}; |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 353 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 354 | result = NEScale::validate(&input, &output, interpolation_policy, default_border_mode); |
| 355 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 356 | |
| 357 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode }); |
| 358 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 359 | } |
| 360 | |
| 361 | TEST_CASE(AreaWithNonU8, framework::DatasetMode::ALL) |
| 362 | { |
| 363 | // InterpolationPolicy::AREA only supports U8 |
| 364 | constexpr auto interpolation_policy = InterpolationPolicy::AREA; |
| 365 | constexpr auto data_type = DataType::F32; |
| 366 | constexpr auto data_layout = DataLayout::NCHW; |
| 367 | |
| 368 | const auto input = TensorInfo{ input_shape, 1, data_type, data_layout }; |
| 369 | const auto output = TensorInfo{ output_shape, 1, data_type, data_layout }; |
| 370 | Status result{}; |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 371 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 372 | result = NEScale::validate(&input, &output, interpolation_policy, default_border_mode); |
| 373 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 374 | |
| 375 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode }); |
| 376 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | TEST_CASE(InvalidAlignedCornerOutput, framework::DatasetMode::ALL) |
| 380 | { |
| 381 | // Bilinear with aligned corners require at least 2x2 output to prevent overflow. |
| 382 | // Also, aligned corners require sampling policy to be TOP_LEFT. |
| 383 | constexpr auto interpolation_policy = InterpolationPolicy::BILINEAR; |
| 384 | constexpr bool align_corners = true; |
| 385 | constexpr auto sampling_policy = SamplingPolicy::TOP_LEFT; |
| 386 | const auto invalid_output_shape = TensorShape{ 1, 1, 3, 2 }; |
| 387 | |
| 388 | const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout }; |
| 389 | const auto output = TensorInfo{ invalid_output_shape, 1, default_data_type, default_data_layout }; |
| 390 | Status result{}; |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 391 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 392 | result = NEScale::validate(&input, &output, interpolation_policy, default_border_mode, PixelValue(), sampling_policy, default_use_padding, align_corners); |
| 393 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 394 | |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 395 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode, PixelValue(), sampling_policy, default_use_padding, align_corners }); |
| 396 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
| 397 | } |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 398 | TEST_SUITE_END() // Validate |
| 399 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 400 | template <typename T> |
| 401 | using NEScaleFixture = ScaleValidationFixture<Tensor, Accessor, NEScale, T>; |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 402 | template <typename T> |
| 403 | using NEScaleQuantizedFixture = ScaleValidationQuantizedFixture<Tensor, Accessor, NEScale, T>; |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 404 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 405 | TEST_SUITE(Float) |
| 406 | TEST_SUITE(FP32) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 407 | const auto f32_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<float>())), framework::dataset::make("DataType", DataType::F32)); |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame^] | 408 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<float>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f32_shape, SamplingPolicySet)) |
| 409 | { |
| 410 | //Create valid region |
| 411 | TensorInfo src_info(_shape, 1, _data_type); |
| 412 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 413 | |
| 414 | // Validate output |
| 415 | validate(Accessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32); |
| 416 | } |
| 417 | FIXTURE_DATA_TEST_CASE(RunSmallAlignCorners, NEScaleFixture<float>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f32_shape, AlignCornersSamplingPolicySet)) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 418 | { |
| 419 | //Create valid region |
| 420 | TensorInfo src_info(_shape, 1, _data_type); |
Diego Lopez Recas | 0085429 | 2018-02-22 13:08:01 +0000 | [diff] [blame] | 421 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 422 | |
| 423 | // Validate output |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 424 | validate(Accessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 425 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 426 | TEST_SUITE_END() // FP32 |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 427 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 428 | TEST_SUITE(FP16) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 429 | const auto f16_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<half>())), framework::dataset::make("DataType", DataType::F16)); |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame^] | 430 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<half>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f16_shape, SamplingPolicySet)) |
| 431 | { |
| 432 | //Create valid region |
| 433 | TensorInfo src_info(_shape, 1, _data_type); |
| 434 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 435 | |
| 436 | // Validate output |
| 437 | validate(Accessor(_target), _reference, valid_region, tolerance_f16); |
| 438 | } |
| 439 | FIXTURE_DATA_TEST_CASE(RunSmallAlignCorners, NEScaleFixture<half>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f16_shape, AlignCornersSamplingPolicySet)) |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 440 | { |
| 441 | //Create valid region |
| 442 | TensorInfo src_info(_shape, 1, _data_type); |
| 443 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 444 | |
| 445 | // Validate output |
| 446 | validate(Accessor(_target), _reference, valid_region, tolerance_f16); |
| 447 | } |
| 448 | TEST_SUITE_END() // FP16 |
| 449 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 450 | TEST_SUITE_END() // Float |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 451 | |
| 452 | TEST_SUITE(Integer) |
| 453 | TEST_SUITE(U8) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 454 | const auto u8_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<uint8_t>())), framework::dataset::make("DataType", DataType::U8)); |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame^] | 455 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(u8_shape, SamplingPolicySet)) |
| 456 | { |
| 457 | //Create valid region |
| 458 | TensorInfo src_info(_shape, 1, _data_type); |
| 459 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 460 | |
| 461 | // Validate output |
| 462 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
| 463 | } |
| 464 | FIXTURE_DATA_TEST_CASE(RunSmallAlignCorners, NEScaleFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(u8_shape, AlignCornersSamplingPolicySet)) |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 465 | { |
| 466 | //Create valid region |
| 467 | TensorInfo src_info(_shape, 1, _data_type); |
Diego Lopez Recas | 0085429 | 2018-02-22 13:08:01 +0000 | [diff] [blame] | 468 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 469 | |
| 470 | // Validate output |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 471 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 472 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 473 | TEST_SUITE_END() // U8 |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 474 | TEST_SUITE(S16) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 475 | const auto s16_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<int16_t>())), framework::dataset::make("DataType", DataType::S16)); |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame^] | 476 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<int16_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(s16_shape, SamplingPolicySet)) |
| 477 | { |
| 478 | //Create valid region |
| 479 | TensorInfo src_info(_shape, 1, _data_type); |
| 480 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 481 | |
| 482 | // Validate output |
| 483 | validate(Accessor(_target), _reference, valid_region, tolerance_s16, tolerance_num_s16); |
| 484 | } |
| 485 | FIXTURE_DATA_TEST_CASE(RunSmallAlignCorners, NEScaleFixture<int16_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(s16_shape, AlignCornersSamplingPolicySet)) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 486 | { |
| 487 | //Create valid region |
| 488 | TensorInfo src_info(_shape, 1, _data_type); |
Diego Lopez Recas | 0085429 | 2018-02-22 13:08:01 +0000 | [diff] [blame] | 489 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 490 | |
| 491 | // Validate output |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 492 | validate(Accessor(_target), _reference, valid_region, tolerance_s16, tolerance_num_s16); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 493 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 494 | TEST_SUITE_END() // S16 |
| 495 | TEST_SUITE_END() // Integer |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 496 | |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 497 | TEST_SUITE(Quantized) |
| 498 | TEST_SUITE(QASYMM8) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 499 | const auto qasymm8_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<uint8_t>())), framework::dataset::make("DataType", DataType::QASYMM8)); |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame^] | 500 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_shape, SamplingPolicySet)) |
| 501 | { |
| 502 | //Create valid region |
| 503 | TensorInfo src_info(_shape, 1, _data_type); |
| 504 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 505 | |
| 506 | // Validate output |
| 507 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
| 508 | } |
| 509 | FIXTURE_DATA_TEST_CASE(RunSmallAlignCorners, NEScaleQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_shape, AlignCornersSamplingPolicySet)) |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 510 | { |
| 511 | //Create valid region |
| 512 | TensorInfo src_info(_shape, 1, _data_type); |
| 513 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 514 | |
| 515 | // Validate output |
| 516 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
| 517 | } |
| 518 | TEST_SUITE_END() // QASYMM8 |
Sheri Zhang | 359c48e | 2020-04-30 22:53:39 +0100 | [diff] [blame] | 519 | TEST_SUITE(QASYMM8_SIGNED) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 520 | const auto qasymm8_signed_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<int8_t>())), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)); |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame^] | 521 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleQuantizedFixture<int8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_signed_shape, SamplingPolicySet)) |
| 522 | { |
| 523 | //Create valid region |
| 524 | TensorInfo src_info(_shape, 1, _data_type); |
| 525 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 526 | |
| 527 | // Validate output |
| 528 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
| 529 | } |
| 530 | FIXTURE_DATA_TEST_CASE(RunSmallAlignCorners, NEScaleQuantizedFixture<int8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_signed_shape, AlignCornersSamplingPolicySet)) |
Sheri Zhang | 359c48e | 2020-04-30 22:53:39 +0100 | [diff] [blame] | 531 | { |
| 532 | //Create valid region |
| 533 | TensorInfo src_info(_shape, 1, _data_type); |
| 534 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 535 | |
| 536 | // Validate output |
| 537 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
| 538 | } |
| 539 | TEST_SUITE_END() // QASYMM8_SIGNED |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 540 | TEST_SUITE_END() // Quantized |
| 541 | |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 542 | TEST_SUITE_END() // Scale |
| 543 | TEST_SUITE_END() // NEON |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 544 | } // namespace validation |
| 545 | } // namespace test |
| 546 | } // namespace arm_compute |