blob: 2cf410f37365b371158c0d42a1471c9cbbd4a34f [file] [log] [blame]
Sanghoon Lee72898fe2017-09-01 11:42:16 +01001/*
Anthony Barbier1c0d0ff2018-01-31 13:05:09 +00002 * Copyright (c) 2017-2018 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));
54const 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 +010055 framework::dataset::make("DataType", DataType::S16));
Sanghoon Lee72898fe2017-09-01 11:42:16 +010056const auto ArithmeticSubtractionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
57 framework::dataset::make("DataType", DataType::F16));
58const auto ArithmeticSubtractionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
59 framework::dataset::make("DataType", DataType::F32));
60} // namespace
61
62TEST_SUITE(CL)
63TEST_SUITE(ArithmeticSubtraction)
64
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000065// *INDENT-OFF*
66// clang-format off
67DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
giuros01164a2722018-11-20 18:34:46 +000068 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
69 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
70 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
71 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
72 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
73 }),
74 framework::dataset::make("Input2Info",{ 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),
77 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
78 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
79 })),
80 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
81 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
82 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8),
83 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
84 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
85 })),
86 framework::dataset::make("Expected", { true, true, false, false, false})),
87 input1_info, input2_info, output_info, expected)
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000088{
Giorgio Arena70623822017-11-27 15:50:10 +000089 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 +000090}
91// clang-format on
92// *INDENT-ON*
93
Georgios Pinitascbf39c62018-09-10 15:07:45 +010094template <typename T>
95using CLArithmeticSubtractionFixture = ArithmeticSubtractionValidationFixture<CLTensor, CLAccessor, CLArithmeticSubtraction, T>;
Sanghoon Lee72898fe2017-09-01 11:42:16 +010096
97TEST_SUITE(U8)
98DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
99 shape, policy)
100{
101 // Create tensors
102 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
103 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
104 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
105
106 // Create and Configure function
giuros01164a2722018-11-20 18:34:46 +0000107 CLArithmeticSubtraction add;
108 add.configure(&ref_src1, &ref_src2, &dst, policy);
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100109
110 // Validate valid region
111 const ValidRegion valid_region = shape_to_valid_region(shape);
112 validate(dst.info()->valid_region(), valid_region);
113
114 // Validate padding
giuros01164a2722018-11-20 18:34:46 +0000115 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100116 validate(ref_src1.info()->padding(), padding);
117 validate(ref_src2.info()->padding(), padding);
118 validate(dst.info()->padding(), padding);
119}
120
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100121FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionU8Dataset),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100122 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
123{
124 // Validate output
125 validate(CLAccessor(_target), _reference);
126}
giuros01164a2722018-11-20 18:34:46 +0000127TEST_SUITE_END()
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100128
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100129template <typename T>
130using CLArithmeticSubtractionQuantizedFixture = ArithmeticSubtractionValidationQuantizedFixture<CLTensor, CLAccessor, CLArithmeticSubtraction, T>;
Isabella Gottardib5908c22017-10-30 15:28:13 +0000131
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100132TEST_SUITE(Quantized)
133TEST_SUITE(QASYMM8)
134DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
135 shape, policy)
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100136{
137 // Create tensors
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100138 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
139 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
140 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
141
142 // Create and Configure function
143 CLArithmeticSubtraction add;
144 add.configure(&ref_src1, &ref_src2, &dst, policy);
145
146 // Validate valid region
147 const ValidRegion valid_region = shape_to_valid_region(shape);
148 validate(dst.info()->valid_region(), valid_region);
149
150 // Validate padding
giuros01164a2722018-11-20 18:34:46 +0000151 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100152 validate(ref_src1.info()->padding(), padding);
153 validate(ref_src2.info()->padding(), padding);
154 validate(dst.info()->padding(), padding);
155}
156
157FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
158 ArithmeticSubtractionQASYMM8Dataset),
159 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
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);
168}
giuros01164a2722018-11-20 18:34:46 +0000169TEST_SUITE_END()
170TEST_SUITE_END()
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100171
172TEST_SUITE(S16)
173DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
174 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
175 shape, data_type, policy)
176{
177 // Create tensors
178 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
179 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100180 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
181
182 // Create and Configure function
giuros01164a2722018-11-20 18:34:46 +0000183 CLArithmeticSubtraction add;
184 add.configure(&ref_src1, &ref_src2, &dst, policy);
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100185
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
giuros01164a2722018-11-20 18:34:46 +0000191 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100192 validate(ref_src1.info()->padding(), padding);
193 validate(ref_src2.info()->padding(), padding);
194 validate(dst.info()->padding(), padding);
195}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100196
197FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionS16Dataset),
198 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100199{
200 // Validate output
201 validate(CLAccessor(_target), _reference);
202}
203
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100204FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionS16Dataset),
205 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100206{
207 // Validate output
208 validate(CLAccessor(_target), _reference);
209}
giuros01164a2722018-11-20 18:34:46 +0000210TEST_SUITE_END()
Isabella Gottardib5908c22017-10-30 15:28:13 +0000211
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100212TEST_SUITE(Float)
213TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100214FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP16Dataset),
215 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100216{
217 // Validate output
218 validate(CLAccessor(_target), _reference);
219}
giuros01164a2722018-11-20 18:34:46 +0000220TEST_SUITE_END()
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100221
222TEST_SUITE(FP32)
223DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
224 shape, policy)
225{
226 // Create tensors
227 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
228 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
229 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
230
231 // Create and Configure function
giuros01164a2722018-11-20 18:34:46 +0000232 CLArithmeticSubtraction add;
233 add.configure(&ref_src1, &ref_src2, &dst, policy);
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100234
235 // Validate valid region
236 const ValidRegion valid_region = shape_to_valid_region(shape);
237 validate(dst.info()->valid_region(), valid_region);
238
239 // Validate padding
giuros01164a2722018-11-20 18:34:46 +0000240 const PaddingSize padding = PaddingCalculator(shape.x(), num_elems_processed_per_iteration).required_padding();
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100241 validate(ref_src1.info()->padding(), padding);
242 validate(ref_src2.info()->padding(), padding);
243 validate(dst.info()->padding(), padding);
244}
245
246FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP32Dataset),
247 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
248{
249 // Validate output
250 validate(CLAccessor(_target), _reference);
251}
252
253FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticSubtractionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionFP32Dataset),
254 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
255{
256 // Validate output
257 validate(CLAccessor(_target), _reference);
258}
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100259
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100260template <typename T>
261using CLArithmeticSubtractionBroadcastFixture = ArithmeticSubtractionBroadcastValidationFixture<CLTensor, CLAccessor, CLArithmeticSubtraction, T>;
262
263FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
264 ArithmeticSubtractionFP32Dataset),
265 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
266{
267 // Validate output
268 validate(CLAccessor(_target), _reference);
269}
270
271FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
272 ArithmeticSubtractionFP32Dataset),
273 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
274{
275 // Validate output
276 validate(CLAccessor(_target), _reference);
277}
giuros01164a2722018-11-20 18:34:46 +0000278TEST_SUITE_END()
279TEST_SUITE_END()
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100280
giuros01164a2722018-11-20 18:34:46 +0000281TEST_SUITE_END()
282TEST_SUITE_END()
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100283} // namespace validation
284} // namespace test
giuros01164a2722018-11-20 18:34:46 +0000285} // namespace arm_compute