blob: 01d18967f8d261712d390ea250665b1bc2e00fce [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));
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010056const auto ElementwiseMinQSYMM16Dataset = combine(combine(framework::dataset::make("DataType", DataType::QSYMM16), framework::dataset::make("DataType", DataType::QSYMM16)),
57 framework::dataset::make("DataType",
58 DataType::QSYMM16));
giuros01164a2722018-11-20 18:34:46 +000059const auto ElementwiseMinS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
60 framework::dataset::make("DataType", DataType::S16));
61const auto ElementwiseMinFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
62 framework::dataset::make("DataType", DataType::F16));
63const auto ElementwiseMinFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
64 framework::dataset::make("DataType", DataType::F32));
65} // namespace
66
67TEST_SUITE(CL)
68TEST_SUITE(ElementwiseMin)
69
70// *INDENT-OFF*
71// clang-format off
72DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
73 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
75 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
76 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
77 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
78 }),
79 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
80 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
81 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
82 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
83 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
84 })),
85 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
86 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
87 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
88 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
89 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
90 })),
91 framework::dataset::make("Expected", { true, true, false, false, false})),
92 input1_info, input2_info, output_info, expected)
93{
94 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);
95}
96// clang-format on
97// *INDENT-ON*
98
99template <typename T>
100using CLElementwiseMinFixture = ElementwiseMinValidationFixture<CLTensor, CLAccessor, CLElementwiseMin, T>;
101
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100102TEST_SUITE(Integer)
giuros01164a2722018-11-20 18:34:46 +0000103TEST_SUITE(U8)
Michalis Spyrou80943252019-01-10 17:19:50 +0000104DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000105 shape)
106{
107 // Create tensors
108 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
109 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
110 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
111
112 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100113 CLElementwiseMin min;
114 min.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000115
116 // Validate valid region
117 const ValidRegion valid_region = shape_to_valid_region(shape);
118 validate(dst.info()->valid_region(), valid_region);
119
120 // Validate padding
121 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
122 validate(ref_src1.info()->padding(), padding);
123 validate(ref_src2.info()->padding(), padding);
124 validate(dst.info()->padding(), padding);
125}
126
127FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMinU8Dataset))
128{
129 // Validate output
130 validate(CLAccessor(_target), _reference);
131}
132TEST_SUITE_END()
133
giuros01164a2722018-11-20 18:34:46 +0000134TEST_SUITE(S16)
Michalis Spyrou80943252019-01-10 17:19:50 +0000135DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
giuros01164a2722018-11-20 18:34:46 +0000136 shape, data_type)
137{
138 // Create tensors
139 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
140 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
141 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
142
143 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100144 CLElementwiseMin min;
145 min.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000146
147 // Validate valid region
148 const ValidRegion valid_region = shape_to_valid_region(shape);
149 validate(dst.info()->valid_region(), valid_region);
150
151 // Validate padding
152 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
153 validate(ref_src1.info()->padding(), padding);
154 validate(ref_src2.info()->padding(), padding);
155 validate(dst.info()->padding(), padding);
156}
157
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000158FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<int16_t>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinS16Dataset))
giuros01164a2722018-11-20 18:34:46 +0000159{
160 // Validate output
161 validate(CLAccessor(_target), _reference);
162}
163TEST_SUITE_END()
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100164TEST_SUITE_END()
165
166template <typename T>
167using CLElementwiseMinQuantizedFixture = ElementwiseMinValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseMin, T>;
168
169TEST_SUITE(Quantized)
170TEST_SUITE(QASYMM8)
171DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
172 shape)
173{
174 // Create tensors
175 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
176 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
177 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
178
179 // Create and Configure function
180 CLElementwiseMin min;
181 min.configure(&ref_src1, &ref_src2, &dst);
182
183 // Validate valid region
184 const ValidRegion valid_region = shape_to_valid_region(shape);
185 validate(dst.info()->valid_region(), valid_region);
186
187 // Validate padding
188 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
189 validate(ref_src1.info()->padding(), padding);
190 validate(ref_src2.info()->padding(), padding);
191 validate(dst.info()->padding(), padding);
192}
193
194FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
195 ElementwiseMinQASYMM8Dataset),
196 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
197 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
198 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) })))
199{
200 // Validate output
201 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
202}
203TEST_SUITE_END()
204TEST_SUITE(QSYMM16)
205DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
206 shape)
207{
208 // Create tensors
209 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
210 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
211 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QSYMM16);
212
213 // Create and Configure function
214 CLElementwiseMin min;
215 min.configure(&ref_src1, &ref_src2, &dst);
216
217 // Validate valid region
218 const ValidRegion valid_region = shape_to_valid_region(shape);
219 validate(dst.info()->valid_region(), valid_region);
220
221 // Validate padding
222 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
223 validate(ref_src1.info()->padding(), padding);
224 validate(ref_src2.info()->padding(), padding);
225 validate(dst.info()->padding(), padding);
226}
227
228FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
229 ElementwiseMinQSYMM16Dataset),
230 framework::dataset::make("SrcQInfo0", { QuantizationInfo(1.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
231 framework::dataset::make("SrcQInfo1", { QuantizationInfo(2.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
232 framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) })))
233{
234 // Validate output
235 validate(CLAccessor(_target), _reference);
236}
237TEST_SUITE_END()
238TEST_SUITE_END()
giuros01164a2722018-11-20 18:34:46 +0000239
240TEST_SUITE(Float)
241TEST_SUITE(FP16)
242FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinFP16Dataset))
243{
244 // Validate output
245 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
246}
247TEST_SUITE_END()
248
249TEST_SUITE(FP32)
Michalis Spyrou80943252019-01-10 17:19:50 +0000250DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, datasets::SmallShapes(),
giuros01164a2722018-11-20 18:34:46 +0000251 shape)
252{
253 // Create tensors
254 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
255 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
256 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
257
258 // Create and Configure function
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100259 CLElementwiseMin min;
260 min.configure(&ref_src1, &ref_src2, &dst);
giuros01164a2722018-11-20 18:34:46 +0000261
262 // Validate valid region
263 const ValidRegion valid_region = shape_to_valid_region(shape);
264 validate(dst.info()->valid_region(), valid_region);
265
266 // Validate padding
267 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
268 validate(ref_src1.info()->padding(), padding);
269 validate(ref_src2.info()->padding(), padding);
270 validate(dst.info()->padding(), padding);
271}
272
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000273FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinFP32Dataset))
giuros01164a2722018-11-20 18:34:46 +0000274{
275 // Validate output
276 validate(CLAccessor(_target), _reference, tolerance_fp32);
277}
giuros01164a2722018-11-20 18:34:46 +0000278template <typename T>
279using CLElementwiseMinBroadcastFixture = ElementwiseMinBroadcastValidationFixture<CLTensor, CLAccessor, CLElementwiseMin, T>;
280
Michalis Spyrou5ce99a22019-01-25 14:17:49 +0000281FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseMinBroadcastFixture<float>, framework::DatasetMode::ALL, combine(datasets::SmallShapesBroadcast(),
282 ElementwiseMinFP32Dataset))
giuros01164a2722018-11-20 18:34:46 +0000283{
284 // Validate output
285 validate(CLAccessor(_target), _reference, tolerance_fp32);
286}
287TEST_SUITE_END()
288TEST_SUITE_END()
289
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100290TEST_SUITE_END() // ElementwiseMin
291TEST_SUITE_END() // CL
giuros01164a2722018-11-20 18:34:46 +0000292} // namespace validation
293} // namespace test
294} // namespace arm_compute