blob: c77f485d29bfc7d560dc0755a0450804e1d8d045 [file] [log] [blame]
giuros0192fd9432018-12-03 17:30:00 +00001/*
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 CONCLCTION 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/NEElementwiseOperations.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
28#include "tests/NEON/Accessor.h"
29#include "tests/datasets/ShapeDatasets.h"
30#include "tests/framework/Asserts.h"
31#include "tests/framework/Macros.h"
32#include "tests/framework/datasets/Datasets.h"
33#include "tests/validation/Validation.h"
34#include "tests/validation/fixtures/ElementwiseOperationsFixture.h"
35
36namespace arm_compute
37{
38namespace test
39{
40namespace validation
41{
42namespace
43{
44RelativeTolerance<float> tolerance_fp32(0.000001f);
45/** Input data sets **/
46const auto ElementwiseMaxQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
47 framework::dataset::make("DataType",
48 DataType::QASYMM8));
49/** Input data sets **/
50const auto ElementwiseMaxS32Dataset = combine(combine(framework::dataset::make("DataType", DataType::S32), framework::dataset::make("DataType", DataType::S32)), framework::dataset::make("DataType",
51 DataType::S32));
52const auto ElementwiseMaxS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
53 framework::dataset::make("DataType", DataType::S16));
54#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
55const auto ElementwiseMaxFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
56 framework::dataset::make("DataType", DataType::F16));
57#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
58const auto ElementwiseMaxFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
59 framework::dataset::make("DataType", DataType::F32));
60} // namespace
61
62TEST_SUITE(NEON)
63TEST_SUITE(ElementwiseMax)
64
65template <typename T>
66using NEElementwiseMaxFixture = ElementwiseMaxValidationFixture<Tensor, Accessor, NEElementwiseMax, T>;
67
68// *INDENT-OFF*
69// clang-format off
70DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
71 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
72 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
73 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32),
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32), // Invalid data type combination
75 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
76 }),
77 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
78 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
79 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32),
80 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
81 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
82 })),
83 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32),
84 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
85 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::S32),
86 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S32),
87 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
88 })),
89 framework::dataset::make("Expected", { true, true, true, false, false})),
90 input1_info, input2_info, output_info, expected)
91{
92 ARM_COMPUTE_EXPECT(bool(NEElementwiseMax::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false))) == expected, framework::LogLevel::ERRORS);
93}
94// clang-format on
95// *INDENT-ON*
96
97TEST_SUITE(S32)
98DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()),
99 shape)
100{
101 // Create tensors
102 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::S32);
103 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::S32);
104 Tensor dst = create_tensor<Tensor>(shape, DataType::S32);
105
106 // Create and Configure function
107 NEElementwiseMax add;
108 add.configure(&ref_src1, &ref_src2, &dst);
109
110 // Validate valid region
111 const ValidRegion valid_region = shape_to_valid_region(shape);
112 validate(dst.info()->valid_region(), valid_region);
113}
114
115FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<int32_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMaxS32Dataset))
116{
117 // Validate output
118 validate(Accessor(_target), _reference);
119}
120TEST_SUITE_END() // S32
121
122TEST_SUITE(S16)
123DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::S16 })),
124 shape, data_type)
125{
126 // Create tensors
127 Tensor ref_src1 = create_tensor<Tensor>(shape, data_type);
128 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::S16);
129 Tensor dst = create_tensor<Tensor>(shape, DataType::S16);
130
131 // Create and Configure function
132 NEElementwiseMax add;
133 add.configure(&ref_src1, &ref_src2, &dst);
134
135 // Validate valid region
136 const ValidRegion valid_region = shape_to_valid_region(shape);
137 validate(dst.info()->valid_region(), valid_region);
138}
139
140FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMaxS16Dataset))
141{
142 // Validate output
143 validate(Accessor(_target), _reference);
144}
145
146FIXTURE_DATA_TEST_CASE(RunLarge, NEElementwiseMaxFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), ElementwiseMaxS16Dataset))
147{
148 // Validate output
149 validate(Accessor(_target), _reference);
150}
151TEST_SUITE_END() // S16
152
153template <typename T>
154using NEElementwiseMaxQuantizedFixture = ElementwiseMaxValidationQuantizedFixture<Tensor, Accessor, NEElementwiseMax, T>;
155
156TEST_SUITE(Quantized)
157TEST_SUITE(QASYMM8)
158DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()),
159 shape)
160{
161 // Create tensors
162 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::QASYMM8);
163 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::QASYMM8);
164 Tensor dst = create_tensor<Tensor>(shape, DataType::QASYMM8);
165
166 // Create and Configure function
167 NEElementwiseMin add;
168 add.configure(&ref_src1, &ref_src2, &dst);
169
170 // Validate valid region
171 const ValidRegion valid_region = shape_to_valid_region(shape);
172 validate(dst.info()->valid_region(), valid_region);
173}
174
175FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
176 ElementwiseMaxQASYMM8Dataset),
177 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
178 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
179 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })))
180{
181 // Validate output
182 validate(Accessor(_target), _reference, tolerance_fp32, 0.01);
183}
184
185template <typename T>
186using NEElementwiseMaxQuantizedBroadcastFixture = ElementwiseMaxQuantizedBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMax, T>;
187
188FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEElementwiseMaxQuantizedBroadcastFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapesBroadcast(),
189 ElementwiseMaxQASYMM8Dataset),
190 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
191 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
192 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) })))
193{
194 // Validate output
195 validate(Accessor(_target), _reference);
196}
197TEST_SUITE_END()
198TEST_SUITE_END()
199
200TEST_SUITE(Float)
201#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
202TEST_SUITE(F16)
203FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMaxFP16Dataset))
204{
205 // Validate output
206 validate(Accessor(_target), _reference);
207}
208TEST_SUITE_END() // F16
209#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
210
211TEST_SUITE(F32)
212DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()),
213 shape)
214{
215 // Create tensors
216 Tensor ref_src1 = create_tensor<Tensor>(shape, DataType::F32);
217 Tensor ref_src2 = create_tensor<Tensor>(shape, DataType::F32);
218 Tensor dst = create_tensor<Tensor>(shape, DataType::F32);
219
220 // Create and Configure function
221 NEElementwiseMax add;
222 add.configure(&ref_src1, &ref_src2, &dst);
223
224 // Validate valid region
225 const ValidRegion valid_region = shape_to_valid_region(shape);
226 validate(dst.info()->valid_region(), valid_region);
227}
228
229FIXTURE_DATA_TEST_CASE(RunSmall, NEElementwiseMaxFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMaxFP32Dataset))
230{
231 // Validate output
232 validate(Accessor(_target), _reference);
233}
234
235FIXTURE_DATA_TEST_CASE(RunLarge, NEElementwiseMaxFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), ElementwiseMaxFP32Dataset))
236{
237 // Validate output
238 validate(Accessor(_target), _reference);
239}
240
241template <typename T>
242using NEElementwiseMaxBroadcastFixture = ElementwiseMaxBroadcastValidationFixture<Tensor, Accessor, NEElementwiseMax, T>;
243
244FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, NEElementwiseMaxBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapesBroadcast(),
245 ElementwiseMaxFP32Dataset))
246{
247 // Validate output
248 validate(Accessor(_target), _reference);
249}
250
251FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, NEElementwiseMaxBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapesBroadcast(),
252 ElementwiseMaxFP32Dataset))
253{
254 // Validate output
255 validate(Accessor(_target), _reference);
256}
257TEST_SUITE_END() // F32
258TEST_SUITE_END() // Float
259
260TEST_SUITE_END() // ElementwiseMax
261TEST_SUITE_END() // NEON
262} // namespace validation
263} // namespace test
264} // namespace arm_compute