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 */ |
| 172 | const auto SamplingPolicySet = framework::dataset::make("SamplingPolicy", |
| 173 | { |
| 174 | SamplingPolicy::TOP_LEFT, |
| 175 | SamplingPolicy::CENTER, |
| 176 | }); |
| 177 | |
Sang-Hoon Park | bb123bd | 2020-01-03 10:57:30 +0000 | [diff] [blame] | 178 | /** Align corners */ |
| 179 | const auto AlignCorners = framework::dataset::make("AlignCorners", |
| 180 | { |
| 181 | false, |
| 182 | true, |
| 183 | }); |
| 184 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 185 | /** Generating dataset for non-quantized data tyeps with the given shapes */ |
| 186 | #define ASSEMBLE_DATASET(shape) \ |
| 187 | combine(combine(combine(combine(combine((shape), ScaleDataLayouts), \ |
| 188 | InterpolationPolicySet), \ |
| 189 | datasets::BorderModes()), \ |
| 190 | SamplingPolicySet), \ |
| 191 | AlignCorners) |
| 192 | |
| 193 | /** Quantization information data set */ |
| 194 | const auto QuantizationInfoSet = framework::dataset::make("QuantizationInfo", |
| 195 | { |
| 196 | QuantizationInfo(0.5f, -10), |
| 197 | }); |
| 198 | |
| 199 | /** Generating dataset for quantized data tyeps with the given shapes */ |
| 200 | #define ASSEMBLE_QUANTIZED_DATASET(shape) \ |
| 201 | combine(combine(combine(combine(combine(combine(shape, \ |
| 202 | QuantizationInfoSet), \ |
| 203 | ScaleDataLayouts), \ |
| 204 | InterpolationPolicySet), \ |
| 205 | datasets::BorderModes()), \ |
| 206 | SamplingPolicySet), \ |
| 207 | AlignCorners) |
| 208 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 209 | /** Tolerance */ |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 210 | constexpr AbsoluteTolerance<uint8_t> tolerance_u8(1); |
| 211 | constexpr AbsoluteTolerance<int16_t> tolerance_s16(1); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 212 | RelativeTolerance<float> tolerance_f32(0.01); |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 213 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 214 | RelativeTolerance<half> tolerance_f16(half(0.1)); |
| 215 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 216 | |
| 217 | constexpr float tolerance_num_s16 = 0.01f; |
| 218 | constexpr float tolerance_num_f32 = 0.01f; |
Isabella Gottardi | 732f368 | 2017-09-05 14:10:12 +0100 | [diff] [blame] | 219 | } // namespace |
| 220 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 221 | TEST_SUITE(NEON) |
| 222 | TEST_SUITE(Scale) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 223 | TEST_SUITE(Validate) |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 224 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 225 | /** Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros |
| 226 | * we use to check the validity of given arguments in @ref NEScale |
| 227 | * and subsequent call to @ref NEScaleKernel. |
| 228 | * Since this is using validate() of @ref NEScale, which pre-adjust |
| 229 | * arguments for @ref NEScaleKernel, the following conditions in |
| 230 | * the kernel are not currently tested. |
| 231 | * - The same input and output |
| 232 | * - Data type of offset, dx and dy |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame^] | 233 | * This suite also tests two different validate() APIs - one is |
| 234 | * using @ref ScaleKernelInfo and the other one is more verbose |
| 235 | * one calls the other one - in the same test case. Even though |
| 236 | * there are possibility that it makes debugging for regression |
| 237 | * harder, belows are reasons of this test case implementation. |
| 238 | * - The more verbose one is just a wrapper function calls |
| 239 | * the other one without any additional logic. So we are |
| 240 | * safe to merge two tests into one. |
| 241 | * - 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] | 242 | */ |
| 243 | |
| 244 | const auto input_shape = TensorShape{ 2, 3, 3, 2 }; |
| 245 | const auto output_shape = TensorShape{ 4, 6, 3, 2 }; |
| 246 | |
| 247 | constexpr auto default_data_type = DataType::U8; |
| 248 | constexpr auto default_data_layout = DataLayout::NHWC; |
| 249 | constexpr auto default_interpolation_policy = InterpolationPolicy::NEAREST_NEIGHBOR; |
| 250 | constexpr auto default_border_mode = BorderMode::UNDEFINED; |
| 251 | constexpr auto default_sampling_policy = SamplingPolicy::CENTER; |
| 252 | constexpr bool default_use_padding = false; |
| 253 | |
| 254 | TEST_CASE(NullPtr, framework::DatasetMode::ALL) |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 255 | { |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 256 | const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout }; |
| 257 | const auto output = TensorInfo{ output_shape, 1, default_data_type, default_data_layout }; |
| 258 | Status result{}; |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 259 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 260 | // nullptr is given as input |
| 261 | result = NEScale::validate(nullptr, &output, default_interpolation_policy, default_border_mode); |
| 262 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
| 263 | |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame^] | 264 | result = NEScale::validate(nullptr, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode }); |
| 265 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
| 266 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 267 | // nullptr is given as output |
| 268 | result = NEScale::validate(&input, nullptr, default_interpolation_policy, default_border_mode); |
| 269 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame^] | 270 | |
| 271 | result = NEScale::validate(&input, nullptr, ScaleKernelInfo{ default_interpolation_policy, default_border_mode }); |
| 272 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | TEST_CASE(SupportDataType, framework::DatasetMode::ALL) |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 276 | { |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 277 | const std::map<DataType, bool> supported_data_types = |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 278 | { |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 279 | { DataType::U8, true }, |
| 280 | { DataType::S8, false }, |
| 281 | { DataType::QSYMM8, false }, |
| 282 | { DataType::QASYMM8, true }, |
| 283 | { DataType::QASYMM8_SIGNED, true }, |
| 284 | { DataType::QSYMM8_PER_CHANNEL, false }, |
| 285 | { DataType::U16, false }, |
| 286 | { DataType::S16, true }, |
| 287 | { DataType::QSYMM16, false }, |
| 288 | { DataType::QASYMM16, false }, |
| 289 | { DataType::U32, false }, |
| 290 | { DataType::S32, false }, |
| 291 | { DataType::U64, false }, |
| 292 | { DataType::S64, false }, |
| 293 | { DataType::BFLOAT16, false }, |
| 294 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 295 | { DataType::F16, true }, |
| 296 | #else // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 297 | { DataType::F16, false }, |
| 298 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 299 | { DataType::F32, true }, |
| 300 | { DataType::F64, false }, |
| 301 | { DataType::SIZET, false }, |
| 302 | }; |
| 303 | Status result{}; |
| 304 | for(auto &kv : supported_data_types) |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 305 | { |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 306 | const auto input = TensorInfo{ input_shape, 1, kv.first, default_data_layout }; |
| 307 | 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^] | 308 | |
| 309 | result = NEScale::validate(&input, &output, default_interpolation_policy, default_border_mode); |
| 310 | ARM_COMPUTE_EXPECT(bool(result) == kv.second, framework::LogLevel::ERRORS); |
| 311 | |
| 312 | 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] | 313 | ARM_COMPUTE_EXPECT(bool(result) == kv.second, framework::LogLevel::ERRORS); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 314 | } |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 315 | } |
| 316 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 317 | TEST_CASE(MissmatchingDataType, framework::DatasetMode::ALL) |
| 318 | { |
| 319 | constexpr auto non_default_data_type = DataType::F32; |
| 320 | |
| 321 | const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout }; |
| 322 | const auto output = TensorInfo{ output_shape, 1, non_default_data_type, default_data_layout }; |
| 323 | Status result{}; |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame^] | 324 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 325 | result = NEScale::validate(&input, &output, default_interpolation_policy, default_border_mode); |
| 326 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame^] | 327 | |
| 328 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode }); |
| 329 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | TEST_CASE(UsePadding, framework::DatasetMode::ALL) |
| 333 | { |
| 334 | const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout }; |
| 335 | const auto output = TensorInfo{ output_shape, 1, default_data_type, default_data_layout }; |
| 336 | Status result{}; |
| 337 | |
| 338 | // When use padding is false, border mode should be constant |
| 339 | constexpr auto border_mode = BorderMode::UNDEFINED; |
| 340 | constexpr bool use_padding = false; |
| 341 | |
| 342 | result = NEScale::validate(&input, &output, default_interpolation_policy, border_mode, PixelValue(), default_sampling_policy, use_padding); |
| 343 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame^] | 344 | |
| 345 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ default_interpolation_policy, border_mode, PixelValue(), default_sampling_policy, use_padding }); |
| 346 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | TEST_CASE(AreaWithNHWC, framework::DatasetMode::ALL) |
| 350 | { |
| 351 | // InterpolationPolicy::AREA is not supported for NHWC |
| 352 | constexpr auto interpolation_policy = InterpolationPolicy::AREA; |
| 353 | constexpr auto data_layout = DataLayout::NHWC; |
| 354 | |
| 355 | const auto input = TensorInfo{ input_shape, 1, default_data_type, data_layout }; |
| 356 | const auto output = TensorInfo{ output_shape, 1, default_data_type, data_layout }; |
| 357 | Status result{}; |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame^] | 358 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 359 | result = NEScale::validate(&input, &output, interpolation_policy, default_border_mode); |
| 360 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame^] | 361 | |
| 362 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode }); |
| 363 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | TEST_CASE(AreaWithNonU8, framework::DatasetMode::ALL) |
| 367 | { |
| 368 | // InterpolationPolicy::AREA only supports U8 |
| 369 | constexpr auto interpolation_policy = InterpolationPolicy::AREA; |
| 370 | constexpr auto data_type = DataType::F32; |
| 371 | constexpr auto data_layout = DataLayout::NCHW; |
| 372 | |
| 373 | const auto input = TensorInfo{ input_shape, 1, data_type, data_layout }; |
| 374 | const auto output = TensorInfo{ output_shape, 1, data_type, data_layout }; |
| 375 | Status result{}; |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame^] | 376 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 377 | result = NEScale::validate(&input, &output, interpolation_policy, default_border_mode); |
| 378 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame^] | 379 | |
| 380 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode }); |
| 381 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | TEST_CASE(InvalidAlignedCornerOutput, framework::DatasetMode::ALL) |
| 385 | { |
| 386 | // Bilinear with aligned corners require at least 2x2 output to prevent overflow. |
| 387 | // Also, aligned corners require sampling policy to be TOP_LEFT. |
| 388 | constexpr auto interpolation_policy = InterpolationPolicy::BILINEAR; |
| 389 | constexpr bool align_corners = true; |
| 390 | constexpr auto sampling_policy = SamplingPolicy::TOP_LEFT; |
| 391 | const auto invalid_output_shape = TensorShape{ 1, 1, 3, 2 }; |
| 392 | |
| 393 | const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout }; |
| 394 | const auto output = TensorInfo{ invalid_output_shape, 1, default_data_type, default_data_layout }; |
| 395 | Status result{}; |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame^] | 396 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 397 | result = NEScale::validate(&input, &output, interpolation_policy, default_border_mode, PixelValue(), sampling_policy, default_use_padding, align_corners); |
| 398 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 399 | |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame^] | 400 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode, PixelValue(), sampling_policy, default_use_padding, align_corners }); |
| 401 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
| 402 | } |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 403 | TEST_SUITE_END() // Validate |
| 404 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 405 | template <typename T> |
| 406 | using NEScaleFixture = ScaleValidationFixture<Tensor, Accessor, NEScale, T>; |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 407 | template <typename T> |
| 408 | using NEScaleQuantizedFixture = ScaleValidationQuantizedFixture<Tensor, Accessor, NEScale, T>; |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 409 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 410 | TEST_SUITE(Float) |
| 411 | TEST_SUITE(FP32) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 412 | const auto f32_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<float>())), framework::dataset::make("DataType", DataType::F32)); |
| 413 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<float>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f32_shape)) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 414 | { |
| 415 | //Create valid region |
| 416 | TensorInfo src_info(_shape, 1, _data_type); |
Diego Lopez Recas | 0085429 | 2018-02-22 13:08:01 +0000 | [diff] [blame] | 417 | 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] | 418 | |
| 419 | // Validate output |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 420 | validate(Accessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 421 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 422 | TEST_SUITE_END() // FP32 |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 423 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 424 | TEST_SUITE(FP16) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 425 | const auto f16_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<half>())), framework::dataset::make("DataType", DataType::F16)); |
| 426 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<half>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f16_shape)) |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 427 | { |
| 428 | //Create valid region |
| 429 | TensorInfo src_info(_shape, 1, _data_type); |
| 430 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 431 | |
| 432 | // Validate output |
| 433 | validate(Accessor(_target), _reference, valid_region, tolerance_f16); |
| 434 | } |
| 435 | TEST_SUITE_END() // FP16 |
| 436 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 437 | TEST_SUITE_END() // Float |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 438 | |
| 439 | TEST_SUITE(Integer) |
| 440 | TEST_SUITE(U8) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 441 | const auto u8_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<uint8_t>())), framework::dataset::make("DataType", DataType::U8)); |
| 442 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(u8_shape)) |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 443 | { |
| 444 | //Create valid region |
| 445 | TensorInfo src_info(_shape, 1, _data_type); |
Diego Lopez Recas | 0085429 | 2018-02-22 13:08:01 +0000 | [diff] [blame] | 446 | 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] | 447 | |
| 448 | // Validate output |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 449 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 450 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 451 | TEST_SUITE_END() // U8 |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 452 | TEST_SUITE(S16) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 453 | const auto s16_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<int16_t>())), framework::dataset::make("DataType", DataType::S16)); |
| 454 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<int16_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(s16_shape)) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 455 | { |
| 456 | //Create valid region |
| 457 | TensorInfo src_info(_shape, 1, _data_type); |
Diego Lopez Recas | 0085429 | 2018-02-22 13:08:01 +0000 | [diff] [blame] | 458 | 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] | 459 | |
| 460 | // Validate output |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 461 | validate(Accessor(_target), _reference, valid_region, tolerance_s16, tolerance_num_s16); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 462 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 463 | TEST_SUITE_END() // S16 |
| 464 | TEST_SUITE_END() // Integer |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 465 | |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 466 | TEST_SUITE(Quantized) |
| 467 | TEST_SUITE(QASYMM8) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 468 | const auto qasymm8_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<uint8_t>())), framework::dataset::make("DataType", DataType::QASYMM8)); |
| 469 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_shape)) |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 470 | { |
| 471 | //Create valid region |
| 472 | TensorInfo src_info(_shape, 1, _data_type); |
| 473 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 474 | |
| 475 | // Validate output |
| 476 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
| 477 | } |
| 478 | TEST_SUITE_END() // QASYMM8 |
Sheri Zhang | 359c48e | 2020-04-30 22:53:39 +0100 | [diff] [blame] | 479 | TEST_SUITE(QASYMM8_SIGNED) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 480 | const auto qasymm8_signed_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<int8_t>())), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)); |
| 481 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleQuantizedFixture<int8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_signed_shape)) |
Sheri Zhang | 359c48e | 2020-04-30 22:53:39 +0100 | [diff] [blame] | 482 | { |
| 483 | //Create valid region |
| 484 | TensorInfo src_info(_shape, 1, _data_type); |
| 485 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 486 | |
| 487 | // Validate output |
| 488 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
| 489 | } |
| 490 | TEST_SUITE_END() // QASYMM8_SIGNED |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 491 | TEST_SUITE_END() // Quantized |
| 492 | |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 493 | TEST_SUITE_END() // Scale |
| 494 | TEST_SUITE_END() // NEON |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 495 | } // namespace validation |
| 496 | } // namespace test |
| 497 | } // namespace arm_compute |