blob: 3d6bde1c98b387addb47ffc9bef24c7cb4a05be6 [file] [log] [blame]
giuros01164a2722018-11-20 18:34:46 +00001/*
Michalis Spyrou80943252019-01-10 17:19:50 +00002 * Copyright (c) 2018-2019 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)),
57 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));
68} // namespace
69
70TEST_SUITE(CL)
71TEST_SUITE(ElementwiseMin)
72
73// *INDENT-OFF*
74// clang-format off
75DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
76 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
77 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
78 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
79 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
80 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
81 }),
82 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
83 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
84 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
85 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
86 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
87 })),
88 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
89 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
90 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
91 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
92 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
93 })),
94 framework::dataset::make("Expected", { true, true, false, false, false})),
95 input1_info, input2_info, output_info, expected)
96{
97 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);
98}
99// clang-format on
100// *INDENT-ON*
101
102template <typename T>
103using CLElementwiseMinFixture = ElementwiseMinValidationFixture<CLTensor, CLAccessor, CLElementwiseMin, T>;
104
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100105TEST_SUITE(Integer)
giuros01164a2722018-11-20 18:34:46 +0000106TEST_SUITE(U8)
Michalis Spyrou80943252019-01-10 17:19:50 +0000107DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000108 shape)
109{
110 // Create tensors
111 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
112 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
113 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
114
115 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100116 CLElementwiseMin min;
117 min.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000118
119 // Validate valid region
120 const ValidRegion valid_region = shape_to_valid_region(shape);
121 validate(dst.info()->valid_region(), valid_region);
122
123 // Validate padding
124 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
125 validate(ref_src1.info()->padding(), padding);
126 validate(ref_src2.info()->padding(), padding);
127 validate(dst.info()->padding(), padding);
128}
129
130FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMinU8Dataset))
131{
132 // Validate output
133 validate(CLAccessor(_target), _reference);
134}
135TEST_SUITE_END()
136
giuros01164a2722018-11-20 18:34:46 +0000137TEST_SUITE(S16)
Michalis Spyrou80943252019-01-10 17:19:50 +0000138DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
giuros01164a2722018-11-20 18:34:46 +0000139 shape, data_type)
140{
141 // Create tensors
142 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
143 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
144 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
145
146 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100147 CLElementwiseMin min;
148 min.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000149
150 // Validate valid region
151 const ValidRegion valid_region = shape_to_valid_region(shape);
152 validate(dst.info()->valid_region(), valid_region);
153
154 // Validate padding
155 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
156 validate(ref_src1.info()->padding(), padding);
157 validate(ref_src2.info()->padding(), padding);
158 validate(dst.info()->padding(), padding);
159}
160
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000161FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinS16Dataset))
giuros01164a2722018-11-20 18:34:46 +0000162{
163 // Validate output
164 validate(CLAccessor(_target), _reference);
165}
166TEST_SUITE_END()
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100167TEST_SUITE_END()
168
169template <typename T>
170using CLElementwiseMinQuantizedFixture = ElementwiseMinValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseMin, T>;
171
172TEST_SUITE(Quantized)
173TEST_SUITE(QASYMM8)
174DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
175 shape)
176{
177 // Create tensors
178 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
179 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
180 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
181
182 // Create and Configure function
183 CLElementwiseMin min;
184 min.configure(&ref_src1, &ref_src2, &dst);
185
186 // Validate valid region
187 const ValidRegion valid_region = shape_to_valid_region(shape);
188 validate(dst.info()->valid_region(), valid_region);
189
190 // Validate padding
191 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
192 validate(ref_src1.info()->padding(), padding);
193 validate(ref_src2.info()->padding(), padding);
194 validate(dst.info()->padding(), padding);
195}
196
197FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
198 ElementwiseMinQASYMM8Dataset),
199 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
200 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
201 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) })))
202{
203 // Validate output
204 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
205}
206TEST_SUITE_END()
Kurtis Charnockec0c4122019-12-05 14:13:46 +0000207TEST_SUITE(QASYMM8_SIGNED)
208DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
209 shape)
210{
211 // Create tensors
212 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8_SIGNED);
213 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8_SIGNED);
214 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8_SIGNED);
215
216 // Create and Configure function
217 CLElementwiseMin min;
218 min.configure(&ref_src1, &ref_src2, &dst);
219
220 // Validate valid region
221 const ValidRegion valid_region = shape_to_valid_region(shape);
222 validate(dst.info()->valid_region(), valid_region);
223
224 // Validate padding
225 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
226 validate(ref_src1.info()->padding(), padding);
227 validate(ref_src2.info()->padding(), padding);
228 validate(dst.info()->padding(), padding);
229}
230
231FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinQuantizedFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
232 ElementwiseMinQASYMM8SignedDataset),
233 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
234 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
235 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) })))
236{
237 // Validate output
238 validate(CLAccessor(_target), _reference);
239}
240TEST_SUITE_END()
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100241TEST_SUITE(QSYMM16)
242DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
243 shape)
244{
245 // Create tensors
246 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
247 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
248 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QSYMM16);
249
250 // Create and Configure function
251 CLElementwiseMin min;
252 min.configure(&ref_src1, &ref_src2, &dst);
253
254 // Validate valid region
255 const ValidRegion valid_region = shape_to_valid_region(shape);
256 validate(dst.info()->valid_region(), valid_region);
257
258 // Validate padding
259 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
260 validate(ref_src1.info()->padding(), padding);
261 validate(ref_src2.info()->padding(), padding);
262 validate(dst.info()->padding(), padding);
263}
264
265FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
266 ElementwiseMinQSYMM16Dataset),
267 framework::dataset::make("SrcQInfo0", { QuantizationInfo(1.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
268 framework::dataset::make("SrcQInfo1", { QuantizationInfo(2.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
269 framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) })))
270{
271 // Validate output
272 validate(CLAccessor(_target), _reference);
273}
274TEST_SUITE_END()
275TEST_SUITE_END()
giuros01164a2722018-11-20 18:34:46 +0000276
277TEST_SUITE(Float)
278TEST_SUITE(FP16)
279FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinFP16Dataset))
280{
281 // Validate output
282 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
283}
284TEST_SUITE_END()
285
286TEST_SUITE(FP32)
Michalis Spyrou80943252019-01-10 17:19:50 +0000287DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000288 shape)
289{
290 // Create tensors
291 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
292 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
293 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
294
295 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100296 CLElementwiseMin min;
297 min.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000298
299 // Validate valid region
300 const ValidRegion valid_region = shape_to_valid_region(shape);
301 validate(dst.info()->valid_region(), valid_region);
302
303 // Validate padding
304 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
305 validate(ref_src1.info()->padding(), padding);
306 validate(ref_src2.info()->padding(), padding);
307 validate(dst.info()->padding(), padding);
308}
309
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000310FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinFP32Dataset))
giuros01164a2722018-11-20 18:34:46 +0000311{
312 // Validate output
313 validate(CLAccessor(_target), _reference, tolerance_fp32);
314}
giuros01164a2722018-11-20 18:34:46 +0000315template <typename T>
316using CLElementwiseMinBroadcastFixture = ElementwiseMinBroadcastValidationFixture<CLTensor, CLAccessor, CLElementwiseMin, T>;
317
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000318FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseMinBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(),
319 ElementwiseMinFP32Dataset))
giuros01164a2722018-11-20 18:34:46 +0000320{
321 // Validate output
322 validate(CLAccessor(_target), _reference, tolerance_fp32);
323}
324TEST_SUITE_END()
325TEST_SUITE_END()
326
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100327TEST_SUITE_END() // ElementwiseMin
328TEST_SUITE_END() // CL
giuros01164a2722018-11-20 18:34:46 +0000329} // namespace validation
330} // namespace test
331} // namespace arm_compute