Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 1 | /* |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2021 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" |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 31 | #include "tests/datasets/ScaleValidationDataset.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Macros.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame] | 34 | #include "tests/validation/Helpers.h" |
| 35 | #include "tests/validation/Validation.h" |
| 36 | #include "tests/validation/fixtures/ScaleFixture.h" |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
Isabella Gottardi | 732f368 | 2017-09-05 14:10:12 +0100 | [diff] [blame] | 44 | namespace |
| 45 | { |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 46 | using datasets::ScaleShapesBaseDataSet; |
| 47 | using datasets::ScaleInterpolationPolicySet; |
| 48 | using datasets::ScaleDataLayouts; |
| 49 | using datasets::ScaleSamplingPolicySet; |
| 50 | using datasets::ScaleAlignCornersSamplingPolicySet; |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 51 | |
| 52 | /** We consider vector size in byte 64 since the maximum size of |
Manuel Bottini | 10b3826 | 2021-02-19 18:16:44 +0000 | [diff] [blame] | 53 | * a vector used by the kernel is currently 64-byte (float32x4x4). |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 54 | * There are possibility to reduce test time further by using |
| 55 | * smaller vector sizes for different data types where applicable. |
| 56 | */ |
| 57 | constexpr uint32_t vector_byte = 64; |
| 58 | |
| 59 | template <typename T> |
| 60 | constexpr uint32_t num_elements_per_vector() |
| 61 | { |
| 62 | return vector_byte / sizeof(T); |
| 63 | } |
| 64 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 65 | /** Scale data types */ |
| 66 | const auto ScaleDataTypes = framework::dataset::make("DataType", |
| 67 | { |
| 68 | DataType::U8, |
| 69 | DataType::S16, |
| 70 | DataType::F32, |
| 71 | }); |
| 72 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 73 | /** Quantization information data set */ |
| 74 | const auto QuantizationInfoSet = framework::dataset::make("QuantizationInfo", |
| 75 | { |
| 76 | QuantizationInfo(0.5f, -10), |
| 77 | }); |
| 78 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 79 | /** Tolerance */ |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 80 | constexpr AbsoluteTolerance<uint8_t> tolerance_u8(1); |
| 81 | constexpr AbsoluteTolerance<int16_t> tolerance_s16(1); |
Sang-Hoon Park | 90251bc | 2020-08-20 13:57:49 +0100 | [diff] [blame] | 82 | RelativeTolerance<float> tolerance_f32(0.05); |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 83 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 84 | RelativeTolerance<half> tolerance_f16(half(0.1)); |
| 85 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 86 | |
| 87 | constexpr float tolerance_num_s16 = 0.01f; |
| 88 | constexpr float tolerance_num_f32 = 0.01f; |
Isabella Gottardi | 732f368 | 2017-09-05 14:10:12 +0100 | [diff] [blame] | 89 | } // namespace |
| 90 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 91 | TEST_SUITE(NEON) |
| 92 | TEST_SUITE(Scale) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 93 | TEST_SUITE(Validate) |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 94 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 95 | /** Validate test suite is to test ARM_COMPUTE_RETURN_ON_* macros |
| 96 | * we use to check the validity of given arguments in @ref NEScale |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 97 | * Since this is using validate() of @ref NEScale, which pre-adjust |
Manuel Bottini | 10b3826 | 2021-02-19 18:16:44 +0000 | [diff] [blame] | 98 | * arguments for the kernel, the following conditions in |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 99 | * the kernel are not currently tested. |
| 100 | * - The same input and output |
| 101 | * - Data type of offset, dx and dy |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 102 | * This suite also tests two different validate() APIs - one is |
| 103 | * using @ref ScaleKernelInfo and the other one is more verbose |
| 104 | * one calls the other one - in the same test case. Even though |
| 105 | * there are possibility that it makes debugging for regression |
| 106 | * harder, belows are reasons of this test case implementation. |
| 107 | * - The more verbose one is just a wrapper function calls |
| 108 | * the other one without any additional logic. So we are |
| 109 | * safe to merge two tests into one. |
| 110 | * - 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] | 111 | */ |
| 112 | |
| 113 | const auto input_shape = TensorShape{ 2, 3, 3, 2 }; |
| 114 | const auto output_shape = TensorShape{ 4, 6, 3, 2 }; |
| 115 | |
| 116 | constexpr auto default_data_type = DataType::U8; |
| 117 | constexpr auto default_data_layout = DataLayout::NHWC; |
| 118 | constexpr auto default_interpolation_policy = InterpolationPolicy::NEAREST_NEIGHBOR; |
Manuel Bottini | fc2f6d0 | 2020-08-26 16:28:38 +0100 | [diff] [blame] | 119 | constexpr auto default_border_mode = BorderMode::CONSTANT; |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 120 | constexpr auto default_sampling_policy = SamplingPolicy::CENTER; |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 121 | |
| 122 | TEST_CASE(NullPtr, framework::DatasetMode::ALL) |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 123 | { |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 124 | const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout }; |
| 125 | const auto output = TensorInfo{ output_shape, 1, default_data_type, default_data_layout }; |
| 126 | Status result{}; |
Georgios Pinitas | 20b4313 | 2018-05-14 16:05:23 +0100 | [diff] [blame] | 127 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 128 | // nullptr is given as input |
Manuel Bottini | fc2f6d0 | 2020-08-26 16:28:38 +0100 | [diff] [blame] | 129 | result = NEScale::validate(nullptr, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode, PixelValue(), SamplingPolicy::CENTER, false }); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 130 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
| 131 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 132 | // nullptr is given as output |
Manuel Bottini | fc2f6d0 | 2020-08-26 16:28:38 +0100 | [diff] [blame] | 133 | result = NEScale::validate(&input, nullptr, ScaleKernelInfo{ default_interpolation_policy, default_border_mode, PixelValue(), SamplingPolicy::CENTER, false }); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 134 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | TEST_CASE(SupportDataType, framework::DatasetMode::ALL) |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 138 | { |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 139 | const std::map<DataType, bool> supported_data_types = |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 140 | { |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 141 | { DataType::U8, true }, |
| 142 | { DataType::S8, false }, |
| 143 | { DataType::QSYMM8, false }, |
| 144 | { DataType::QASYMM8, true }, |
| 145 | { DataType::QASYMM8_SIGNED, true }, |
| 146 | { DataType::QSYMM8_PER_CHANNEL, false }, |
| 147 | { DataType::U16, false }, |
| 148 | { DataType::S16, true }, |
| 149 | { DataType::QSYMM16, false }, |
| 150 | { DataType::QASYMM16, false }, |
| 151 | { DataType::U32, false }, |
| 152 | { DataType::S32, false }, |
| 153 | { DataType::U64, false }, |
| 154 | { DataType::S64, false }, |
| 155 | { DataType::BFLOAT16, false }, |
| 156 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 157 | { DataType::F16, true }, |
| 158 | #else // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 159 | { DataType::F16, false }, |
| 160 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 161 | { DataType::F32, true }, |
| 162 | { DataType::F64, false }, |
| 163 | { DataType::SIZET, false }, |
| 164 | }; |
| 165 | Status result{}; |
| 166 | for(auto &kv : supported_data_types) |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 167 | { |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 168 | const auto input = TensorInfo{ input_shape, 1, kv.first, default_data_layout }; |
| 169 | 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] | 170 | |
Manuel Bottini | fc2f6d0 | 2020-08-26 16:28:38 +0100 | [diff] [blame] | 171 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode, PixelValue(), SamplingPolicy::CENTER, false }); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 172 | ARM_COMPUTE_EXPECT(bool(result) == kv.second, framework::LogLevel::ERRORS); |
Georgios Pinitas | 393fa4c | 2018-05-08 15:54:53 +0100 | [diff] [blame] | 173 | } |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 174 | } |
| 175 | |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 176 | TEST_CASE(MissmatchingDataType, framework::DatasetMode::ALL) |
| 177 | { |
| 178 | constexpr auto non_default_data_type = DataType::F32; |
| 179 | |
| 180 | const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout }; |
| 181 | const auto output = TensorInfo{ output_shape, 1, non_default_data_type, default_data_layout }; |
| 182 | Status result{}; |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 183 | |
Manuel Bottini | fc2f6d0 | 2020-08-26 16:28:38 +0100 | [diff] [blame] | 184 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ default_interpolation_policy, default_border_mode, PixelValue(), SamplingPolicy::CENTER, false }); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 185 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | TEST_CASE(UsePadding, framework::DatasetMode::ALL) |
| 189 | { |
| 190 | const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout }; |
| 191 | const auto output = TensorInfo{ output_shape, 1, default_data_type, default_data_layout }; |
| 192 | Status result{}; |
| 193 | |
Manuel Bottini | fc2f6d0 | 2020-08-26 16:28:38 +0100 | [diff] [blame] | 194 | // Padding is not supported anymore |
| 195 | constexpr auto border_mode = BorderMode::CONSTANT; |
| 196 | constexpr bool use_padding = true; |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 197 | |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 198 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ default_interpolation_policy, border_mode, PixelValue(), default_sampling_policy, use_padding }); |
| 199 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | TEST_CASE(AreaWithNHWC, framework::DatasetMode::ALL) |
| 203 | { |
| 204 | // InterpolationPolicy::AREA is not supported for NHWC |
| 205 | constexpr auto interpolation_policy = InterpolationPolicy::AREA; |
| 206 | constexpr auto data_layout = DataLayout::NHWC; |
| 207 | |
| 208 | const auto input = TensorInfo{ input_shape, 1, default_data_type, data_layout }; |
| 209 | const auto output = TensorInfo{ output_shape, 1, default_data_type, data_layout }; |
| 210 | Status result{}; |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 211 | |
Manuel Bottini | fc2f6d0 | 2020-08-26 16:28:38 +0100 | [diff] [blame] | 212 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode, PixelValue(), SamplingPolicy::CENTER, false }); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 213 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | TEST_CASE(AreaWithNonU8, framework::DatasetMode::ALL) |
| 217 | { |
| 218 | // InterpolationPolicy::AREA only supports U8 |
| 219 | constexpr auto interpolation_policy = InterpolationPolicy::AREA; |
| 220 | constexpr auto data_type = DataType::F32; |
| 221 | constexpr auto data_layout = DataLayout::NCHW; |
| 222 | |
| 223 | const auto input = TensorInfo{ input_shape, 1, data_type, data_layout }; |
| 224 | const auto output = TensorInfo{ output_shape, 1, data_type, data_layout }; |
| 225 | Status result{}; |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 226 | |
Manuel Bottini | fc2f6d0 | 2020-08-26 16:28:38 +0100 | [diff] [blame] | 227 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode, PixelValue(), SamplingPolicy::CENTER, false }); |
Sang-Hoon Park | c261798 | 2020-05-20 22:13:47 +0100 | [diff] [blame] | 228 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 229 | } |
| 230 | |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 231 | TEST_CASE(AlignedCornerNotSupported, framework::DatasetMode::ALL) |
| 232 | { |
| 233 | // Aligned corners require sampling policy to be TOP_LEFT. |
| 234 | constexpr auto interpolation_policy = InterpolationPolicy::BILINEAR; |
| 235 | constexpr bool align_corners = true; |
| 236 | constexpr auto sampling_policy = SamplingPolicy::CENTER; |
| 237 | |
| 238 | const auto input = TensorInfo{ input_shape, 1, default_data_type, default_data_layout }; |
| 239 | const auto output = TensorInfo{ output_shape, 1, default_data_type, default_data_layout }; |
| 240 | Status result{}; |
| 241 | |
Manuel Bottini | fc2f6d0 | 2020-08-26 16:28:38 +0100 | [diff] [blame] | 242 | result = NEScale::validate(&input, &output, ScaleKernelInfo{ interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false, align_corners }); |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 243 | ARM_COMPUTE_EXPECT(bool(result) == false, framework::LogLevel::ERRORS); |
| 244 | } |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 245 | TEST_SUITE_END() // Validate |
| 246 | |
Manuel Bottini | fc2f6d0 | 2020-08-26 16:28:38 +0100 | [diff] [blame] | 247 | DATA_TEST_CASE(CheckNoPadding, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::Medium4DShapes(), |
| 248 | framework::dataset::make("DataType", { DataType::F32, DataType::QASYMM8 })), |
| 249 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::BILINEAR, InterpolationPolicy::NEAREST_NEIGHBOR })), |
| 250 | framework::dataset::make("SamplingPolicy", { SamplingPolicy::CENTER, SamplingPolicy::TOP_LEFT })), |
| 251 | framework::dataset::make("DataLayout", { DataLayout::NHWC, DataLayout::NCHW })), |
| 252 | shape, data_type, interpolation_policy, sampling_policy, data_layout) |
| 253 | { |
| 254 | constexpr auto default_border_mode = BorderMode::CONSTANT; |
| 255 | ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false); |
| 256 | |
| 257 | // Create tensors |
| 258 | Tensor src = create_tensor<Tensor>(shape, data_type); |
| 259 | src.info()->set_data_layout(data_layout); |
| 260 | |
| 261 | const float scale_x = 0.5f; |
| 262 | const float scale_y = 0.5f; |
| 263 | TensorShape shape_scaled(shape); |
| 264 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 265 | const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 266 | shape_scaled.set(idx_width, shape[idx_width] * scale_x, /* apply_dim_correction = */ false); |
| 267 | shape_scaled.set(idx_height, shape[idx_height] * scale_y, /* apply_dim_correction = */ false); |
| 268 | Tensor dst = create_tensor<Tensor>(shape_scaled, data_type); |
| 269 | |
| 270 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 271 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 272 | |
| 273 | // Create and configure function |
| 274 | NEScale scale; |
| 275 | scale.configure(&src, &dst, info); |
| 276 | |
| 277 | validate(src.info()->padding(), PaddingSize(0, 0, 0, 0)); |
| 278 | validate(dst.info()->padding(), PaddingSize(0, 0, 0, 0)); |
| 279 | } |
| 280 | |
| 281 | DATA_TEST_CASE(CheckNoPaddingInterpAREA, framework::DatasetMode::ALL, combine(combine(combine(combine(datasets::Medium4DShapes(), |
| 282 | framework::dataset::make("DataType", { DataType::U8 })), |
| 283 | framework::dataset::make("InterpolationPolicy", { InterpolationPolicy::AREA })), |
| 284 | framework::dataset::make("SamplingPolicy", { SamplingPolicy::CENTER, SamplingPolicy::TOP_LEFT })), |
| 285 | framework::dataset::make("DataLayout", { DataLayout::NCHW })), |
| 286 | shape, data_type, interpolation_policy, sampling_policy, data_layout) |
| 287 | { |
| 288 | constexpr auto default_border_mode = BorderMode::CONSTANT; |
| 289 | ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false); |
| 290 | |
| 291 | // Create tensors |
| 292 | Tensor src = create_tensor<Tensor>(shape, data_type); |
| 293 | src.info()->set_data_layout(data_layout); |
| 294 | |
| 295 | const float scale_x = 0.5f; |
| 296 | const float scale_y = 0.5f; |
| 297 | TensorShape shape_scaled(shape); |
| 298 | const int idx_width = get_data_layout_dimension_index(data_layout, DataLayoutDimension::WIDTH); |
| 299 | const int idx_height = get_data_layout_dimension_index(data_layout, DataLayoutDimension::HEIGHT); |
| 300 | shape_scaled.set(idx_width, shape[idx_width] * scale_x, /* apply_dim_correction = */ false); |
| 301 | shape_scaled.set(idx_height, shape[idx_height] * scale_y, /* apply_dim_correction = */ false); |
| 302 | |
| 303 | Tensor dst = create_tensor<Tensor>(shape, data_type); |
| 304 | |
| 305 | ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 306 | ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS); |
| 307 | |
| 308 | // Create and configure function |
| 309 | NEScale scale; |
| 310 | scale.configure(&src, &dst, info); |
| 311 | |
| 312 | validate(src.info()->padding(), PaddingSize(0, 0, 0, 0)); |
| 313 | validate(dst.info()->padding(), PaddingSize(0, 0, 0, 0)); |
| 314 | } |
| 315 | |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 316 | template <typename T> |
| 317 | using NEScaleFixture = ScaleValidationFixture<Tensor, Accessor, NEScale, T>; |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 318 | template <typename T> |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 319 | using NEScaleMixedDataLayoutFixture = ScaleValidationFixture<Tensor, Accessor, NEScale, T, true>; |
| 320 | template <typename T> |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 321 | using NEScaleQuantizedFixture = ScaleValidationQuantizedFixture<Tensor, Accessor, NEScale, T>; |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 322 | template <typename T> |
| 323 | using NEScaleQuantizedMixedDataLayoutFixture = ScaleValidationQuantizedFixture<Tensor, Accessor, NEScale, T, true>; |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 324 | |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 325 | TEST_SUITE(Float) |
| 326 | TEST_SUITE(FP32) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 327 | const auto f32_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<float>())), framework::dataset::make("DataType", DataType::F32)); |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 328 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<float>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f32_shape, ScaleSamplingPolicySet)) |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame] | 329 | { |
| 330 | //Create valid region |
| 331 | TensorInfo src_info(_shape, 1, _data_type); |
| 332 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 333 | |
| 334 | // Validate output |
| 335 | validate(Accessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32); |
| 336 | } |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 337 | FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEScaleMixedDataLayoutFixture<float>, framework::DatasetMode::PRECOMMIT, ASSEMBLE_DATASET(f32_shape, ScaleSamplingPolicySet)) |
| 338 | { |
| 339 | //Create valid region |
| 340 | TensorInfo src_info(_shape, 1, _data_type); |
| 341 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 342 | |
| 343 | // Validate output |
| 344 | validate(Accessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32); |
| 345 | } |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 346 | FIXTURE_DATA_TEST_CASE(RunSmallAlignCorners, NEScaleFixture<float>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f32_shape, ScaleAlignCornersSamplingPolicySet)) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 347 | { |
| 348 | //Create valid region |
| 349 | TensorInfo src_info(_shape, 1, _data_type); |
Diego Lopez Recas | 0085429 | 2018-02-22 13:08:01 +0000 | [diff] [blame] | 350 | 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] | 351 | |
| 352 | // Validate output |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 353 | validate(Accessor(_target), _reference, valid_region, tolerance_f32, tolerance_num_f32); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 354 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 355 | TEST_SUITE_END() // FP32 |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 356 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 357 | TEST_SUITE(FP16) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 358 | const auto f16_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<half>())), framework::dataset::make("DataType", DataType::F16)); |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 359 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<half>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f16_shape, ScaleSamplingPolicySet)) |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame] | 360 | { |
| 361 | //Create valid region |
| 362 | TensorInfo src_info(_shape, 1, _data_type); |
| 363 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 364 | |
| 365 | // Validate output |
| 366 | validate(Accessor(_target), _reference, valid_region, tolerance_f16); |
| 367 | } |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 368 | FIXTURE_DATA_TEST_CASE(RunSmallAlignCorners, NEScaleFixture<half>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(f16_shape, ScaleAlignCornersSamplingPolicySet)) |
Georgios Pinitas | c47ef20 | 2018-11-16 18:19:43 +0000 | [diff] [blame] | 369 | { |
| 370 | //Create valid region |
| 371 | TensorInfo src_info(_shape, 1, _data_type); |
| 372 | const ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 373 | |
| 374 | // Validate output |
| 375 | validate(Accessor(_target), _reference, valid_region, tolerance_f16); |
| 376 | } |
| 377 | TEST_SUITE_END() // FP16 |
| 378 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 379 | TEST_SUITE_END() // Float |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 380 | |
| 381 | TEST_SUITE(Integer) |
| 382 | TEST_SUITE(U8) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 383 | const auto u8_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<uint8_t>())), framework::dataset::make("DataType", DataType::U8)); |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 384 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(u8_shape, ScaleSamplingPolicySet)) |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame] | 385 | { |
| 386 | //Create valid region |
| 387 | TensorInfo src_info(_shape, 1, _data_type); |
| 388 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 389 | |
| 390 | // Validate output |
| 391 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
| 392 | } |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 393 | FIXTURE_DATA_TEST_CASE(RunSmallAlignCorners, NEScaleFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(u8_shape, ScaleAlignCornersSamplingPolicySet)) |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 394 | { |
| 395 | //Create valid region |
| 396 | TensorInfo src_info(_shape, 1, _data_type); |
Diego Lopez Recas | 0085429 | 2018-02-22 13:08:01 +0000 | [diff] [blame] | 397 | 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] | 398 | |
| 399 | // Validate output |
Georgios Pinitas | 99d4f4a | 2017-09-19 16:51:42 +0100 | [diff] [blame] | 400 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 401 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 402 | TEST_SUITE_END() // U8 |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 403 | TEST_SUITE(S16) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 404 | const auto s16_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<int16_t>())), framework::dataset::make("DataType", DataType::S16)); |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 405 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleFixture<int16_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(s16_shape, ScaleSamplingPolicySet)) |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame] | 406 | { |
| 407 | //Create valid region |
| 408 | TensorInfo src_info(_shape, 1, _data_type); |
| 409 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 410 | |
| 411 | // Validate output |
| 412 | validate(Accessor(_target), _reference, valid_region, tolerance_s16, tolerance_num_s16); |
| 413 | } |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 414 | FIXTURE_DATA_TEST_CASE(RunSmallAlignCorners, NEScaleFixture<int16_t>, framework::DatasetMode::ALL, ASSEMBLE_DATASET(s16_shape, ScaleAlignCornersSamplingPolicySet)) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 415 | { |
| 416 | //Create valid region |
| 417 | TensorInfo src_info(_shape, 1, _data_type); |
Diego Lopez Recas | 0085429 | 2018-02-22 13:08:01 +0000 | [diff] [blame] | 418 | 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] | 419 | |
| 420 | // Validate output |
Moritz Pflanzer | ff1c360 | 2017-09-22 12:41:25 +0100 | [diff] [blame] | 421 | validate(Accessor(_target), _reference, valid_region, tolerance_s16, tolerance_num_s16); |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 422 | } |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 423 | TEST_SUITE_END() // S16 |
| 424 | TEST_SUITE_END() // Integer |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 425 | |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 426 | TEST_SUITE(Quantized) |
| 427 | TEST_SUITE(QASYMM8) |
Sang-Hoon Park | c72dabc | 2020-05-27 13:03:18 +0100 | [diff] [blame] | 428 | const auto qasymm8_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<uint8_t>())), framework::dataset::make("DataType", DataType::QASYMM8)); |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 429 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_shape, ScaleSamplingPolicySet, QuantizationInfoSet)) |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame] | 430 | { |
| 431 | //Create valid region |
| 432 | TensorInfo src_info(_shape, 1, _data_type); |
| 433 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 434 | |
| 435 | // Validate output |
| 436 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
| 437 | } |
Manuel Bottini | ca62c6f | 2021-03-23 11:50:34 +0000 | [diff] [blame] | 438 | FIXTURE_DATA_TEST_CASE(RunMixedDataLayout, NEScaleQuantizedMixedDataLayoutFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_shape, ScaleSamplingPolicySet, QuantizationInfoSet)) |
| 439 | { |
| 440 | //Create valid region |
| 441 | TensorInfo src_info(_shape, 1, _data_type); |
| 442 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 443 | |
| 444 | // Validate output |
| 445 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
| 446 | } |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 447 | FIXTURE_DATA_TEST_CASE(RunSmallAlignCorners, NEScaleQuantizedFixture<uint8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_shape, ScaleAlignCornersSamplingPolicySet, |
| 448 | QuantizationInfoSet)) |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 449 | { |
| 450 | //Create valid region |
| 451 | TensorInfo src_info(_shape, 1, _data_type); |
| 452 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 453 | |
| 454 | // Validate output |
| 455 | validate(Accessor(_target), _reference, valid_region, tolerance_u8); |
| 456 | } |
| 457 | TEST_SUITE_END() // QASYMM8 |
Sheri Zhang | 359c48e | 2020-04-30 22:53:39 +0100 | [diff] [blame] | 458 | TEST_SUITE(QASYMM8_SIGNED) |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 459 | const auto qasymm8_signed_shape = combine((SCALE_SHAPE_DATASET(num_elements_per_vector<int8_t>())), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)); |
| 460 | constexpr AbsoluteTolerance<int8_t> tolerance_qasymm8_signed{ 1 }; |
| 461 | FIXTURE_DATA_TEST_CASE(RunSmall, NEScaleQuantizedFixture<int8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_signed_shape, ScaleSamplingPolicySet, QuantizationInfoSet)) |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame] | 462 | { |
| 463 | //Create valid region |
| 464 | TensorInfo src_info(_shape, 1, _data_type); |
| 465 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 466 | |
| 467 | // Validate output |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 468 | validate(Accessor(_target), _reference, valid_region, tolerance_qasymm8_signed); |
Sang-Hoon Park | f025a77 | 2020-05-26 11:11:32 +0100 | [diff] [blame] | 469 | } |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 470 | FIXTURE_DATA_TEST_CASE(RunSmallAlignCorners, NEScaleQuantizedFixture<int8_t>, framework::DatasetMode::ALL, ASSEMBLE_QUANTIZED_DATASET(qasymm8_signed_shape, ScaleAlignCornersSamplingPolicySet, |
| 471 | QuantizationInfoSet)) |
Sheri Zhang | 359c48e | 2020-04-30 22:53:39 +0100 | [diff] [blame] | 472 | { |
| 473 | //Create valid region |
| 474 | TensorInfo src_info(_shape, 1, _data_type); |
| 475 | ValidRegion valid_region = calculate_valid_region_scale(src_info, _reference.shape(), _policy, _sampling_policy, (_border_mode == BorderMode::UNDEFINED)); |
| 476 | |
| 477 | // Validate output |
Sang-Hoon Park | 27a9e4f | 2020-06-08 19:21:34 +0100 | [diff] [blame] | 478 | validate(Accessor(_target), _reference, valid_region, tolerance_qasymm8_signed); |
Sheri Zhang | 359c48e | 2020-04-30 22:53:39 +0100 | [diff] [blame] | 479 | } |
| 480 | TEST_SUITE_END() // QASYMM8_SIGNED |
Vidhya Sudhan Loganathan | 3ac2f3a | 2019-01-17 15:16:19 +0000 | [diff] [blame] | 481 | TEST_SUITE_END() // Quantized |
| 482 | |
Michalis Spyrou | aeebe4a | 2019-01-09 14:21:03 +0000 | [diff] [blame] | 483 | TEST_SUITE_END() // Scale |
Sheri Zhang | ac6499a | 2021-02-10 15:32:38 +0000 | [diff] [blame] | 484 | TEST_SUITE_END() // Neon |
Isabella Gottardi | 1fab09f | 2017-07-13 15:55:57 +0100 | [diff] [blame] | 485 | } // namespace validation |
| 486 | } // namespace test |
| 487 | } // namespace arm_compute |