blob: cd13f42ec44c724ecb62f2689e8b52e989973e07 [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"
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"
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{
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));
Georgios Pinitascbf39c62018-09-10 15:07:45 +010050const auto ArithmeticSubtractionQASYMM8Dataset = combine(combine(framework::dataset::make("DataType", DataType::QASYMM8), framework::dataset::make("DataType", DataType::QASYMM8)),
51 framework::dataset::make("DataType",
52 DataType::QASYMM8));
53const 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 +010054 framework::dataset::make("DataType", DataType::S16));
Sanghoon Lee72898fe2017-09-01 11:42:16 +010055const auto ArithmeticSubtractionFP16Dataset = combine(combine(framework::dataset::make("DataType", DataType::F16), framework::dataset::make("DataType", DataType::F16)),
56 framework::dataset::make("DataType", DataType::F16));
57const auto ArithmeticSubtractionFP32Dataset = combine(combine(framework::dataset::make("DataType", DataType::F32), framework::dataset::make("DataType", DataType::F32)),
58 framework::dataset::make("DataType", DataType::F32));
59} // namespace
60
61TEST_SUITE(CL)
62TEST_SUITE(ArithmeticSubtraction)
63
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000064// *INDENT-OFF*
65// clang-format off
66DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
Georgios Pinitascbf39c62018-09-10 15:07:45 +010067 framework::dataset::make("Input1Info", { TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
68 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8),
69 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::U8), // Window shrink
70 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::U8), // Invalid data type combination
71 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::F32), // Mismatching shapes
72 }),
73 framework::dataset::make("Input2Info",{ 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),
76 TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
77 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
78 })),
79 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(32U, 13U, 2U), 1, DataType::S16),
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::U8),
83 TensorInfo(TensorShape(48U, 11U, 2U), 1, DataType::F32),
84 })),
85 framework::dataset::make("Expected", { true, true, false, false, false})),
86 input1_info, input2_info, output_info, expected)
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +000087{
Giorgio Arena70623822017-11-27 15:50:10 +000088 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 +000089}
90// clang-format on
91// *INDENT-ON*
92
Georgios Pinitascbf39c62018-09-10 15:07:45 +010093template <typename T>
94using CLArithmeticSubtractionFixture = ArithmeticSubtractionValidationFixture<CLTensor, CLAccessor, CLArithmeticSubtraction, T>;
Sanghoon Lee72898fe2017-09-01 11:42:16 +010095
96TEST_SUITE(U8)
97DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
98 shape, policy)
99{
100 // Create tensors
101 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::U8);
102 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::U8);
103 CLTensor dst = create_tensor<CLTensor>(shape, DataType::U8);
104
105 // Create and Configure function
106 CLArithmeticSubtraction sub;
107 sub.configure(&ref_src1, &ref_src2, &dst, policy);
108
109 // Validate valid region
110 const ValidRegion valid_region = shape_to_valid_region(shape);
111 validate(dst.info()->valid_region(), valid_region);
112
113 // Validate padding
114 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
115 validate(ref_src1.info()->padding(), padding);
116 validate(ref_src2.info()->padding(), padding);
117 validate(dst.info()->padding(), padding);
118}
119
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100120FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionU8Dataset),
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100121 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
122{
123 // Validate output
124 validate(CLAccessor(_target), _reference);
125}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100126TEST_SUITE_END() // U8
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100127
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100128template <typename T>
129using CLArithmeticSubtractionQuantizedFixture = ArithmeticSubtractionValidationQuantizedFixture<CLTensor, CLAccessor, CLArithmeticSubtraction, T>;
Isabella Gottardib5908c22017-10-30 15:28:13 +0000130
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100131TEST_SUITE(Quantized)
132TEST_SUITE(QASYMM8)
133DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
134 shape, policy)
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100135{
136 // Create tensors
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100137 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
138 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::QASYMM8);
139 CLTensor dst = create_tensor<CLTensor>(shape, DataType::QASYMM8);
140
141 // Create and Configure function
142 CLArithmeticSubtraction add;
143 add.configure(&ref_src1, &ref_src2, &dst, policy);
144
145 // Validate valid region
146 const ValidRegion valid_region = shape_to_valid_region(shape);
147 validate(dst.info()->valid_region(), valid_region);
148
149 // Validate padding
150 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
151 validate(ref_src1.info()->padding(), padding);
152 validate(ref_src2.info()->padding(), padding);
153 validate(dst.info()->padding(), padding);
154}
155
156FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(combine(datasets::SmallShapes(),
157 ArithmeticSubtractionQASYMM8Dataset),
158 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
159 framework::dataset::make("QuantizationInfo", { QuantizationInfo(5.f / 255.f, 20) })),
160 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
161 framework::dataset::make("QuantizationInfo", { QuantizationInfo(1.f / 255.f, 5) }))
162
163 )
164{
165 // Validate output
166 validate(CLAccessor(_target), _reference);
167}
168TEST_SUITE_END() // QASYMM8
169TEST_SUITE_END() // Quantized
170
171TEST_SUITE(S16)
172DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
173 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
174 shape, data_type, policy)
175{
176 // Create tensors
177 CLTensor ref_src1 = create_tensor<CLTensor>(shape, data_type);
178 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::S16);
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100179 CLTensor dst = create_tensor<CLTensor>(shape, DataType::S16);
180
181 // Create and Configure function
182 CLArithmeticSubtraction sub;
183 sub.configure(&ref_src1, &ref_src2, &dst, policy);
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(), 16).required_padding();
191 validate(ref_src1.info()->padding(), padding);
192 validate(ref_src2.info()->padding(), padding);
193 validate(dst.info()->padding(), padding);
194}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100195
196FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionS16Dataset),
197 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100198{
199 // Validate output
200 validate(CLAccessor(_target), _reference);
201}
202
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100203FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticSubtractionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionS16Dataset),
204 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100205{
206 // Validate output
207 validate(CLAccessor(_target), _reference);
208}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100209TEST_SUITE_END() // S16
Isabella Gottardib5908c22017-10-30 15:28:13 +0000210
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100211TEST_SUITE(Float)
212TEST_SUITE(FP16)
Georgios Pinitas583137c2017-08-31 18:12:42 +0100213FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<half>, framework::DatasetMode::ALL, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP16Dataset),
214 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100215{
216 // Validate output
217 validate(CLAccessor(_target), _reference);
218}
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100219TEST_SUITE_END() // FP16
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100220
221TEST_SUITE(FP32)
222DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })),
223 shape, policy)
224{
225 // Create tensors
226 CLTensor ref_src1 = create_tensor<CLTensor>(shape, DataType::F32);
227 CLTensor ref_src2 = create_tensor<CLTensor>(shape, DataType::F32);
228 CLTensor dst = create_tensor<CLTensor>(shape, DataType::F32);
229
230 // Create and Configure function
231 CLArithmeticSubtraction sub;
232 sub.configure(&ref_src1, &ref_src2, &dst, policy);
233
234 // Validate valid region
235 const ValidRegion valid_region = shape_to_valid_region(shape);
236 validate(dst.info()->valid_region(), valid_region);
237
238 // Validate padding
239 const PaddingSize padding = PaddingCalculator(shape.x(), 16).required_padding();
240 validate(ref_src1.info()->padding(), padding);
241 validate(ref_src2.info()->padding(), padding);
242 validate(dst.info()->padding(), padding);
243}
244
245FIXTURE_DATA_TEST_CASE(RunSmall, CLArithmeticSubtractionFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), ArithmeticSubtractionFP32Dataset),
246 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
247{
248 // Validate output
249 validate(CLAccessor(_target), _reference);
250}
251
252FIXTURE_DATA_TEST_CASE(RunLarge, CLArithmeticSubtractionFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapes(), ArithmeticSubtractionFP32Dataset),
253 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
254{
255 // Validate output
256 validate(CLAccessor(_target), _reference);
257}
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100258
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100259template <typename T>
260using CLArithmeticSubtractionBroadcastFixture = ArithmeticSubtractionBroadcastValidationFixture<CLTensor, CLAccessor, CLArithmeticSubtraction, T>;
261
262FIXTURE_DATA_TEST_CASE(RunSmallBroadcast, CLArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapesBroadcast(),
263 ArithmeticSubtractionFP32Dataset),
264 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
265{
266 // Validate output
267 validate(CLAccessor(_target), _reference);
268}
269
270FIXTURE_DATA_TEST_CASE(RunLargeBroadcast, CLArithmeticSubtractionBroadcastFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeShapesBroadcast(),
271 ArithmeticSubtractionFP32Dataset),
272 framework::dataset::make("ConvertPolicy", { ConvertPolicy::SATURATE, ConvertPolicy::WRAP })))
273{
274 // Validate output
275 validate(CLAccessor(_target), _reference);
276}
277TEST_SUITE_END() // FP32
278TEST_SUITE_END() // Float
279
280TEST_SUITE_END() // ArithmeticSubtraction
281TEST_SUITE_END() // CL
Sanghoon Lee72898fe2017-09-01 11:42:16 +0100282} // namespace validation
283} // namespace test
Georgios Pinitascbf39c62018-09-10 15:07:45 +0100284} // namespace arm_compute