Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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/NEPoolingLayer.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 28 | #include "tests/NEON/Accessor.h" |
| 29 | #include "tests/PaddingCalculator.h" |
Moritz Pflanzer | a09de0c | 2017-09-01 20:41:12 +0100 | [diff] [blame^] | 30 | #include "tests/datasets/PoolingTypesDataset.h" |
| 31 | #include "tests/datasets/ShapeDatasets.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Macros.h" |
| 34 | #include "tests/framework/datasets/Datasets.h" |
| 35 | #include "tests/validation/Validation.h" |
| 36 | #include "tests/validation/fixtures/PoolingLayerFixture.h" |
| 37 | #include "tests/validation/half.h" |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 38 | |
| 39 | namespace arm_compute |
| 40 | { |
| 41 | namespace test |
| 42 | { |
| 43 | namespace validation |
| 44 | { |
| 45 | namespace |
| 46 | { |
| 47 | /** Input data set for float data types */ |
| 48 | const auto PoolingLayerDatasetFP = combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { 2, 3, 7 })), |
| 49 | framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })); |
| 50 | |
| 51 | /** Input data set for quantized data types */ |
| 52 | const auto PoolingLayerDatasetQS = combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { 2, 3 })), |
| 53 | framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })); |
| 54 | |
| 55 | constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for float types */ |
| 56 | #ifdef ARM_COMPUTE_ENABLE_FP16 |
| 57 | constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for float types */ |
| 58 | #endif /* ARM_COMPUTE_ENABLE_FP16 */ |
| 59 | constexpr AbsoluteTolerance<float> tolerance_qs8(0); /**< Tolerance value for comparing reference's output against implementation's output for quantized input */ |
| 60 | constexpr AbsoluteTolerance<float> tolerance_qs16(0); /**< Tolerance value for comparing reference's output against implementation's output for quantized input */ |
| 61 | } // namespace |
| 62 | |
| 63 | TEST_SUITE(NEON) |
| 64 | TEST_SUITE(PoolingLayer) |
| 65 | |
| 66 | //TODO(COMPMID-415): Configuration tests? |
| 67 | |
| 68 | template <typename T> |
| 69 | using NEPoolingLayerFixture = PoolingLayerValidationFixture<Tensor, Accessor, NEPoolingLayer, T>; |
| 70 | |
| 71 | TEST_SUITE(Float) |
| 72 | TEST_SUITE(FP32) |
| 73 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType", |
| 74 | DataType::F32)))) |
| 75 | { |
| 76 | // Validate output |
| 77 | validate(Accessor(_target), _reference, tolerance_f32); |
| 78 | } |
| 79 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType", |
| 80 | DataType::F32)))) |
| 81 | { |
| 82 | // Validate output |
| 83 | validate(Accessor(_target), _reference, tolerance_f32); |
| 84 | } |
| 85 | TEST_SUITE_END() |
| 86 | |
| 87 | #ifdef ARM_COMPUTE_ENABLE_FP16 |
| 88 | TEST_SUITE(FP16) |
| 89 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixture<half_float::half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, |
| 90 | framework::dataset::make("DataType", DataType::F16)))) |
| 91 | { |
| 92 | // Validate output |
| 93 | validate(Accessor(_target), _reference, tolerance_f16); |
| 94 | } |
| 95 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixture<half_float::half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, |
| 96 | framework::dataset::make("DataType", DataType::F16)))) |
| 97 | { |
| 98 | // Validate output |
| 99 | validate(Accessor(_target), _reference, tolerance_f16); |
| 100 | } |
| 101 | TEST_SUITE_END() |
| 102 | #endif /* ARM_COMPUTE_ENABLE_FP16 */ |
| 103 | TEST_SUITE_END() |
| 104 | |
| 105 | template <typename T> |
| 106 | using NEPoolingLayerFixedPointFixture = PoolingLayerValidationFixedPointFixture<Tensor, Accessor, NEPoolingLayer, T>; |
| 107 | |
| 108 | TEST_SUITE(Quantized) |
| 109 | TEST_SUITE(QS8) |
| 110 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS, |
| 111 | framework::dataset::make("DataType", DataType::QS8))), |
| 112 | framework::dataset::make("FractionalBits", 1, 5))) |
| 113 | { |
| 114 | // Validate output |
| 115 | validate(Accessor(_target), _reference, tolerance_qs8); |
| 116 | } |
| 117 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQS, |
| 118 | framework::dataset::make("DataType", DataType::QS8))), |
| 119 | framework::dataset::make("FractionalBits", 1, 5))) |
| 120 | { |
| 121 | // Validate output |
| 122 | validate(Accessor(_target), _reference, tolerance_qs8); |
| 123 | } |
| 124 | TEST_SUITE_END() |
| 125 | |
| 126 | TEST_SUITE(QS16) |
| 127 | FIXTURE_DATA_TEST_CASE(RunSmall, NEPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS, |
| 128 | framework::dataset::make("DataType", DataType::QS16))), |
| 129 | framework::dataset::make("FractionalBits", 1, 13))) |
| 130 | { |
| 131 | // Validate output |
| 132 | validate(Accessor(_target), _reference, tolerance_qs16); |
| 133 | } |
| 134 | FIXTURE_DATA_TEST_CASE(RunLarge, NEPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQS, |
| 135 | framework::dataset::make("DataType", DataType::QS16))), |
| 136 | framework::dataset::make("FractionalBits", 1, 13))) |
| 137 | { |
| 138 | // Validate output |
| 139 | validate(Accessor(_target), _reference, tolerance_qs16); |
| 140 | } |
| 141 | TEST_SUITE_END() |
| 142 | TEST_SUITE_END() |
| 143 | |
| 144 | TEST_SUITE_END() |
| 145 | TEST_SUITE_END() |
| 146 | } // namespace validation |
| 147 | } // namespace test |
| 148 | } // namespace arm_compute |