blob: 332fa80d722caf1bcc694cdcae816baefc1ed2b7 [file] [log] [blame]
giuros01164a2722018-11-20 18:34:46 +00001/*
Giorgio Arena8b2a7d32020-02-11 17:21:31 +00002 * Copyright (c) 2018-2020 ARM Limited.
giuros01164a2722018-11-20 18:34:46 +00003 *
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/CLElementwiseOperations.h"
28#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/ConvertPolicyDataset.h"
31#include "tests/datasets/ShapeDatasets.h"
32#include "tests/framework/Asserts.h"
33#include "tests/framework/Macros.h"
34#include "tests/framework/datasets/Datasets.h"
35#include "tests/validation/Validation.h"
36#include "tests/validation/fixtures/ElementwiseOperationsFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46RelativeTolerance<float> tolerance_fp32(0.000001f);
47RelativeTolerance<float> tolerance_fp16(0.001f);
48
49constexpr unsigned int num_elems_processed_per_iteration = 16;
50/** Input data sets **/
51const auto ElementwiseMinU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)), framework::dataset::make("DataType",
52 DataType::U8));
53const auto ElementwiseMinQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
54 framework::dataset::make("DataType",
55 DataType::QASYMM8));
Kurtis Charnockec0c4122019-12-05 14:13:46 +000056const auto ElementwiseMinQASYMM8SignedDataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8_SIGNED), framework::dataset::make("DataType", DataType::QASYMM8_SIGNED)),
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000057 framework::dataset::make("DataType",
58 DataType::QASYMM8_SIGNED));
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010059const auto ElementwiseMinQSYMM16Dataset = combine(combine(framework::dataset::make("DataType", DataType::QSYMM16), framework::dataset::make("DataType", DataType::QSYMM16)),
60 framework::dataset::make("DataType",
61 DataType::QSYMM16));
giuros01164a2722018-11-20 18:34:46 +000062const auto ElementwiseMinS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
63 framework::dataset::make("DataType", DataType::S16));
64const auto ElementwiseMinFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
65 framework::dataset::make("DataType", DataType::F16));
66const auto ElementwiseMinFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
67 framework::dataset::make("DataType", DataType::F32));
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000068const auto EmptyActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
69{ ActivationLayerInfo() });
70const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
71{
72 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.75f, 0.25f),
73 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC, 0.75f, 0.25f)
74});
giuros01164a2722018-11-20 18:34:46 +000075} // namespace
76
77TEST_SUITE(CL)
78TEST_SUITE(ElementwiseMin)
79
80// *INDENT-OFF*
81// clang-format off
82DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
83 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
84 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
85 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
86 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
87 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
88 }),
89 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
90 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
91 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
92 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
93 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
94 })),
95 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
96 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
97 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
98 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
99 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
100 })),
101 framework::dataset::make("Expected", { true, true, false, false, false})),
102 input1_info, input2_info, output_info, expected)
103{
104 ARM_COMPUTE_EXPECT(bool(CLElementwiseMin::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);
105}
106// clang-format on
107// *INDENT-ON*
108
109template <typename T>
110using CLElementwiseMinFixture = ElementwiseMinValidationFixture<CLTensor, CLAccessor, CLElementwiseMin, T>;
111
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100112TEST_SUITE(Integer)
giuros01164a2722018-11-20 18:34:46 +0000113TEST_SUITE(U8)
Michalis Spyrou80943252019-01-10 17:19:50 +0000114DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000115 shape)
116{
117 // Create tensors
118 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
119 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
120 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
121
122 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100123 CLElementwiseMin min;
124 min.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000125
126 // Validate valid region
127 const ValidRegion valid_region = shape_to_valid_region(shape);
128 validate(dst.info()->valid_region(), valid_region);
129
130 // Validate padding
131 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
132 validate(ref_src1.info()->padding(), padding);
133 validate(ref_src2.info()->padding(), padding);
134 validate(dst.info()->padding(), padding);
135}
136
137FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMinU8Dataset))
138{
139 // Validate output
140 validate(CLAccessor(_target), _reference);
141}
142TEST_SUITE_END()
143
giuros01164a2722018-11-20 18:34:46 +0000144TEST_SUITE(S16)
Michalis Spyrou80943252019-01-10 17:19:50 +0000145DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
giuros01164a2722018-11-20 18:34:46 +0000146 shape, data_type)
147{
148 // Create tensors
149 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
150 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
151 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
152
153 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100154 CLElementwiseMin min;
155 min.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000156
157 // Validate valid region
158 const ValidRegion valid_region = shape_to_valid_region(shape);
159 validate(dst.info()->valid_region(), valid_region);
160
161 // Validate padding
162 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
163 validate(ref_src1.info()->padding(), padding);
164 validate(ref_src2.info()->padding(), padding);
165 validate(dst.info()->padding(), padding);
166}
167
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000168FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinS16Dataset))
giuros01164a2722018-11-20 18:34:46 +0000169{
170 // Validate output
171 validate(CLAccessor(_target), _reference);
172}
173TEST_SUITE_END()
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100174TEST_SUITE_END()
175
176template <typename T>
177using CLElementwiseMinQuantizedFixture = ElementwiseMinValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseMin, T>;
178
179TEST_SUITE(Quantized)
180TEST_SUITE(QASYMM8)
181DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
182 shape)
183{
184 // Create tensors
185 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
186 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
187 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
188
189 // Create and Configure function
190 CLElementwiseMin min;
191 min.configure(&ref_src1, &ref_src2, &dst);
192
193 // Validate valid region
194 const ValidRegion valid_region = shape_to_valid_region(shape);
195 validate(dst.info()->valid_region(), valid_region);
196
197 // Validate padding
198 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
199 validate(ref_src1.info()->padding(), padding);
200 validate(ref_src2.info()->padding(), padding);
201 validate(dst.info()->padding(), padding);
202}
203
204FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
205 ElementwiseMinQASYMM8Dataset),
206 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
207 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
208 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) })))
209{
210 // Validate output
211 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
212}
213TEST_SUITE_END()
Kurtis Charnockec0c4122019-12-05 14:13:46 +0000214TEST_SUITE(QASYMM8_SIGNED)
215DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
216 shape)
217{
218 // Create tensors
219 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8_SIGNED);
220 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8_SIGNED);
221 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8_SIGNED);
222
223 // Create and Configure function
224 CLElementwiseMin min;
225 min.configure(&ref_src1, &ref_src2, &dst);
226
227 // Validate valid region
228 const ValidRegion valid_region = shape_to_valid_region(shape);
229 validate(dst.info()->valid_region(), valid_region);
230
231 // Validate padding
232 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
233 validate(ref_src1.info()->padding(), padding);
234 validate(ref_src2.info()->padding(), padding);
235 validate(dst.info()->padding(), padding);
236}
237
238FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000239 ElementwiseMinQASYMM8SignedDataset),
240 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
241 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
242 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) })))
Kurtis Charnockec0c4122019-12-05 14:13:46 +0000243{
244 // Validate output
245 validate(CLAccessor(_target), _reference);
246}
247TEST_SUITE_END()
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100248TEST_SUITE(QSYMM16)
249DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
250 shape)
251{
252 // Create tensors
253 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
254 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
255 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QSYMM16);
256
257 // Create and Configure function
258 CLElementwiseMin min;
259 min.configure(&ref_src1, &ref_src2, &dst);
260
261 // Validate valid region
262 const ValidRegion valid_region = shape_to_valid_region(shape);
263 validate(dst.info()->valid_region(), valid_region);
264
265 // Validate padding
266 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
267 validate(ref_src1.info()->padding(), padding);
268 validate(ref_src2.info()->padding(), padding);
269 validate(dst.info()->padding(), padding);
270}
271
272FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
273 ElementwiseMinQSYMM16Dataset),
274 framework::dataset::make("SrcQInfo0", { QuantizationInfo(1.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
275 framework::dataset::make("SrcQInfo1", { QuantizationInfo(2.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
276 framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) })))
277{
278 // Validate output
279 validate(CLAccessor(_target), _reference);
280}
281TEST_SUITE_END()
282TEST_SUITE_END()
giuros01164a2722018-11-20 18:34:46 +0000283
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000284template <typename T>
285using CLElementwiseMinFloatFixture = ElementwiseMinValidationFloatFixture<CLTensor, CLAccessor, CLElementwiseMin, T>;
286
giuros01164a2722018-11-20 18:34:46 +0000287TEST_SUITE(Float)
288TEST_SUITE(FP16)
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000289FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseMinFP16Dataset), EmptyActivationFunctionsDataset))
290{
291 // Validate output
292 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
293}
294FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwiseMinFloatFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ElementwiseMinFP16Dataset),
295 ActivationFunctionsDataset))
giuros01164a2722018-11-20 18:34:46 +0000296{
297 // Validate output
298 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
299}
300TEST_SUITE_END()
301
302TEST_SUITE(FP32)
Michalis Spyrou80943252019-01-10 17:19:50 +0000303DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000304 shape)
305{
306 // Create tensors
307 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
308 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
309 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
310
311 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100312 CLElementwiseMin min;
313 min.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000314
315 // Validate valid region
316 const ValidRegion valid_region = shape_to_valid_region(shape);
317 validate(dst.info()->valid_region(), valid_region);
318
319 // Validate padding
320 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
321 validate(ref_src1.info()->padding(), padding);
322 validate(ref_src2.info()->padding(), padding);
323 validate(dst.info()->padding(), padding);
324}
325
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000326FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ElementwiseMinFP32Dataset),
327 EmptyActivationFunctionsDataset))
328{
329 // Validate output
330 validate(CLAccessor(_target), _reference, tolerance_fp32);
331}
332FIXTURE_DATA_TEST_CASE(RunWithActivation, CLElementwiseMinFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapes(), ElementwiseMinFP32Dataset),
333 ActivationFunctionsDataset))
giuros01164a2722018-11-20 18:34:46 +0000334{
335 // Validate output
336 validate(CLAccessor(_target), _reference, tolerance_fp32);
337}
giuros01164a2722018-11-20 18:34:46 +0000338template <typename T>
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000339using CLElementwiseMinBroadcastFloatFixture = ElementwiseMinBroadcastValidationFloatFixture<CLTensor, CLAccessor, CLElementwiseMin, T>;
giuros01164a2722018-11-20 18:34:46 +0000340
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000341FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseMinBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapesBroadcast(),
342 ElementwiseMinFP32Dataset),
343 EmptyActivationFunctionsDataset))
344{
345 // Validate output
346 validate(CLAccessor(_target), _reference, tolerance_fp32);
347}
348FIXTURE_DATA_TEST_CASE(RunWithActivationBroadcast, CLElementwiseMinBroadcastFloatFixture<float>, framework::DatasetMode::ALL, combine(combine(datasets::TinyShapesBroadcast(),
349 ElementwiseMinFP32Dataset),
350 ActivationFunctionsDataset))
giuros01164a2722018-11-20 18:34:46 +0000351{
352 // Validate output
353 validate(CLAccessor(_target), _reference, tolerance_fp32);
354}
355TEST_SUITE_END()
356TEST_SUITE_END()
357
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100358TEST_SUITE_END() // ElementwiseMin
359TEST_SUITE_END() // CL
giuros01164a2722018-11-20 18:34:46 +0000360} // namespace validation
361} // namespace test
362} // namespace arm_compute