blob: 9a290cfe308e93ef24702f032b42d26ad93ef342 [file] [log] [blame]
Sanghoon Lee72898fe2017-09-01 11:42:16 +01001/*
2 * Copyright (c) 2017 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 CONCLCTION 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/CLArithmeticSubtraction.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/ArithmeticSubtractionFixture.h"
Sanghoon Lee72898fe2017-09-01 11:42:16 +010037
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46/** Input data sets **/
47const auto ArithmeticSubtractionU8Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)),
48 framework::dataset::make("DataType",
49 DataType::U8));
Isabella Gottardib5908c22017-10-30 15:28:13 +000050const auto ArithmeticSubtractionS16Dataset = combine(combine(framework::dataset::make("DataType", DataType::S16), framework::dataset::make("DataType", DataType::S16)),
Sanghoon Lee72898fe2017-09-01 11:42:16 +010051 framework::dataset::make("DataType", DataType::S16));
Isabella Gottardib5908c22017-10-30 15:28:13 +000052const auto ArithmeticSubtractionU8U8S16Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::U8)),
53 framework::dataset::make("DataType", DataType::S16));
54const auto ArithmeticSubtractionS16U8S16Dataset = combine(combine(framework::dataset::make("DataType", DataType::S16), framework::dataset::make("DataType", DataType::U8)),
55 framework::dataset::make("DataType", DataType::S16));
56const auto ArithmeticSubtractionU8S16S16Dataset = combine(combine(framework::dataset::make("DataType", DataType::U8), framework::dataset::make("DataType", DataType::S16)),
57 framework::dataset::make("DataType", DataType::S16));
Sanghoon Lee72898fe2017-09-01 11:42:16 +010058const auto ArithmeticSubtractionQS8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QS8), framework::dataset::make("DataType", DataType::QS8)),
59 framework::dataset::make("DataType", DataType::QS8));
60const auto ArithmeticSubtractionQS16Dataset = combine(combine(framework::dataset::make("DataType", DataType::QS16), framework::dataset::make("DataType", DataType::QS16)),
61 framework::dataset::make("DataType", DataType::QS16));
62const auto ArithmeticSubtractionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
63 framework::dataset::make("DataType", DataType::F16));
64const auto ArithmeticSubtractionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
65 framework::dataset::make("DataType", DataType::F32));
66} // namespace
67
68TEST_SUITE(CL)
69TEST_SUITE(ArithmeticSubtraction)
70
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000071// *INDENT-OFF*
72// clang-format off
73DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Giorgio Arena70623822017-11-27 15:50:10 +000074 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
75 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
76 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
77 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
78 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
79 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2), // Mismatching fixed point
80 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000081 }),
Giorgio Arena70623822017-11-27 15:50:10 +000082 framework::dataset::make("Input2Info",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
83 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000084 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +000085 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
86 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
87 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 3),
88 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000089 })),
Giorgio Arena70623822017-11-27 15:50:10 +000090 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
91 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000092 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
Giorgio Arena70623822017-11-27 15:50:10 +000093 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
94 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
95 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 3),
96 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::QS8, 2),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000097 })),
Giorgio Arena70623822017-11-27 15:50:10 +000098 framework::dataset::make("Expected", { false, false, true, true, true, true, false })),
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000099 input1_info, input2_info, output_info, expected)
100{
Giorgio Arena70623822017-11-27 15:50:10 +0000101 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 +0000102}
103// clang-format on
104// *INDENT-ON*
105
Isabella Gottardib5908c22017-10-30 15:28:13 +0000106template <typename T1, typename T2 = T1, typename T3 = T1>
107using CLArithmeticSubtractionFixture = ArithmeticSubtractionValidationFixture<CLTensor, CLAccessor, CLArithmeticSubtraction, T1, T2, T3>;
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100108
109TEST_SUITE(U8)
110DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
111 shape, policy)
112{
113 // Create tensors
114 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
115 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
116 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
117
118 // Create and Configure function
119 CLArithmeticSubtraction sub;
120 sub.configure(&ref_src1, &ref_src2, &dst, policy);
121
122 // Validate valid region
123 const ValidRegion valid_region = shape_to_valid_region(shape);
124 validate(dst.info()->valid_region(), valid_region);
125
126 // Validate padding
127 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
128 validate(ref_src1.info()->padding(), padding);
129 validate(ref_src2.info()->padding(), padding);
130 validate(dst.info()->padding(), padding);
131}
132
Isabella Gottardib5908c22017-10-30 15:28:13 +0000133FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(),
134 ArithmeticSubtractionU8Dataset),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100135 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
136{
137 // Validate output
138 validate(CLAccessor(_target), _reference);
139}
140TEST_SUITE_END()
141
Isabella Gottardib5908c22017-10-30 15:28:13 +0000142template <typename T1, typename T2 = T1>
143using CLArithmeticSubtractionToS16Fixture = CLArithmeticSubtractionFixture<T1, T2, int16_t>;
144
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100145TEST_SUITE(S16)
Isabella Gottardib5908c22017-10-30 15:28:13 +0000146DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()),
147 framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
148 framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100149 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
Isabella Gottardib5908c22017-10-30 15:28:13 +0000150 shape, data_type1, data_type2, policy)
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100151{
152 // Create tensors
Isabella Gottardib5908c22017-10-30 15:28:13 +0000153 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type1);
154 CLTensor ref_src2 = create_tensor<CLTensor>(shape, data_type2);
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100155 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
156
157 // Create and Configure function
158 CLArithmeticSubtraction sub;
159 sub.configure(&ref_src1, &ref_src2, &dst, policy);
160
161 // Validate valid region
162 const ValidRegion valid_region = shape_to_valid_region(shape);
163 validate(dst.info()->valid_region(), valid_region);
164
165 // Validate padding
166 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
167 validate(ref_src1.info()->padding(), padding);
168 validate(ref_src2.info()->padding(), padding);
169 validate(dst.info()->padding(), padding);
170}
Isabella Gottardib5908c22017-10-30 15:28:13 +0000171TEST_SUITE(S16_S16_S16)
172FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionToS16Fixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionS16Dataset),
173 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100174{
175 // Validate output
176 validate(CLAccessor(_target), _reference);
177}
178
Isabella Gottardib5908c22017-10-30 15:28:13 +0000179FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticSubtractionToS16Fixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionS16Dataset),
180 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100181{
182 // Validate output
183 validate(CLAccessor(_target), _reference);
184}
185TEST_SUITE_END()
186
Isabella Gottardib5908c22017-10-30 15:28:13 +0000187TEST_SUITE(U8_U8_S16)
188FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionToS16Fixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(),
189 ArithmeticSubtractionU8U8S16Dataset),
190 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
191{
192 // Validate output
193 validate(CLAccessor(_target), _reference);
194}
195
196FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticSubtractionToS16Fixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(),
197 ArithmeticSubtractionU8U8S16Dataset),
198 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
199{
200 // Validate output
201 validate(CLAccessor(_target), _reference);
202}
203TEST_SUITE_END()
204
205TEST_SUITE(S16_U8_S16)
206using CLAriSubS16U8ToS16Fixture = CLArithmeticSubtractionToS16Fixture<int16_t, uint8_t>;
207FIXTURE_DATA_TEST_CASE(RunSmall, CLAriSubS16U8ToS16Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(),
208 ArithmeticSubtractionS16U8S16Dataset),
209 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
210{
211 // Validate output
212 validate(CLAccessor(_target), _reference);
213}
214
215FIXTURE_DATA_TEST_CASE(RunLarge, CLAriSubS16U8ToS16Fixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(),
216 ArithmeticSubtractionS16U8S16Dataset),
217 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
218{
219 // Validate output
220 validate(CLAccessor(_target), _reference);
221}
222TEST_SUITE_END()
223
224TEST_SUITE(U8_S16_S16)
225using CLAriSubU8S16ToS16Fixture = CLArithmeticSubtractionToS16Fixture<uint8_t, int16_t>;
226FIXTURE_DATA_TEST_CASE(RunSmall, CLAriSubU8S16ToS16Fixture, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(),
227 ArithmeticSubtractionU8S16S16Dataset),
228 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
229{
230 // Validate output
231 validate(CLAccessor(_target), _reference);
232}
233
234FIXTURE_DATA_TEST_CASE(RunLarge, CLAriSubU8S16ToS16Fixture, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(),
235 ArithmeticSubtractionU8S16S16Dataset),
236 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
237{
238 // Validate output
239 validate(CLAccessor(_target), _reference);
240}
241TEST_SUITE_END()
242TEST_SUITE_END()
243
244template <typename T1, typename T2 = T1, typename T3 = T1>
245using CLArithmeticSubtractionFixedPointFixture = ArithmeticSubtractionValidationFixedPointFixture<CLTensor, CLAccessor, CLArithmeticSubtraction, T1, T2, T3>;
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100246
247TEST_SUITE(Quantized)
248TEST_SUITE(QS8)
Isabella Gottardib5908c22017-10-30 15:28:13 +0000249FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixedPointFixture<int8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(),
250 ArithmeticSubtractionQS8Dataset),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100251 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
252 framework::dataset::make("FractionalBits", 1, 7)))
253{
254 // Validate output
255 validate(CLAccessor(_target), _reference);
256}
257
Isabella Gottardib5908c22017-10-30 15:28:13 +0000258FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticSubtractionFixedPointFixture<int8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(),
259 ArithmeticSubtractionQS8Dataset),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100260 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
261 framework::dataset::make("FractionalBits", 1, 7)))
262{
263 // Validate output
264 validate(CLAccessor(_target), _reference);
265}
266TEST_SUITE_END()
267
268TEST_SUITE(QS16)
269FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixedPointFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(),
270 ArithmeticSubtractionQS16Dataset),
271 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
272 framework::dataset::make("FractionalBits", 1, 15)))
273{
274 // Validate output
275 validate(CLAccessor(_target), _reference);
276}
277
Isabella Gottardib5908c22017-10-30 15:28:13 +0000278FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticSubtractionFixedPointFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(),
279 ArithmeticSubtractionQS16Dataset),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100280 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
281 framework::dataset::make("FractionalBits", 1, 15)))
282{
283 // Validate output
284 validate(CLAccessor(_target), _reference);
285}
286TEST_SUITE_END()
287TEST_SUITE_END()
288
289TEST_SUITE(Float)
290TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100291FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP16Dataset),
292 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100293{
294 // Validate output
295 validate(CLAccessor(_target), _reference);
296}
297TEST_SUITE_END()
298
299TEST_SUITE(FP32)
300DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
301 shape, policy)
302{
303 // Create tensors
304 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
305 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
306 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
307
308 // Create and Configure function
309 CLArithmeticSubtraction sub;
310 sub.configure(&ref_src1, &ref_src2, &dst, policy);
311
312 // Validate valid region
313 const ValidRegion valid_region = shape_to_valid_region(shape);
314 validate(dst.info()->valid_region(), valid_region);
315
316 // Validate padding
317 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
318 validate(ref_src1.info()->padding(), padding);
319 validate(ref_src2.info()->padding(), padding);
320 validate(dst.info()->padding(), padding);
321}
322
323FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP32Dataset),
324 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
325{
326 // Validate output
327 validate(CLAccessor(_target), _reference);
328}
329
330FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticSubtractionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionFP32Dataset),
331 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
332{
333 // Validate output
334 validate(CLAccessor(_target), _reference);
335}
336TEST_SUITE_END()
337TEST_SUITE_END()
338
339TEST_SUITE_END()
340TEST_SUITE_END()
341} // namespace validation
342} // namespace test
343} // namespace arm_compute