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/CL/CLTensor.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 27 | #include "arm_compute/runtime/CL/functions/CLPoolingLayer.h" |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 28 | #include "tests/CL/CLAccessor.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" |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 37 | |
| 38 | namespace arm_compute |
| 39 | { |
| 40 | namespace test |
| 41 | { |
| 42 | namespace validation |
| 43 | { |
| 44 | namespace |
| 45 | { |
| 46 | /** Input data set for float data types */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 47 | const auto PoolingLayerDatasetFP = combine(combine(combine(datasets::PoolingTypes(), framework::dataset::make("PoolingSize", { 2, 3, 4, 7, 9 })), |
| 48 | framework::dataset::make("PadStride", { PadStrideInfo(1, 1, 0, 0), PadStrideInfo(2, 1, 0, 0), PadStrideInfo(1, 2, 1, 1), PadStrideInfo(2, 2, 1, 0) })), |
| 49 | framework::dataset::make("ExcludePadding", { true, false })); |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 50 | |
| 51 | /** Input data set for quantized data types */ |
Georgios Pinitas | adaae7e | 2017-10-30 15:56:32 +0000 | [diff] [blame] | 52 | const auto PoolingLayerDatasetQS = combine(combine(combine(framework::dataset::make("PoolingType", { PoolingType::MAX, PoolingType::AVG }), 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 | framework::dataset::make("ExcludePadding", { true, false })); |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 55 | constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for float types */ |
| 56 | constexpr AbsoluteTolerance<float> tolerance_f16(0.01f); /**< Tolerance value for comparing reference's output against implementation's output for float types */ |
| 57 | constexpr AbsoluteTolerance<float> tolerance_qs8(3); /**< Tolerance value for comparing reference's output against implementation's output for quantized input */ |
| 58 | constexpr AbsoluteTolerance<float> tolerance_qs16(6); /**< Tolerance value for comparing reference's output against implementation's output for quantized input */ |
| 59 | } // namespace |
| 60 | |
| 61 | TEST_SUITE(CL) |
| 62 | TEST_SUITE(PoolingLayer) |
| 63 | |
Georgios Pinitas | 3faea25 | 2017-10-30 14:13:50 +0000 | [diff] [blame] | 64 | // *INDENT-OFF* |
| 65 | // clang-format off |
| 66 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip( |
| 67 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), |
| 68 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), |
| 69 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS8, 4), |
| 70 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS16, 11), |
| 71 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), |
| 72 | TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), |
| 73 | }), |
| 74 | framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16, 0), |
| 75 | TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32, 0), |
| 76 | TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS8, 5), |
| 77 | TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::QS16, 11), |
| 78 | TensorInfo(TensorShape(30U, 11U, 2U), 1, DataType::F32, 0), |
| 79 | TensorInfo(TensorShape(25U, 16U, 2U), 1, DataType::F32, 0), |
| 80 | })), |
| 81 | framework::dataset::make("PoolInfo", { PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
| 82 | PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
| 83 | PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
| 84 | PoolingLayerInfo(PoolingType::AVG, 3, PadStrideInfo(1, 1, 0, 0)), |
| 85 | PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 2, 0)), |
| 86 | PoolingLayerInfo(PoolingType::AVG, 2, PadStrideInfo(1, 1, 0, 2)), |
| 87 | })), |
| 88 | framework::dataset::make("Expected", { true, false, true, false, true, true})), |
| 89 | input_info, output_info, pool_info, expected) |
| 90 | { |
| 91 | ARM_COMPUTE_EXPECT(bool(CLPoolingLayer::validate(&input_info, &output_info, pool_info)) == expected, framework::LogLevel::ERRORS); |
| 92 | } |
| 93 | // clang-format on |
| 94 | // *INDENT-ON* |
| 95 | |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 96 | template <typename T> |
| 97 | using CLPoolingLayerFixture = PoolingLayerValidationFixture<CLTensor, CLAccessor, CLPoolingLayer, T>; |
| 98 | |
| 99 | TEST_SUITE(Float) |
| 100 | TEST_SUITE(FP32) |
| 101 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType", |
| 102 | DataType::F32)))) |
| 103 | { |
| 104 | // Validate output |
| 105 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 106 | } |
| 107 | FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, framework::dataset::make("DataType", |
| 108 | DataType::F32)))) |
| 109 | { |
| 110 | // Validate output |
| 111 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 112 | } |
| 113 | TEST_SUITE_END() |
| 114 | |
| 115 | TEST_SUITE(FP16) |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 116 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), combine(PoolingLayerDatasetFP, |
| 117 | framework::dataset::make("DataType", DataType::F16)))) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 118 | { |
| 119 | // Validate output |
| 120 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 121 | } |
Georgios Pinitas | 583137c | 2017-08-31 18:12:42 +0100 | [diff] [blame] | 122 | FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), combine(PoolingLayerDatasetFP, |
| 123 | framework::dataset::make("DataType", DataType::F16)))) |
Georgios Pinitas | dc460f1 | 2017-08-24 19:02:44 +0100 | [diff] [blame] | 124 | { |
| 125 | // Validate output |
| 126 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 127 | } |
| 128 | TEST_SUITE_END() |
| 129 | TEST_SUITE_END() |
| 130 | |
| 131 | template <typename T> |
| 132 | using CLPoolingLayerFixedPointFixture = PoolingLayerValidationFixedPointFixture<CLTensor, CLAccessor, CLPoolingLayer, T>; |
| 133 | |
| 134 | TEST_SUITE(Quantized) |
| 135 | TEST_SUITE(QS8) |
| 136 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS, |
| 137 | framework::dataset::make("DataType", DataType::QS8))), |
| 138 | framework::dataset::make("FractionalBits", 1, 4))) |
| 139 | { |
| 140 | // Validate output |
| 141 | validate(CLAccessor(_target), _reference, tolerance_qs8); |
| 142 | } |
| 143 | FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQS, |
| 144 | framework::dataset::make("DataType", DataType::QS8))), |
| 145 | framework::dataset::make("FractionalBits", 1, 4))) |
| 146 | { |
| 147 | // Validate output |
| 148 | validate(CLAccessor(_target), _reference, tolerance_qs8); |
| 149 | } |
| 150 | TEST_SUITE_END() |
| 151 | |
| 152 | TEST_SUITE(QS16) |
| 153 | FIXTURE_DATA_TEST_CASE(RunSmall, CLPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), combine(PoolingLayerDatasetQS, |
| 154 | framework::dataset::make("DataType", DataType::QS16))), |
| 155 | framework::dataset::make("FractionalBits", 1, 12))) |
| 156 | { |
| 157 | // Validate output |
| 158 | validate(CLAccessor(_target), _reference, tolerance_qs16); |
| 159 | } |
| 160 | FIXTURE_DATA_TEST_CASE(RunLarge, CLPoolingLayerFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), combine(PoolingLayerDatasetQS, |
| 161 | framework::dataset::make("DataType", DataType::QS16))), |
| 162 | framework::dataset::make("FractionalBits", 1, 12))) |
| 163 | { |
| 164 | // Validate output |
| 165 | validate(CLAccessor(_target), _reference, tolerance_qs16); |
| 166 | } |
| 167 | TEST_SUITE_END() |
| 168 | TEST_SUITE_END() |
| 169 | |
| 170 | TEST_SUITE_END() |
| 171 | TEST_SUITE_END() |
| 172 | } // namespace validation |
| 173 | } // namespace test |
| 174 | } // namespace arm_compute |