blob: 50697112966482caea9795961cbe97d9ea561a8a [file] [log] [blame]
Michalis Spyrou7e9391b2018-10-05 14:49:28 +01001/*
Michalis Spyrou19bd4122020-01-22 10:27:06 +00002 * Copyright (c) 2018-2020 ARM Limited.
Michalis Spyrou7e9391b2018-10-05 14:49:28 +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/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
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 */
46constexpr AbsoluteTolerance<float> tolerance_f16(0.03f); /**< Tolerance value for comparing reference's output against implementation's output for 16-bit floating-point type */
Michalis Spyrou19bd4122020-01-22 10:27:06 +000047constexpr AbsoluteTolerance<uint8_t> tolerance_qasymm8(2); /**< Tolerance value for comparing reference's output against implementation's output for 8-bit asymmetric quantized type */
Michalis Spyrou7e9391b2018-10-05 14:49:28 +010048
49const 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 Spyrou96f84612018-10-24 14:01:04 +010051const 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 Spyrou7e9391b2018-10-05 14:49:28 +010052} // namespace
53TEST_SUITE(CL)
54TEST_SUITE(ReduceMean)
55
56// *INDENT-OFF*
57// clang-format off
Pablo Telloa0a4ba12019-12-11 13:04:34 +000058DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(
Michalis Spyrou7e9391b2018-10-05 14:49:28 +010059 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 Telloa0a4ba12019-12-11 13:04:34 +000061 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 Spyrou7e9391b2018-10-05 14:49:28 +010064 }),
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 Telloa0a4ba12019-12-11 13:04:34 +000067 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 Spyrou7e9391b2018-10-05 14:49:28 +010071 })),
Pablo Telloa0a4ba12019-12-11 13:04:34 +000072 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 Spyrou7e9391b2018-10-05 14:49:28 +010076{
Pablo Telloa0a4ba12019-12-11 13:04:34 +000077 const Status status = CLReduceMean::validate(&input_info.clone()->set_is_resizable(false), axis, keep, &output_info.clone()->set_is_resizable(false));
Michalis Spyrou7e9391b2018-10-05 14:49:28 +010078 ARM_COMPUTE_EXPECT(bool(status) == expected, framework::LogLevel::ERRORS);
79}
80// clang-format on
81// *INDENT-ON*
82
Michalis Spyrou7e9391b2018-10-05 14:49:28 +010083template <typename T>
84using CLReduceMeanFixture = ReduceMeanFixture<CLTensor, CLAccessor, CLReduceMean, T>;
85
86TEST_SUITE(Float)
87TEST_SUITE(FP16)
88FIXTURE_DATA_TEST_CASE(RunSmall,
89 CLReduceMeanFixture<half>,
90 framework::DatasetMode::PRECOMMIT,
91 combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F16)), concat(axis_keep, axis_drop)))
92{
93 // Validate output
94 validate(CLAccessor(_target), _reference, tolerance_f16);
95}
96
97FIXTURE_DATA_TEST_CASE(RunLarge,
98 CLReduceMeanFixture<half>,
99 framework::DatasetMode::NIGHTLY,
100 combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F16)), concat(axis_keep, axis_drop)))
101{
102 // Validate output
103 validate(CLAccessor(_target), _reference, tolerance_f16);
104}
105TEST_SUITE_END() // FP16
106
107TEST_SUITE(FP32)
108FIXTURE_DATA_TEST_CASE(RunSmall,
109 CLReduceMeanFixture<float>,
110 framework::DatasetMode::PRECOMMIT,
111 combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::F32)), concat(axis_keep, axis_drop)))
112{
113 // Validate output
114 validate(CLAccessor(_target), _reference, tolerance_f32);
115}
116
117FIXTURE_DATA_TEST_CASE(RunLarge,
118 CLReduceMeanFixture<float>,
119 framework::DatasetMode::NIGHTLY,
120 combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::F32)), concat(axis_keep, axis_drop)))
121{
122 // Validate output
123 validate(CLAccessor(_target), _reference, tolerance_f32);
124}
125TEST_SUITE_END() // FP32
126TEST_SUITE_END() // Float
127
128template <typename T>
129using CLReduceMeanQuantizedFixture = ReduceMeanQuantizedFixture<CLTensor, CLAccessor, CLReduceMean, T>;
130
131TEST_SUITE(Quantized)
132TEST_SUITE(QASYMM8)
133FIXTURE_DATA_TEST_CASE(RunSmall,
134 CLReduceMeanQuantizedFixture<uint8_t>,
135 framework::DatasetMode::PRECOMMIT,
136 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) })))
137{
138 // Validate output
139 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
140}
141
142FIXTURE_DATA_TEST_CASE(RunLarge,
143 CLReduceMeanQuantizedFixture<uint8_t>,
144 framework::DatasetMode::NIGHTLY,
145 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) })))
146{
147 // Validate output
148 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
149}
150TEST_SUITE_END() // QASYMM8
Michalis Spyrou0b18d972020-01-30 18:11:13 +0000151
152TEST_SUITE(QASYMM8_SIGNED)
153FIXTURE_DATA_TEST_CASE(RunSmall,
154 CLReduceMeanQuantizedFixture<int8_t>,
155 framework::DatasetMode::PRECOMMIT,
156 combine(combine(combine(datasets::Small4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), concat(axis_keep, axis_drop)), framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 102, 2) })))
157{
158 // Validate output
159 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
160}
161
162FIXTURE_DATA_TEST_CASE(RunLarge,
163 CLReduceMeanQuantizedFixture<int8_t>,
164 framework::DatasetMode::NIGHTLY,
165 combine(combine(combine(datasets::Large4DShapes(), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)), concat(axis_keep, axis_drop)), framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 102, 2) })))
166{
167 // Validate output
168 validate(CLAccessor(_target), _reference, tolerance_qasymm8);
169}
170TEST_SUITE_END() // QASYMM8_SIGNED
Michalis Spyrou7e9391b2018-10-05 14:49:28 +0100171TEST_SUITE_END() // Quantized
172TEST_SUITE_END() // ReduceMean
173TEST_SUITE_END() // CL
174} // namespace validation
175} // namespace test
176} // namespace arm_compute