Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +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/Types.h" |
| 25 | #include "arm_compute/runtime/NEON/functions/NEReduceMean.h" |
| 26 | #include "arm_compute/runtime/Tensor.h" |
| 27 | #include "arm_compute/runtime/TensorAllocator.h" |
| 28 | |
| 29 | #include "tests/NEON/Accessor.h" |
| 30 | #include "tests/datasets/ShapeDatasets.h" |
| 31 | #include "tests/datasets/SplitDataset.h" |
| 32 | #include "tests/framework/Asserts.h" |
| 33 | #include "tests/framework/Macros.h" |
| 34 | #include "tests/validation/Validation.h" |
| 35 | #include "tests/validation/fixtures/ReduceMeanFixture.h" |
| 36 | |
| 37 | namespace arm_compute |
| 38 | { |
| 39 | namespace test |
| 40 | { |
| 41 | namespace validation |
| 42 | { |
| 43 | namespace |
| 44 | { |
| 45 | constexpr AbsoluteTolerance<float> tolerance_f32(0.001f); /**< Tolerance value for comparing reference's output against implementation's output for 32-bit floating-point type */ |
| 46 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Manuel Bottini | 77b8859 | 2020-05-04 18:42:32 +0100 | [diff] [blame] | 47 | constexpr AbsoluteTolerance<float> tolerance_f16(0.03f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */ |
| 48 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 49 | constexpr AbsoluteTolerance<uint8_t> tolerance_u8(1); /**< Tolerance value for comparing reference's output against implementation's output for unsigned 8-bit asymmetric quantized type */ |
Michele Di Giorgio | 5489394 | 2020-09-08 12:08:12 +0100 | [diff] [blame^] | 50 | #ifdef __aarch64__ |
Manuel Bottini | 77b8859 | 2020-05-04 18:42:32 +0100 | [diff] [blame] | 51 | constexpr AbsoluteTolerance<int8_t> tolerance_s8(1); /**< Tolerance value for comparing reference's output against implementation's output for signed 8-bit asymmetric quantized type */ |
Michele Di Giorgio | 5489394 | 2020-09-08 12:08:12 +0100 | [diff] [blame^] | 52 | #else // __aarch64__ |
| 53 | constexpr AbsoluteTolerance<int8_t> tolerance_s8(2); /**< Tolerance value for comparing reference's output against implementation's output for signed 8-bit asymmetric quantized type */ |
| 54 | #endif // __aarch64__ |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 55 | |
| 56 | const auto axis_keep = combine(framework::dataset::make("Axis", { Coordinates(0), Coordinates(1, 0), Coordinates(1, 2), Coordinates(0, 2), Coordinates(1, 3), Coordinates(0, 1, 2, 3) }), |
| 57 | framework::dataset::make("KeepDims", { true })); |
| 58 | const auto axis_drop = combine(framework::dataset::make("Axis", { Coordinates(0), Coordinates(1), Coordinates(3) }), framework::dataset::make("KeepDims", { false })); |
| 59 | } // namespace |
| 60 | TEST_SUITE(NEON) |
| 61 | TEST_SUITE(ReduceMean) |
| 62 | |
| 63 | // *INDENT-OFF* |
| 64 | // clang-format off |
Pablo Tello | 9397515 | 2019-11-08 13:47:53 +0000 | [diff] [blame] | 65 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 66 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis |
| 67 | TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape |
Pablo Tello | 9397515 | 2019-11-08 13:47:53 +0000 | [diff] [blame] | 68 | TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32),// OK |
| 69 | TensorInfo(TensorShape{228U, 19U, 2U, 2U}, 1, DataType::F32),// OK |
| 70 | TensorInfo(TensorShape{228U, 19U, 2U, 1U}, 1, DataType::F32) // Cannot support axis 3 not valid |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 71 | }), |
| 72 | framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 1U, 2U), 1, DataType::F32), |
| 73 | TensorInfo(TensorShape(27U, 3U, 1U, 2U), 1, DataType::F32), |
Pablo Tello | 9397515 | 2019-11-08 13:47:53 +0000 | [diff] [blame] | 74 | TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::F32), |
| 75 | TensorInfo(TensorShape(19U), 1, DataType::F32), |
| 76 | TensorInfo(TensorShape(19U), 1, DataType::F32) |
| 77 | |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 78 | })), |
Pablo Tello | 9397515 | 2019-11-08 13:47:53 +0000 | [diff] [blame] | 79 | framework::dataset::make("Axis", { Coordinates(4), Coordinates(0,2), Coordinates(2), Coordinates(3,2,0), Coordinates(3,2,0) })), |
| 80 | framework::dataset::make("Keep", { true, true, true, false, false })), |
| 81 | framework::dataset::make("Expected", { false, false, true, true, false })), |
| 82 | input_info, output_info, axis, keep, expected) |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 83 | { |
Pablo Tello | 9397515 | 2019-11-08 13:47:53 +0000 | [diff] [blame] | 84 | const Status status = NEReduceMean::validate(&input_info.clone()->set_is_resizable(false), axis, keep, &output_info.clone()->set_is_resizable(false)); |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 85 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 86 | } |
| 87 | // clang-format on |
| 88 | // *INDENT-ON* |
| 89 | |
| 90 | DATA_TEST_CASE(Configuration, |
| 91 | framework::DatasetMode::ALL, |
| 92 | combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F32 })), |
| 93 | shape, data_type) |
| 94 | { |
| 95 | // Create tensors |
| 96 | Tensor ref_src = create_tensor<Tensor>(shape, data_type); |
| 97 | Tensor dst; |
| 98 | |
| 99 | Coordinates axis(1); |
| 100 | |
| 101 | // Create and Configure function |
| 102 | NEReduceMean reduce_mean; |
| 103 | reduce_mean.configure(&ref_src, axis, true, &dst); |
| 104 | |
| 105 | // Validate valid region |
| 106 | TensorShape output_shape = shape; |
| 107 | output_shape.set(1, 1); |
| 108 | const ValidRegion valid_region = shape_to_valid_region(output_shape); |
| 109 | validate(dst.info()->valid_region(), valid_region); |
| 110 | } |
| 111 | |
| 112 | template <typename T> |
| 113 | using NEReduceMeanFixture = ReduceMeanFixture<Tensor, Accessor, NEReduceMean, T>; |
| 114 | |
| 115 | TEST_SUITE(Float) |
| 116 | |
| 117 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 118 | TEST_SUITE(FP16) |
| 119 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 120 | NEReduceMeanFixture<half>, |
| 121 | framework::DatasetMode::PRECOMMIT, |
| 122 | combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F16)), concat(axis_keep, axis_drop))) |
| 123 | { |
| 124 | // Validate output |
| 125 | validate(Accessor(_target), _reference, tolerance_f16); |
| 126 | } |
| 127 | |
| 128 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 129 | NEReduceMeanFixture<half>, |
| 130 | framework::DatasetMode::NIGHTLY, |
| 131 | combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F16)), concat(axis_keep, axis_drop))) |
| 132 | { |
| 133 | // Validate output |
| 134 | validate(Accessor(_target), _reference, tolerance_f16); |
| 135 | } |
| 136 | TEST_SUITE_END() // FP16 |
| 137 | #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
| 138 | TEST_SUITE(FP32) |
| 139 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 140 | NEReduceMeanFixture<float>, |
| 141 | framework::DatasetMode::PRECOMMIT, |
| 142 | combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F32)), concat(axis_keep, axis_drop))) |
| 143 | { |
| 144 | // Validate output |
| 145 | validate(Accessor(_target), _reference, tolerance_f32); |
| 146 | } |
| 147 | |
| 148 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 149 | NEReduceMeanFixture<float>, |
| 150 | framework::DatasetMode::NIGHTLY, |
| 151 | combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F32)), concat(axis_keep, axis_drop))) |
| 152 | { |
| 153 | // Validate output |
| 154 | validate(Accessor(_target), _reference, tolerance_f32); |
| 155 | } |
| 156 | TEST_SUITE_END() // FP32 |
| 157 | TEST_SUITE_END() // Float |
| 158 | |
| 159 | template <typename T> |
| 160 | using NEReduceMeanQuantizedFixture = ReduceMeanQuantizedFixture<Tensor, Accessor, NEReduceMean, T>; |
| 161 | |
| 162 | TEST_SUITE(Quantized) |
| 163 | TEST_SUITE(QASYMM8) |
| 164 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 165 | NEReduceMeanQuantizedFixture<uint8_t>, |
| 166 | framework::DatasetMode::PRECOMMIT, |
Manuel Bottini | c58f0ad | 2020-08-07 16:49:15 +0100 | [diff] [blame] | 167 | combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), concat(axis_keep, axis_drop)), |
| 168 | framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.f / 255, 5) })), |
| 169 | framework::dataset::make("QuantizationInfoOutput", { QuantizationInfo(1.f / 255, 5) }))) |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 170 | { |
| 171 | // Validate output |
Manuel Bottini | 77b8859 | 2020-05-04 18:42:32 +0100 | [diff] [blame] | 172 | validate(Accessor(_target), _reference, tolerance_u8); |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 173 | } |
| 174 | |
Manuel Bottini | c58f0ad | 2020-08-07 16:49:15 +0100 | [diff] [blame] | 175 | TEST_SUITE(Requant) |
| 176 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 177 | NEReduceMeanQuantizedFixture<uint8_t>, |
| 178 | framework::DatasetMode::PRECOMMIT, |
| 179 | combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), axis_drop), |
| 180 | framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.f / 255, 5) })), |
| 181 | framework::dataset::make("QuantizationInfoOutput", { QuantizationInfo(1.f / 200, 16) }))) |
| 182 | { |
| 183 | // Validate output |
| 184 | validate(Accessor(_target), _reference, tolerance_u8); |
| 185 | } |
| 186 | TEST_SUITE_END() // Requant |
| 187 | |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 188 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 189 | NEReduceMeanQuantizedFixture<uint8_t>, |
| 190 | framework::DatasetMode::NIGHTLY, |
Manuel Bottini | c58f0ad | 2020-08-07 16:49:15 +0100 | [diff] [blame] | 191 | combine(combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), concat(axis_keep, axis_drop)), |
| 192 | framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.f / 255, 5) })), |
| 193 | framework::dataset::make("QuantizationInfoOutput", { QuantizationInfo(1.f / 255, 5) }))) |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 194 | { |
| 195 | // Validate output |
Manuel Bottini | 77b8859 | 2020-05-04 18:42:32 +0100 | [diff] [blame] | 196 | validate(Accessor(_target), _reference, tolerance_u8); |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 197 | } |
| 198 | TEST_SUITE_END() // QASYMM8 |
Luca Foschiani | ee939fb | 2020-01-28 10:38:07 +0000 | [diff] [blame] | 199 | |
| 200 | TEST_SUITE(QASYMM8_SIGNED) |
| 201 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 202 | NEReduceMeanQuantizedFixture<int8_t>, |
| 203 | framework::DatasetMode::PRECOMMIT, |
Manuel Bottini | c58f0ad | 2020-08-07 16:49:15 +0100 | [diff] [blame] | 204 | combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), concat(axis_keep, axis_drop)), |
| 205 | framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.f / 127, -10), QuantizationInfo(1.f / 250, -20) })), |
| 206 | framework::dataset::make("QuantizationInfoInputOutput", { QuantizationInfo(1.f / 127, -10) }))) |
Luca Foschiani | ee939fb | 2020-01-28 10:38:07 +0000 | [diff] [blame] | 207 | { |
| 208 | // Validate output |
Manuel Bottini | 77b8859 | 2020-05-04 18:42:32 +0100 | [diff] [blame] | 209 | validate(Accessor(_target), _reference, tolerance_s8); |
Luca Foschiani | ee939fb | 2020-01-28 10:38:07 +0000 | [diff] [blame] | 210 | } |
Manuel Bottini | c58f0ad | 2020-08-07 16:49:15 +0100 | [diff] [blame] | 211 | TEST_SUITE(Requant) |
| 212 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 213 | NEReduceMeanQuantizedFixture<int8_t>, |
| 214 | framework::DatasetMode::PRECOMMIT, |
| 215 | combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), axis_drop), |
| 216 | framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.f / 102, 2) })), |
| 217 | framework::dataset::make("QuantizationInfoOutput", { QuantizationInfo(1.f / 113, 10) }))) |
| 218 | { |
| 219 | // Validate output |
| 220 | validate(Accessor(_target), _reference, tolerance_s8); |
| 221 | } |
| 222 | TEST_SUITE_END() // Requant |
| 223 | |
Luca Foschiani | ee939fb | 2020-01-28 10:38:07 +0000 | [diff] [blame] | 224 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 225 | NEReduceMeanQuantizedFixture<int8_t>, |
| 226 | framework::DatasetMode::NIGHTLY, |
Manuel Bottini | c58f0ad | 2020-08-07 16:49:15 +0100 | [diff] [blame] | 227 | combine(combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), concat(axis_keep, axis_drop)), |
| 228 | framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.f / 127, -10) })), |
| 229 | framework::dataset::make("QuantizationInfoInputOutput", { QuantizationInfo(1.f / 127, -10) }))) |
Luca Foschiani | ee939fb | 2020-01-28 10:38:07 +0000 | [diff] [blame] | 230 | { |
| 231 | // Validate output |
Manuel Bottini | 77b8859 | 2020-05-04 18:42:32 +0100 | [diff] [blame] | 232 | validate(Accessor(_target), _reference, tolerance_s8); |
Luca Foschiani | ee939fb | 2020-01-28 10:38:07 +0000 | [diff] [blame] | 233 | } |
| 234 | TEST_SUITE_END() // QASYMM8_SIGNED |
Michalis Spyrou | bcf8a96 | 2018-10-12 10:51:31 +0100 | [diff] [blame] | 235 | TEST_SUITE_END() // Quantized |
| 236 | TEST_SUITE_END() // ReduceMean |
| 237 | TEST_SUITE_END() // NEON |
| 238 | } // namespace validation |
| 239 | } // namespace test |
| 240 | } // namespace arm_compute |