blob: 3cd7ce362eb1ea4fbdd8037f8f7d8bd322e73454 [file] [log] [blame]
Michalis Spyroubcf8a962018-10-12 10:51:31 +01001/*
2 * Copyright (c) 2018 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/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
60DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
61 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
63 TensorInfo(TensorShape(32U, 16U, 16U, 2U), 1, DataType::F32)
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),
67 TensorInfo(TensorShape(32U, 16U, 1U, 2U), 1, DataType::F32)
68 })),
69 framework::dataset::make("Axis", { Coordinates(4), Coordinates(0,2), Coordinates(2) })),
70 framework::dataset::make("Expected", { false, false, true })),
71 input_info, output_info, axis, expected)
72{
73 const Status status = NEReduceMean::validate(&input_info.clone()->set_is_resizable(false), axis, true, &output_info.clone()->set_is_resizable(false));
74 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
75}
76// clang-format on
77// *INDENT-ON*
78
79DATA_TEST_CASE(Configuration,
80 framework::DatasetMode::ALL,
81 combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::F32 })),
82 shape, data_type)
83{
84 // Create tensors
85 Tensor ref_src = create_tensor<Tensor>(shape, data_type);
86 Tensor dst;
87
88 Coordinates axis(1);
89
90 // Create and Configure function
91 NEReduceMean reduce_mean;
92 reduce_mean.configure(&ref_src, axis, true, &dst);
93
94 // Validate valid region
95 TensorShape output_shape = shape;
96 output_shape.set(1, 1);
97 const ValidRegion valid_region = shape_to_valid_region(output_shape);
98 validate(dst.info()->valid_region(), valid_region);
99}
100
101template <typename T>
102using NEReduceMeanFixture = ReduceMeanFixture<Tensor, Accessor, NEReduceMean, T>;
103
104TEST_SUITE(Float)
105
106#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
107TEST_SUITE(FP16)
108FIXTURE_DATA_TEST_CASE(RunSmall,
109 NEReduceMeanFixture<half>,
110 framework::DatasetMode::PRECOMMIT,
111 combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F16)), concat(axis_keep, axis_drop)))
112{
113 // Validate output
114 validate(Accessor(_target), _reference, tolerance_f16);
115}
116
117FIXTURE_DATA_TEST_CASE(RunLarge,
118 NEReduceMeanFixture<half>,
119 framework::DatasetMode::NIGHTLY,
120 combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F16)), concat(axis_keep, axis_drop)))
121{
122 // Validate output
123 validate(Accessor(_target), _reference, tolerance_f16);
124}
125TEST_SUITE_END() // FP16
126#endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
127TEST_SUITE(FP32)
128FIXTURE_DATA_TEST_CASE(RunSmall,
129 NEReduceMeanFixture<float>,
130 framework::DatasetMode::PRECOMMIT,
131 combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F32)), concat(axis_keep, axis_drop)))
132{
133 // Validate output
134 validate(Accessor(_target), _reference, tolerance_f32);
135}
136
137FIXTURE_DATA_TEST_CASE(RunLarge,
138 NEReduceMeanFixture<float>,
139 framework::DatasetMode::NIGHTLY,
140 combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F32)), concat(axis_keep, axis_drop)))
141{
142 // Validate output
143 validate(Accessor(_target), _reference, tolerance_f32);
144}
145TEST_SUITE_END() // FP32
146TEST_SUITE_END() // Float
147
148template <typename T>
149using NEReduceMeanQuantizedFixture = ReduceMeanQuantizedFixture<Tensor, Accessor, NEReduceMean, T>;
150
151TEST_SUITE(Quantized)
152TEST_SUITE(QASYMM8)
153FIXTURE_DATA_TEST_CASE(RunSmall,
154 NEReduceMeanQuantizedFixture<uint8_t>,
155 framework::DatasetMode::PRECOMMIT,
156 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) })))
157{
158 // Validate output
159 validate(Accessor(_target), _reference, tolerance_qasymm8);
160}
161
162FIXTURE_DATA_TEST_CASE(RunLarge,
163 NEReduceMeanQuantizedFixture<uint8_t>,
164 framework::DatasetMode::NIGHTLY,
165 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) })))
166{
167 // Validate output
168 validate(Accessor(_target), _reference, tolerance_qasymm8);
169}
170TEST_SUITE_END() // QASYMM8
171TEST_SUITE_END() // Quantized
172TEST_SUITE_END() // ReduceMean
173TEST_SUITE_END() // NEON
174} // namespace validation
175} // namespace test
176} // namespace arm_compute