blob: b6a8139c0d942d174408efcec2e98971f9bc35a4 [file] [log] [blame]
Sanghoon Lee72898fe2017-09-01 11:42:16 +01001/*
Michalis Spyrou80943252019-01-10 17:19:50 +00002 * Copyright (c) 2017-2019 ARM Limited.
Sanghoon Lee72898fe2017-09-01 11:42:16 +01003 *
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,
Georgios Pinitascbf39c62018-09-10 15:07:45 +010021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Sanghoon Lee72898fe2017-09-01 11:42:16 +010022 * 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"
giuros01164a2722018-11-20 18:34:46 +000027#include "arm_compute/runtime/CL/functions/CLElementwiseOperations.h"
Sanghoon Lee72898fe2017-09-01 11:42:16 +010028#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"
Georgios Pinitascbf39c62018-09-10 15:07:45 +010036#include "tests/validation/fixtures/ArithmeticOperationsFixture.h"
Sanghoon Lee72898fe2017-09-01 11:42:16 +010037
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
giuros01164a2722018-11-20 18:34:46 +000046constexpr unsigned int num_elems_processed_per_iteration = 16;
Sanghoon Lee72898fe2017-09-01 11:42:16 +010047/** Input data sets **/
48const auto ArithmeticSubtractionU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)),
49 framework::dataset::make("DataType",
50 DataType::U8));
Georgios Pinitascbf39c62018-09-10 15:07:45 +010051const auto ArithmeticSubtractionQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
52 framework::dataset::make("DataType",
53 DataType::QASYMM8));
Michele Di Giorgio6997fc92019-06-18 10:23:22 +010054const auto ArithmeticSubtractionQSYMM16Dataset = combine(combine(framework::dataset::make("DataType", DataType::QSYMM16), framework::dataset::make("DataType", DataType::QSYMM16)),
55 framework::dataset::make("DataType",
56 DataType::QSYMM16));
Georgios Pinitascbf39c62018-09-10 15:07:45 +010057const auto ArithmeticSubtractionS16Dataset = combine(combine(framework::dataset::make("DataType", { DataType::U8, DataType::S16 }), framework::dataset::make("DataType", DataType::S16)),
Sanghoon Lee72898fe2017-09-01 11:42:16 +010058 framework::dataset::make("DataType", DataType::S16));
Sanghoon Lee72898fe2017-09-01 11:42:16 +010059const auto ArithmeticSubtractionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
60 framework::dataset::make("DataType", DataType::F16));
61const auto ArithmeticSubtractionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
62 framework::dataset::make("DataType", DataType::F32));
63} // namespace
64
65TEST_SUITE(CL)
66TEST_SUITE(ArithmeticSubtraction)
67
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000068// *INDENT-OFF*
69// clang-format off
70DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
giuros01164a2722018-11-20 18:34:46 +000071 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
72 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
73 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
74 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // 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::U8),
78 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
79 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
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::S16),
84 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
85 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
86 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
87 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
88 })),
89 framework::dataset::make("Expected", { true, true, false, false, false})),
90 input1_info, input2_info, output_info, expected)
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000091{
Giorgio Arena70623822017-11-27 15:50:10 +000092 ARM_COMPUTE_EXPECT(bool(CLArithmeticSubtraction::validate(&input1_info.clone()->set_is_resizable(false), &input2_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), ConvertPolicy::WRAP)) == expected, framework::LogLevel::ERRORS);
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000093}
94// clang-format on
95// *INDENT-ON*
96
Georgios Pinitascbf39c62018-09-10 15:07:45 +010097template <typename T>
98using CLArithmeticSubtractionFixture = ArithmeticSubtractionValidationFixture<CLTensor, CLAccessor, CLArithmeticSubtraction, T>;
Sanghoon Lee72898fe2017-09-01 11:42:16 +010099
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100100TEST_SUITE(Integer)
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100101TEST_SUITE(U8)
Michalis Spyrou80943252019-01-10 17:19:50 +0000102DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100103 shape, policy)
104{
105 // Create tensors
106 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
107 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
108 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
109
110 // Create and Configure function
giuros01164a2722018-11-20 18:34:46 +0000111 CLArithmeticSubtraction add;
112 add.configure(&ref_src1, &ref_src2, &dst, policy);
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100113
114 // Validate valid region
115 const ValidRegion valid_region = shape_to_valid_region(shape);
116 validate(dst.info()->valid_region(), valid_region);
117
118 // Validate padding
giuros01164a2722018-11-20 18:34:46 +0000119 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100120 validate(ref_src1.info()->padding(), padding);
121 validate(ref_src2.info()->padding(), padding);
122 validate(dst.info()->padding(), padding);
123}
124
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100125FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionU8Dataset),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100126 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
127{
128 // Validate output
129 validate(CLAccessor(_target), _reference);
130}
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100131TEST_SUITE_END() // U8
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100132
133TEST_SUITE(S16)
Michalis Spyrou80943252019-01-10 17:19:50 +0000134DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100135 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
136 shape, data_type, policy)
137{
138 // Create tensors
139 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
140 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100141 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
142
143 // Create and Configure function
giuros01164a2722018-11-20 18:34:46 +0000144 CLArithmeticSubtraction add;
145 add.configure(&ref_src1, &ref_src2, &dst, policy);
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100146
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
giuros01164a2722018-11-20 18:34:46 +0000152 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100153 validate(ref_src1.info()->padding(), padding);
154 validate(ref_src2.info()->padding(), padding);
155 validate(dst.info()->padding(), padding);
156}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100157
158FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionS16Dataset),
159 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100160{
161 // Validate output
162 validate(CLAccessor(_target), _reference);
163}
164
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100165FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionS16Dataset),
166 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100167{
168 // Validate output
169 validate(CLAccessor(_target), _reference);
170}
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100171TEST_SUITE_END() // S16
172TEST_SUITE_END() // Integer
173
174template <typename T>
175using CLArithmeticSubtractionQuantizedFixture = ArithmeticSubtractionValidationQuantizedFixture<CLTensor, CLAccessor, CLArithmeticSubtraction, T>;
176
177TEST_SUITE(Quantized)
178TEST_SUITE(QASYMM8)
179DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
180 shape, policy)
181{
182 // Create tensors
183 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
184 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
185 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
186
187 // Create and Configure function
188 CLArithmeticSubtraction add;
189 add.configure(&ref_src1, &ref_src2, &dst, policy);
190
191 // Validate valid region
192 const ValidRegion valid_region = shape_to_valid_region(shape);
193 validate(dst.info()->valid_region(), valid_region);
194
195 // Validate padding
196 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
197 validate(ref_src1.info()->padding(), padding);
198 validate(ref_src2.info()->padding(), padding);
199 validate(dst.info()->padding(), padding);
200}
201
202FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
203 ArithmeticSubtractionQASYMM8Dataset),
204 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
205 framework::dataset::make("Src0QInfo", { QuantizationInfo(5.f / 255.f, 20) })),
206 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 255.f, 10) })),
207 framework::dataset::make("OutQInfo", { QuantizationInfo(1.f / 255.f, 5) })))
208{
209 // Validate output
210 validate(CLAccessor(_target), _reference);
211}
212TEST_SUITE_END() // QASYMM8
213TEST_SUITE(QSYMM16)
214DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
215 shape, policy)
216{
217 // Create tensors
218 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
219 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QSYMM16);
220 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QSYMM16);
221
222 // Create and Configure function
223 CLArithmeticSubtraction sub;
224 sub.configure(&ref_src1, &ref_src2, &dst, policy);
225
226 // Validate valid region
227 const ValidRegion valid_region = shape_to_valid_region(shape);
228 validate(dst.info()->valid_region(), valid_region);
229
230 // Validate padding
231 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
232 validate(ref_src1.info()->padding(), padding);
233 validate(ref_src2.info()->padding(), padding);
234 validate(dst.info()->padding(), padding);
235}
236
237FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionQuantizedFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
238 ArithmeticSubtractionQSYMM16Dataset),
239 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE })),
240 framework::dataset::make("Src0QInfo", { QuantizationInfo(1.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
241 framework::dataset::make("Src1QInfo", { QuantizationInfo(2.f / 32768.f, 0), QuantizationInfo(5.f / 32768.f, 0) })),
242 framework::dataset::make("OutQInfo", { QuantizationInfo(5.f / 32768.f, 0) })))
243{
244 // Validate output
245 validate(CLAccessor(_target), _reference);
246}
247TEST_SUITE_END() // QSYMM16
248TEST_SUITE_END() // Quantized
Isabella Gottardib5908c22017-10-30 15:28:13 +0000249
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100250TEST_SUITE(Float)
251TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100252FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP16Dataset),
253 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100254{
255 // Validate output
256 validate(CLAccessor(_target), _reference);
257}
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100258TEST_SUITE_END() // FP16
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100259
260TEST_SUITE(FP32)
Michalis Spyrou80943252019-01-10 17:19:50 +0000261DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(datasets::SmallShapes(), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100262 shape, policy)
263{
264 // Create tensors
265 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
266 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
267 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
268
269 // Create and Configure function
giuros01164a2722018-11-20 18:34:46 +0000270 CLArithmeticSubtraction add;
271 add.configure(&ref_src1, &ref_src2, &dst, policy);
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100272
273 // Validate valid region
274 const ValidRegion valid_region = shape_to_valid_region(shape);
275 validate(dst.info()->valid_region(), valid_region);
276
277 // Validate padding
giuros01164a2722018-11-20 18:34:46 +0000278 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100279 validate(ref_src1.info()->padding(), padding);
280 validate(ref_src2.info()->padding(), padding);
281 validate(dst.info()->padding(), padding);
282}
283
284FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP32Dataset),
285 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
286{
287 // Validate output
288 validate(CLAccessor(_target), _reference);
289}
290
291FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticSubtractionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionFP32Dataset),
292 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
293{
294 // Validate output
295 validate(CLAccessor(_target), _reference);
296}
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100297
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100298template <typename T>
299using CLArithmeticSubtractionBroadcastFixture = ArithmeticSubtractionBroadcastValidationFixture<CLTensor, CLAccessor, CLArithmeticSubtraction, T>;
300
301FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
302 ArithmeticSubtractionFP32Dataset),
303 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
304{
305 // Validate output
306 validate(CLAccessor(_target), _reference);
307}
308
309FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
310 ArithmeticSubtractionFP32Dataset),
311 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
312{
313 // Validate output
314 validate(CLAccessor(_target), _reference);
315}
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100316TEST_SUITE_END() // FP32
317TEST_SUITE_END() // Float
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100318
Michele Di Giorgio6997fc92019-06-18 10:23:22 +0100319TEST_SUITE_END() // ArithmeticSubtraction
320TEST_SUITE_END() // CL
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100321} // namespace validation
322} // namespace test
giuros01164a2722018-11-20 18:34:46 +0000323} // namespace arm_compute