Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | 19bd412 | 2020-01-22 10:27:06 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2018-2020 ARM Limited. |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +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/CL/CLTensor.h" |
| 26 | #include "arm_compute/runtime/CL/CLTensorAllocator.h" |
| 27 | #include "arm_compute/runtime/CL/functions/CLReduceMean.h" |
| 28 | |
| 29 | #include "tests/CL/CLAccessor.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 | constexpr AbsoluteTolerance<float> tolerance_f16(0.03f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */ |
Michalis Spyrou | 19bd412 | 2020-01-22 10:27:06 +0000 | [diff] [blame^] | 47 | constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(2); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit asymmetric quantized type */ |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 48 | |
| 49 | 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) }), |
| 50 | framework::dataset::make("KeepDims", { true })); |
Michalis Spyrou | 96f8461 | 2018-10-24 14:01:04 +0100 | [diff] [blame] | 51 | const auto axis_drop = combine(framework::dataset::make("Axis", { Coordinates(0), Coordinates(1), Coordinates(3), Coordinates(1, 2), Coordinates(2, 1) }), framework::dataset::make("KeepDims", { false })); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 52 | } // namespace |
| 53 | TEST_SUITE(CL) |
| 54 | TEST_SUITE(ReduceMean) |
| 55 | |
| 56 | // *INDENT-OFF* |
| 57 | // clang-format off |
Pablo Tello | a0a4ba1 | 2019-12-11 13:04:34 +0000 | [diff] [blame] | 58 | DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip( |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 59 | framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis |
| 60 | TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape |
Pablo Tello | a0a4ba1 | 2019-12-11 13:04:34 +0000 | [diff] [blame] | 61 | TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32),// OK |
| 62 | TensorInfo(TensorShape{228U, 19U, 2U, 2U}, 1, DataType::F32),// OK |
| 63 | TensorInfo(TensorShape{228U, 19U, 2U, 1U}, 1, DataType::F32) // Cannot support axis 3 not valid |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 64 | }), |
| 65 | framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 1U, 2U), 1, DataType::F32), |
| 66 | TensorInfo(TensorShape(27U, 3U, 1U, 2U), 1, DataType::F32), |
Pablo Tello | a0a4ba1 | 2019-12-11 13:04:34 +0000 | [diff] [blame] | 67 | TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::F32), |
| 68 | TensorInfo(TensorShape(19U), 1, DataType::F32), |
| 69 | TensorInfo(TensorShape(19U), 1, DataType::F32) |
| 70 | |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 71 | })), |
Pablo Tello | a0a4ba1 | 2019-12-11 13:04:34 +0000 | [diff] [blame] | 72 | framework::dataset::make("Axis", { Coordinates(4), Coordinates(0,2), Coordinates(2), Coordinates(3,2,0), Coordinates(3,2,0) })), |
| 73 | framework::dataset::make("Keep", { true, true, true, false, false })), |
| 74 | framework::dataset::make("Expected", { false, false, true, true, false })), |
| 75 | input_info, output_info, axis, keep, expected) |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 76 | { |
Pablo Tello | a0a4ba1 | 2019-12-11 13:04:34 +0000 | [diff] [blame] | 77 | const Status status = CLReduceMean::validate(&input_info.clone()->set_is_resizable(false), axis, keep, &output_info.clone()->set_is_resizable(false)); |
Michalis Spyrou | 7e9391b | 2018-10-05 14:49:28 +0100 | [diff] [blame] | 78 | ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS); |
| 79 | } |
| 80 | // clang-format on |
| 81 | // *INDENT-ON* |
| 82 | |
| 83 | DATA_TEST_CASE(Configuration, |
| 84 | framework::DatasetMode::ALL, |
| 85 | combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F16, DataType::F32 })), |
| 86 | shape, data_type) |
| 87 | { |
| 88 | // Create tensors |
| 89 | CLTensor ref_src = create_tensor<CLTensor>(shape, data_type); |
| 90 | CLTensor dst; |
| 91 | |
| 92 | Coordinates axis(1); |
| 93 | |
| 94 | // Create and Configure function |
| 95 | CLReduceMean reduce_mean; |
| 96 | reduce_mean.configure(&ref_src, axis, true, &dst); |
| 97 | |
| 98 | // Validate valid region |
| 99 | TensorShape output_shape = shape; |
| 100 | output_shape.set(1, 1); |
| 101 | const ValidRegion valid_region = shape_to_valid_region(output_shape); |
| 102 | validate(dst.info()->valid_region(), valid_region); |
| 103 | } |
| 104 | |
| 105 | template <typename T> |
| 106 | using CLReduceMeanFixture = ReduceMeanFixture<CLTensor, CLAccessor, CLReduceMean, T>; |
| 107 | |
| 108 | TEST_SUITE(Float) |
| 109 | TEST_SUITE(FP16) |
| 110 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 111 | CLReduceMeanFixture<half>, |
| 112 | framework::DatasetMode::PRECOMMIT, |
| 113 | combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F16)), concat(axis_keep, axis_drop))) |
| 114 | { |
| 115 | // Validate output |
| 116 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 117 | } |
| 118 | |
| 119 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 120 | CLReduceMeanFixture<half>, |
| 121 | framework::DatasetMode::NIGHTLY, |
| 122 | combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F16)), concat(axis_keep, axis_drop))) |
| 123 | { |
| 124 | // Validate output |
| 125 | validate(CLAccessor(_target), _reference, tolerance_f16); |
| 126 | } |
| 127 | TEST_SUITE_END() // FP16 |
| 128 | |
| 129 | TEST_SUITE(FP32) |
| 130 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 131 | CLReduceMeanFixture<float>, |
| 132 | framework::DatasetMode::PRECOMMIT, |
| 133 | combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F32)), concat(axis_keep, axis_drop))) |
| 134 | { |
| 135 | // Validate output |
| 136 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 137 | } |
| 138 | |
| 139 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 140 | CLReduceMeanFixture<float>, |
| 141 | framework::DatasetMode::NIGHTLY, |
| 142 | combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F32)), concat(axis_keep, axis_drop))) |
| 143 | { |
| 144 | // Validate output |
| 145 | validate(CLAccessor(_target), _reference, tolerance_f32); |
| 146 | } |
| 147 | TEST_SUITE_END() // FP32 |
| 148 | TEST_SUITE_END() // Float |
| 149 | |
| 150 | template <typename T> |
| 151 | using CLReduceMeanQuantizedFixture = ReduceMeanQuantizedFixture<CLTensor, CLAccessor, CLReduceMean, T>; |
| 152 | |
| 153 | TEST_SUITE(Quantized) |
| 154 | TEST_SUITE(QASYMM8) |
| 155 | FIXTURE_DATA_TEST_CASE(RunSmall, |
| 156 | CLReduceMeanQuantizedFixture<uint8_t>, |
| 157 | framework::DatasetMode::PRECOMMIT, |
| 158 | combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), concat(axis_keep, axis_drop)), framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255, 0) }))) |
| 159 | { |
| 160 | // Validate output |
| 161 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 162 | } |
| 163 | |
| 164 | FIXTURE_DATA_TEST_CASE(RunLarge, |
| 165 | CLReduceMeanQuantizedFixture<uint8_t>, |
| 166 | framework::DatasetMode::NIGHTLY, |
| 167 | combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), concat(axis_keep, axis_drop)), framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255, 0) }))) |
| 168 | { |
| 169 | // Validate output |
| 170 | validate(CLAccessor(_target), _reference, tolerance_qasymm8); |
| 171 | } |
| 172 | TEST_SUITE_END() // QASYMM8 |
| 173 | TEST_SUITE_END() // Quantized |
| 174 | TEST_SUITE_END() // ReduceMean |
| 175 | TEST_SUITE_END() // CL |
| 176 | } // namespace validation |
| 177 | } // namespace test |
| 178 | } // namespace arm_compute |