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