blob: 05abfc853f93b1f21d2425714405c715f3b77ead [file] [log] [blame]
giuros01164a2722018-11-20 18:34:46 +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 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));
56const auto ElementwiseMinS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
57 framework::dataset::make("DataType", DataType::S16));
58const auto ElementwiseMinFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
59 framework::dataset::make("DataType", DataType::F16));
60const auto ElementwiseMinFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
61 framework::dataset::make("DataType", DataType::F32));
62} // namespace
63
64TEST_SUITE(CL)
65TEST_SUITE(ElementwiseMin)
66
67// *INDENT-OFF*
68// clang-format off
69DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
70 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
71 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
72 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
73 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
75 }),
76 framework::dataset::make("Input2Info",{ 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),
79 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
80 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
81 })),
82 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
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::U8),
86 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
87 })),
88 framework::dataset::make("Expected", { true, true, false, false, false})),
89 input1_info, input2_info, output_info, expected)
90{
91 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);
92}
93// clang-format on
94// *INDENT-ON*
95
96template <typename T>
97using CLElementwiseMinFixture = ElementwiseMinValidationFixture<CLTensor, CLAccessor, CLElementwiseMin, T>;
98
99TEST_SUITE(U8)
100DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()),
101 shape)
102{
103 // Create tensors
104 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
105 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
106 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
107
108 // Create and Configure function
109 CLElementwiseMin add;
110 add.configure(&ref_src1, &ref_src2, &dst);
111
112 // Validate valid region
113 const ValidRegion valid_region = shape_to_valid_region(shape);
114 validate(dst.info()->valid_region(), valid_region);
115
116 // Validate padding
117 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
118 validate(ref_src1.info()->padding(), padding);
119 validate(ref_src2.info()->padding(), padding);
120 validate(dst.info()->padding(), padding);
121}
122
123FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMinU8Dataset))
124{
125 // Validate output
126 validate(CLAccessor(_target), _reference);
127}
128TEST_SUITE_END()
129
130template <typename T>
131using CLElementwiseMinQuantizedFixture = ElementwiseMinValidationQuantizedFixture<CLTensor, CLAccessor, CLElementwiseMin, T>;
132
133TEST_SUITE(Quantized)
134TEST_SUITE(QASYMM8)
135DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()),
136 shape)
137{
138 // Create tensors
139 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
140 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
141 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
142
143 // Create and Configure function
144 CLElementwiseMin add;
145 add.configure(&ref_src1, &ref_src2, &dst);
146
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
158FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(),
159 ElementwiseMinQASYMM8Dataset),
160 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
161 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
162 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))
163
164 )
165{
166 // Validate output
167 validate(CLAccessor(_target), _reference, tolerance_fp32, 0.01);
168}
169TEST_SUITE_END()
170TEST_SUITE_END()
171
172TEST_SUITE(S16)
173DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
174 shape, data_type)
175{
176 // Create tensors
177 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
178 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
179 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
180
181 // Create and Configure function
182 CLElementwiseMin add;
183 add.configure(&ref_src1, &ref_src2, &dst);
184
185 // Validate valid region
186 const ValidRegion valid_region = shape_to_valid_region(shape);
187 validate(dst.info()->valid_region(), valid_region);
188
189 // Validate padding
190 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
191 validate(ref_src1.info()->padding(), padding);
192 validate(ref_src2.info()->padding(), padding);
193 validate(dst.info()->padding(), padding);
194}
195
196FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMinS16Dataset))
197{
198 // Validate output
199 validate(CLAccessor(_target), _reference);
200}
201
202FIXTURE_DATA_TEST_CASE(RunLarge, CLElementwiseMinFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), ElementwiseMinS16Dataset))
203{
204 // Validate output
205 validate(CLAccessor(_target), _reference);
206}
207TEST_SUITE_END()
208
209TEST_SUITE(Float)
210TEST_SUITE(FP16)
211FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<half>, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), ElementwiseMinFP16Dataset))
212{
213 // Validate output
214 validate(CLAccessor(_target), _reference, tolerance_fp16, 0.01);
215}
216TEST_SUITE_END()
217
218TEST_SUITE(FP32)
219DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()),
220 shape)
221{
222 // Create tensors
223 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
224 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
225 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
226
227 // Create and Configure function
228 CLElementwiseMin add;
229 add.configure(&ref_src1, &ref_src2, &dst);
230
231 // Validate valid region
232 const ValidRegion valid_region = shape_to_valid_region(shape);
233 validate(dst.info()->valid_region(), valid_region);
234
235 // Validate padding
236 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
237 validate(ref_src1.info()->padding(), padding);
238 validate(ref_src2.info()->padding(), padding);
239 validate(dst.info()->padding(), padding);
240}
241
242FIXTURE_DATA_TEST_CASE(RunSmall, CLElementwiseMinFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapes(), ElementwiseMinFP32Dataset))
243{
244 // Validate output
245 validate(CLAccessor(_target), _reference, tolerance_fp32);
246}
247
248FIXTURE_DATA_TEST_CASE(RunLarge, CLElementwiseMinFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapes(), ElementwiseMinFP32Dataset))
249{
250 // Validate output
251 validate(CLAccessor(_target), _reference, tolerance_fp32);
252}
253
254template <typename T>
255using CLElementwiseMinBroadcastFixture = ElementwiseMinBroadcastValidationFixture<CLTensor, CLAccessor, CLElementwiseMin, T>;
256
257FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLElementwiseMinBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallShapesBroadcast(),
258 ElementwiseMinFP32Dataset))
259{
260 // Validate output
261 validate(CLAccessor(_target), _reference, tolerance_fp32);
262}
263
264FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLElementwiseMinBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeShapesBroadcast(),
265 ElementwiseMinFP32Dataset))
266{
267 // Validate output
268 validate(CLAccessor(_target), _reference, tolerance_fp32);
269}
270TEST_SUITE_END()
271TEST_SUITE_END()
272
273TEST_SUITE_END()
274TEST_SUITE_END()
275} // namespace validation
276} // namespace test
277} // namespace arm_compute