blob: 02cfcee262e6d518f2172a1458ea411253680c77 [file] [log] [blame]
Michalis Spyroubcf8a962018-10-12 10:51:31 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Michalis Spyroubcf8a962018-10-12 10:51:31 +01003 *
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
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
45constexpr 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 Bottini77b88592020-05-04 18:42:32 +010047constexpr 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
49constexpr 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 Giorgio54893942020-09-08 12:08:12 +010050#ifdef __aarch64__
Michalis Spyroud175ece2020-07-30 23:39:32 +010051constexpr AbsoluteTolerance<int8_t> tolerance_s8(1); /**< Tolerance value for comparing reference's output against implementation's output for signed 8-bit asymmetric quantized type */
52#else // __aarch64__
53constexpr 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 Spyroubcf8a962018-10-12 10:51:31 +010055
56const 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 }));
58const auto axis_drop = combine(framework::dataset::make("Axis", { Coordinates(0), Coordinates(1), Coordinates(3) }), framework::dataset::make("KeepDims", { false }));
59} // namespace
60TEST_SUITE(NEON)
61TEST_SUITE(ReduceMean)
62
63// *INDENT-OFF*
64// clang-format off
Pablo Tello93975152019-11-08 13:47:53 +000065DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
Michalis Spyroubcf8a962018-10-12 10:51:31 +010066 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 Tello93975152019-11-08 13:47:53 +000068 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 Spyroubcf8a962018-10-12 10:51:31 +010071 }),
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 Tello93975152019-11-08 13:47:53 +000074 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 Spyroubcf8a962018-10-12 10:51:31 +010078 })),
Pablo Tello93975152019-11-08 13:47:53 +000079 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 Spyroubcf8a962018-10-12 10:51:31 +010083{
Pablo Tello93975152019-11-08 13:47:53 +000084 const Status status = NEReduceMean::validate(&input_info.clone()->set_is_resizable(false), axis, keep, &output_info.clone()->set_is_resizable(false));
Michalis Spyroubcf8a962018-10-12 10:51:31 +010085 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
86}
87// clang-format on
88// *INDENT-ON*
89
Michalis Spyroubcf8a962018-10-12 10:51:31 +010090template <typename T>
91using NEReduceMeanFixture = ReduceMeanFixture<Tensor, Accessor, NEReduceMean, T>;
92
93TEST_SUITE(Float)
94
95#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
96TEST_SUITE(FP16)
97FIXTURE_DATA_TEST_CASE(RunSmall,
98 NEReduceMeanFixture<half>,
99 framework::DatasetMode::PRECOMMIT,
100 combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F16)), concat(axis_keep, axis_drop)))
101{
102 // Validate output
103 validate(Accessor(_target), _reference, tolerance_f16);
104}
105
106FIXTURE_DATA_TEST_CASE(RunLarge,
107 NEReduceMeanFixture<half>,
108 framework::DatasetMode::NIGHTLY,
109 combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F16)), concat(axis_keep, axis_drop)))
110{
111 // Validate output
112 validate(Accessor(_target), _reference, tolerance_f16);
113}
114TEST_SUITE_END() // FP16
115#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
116TEST_SUITE(FP32)
117FIXTURE_DATA_TEST_CASE(RunSmall,
118 NEReduceMeanFixture<float>,
119 framework::DatasetMode::PRECOMMIT,
120 combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F32)), concat(axis_keep, axis_drop)))
121{
122 // Validate output
123 validate(Accessor(_target), _reference, tolerance_f32);
124}
125
126FIXTURE_DATA_TEST_CASE(RunLarge,
127 NEReduceMeanFixture<float>,
128 framework::DatasetMode::NIGHTLY,
129 combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F32)), concat(axis_keep, axis_drop)))
130{
131 // Validate output
132 validate(Accessor(_target), _reference, tolerance_f32);
133}
134TEST_SUITE_END() // FP32
135TEST_SUITE_END() // Float
136
137template <typename T>
138using NEReduceMeanQuantizedFixture = ReduceMeanQuantizedFixture<Tensor, Accessor, NEReduceMean, T>;
139
140TEST_SUITE(Quantized)
141TEST_SUITE(QASYMM8)
142FIXTURE_DATA_TEST_CASE(RunSmall,
143 NEReduceMeanQuantizedFixture<uint8_t>,
144 framework::DatasetMode::PRECOMMIT,
Manuel Bottinic58f0ad2020-08-07 16:49:15 +0100145 combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), concat(axis_keep, axis_drop)),
146 framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.f / 255, 5) })),
147 framework::dataset::make("QuantizationInfoOutput", { QuantizationInfo(1.f / 255, 5) })))
Michalis Spyroubcf8a962018-10-12 10:51:31 +0100148{
149 // Validate output
Manuel Bottini77b88592020-05-04 18:42:32 +0100150 validate(Accessor(_target), _reference, tolerance_u8);
Michalis Spyroubcf8a962018-10-12 10:51:31 +0100151}
152
Manuel Bottinic58f0ad2020-08-07 16:49:15 +0100153TEST_SUITE(Requant)
154FIXTURE_DATA_TEST_CASE(RunSmall,
155 NEReduceMeanQuantizedFixture<uint8_t>,
156 framework::DatasetMode::PRECOMMIT,
157 combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), axis_drop),
158 framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.f / 255, 5) })),
159 framework::dataset::make("QuantizationInfoOutput", { QuantizationInfo(1.f / 200, 16) })))
160{
161 // Validate output
162 validate(Accessor(_target), _reference, tolerance_u8);
163}
164TEST_SUITE_END() // Requant
165
Michalis Spyroubcf8a962018-10-12 10:51:31 +0100166FIXTURE_DATA_TEST_CASE(RunLarge,
167 NEReduceMeanQuantizedFixture<uint8_t>,
168 framework::DatasetMode::NIGHTLY,
Manuel Bottinic58f0ad2020-08-07 16:49:15 +0100169 combine(combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8)), concat(axis_keep, axis_drop)),
170 framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.f / 255, 5) })),
171 framework::dataset::make("QuantizationInfoOutput", { QuantizationInfo(1.f / 255, 5) })))
Michalis Spyroubcf8a962018-10-12 10:51:31 +0100172{
173 // Validate output
Manuel Bottini77b88592020-05-04 18:42:32 +0100174 validate(Accessor(_target), _reference, tolerance_u8);
Michalis Spyroubcf8a962018-10-12 10:51:31 +0100175}
176TEST_SUITE_END() // QASYMM8
Luca Foschianiee939fb2020-01-28 10:38:07 +0000177
178TEST_SUITE(QASYMM8_SIGNED)
179FIXTURE_DATA_TEST_CASE(RunSmall,
180 NEReduceMeanQuantizedFixture<int8_t>,
181 framework::DatasetMode::PRECOMMIT,
Manuel Bottinic58f0ad2020-08-07 16:49:15 +0100182 combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), concat(axis_keep, axis_drop)),
183 framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.f / 127, -10), QuantizationInfo(1.f / 250, -20) })),
184 framework::dataset::make("QuantizationInfoInputOutput", { QuantizationInfo(1.f / 127, -10) })))
Luca Foschianiee939fb2020-01-28 10:38:07 +0000185{
186 // Validate output
Manuel Bottini77b88592020-05-04 18:42:32 +0100187 validate(Accessor(_target), _reference, tolerance_s8);
Luca Foschianiee939fb2020-01-28 10:38:07 +0000188}
Manuel Bottinic58f0ad2020-08-07 16:49:15 +0100189TEST_SUITE(Requant)
190FIXTURE_DATA_TEST_CASE(RunSmall,
191 NEReduceMeanQuantizedFixture<int8_t>,
192 framework::DatasetMode::PRECOMMIT,
193 combine(combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), axis_drop),
194 framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.f / 102, 2) })),
195 framework::dataset::make("QuantizationInfoOutput", { QuantizationInfo(1.f / 113, 10) })))
196{
197 // Validate output
198 validate(Accessor(_target), _reference, tolerance_s8);
199}
200TEST_SUITE_END() // Requant
201
Luca Foschianiee939fb2020-01-28 10:38:07 +0000202FIXTURE_DATA_TEST_CASE(RunLarge,
203 NEReduceMeanQuantizedFixture<int8_t>,
204 framework::DatasetMode::NIGHTLY,
Manuel Bottinic58f0ad2020-08-07 16:49:15 +0100205 combine(combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), concat(axis_keep, axis_drop)),
206 framework::dataset::make("QuantizationInfoInput", { QuantizationInfo(1.f / 127, -10) })),
207 framework::dataset::make("QuantizationInfoInputOutput", { QuantizationInfo(1.f / 127, -10) })))
Luca Foschianiee939fb2020-01-28 10:38:07 +0000208{
209 // Validate output
Manuel Bottini77b88592020-05-04 18:42:32 +0100210 validate(Accessor(_target), _reference, tolerance_s8);
Luca Foschianiee939fb2020-01-28 10:38:07 +0000211}
212TEST_SUITE_END() // QASYMM8_SIGNED
Michalis Spyroubcf8a962018-10-12 10:51:31 +0100213TEST_SUITE_END() // Quantized
214TEST_SUITE_END() // ReduceMean
215TEST_SUITE_END() // NEON
216} // namespace validation
217} // namespace test
218} // namespace arm_compute