Adnan AlSinan | 171fc3d | 2022-03-15 18:46:42 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2022 Arm Limited. |
| 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/Types.h" |
| 25 | #include "arm_compute/runtime/NEON/functions/NEPooling3dLayer.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
| 28 | #include "tests/NEON/Accessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
| 30 | #include "tests/datasets/Pooling3dLayerDataset.h" |
| 31 | #include "tests/datasets/PoolingTypesDataset.h" |
| 32 | #include "tests/datasets/ShapeDatasets.h" |
| 33 | #include "tests/framework/Asserts.h" |
| 34 | #include "tests/framework/Macros.h" |
| 35 | #include "tests/framework/datasets/Datasets.h" |
| 36 | #include "tests/validation/Validation.h" |
| 37 | #include "tests/validation/fixtures/Pooling3dLayerFixture.h" |
| 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | namespace |
| 46 | { |
| 47 | /** Input data sets for floating-point data types */ |
| 48 | const auto Pooling3dLayerDatasetFP = combine(combine(combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { Size3D(2, 3, 2) })), |
| 49 | framework::dataset::make("Stride", { Size3D(1, 1, 1), Size3D(2, 1, 1), Size3D(1, 2, 1), Size3D(2, 2, 1) })), |
| 50 | framework::dataset::make("Padding", { Padding3D(0, 1, 0), Padding3D(1, 1, 1) })), |
| 51 | framework::dataset::make("ExcludePadding", { true, false })); |
| 52 | |
| 53 | const auto Pooling3dLayerDatasetFPSmall = combine(combine(combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { Size3D(2, 2, 2), Size3D(3, 3, 3) })), |
| 54 | framework::dataset::make("Stride", { Size3D(2, 2, 2), Size3D(2, 1, 1) })), |
| 55 | framework::dataset::make("Padding", { Padding3D(0, 0, 0), Padding3D(1, 1, 1), Padding3D(1, 0, 0) })), |
| 56 | framework::dataset::make("ExcludePadding", { true, false })); |
| 57 | |
| 58 | using ShapeDataset = framework::dataset::ContainerDataset<std::vector<TensorShape>>; |
| 59 | |
| 60 | constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for 32-bit floating-point type */ |
Adnan AlSinan | 4c17ba9 | 2022-04-01 19:09:46 +0100 | [diff] [blame^] | 61 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Adnan AlSinan | 171fc3d | 2022-03-15 18:46:42 +0000 | [diff] [blame] | 62 | constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */ |
Adnan AlSinan | 4c17ba9 | 2022-04-01 19:09:46 +0100 | [diff] [blame^] | 63 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Adnan AlSinan | 171fc3d | 2022-03-15 18:46:42 +0000 | [diff] [blame] | 64 | } //namespace |
| 65 | |
| 66 | TEST_SUITE(NEON) |
| 67 | TEST_SUITE(Pooling3dLayer) |
| 68 | |
| 69 | // *INDENT-OFF* |
| 70 | // clang-format off |
| 71 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 72 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(2U, 27U, 13U, 4U, 3U), 1, DataType::F32, DataLayout::NDHWC), // Mismatching data type |
| 73 | TensorInfo(TensorShape(2U, 27U, 13U, 4U, 2U), 1, DataType::F32, DataLayout::NDHWC), // Invalid pad/size combination |
| 74 | TensorInfo(TensorShape(2U, 27U, 13U, 4U, 2U), 1, DataType::F32, DataLayout::NDHWC), // Invalid pad/size combination |
| 75 | TensorInfo(TensorShape(2U, 27U, 13U, 4U, 3U), 1, DataType::F32, DataLayout::NDHWC), // Invalid output shape |
| 76 | TensorInfo(TensorShape(5U, 13U, 15U, 2U, 3U), 1, DataType::F32, DataLayout::NDHWC), // Global Pooling |
| 77 | TensorInfo(TensorShape(13U,13U, 5U, 1U, 2U), 1, DataType::F32, DataLayout::NDHWC), // Invalid output Global Pooling |
| 78 | TensorInfo(TensorShape(5U, 13U, 13U, 4U, 4U), 1, DataType::F32, DataLayout::NDHWC), |
| 79 | TensorInfo(TensorShape(5U, 13U, 13U, 4U, 4U), 1, DataType::F32, DataLayout::NDHWC), // Invalid data type |
| 80 | TensorInfo(TensorShape(5U, 13U, 13U, 4U, 4U), 1, DataType::F32, DataLayout::NHWC), // Invalid data layout |
| 81 | TensorInfo(TensorShape(5U, 13U, 13U, 5U, 4U), 1, DataType::F32, DataLayout::NDHWC), |
| 82 | TensorInfo(TensorShape(1U, 16U, 1U, 3U, 4U), 1, DataType::F32, DataLayout::NDHWC), |
| 83 | TensorInfo(TensorShape(5U, 13U, 13U, 4U, 3U), 1, DataType::F32, DataLayout::NDHWC), |
| 84 | TensorInfo(TensorShape(5U, 13U, 13U, 4U, 2U), 1, DataType::F32, DataLayout::NDHWC), |
| 85 | TensorInfo(TensorShape(5U, 13U, 13U, 4U, 3U), 1, DataType::F32, DataLayout::NDHWC), |
| 86 | }), |
| 87 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(2U, 25U, 11U, 3U, 3U), 1, DataType::F16, DataLayout::NDHWC), |
| 88 | TensorInfo(TensorShape(2U, 30U, 11U, 3U, 2U), 1, DataType::F32, DataLayout::NDHWC), |
| 89 | TensorInfo(TensorShape(2U, 25U, 16U, 3U, 2U), 1, DataType::F32, DataLayout::NDHWC), |
| 90 | TensorInfo(TensorShape(2U, 27U, 13U, 3U, 3U), 1, DataType::F32, DataLayout::NDHWC), |
| 91 | TensorInfo(TensorShape(5U, 1U, 1U, 1U, 3U), 1, DataType::F32, DataLayout::NDHWC), // Global pooling applied |
| 92 | TensorInfo(TensorShape(5U, 2U, 2U, 2U, 2U), 1, DataType::F32, DataLayout::NDHWC), // Invalid output Global Pooling |
| 93 | TensorInfo(TensorShape(5U, 12U, 12U, 3U, 4U), 1, DataType::F32, DataLayout::NDHWC), |
| 94 | TensorInfo(TensorShape(5U, 12U, 12U, 3U, 4U), 1, DataType::QASYMM8, DataLayout::NDHWC), // Invalid data type |
| 95 | TensorInfo(TensorShape(5U, 12U, 12U, 3U, 4U), 1, DataType::F32, DataLayout::NDHWC), // Invalid data layout |
| 96 | TensorInfo(TensorShape(5U, 1U, 1U, 1U, 4U), 1, DataType::F32, DataLayout::NDHWC), |
| 97 | TensorInfo(TensorShape(1U, 15U, 1U, 2U, 4U), 1, DataType::F32, DataLayout::NDHWC), // size larger than height |
| 98 | TensorInfo(TensorShape(5U, 6U, 6U, 2U, 3U), 1, DataType::F32, DataLayout::NDHWC), |
| 99 | TensorInfo(TensorShape(5U, 6U, 6U, 2U, 2U), 1, DataType::F32, DataLayout::NDHWC), |
| 100 | TensorInfo(TensorShape(5U, 6U, 6U, 2U, 3U), 1, DataType::F32, DataLayout::NDHWC), |
| 101 | })), |
| 102 | framework::dataset::make("PoolInfo", { Pooling3dLayerInfo(PoolingType::AVG, 3, Size3D(1, 1, 1), Padding3D(0, 0, 0)), |
| 103 | Pooling3dLayerInfo(PoolingType::AVG, 2, Size3D(1, 1, 1), Padding3D(2, 0, 0)), |
| 104 | Pooling3dLayerInfo(PoolingType::AVG, 2, Size3D(1, 1, 1), Padding3D(0, 0, 0)), |
| 105 | Pooling3dLayerInfo(PoolingType::L2, 3, Size3D(1, 1, 1), Padding3D(0, 0, 0)), |
| 106 | Pooling3dLayerInfo(PoolingType::AVG), |
| 107 | Pooling3dLayerInfo(PoolingType::MAX), |
| 108 | Pooling3dLayerInfo(PoolingType::AVG, 2, Size3D(), Padding3D(), false), |
| 109 | Pooling3dLayerInfo(PoolingType::AVG, 2, Size3D(1U, 1U, 1U), Padding3D(), false), |
| 110 | Pooling3dLayerInfo(PoolingType::AVG, 2, Size3D(1U, 1U, 1U), Padding3D(), false), |
| 111 | Pooling3dLayerInfo(PoolingType::AVG), |
| 112 | Pooling3dLayerInfo(PoolingType::MAX, 2, Size3D(1, 1, 2), Padding3D(0, 0, 0), false), |
| 113 | Pooling3dLayerInfo(PoolingType::AVG, 2, Size3D(2U, 2U, 2U), Padding3D(), false), |
| 114 | Pooling3dLayerInfo(PoolingType::AVG, 1, Size3D(2U, 2U, 2U), Padding3D(2, 2, 2), true), // pool size is equal to the padding size |
| 115 | Pooling3dLayerInfo(PoolingType::AVG, 1, Size3D(2U, 2U, 2U), Padding3D(2, 2, 2), false), // pool size is equal to the padding size |
| 116 | Pooling3dLayerInfo(PoolingType::AVG, 3, Size3D(2U, 2U, 2U), Padding3D(2,1,2,2,1,2), false, false, DimensionRoundingType::CEIL), // CEIL with asymmetric Padding |
| 117 | })), |
| 118 | framework::dataset::make("Expected", { false, false, false, false, true, false, false, false, false, true , false, true, false, false, false})), |
| 119 | input_info, output_info, pool_info, expected) |
| 120 | { |
| 121 | bool is_valid = bool(NEPooling3dLayer::validate(&input_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), pool_info)); |
| 122 | ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS); |
| 123 | } |
| 124 | // clang-format on |
| 125 | // *INDENT-ON* |
| 126 | |
| 127 | template <typename T> |
| 128 | using NEPoolingLayer3dFixture = Pooling3dLayerValidationFixture<Tensor, Accessor, NEPooling3dLayer, T>; |
| 129 | |
| 130 | template <typename T> |
| 131 | using NESpecial3dPoolingLayerFixture = SpecialPooling3dLayerValidationFixture<Tensor, Accessor, NEPooling3dLayer, T>; |
| 132 | |
| 133 | template <typename T> |
| 134 | using NEPooling3dLayerGlobalFixture = Pooling3dLayerGlobalValidationFixture<Tensor, Accessor, NEPooling3dLayer, T>; |
| 135 | |
| 136 | // clang-format on |
| 137 | // *INDENT-ON* |
| 138 | TEST_SUITE(Float) |
| 139 | TEST_SUITE(FP32) |
| 140 | |
| 141 | FIXTURE_DATA_TEST_CASE(RunSpecial, NESpecial3dPoolingLayerFixture<float>, framework::DatasetMode::ALL, datasets::Pooling3dLayerDatasetSpecial() * framework::dataset::make("DataType", DataType::F32)) |
| 142 | { |
| 143 | // Validate output |
| 144 | validate(Accessor(_target), _reference, tolerance_f32); |
| 145 | } |
| 146 | |
| 147 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayer3dFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small5dShapes(), combine(Pooling3dLayerDatasetFPSmall, |
| 148 | framework::dataset::make("DataType", DataType::F32)))) |
| 149 | { |
| 150 | // Validate output |
| 151 | validate(Accessor(_target), _reference, tolerance_f32); |
| 152 | } |
| 153 | |
| 154 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayer3dFixture<float>, framework::DatasetMode::NIGHTLY, |
| 155 | combine(datasets::Large5dShapes(), combine(Pooling3dLayerDatasetFPSmall, framework::dataset::make("DataType", DataType::F32)))) |
| 156 | { |
| 157 | // Validate output |
| 158 | validate(Accessor(_target), _reference, tolerance_f32); |
| 159 | } |
| 160 | |
| 161 | TEST_SUITE(GlobalPooling) |
| 162 | // *INDENT-OFF* |
| 163 | // clang-format off |
| 164 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayer3dFixture<float>, framework::DatasetMode::ALL, |
| 165 | combine(combine(combine(combine(combine(combine( |
| 166 | framework::dataset::make("InputShape", { TensorShape(3U, 27U, 13U, 4U), |
| 167 | TensorShape(4U, 27U, 13U, 4U, 2U) |
| 168 | }), |
| 169 | framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::L2, PoolingType::MAX })), |
| 170 | framework::dataset::make("PoolingSize", { Size3D(27, 13, 4) })), |
| 171 | framework::dataset::make("Strides", Size3D(1, 1, 1))), |
| 172 | framework::dataset::make("Paddings", Padding3D(0, 0, 0))), |
| 173 | framework::dataset::make("ExcludePadding", {false, true})), |
| 174 | framework::dataset::make("DataType", DataType::F32))) |
| 175 | { |
| 176 | // Validate output |
| 177 | validate(Accessor(_target), _reference, tolerance_f32); |
| 178 | } |
| 179 | |
| 180 | FIXTURE_DATA_TEST_CASE(RunGlobalSmall, NEPooling3dLayerGlobalFixture<float>, framework::DatasetMode::ALL, |
| 181 | combine(combine( |
| 182 | framework::dataset::make("InputShape", { TensorShape(27U, 13U, 4U, 3U), |
| 183 | TensorShape(27U, 13U, 4U, 4U, 2U) |
| 184 | }), |
| 185 | framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::L2, PoolingType::MAX })), |
| 186 | framework::dataset::make("DataType", DataType::F32))) |
| 187 | { |
| 188 | // Validate output |
| 189 | validate(Accessor(_target), _reference, tolerance_f32); |
| 190 | } |
| 191 | |
| 192 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayer3dFixture<float>, framework::DatasetMode::NIGHTLY, |
| 193 | combine(combine(combine(combine(combine(combine( |
| 194 | framework::dataset::make("InputShape", { TensorShape(4U, 79U, 37U, 11U), |
| 195 | TensorShape(4U, 79U, 37U, 11U, 2U) |
| 196 | }), |
| 197 | framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::L2, PoolingType::MAX })), |
| 198 | framework::dataset::make("PoolingSize", { Size3D(79, 37, 11) })), |
| 199 | framework::dataset::make("Strides", Size3D(1, 1, 1))), |
| 200 | framework::dataset::make("Paddings", Padding3D(0, 0, 0))), |
| 201 | framework::dataset::make("ExcludePadding", {false, true})), |
| 202 | framework::dataset::make("DataType", DataType::F32))) |
| 203 | { |
| 204 | // Validate output |
| 205 | validate(Accessor(_target), _reference, tolerance_f32); |
| 206 | } |
| 207 | |
| 208 | TEST_SUITE_END() // GlobalPooling |
| 209 | TEST_SUITE_END() // FP32 |
| 210 | |
| 211 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 212 | TEST_SUITE(FP16) |
| 213 | |
| 214 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayer3dFixture<half>, framework::DatasetMode::PRECOMMIT, combine(datasets::Small5x5Shapes(), combine(Pooling3dLayerDatasetFPSmall, |
| 215 | framework::dataset::make("DataType", DataType::F16)))) |
| 216 | { |
| 217 | // Validate output |
| 218 | validate(Accessor(_target), _reference, tolerance_f16); |
| 219 | } |
| 220 | |
| 221 | |
| 222 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayer3dFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::Large5dShapes(), combine(Pooling3dLayerDatasetFP, |
| 223 | framework::dataset::make("DataType", |
| 224 | DataType::F16)))) |
| 225 | { |
| 226 | // Validate output |
| 227 | validate(Accessor(_target), _reference, tolerance_f16); |
| 228 | } |
| 229 | |
| 230 | TEST_SUITE(GlobalPooling) |
| 231 | // *INDENT-OFF* |
| 232 | // clang-format off |
| 233 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayer3dFixture<half>, framework::DatasetMode::ALL, |
| 234 | combine(combine(combine(combine(combine(combine( |
| 235 | framework::dataset::make("InputShape", { TensorShape(3U, 27U, 13U, 4U), |
| 236 | TensorShape(4U, 27U, 13U, 4U, 2U) |
| 237 | }), |
| 238 | framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::L2, PoolingType::MAX })), |
| 239 | framework::dataset::make("PoolingSize", { Size3D(27, 13, 4) })), |
| 240 | framework::dataset::make("Strides", Size3D(1, 1, 1))), |
| 241 | framework::dataset::make("Paddings", Padding3D(0, 0, 0))), |
| 242 | framework::dataset::make("ExcludePadding", {false, true})), |
| 243 | framework::dataset::make("DataType", DataType::F16))) |
| 244 | { |
| 245 | // Validate output |
| 246 | validate(Accessor(_target), _reference, tolerance_f16); |
| 247 | } |
| 248 | |
| 249 | |
| 250 | FIXTURE_DATA_TEST_CASE(RunSmallGlobal, NEPooling3dLayerGlobalFixture<half>, framework::DatasetMode::ALL, |
| 251 | combine(combine( |
| 252 | framework::dataset::make("InputShape", { TensorShape(27U, 13U, 4U, 3U), |
| 253 | TensorShape(27U, 13U, 4U, 4U, 2U) |
| 254 | }), |
| 255 | framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::L2, PoolingType::MAX })), |
| 256 | framework::dataset::make("DataType", DataType::F16))) |
| 257 | { |
| 258 | // Validate output |
| 259 | validate(Accessor(_target), _reference, tolerance_f16); |
| 260 | } |
| 261 | |
| 262 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayer3dFixture<half>, framework::DatasetMode::NIGHTLY, |
| 263 | combine(combine(combine(combine(combine(combine( |
| 264 | framework::dataset::make("InputShape", { TensorShape(4U, 79U, 37U, 11U), |
| 265 | TensorShape(4U, 79U, 37U, 11U, 2U) |
| 266 | }), |
| 267 | framework::dataset::make("PoolingType", { PoolingType::AVG, PoolingType::L2, PoolingType::MAX })), |
| 268 | framework::dataset::make("PoolingSize", { Size3D(79, 37, 11) })), |
| 269 | framework::dataset::make("Strides", Size3D(1, 1, 1))), |
| 270 | framework::dataset::make("Paddings", Padding3D(0, 0, 0))), |
| 271 | framework::dataset::make("ExcludePadding", false)), |
| 272 | framework::dataset::make("DataType", DataType::F16))) |
| 273 | { |
| 274 | // Validate output |
| 275 | validate(Accessor(_target), _reference, tolerance_f16); |
| 276 | } |
| 277 | |
| 278 | // clang-format on |
| 279 | // *INDENT-ON* |
| 280 | TEST_SUITE_END() // GlobalPooling |
| 281 | TEST_SUITE_END() // FP16 |
| 282 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
| 283 | |
| 284 | TEST_SUITE_END() // Float |
| 285 | TEST_SUITE_END() // Pooling3dLayer |
| 286 | TEST_SUITE_END() // NEON |
| 287 | } // namespace validation |
| 288 | } // namespace test |
| 289 | } // namespace arm_compute |