blob: 6d0caf71608cbc891e3efb653723143bb0742f1d [file] [log] [blame]
Michalis Spyroubcf8a962018-10-12 10:51:31 +01001/*
Pablo Tello6f58d1e2019-11-08 13:47:53 +00002 * Copyright (c) 2018-2019 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
47constexpr 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_qasymm8(1); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit asymmetric quantized type */
50
51const 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) }),
52 framework::dataset::make("KeepDims", { true }));
53const auto axis_drop = combine(framework::dataset::make("Axis", { Coordinates(0), Coordinates(1), Coordinates(3) }), framework::dataset::make("KeepDims", { false }));
54} // namespace
55TEST_SUITE(NEON)
56TEST_SUITE(ReduceMean)
57
58// *INDENT-OFF*
59// clang-format off
Pablo Tello6f58d1e2019-11-08 13:47:53 +000060DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
Michalis Spyroubcf8a962018-10-12 10:51:31 +010061 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid axis
62 TensorInfo(TensorShape(27U, 3U, 16U, 2U), 1, DataType::F32), // Invalid output shape
Pablo Tello6f58d1e2019-11-08 13:47:53 +000063 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32),// OK
64 TensorInfo(TensorShape{228U, 19U, 2U, 2U}, 1, DataType::F32),// OK
65 TensorInfo(TensorShape{228U, 19U, 2U, 1U}, 1, DataType::F32) // Cannot support axis 3 not valid
Michalis Spyroubcf8a962018-10-12 10:51:31 +010066 }),
67 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(27U, 3U, 1U, 2U), 1, DataType::F32),
68 TensorInfo(TensorShape(27U, 3U, 1U, 2U), 1, DataType::F32),
Pablo Tello6f58d1e2019-11-08 13:47:53 +000069 TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::F32),
70 TensorInfo(TensorShape(19U), 1, DataType::F32),
71 TensorInfo(TensorShape(19U), 1, DataType::F32)
72
Michalis Spyroubcf8a962018-10-12 10:51:31 +010073 })),
Pablo Tello6f58d1e2019-11-08 13:47:53 +000074 framework::dataset::make("Axis", { Coordinates(4), Coordinates(0,2), Coordinates(2), Coordinates(3,2,0), Coordinates(3,2,0) })),
75 framework::dataset::make("Keep", { true, true, true, false, false })),
76 framework::dataset::make("Expected", { false, false, true, true, false })),
77 input_info, output_info, axis, keep, expected)
Michalis Spyroubcf8a962018-10-12 10:51:31 +010078{
Pablo Tello6f58d1e2019-11-08 13:47:53 +000079 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 +010080 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
81}
82// clang-format on
83// *INDENT-ON*
84
85DATA_TEST_CASE(Configuration,
86 framework::DatasetMode::ALL,
87 combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F32 })),
88 shape, data_type)
89{
90 // Create tensors
91 Tensor ref_src = create_tensor<Tensor>(shape, data_type);
92 Tensor dst;
93
94 Coordinates axis(1);
95
96 // Create and Configure function
97 NEReduceMean reduce_mean;
98 reduce_mean.configure(&ref_src, axis, true, &dst);
99
100 // Validate valid region
101 TensorShape output_shape = shape;
102 output_shape.set(1, 1);
103 const ValidRegion valid_region = shape_to_valid_region(output_shape);
104 validate(dst.info()->valid_region(), valid_region);
105}
106
107template <typename T>
108using NEReduceMeanFixture = ReduceMeanFixture<Tensor, Accessor, NEReduceMean, T>;
109
110TEST_SUITE(Float)
111
112#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
113TEST_SUITE(FP16)
114FIXTURE_DATA_TEST_CASE(RunSmall,
115 NEReduceMeanFixture<half>,
116 framework::DatasetMode::PRECOMMIT,
117 combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F16)), concat(axis_keep, axis_drop)))
118{
119 // Validate output
120 validate(Accessor(_target), _reference, tolerance_f16);
121}
122
123FIXTURE_DATA_TEST_CASE(RunLarge,
124 NEReduceMeanFixture<half>,
125 framework::DatasetMode::NIGHTLY,
126 combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F16)), concat(axis_keep, axis_drop)))
127{
128 // Validate output
129 validate(Accessor(_target), _reference, tolerance_f16);
130}
131TEST_SUITE_END() // FP16
132#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
133TEST_SUITE(FP32)
134FIXTURE_DATA_TEST_CASE(RunSmall,
135 NEReduceMeanFixture<float>,
136 framework::DatasetMode::PRECOMMIT,
137 combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F32)), concat(axis_keep, axis_drop)))
138{
139 // Validate output
140 validate(Accessor(_target), _reference, tolerance_f32);
141}
142
143FIXTURE_DATA_TEST_CASE(RunLarge,
144 NEReduceMeanFixture<float>,
145 framework::DatasetMode::NIGHTLY,
146 combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F32)), concat(axis_keep, axis_drop)))
147{
148 // Validate output
149 validate(Accessor(_target), _reference, tolerance_f32);
150}
151TEST_SUITE_END() // FP32
152TEST_SUITE_END() // Float
153
154template <typename T>
155using NEReduceMeanQuantizedFixture = ReduceMeanQuantizedFixture<Tensor, Accessor, NEReduceMean, T>;
156
157TEST_SUITE(Quantized)
158TEST_SUITE(QASYMM8)
159FIXTURE_DATA_TEST_CASE(RunSmall,
160 NEReduceMeanQuantizedFixture<uint8_t>,
161 framework::DatasetMode::PRECOMMIT,
162 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) })))
163{
164 // Validate output
165 validate(Accessor(_target), _reference, tolerance_qasymm8);
166}
167
168FIXTURE_DATA_TEST_CASE(RunLarge,
169 NEReduceMeanQuantizedFixture<uint8_t>,
170 framework::DatasetMode::NIGHTLY,
171 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) })))
172{
173 // Validate output
174 validate(Accessor(_target), _reference, tolerance_qasymm8);
175}
176TEST_SUITE_END() // QASYMM8
177TEST_SUITE_END() // Quantized
178TEST_SUITE_END() // ReduceMean
179TEST_SUITE_END() // NEON
180} // namespace validation
181} // namespace test
182} // namespace arm_compute