blob: 56f391965d1365aca50798897ee159cf52843cc5 [file] [log] [blame]
Sanghoon Leec8a85ba2017-11-29 11:23:14 +00001/*
Sanghoon Leec8d23162018-01-12 16:19:10 +00002 * Copyright (c) 2017-2018 ARM Limited.
Sanghoon Leec8a85ba2017-11-29 11:23:14 +00003 *
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/functions/CLConvolution.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
28#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/BorderModeDataset.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/ConvolutionFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000046} // namespace
47
48TEST_SUITE(CL)
49TEST_SUITE(CustomConvolution)
Sanghoon Leed7ba5392017-12-13 11:28:50 +000050TEST_SUITE(CustomConvolutionSquare)
Sanghoon Leec8d23162018-01-12 16:19:10 +000051TEST_SUITE(CustomConvolutionSquare3x3)
52DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
Sanghoon Leed7ba5392017-12-13 11:28:50 +000053 datasets::BorderModes()),
54 framework::dataset::make("filter_size", { 3 })),
Sanghoon Leec8d23162018-01-12 16:19:10 +000055 shape, output_data_type, border_mode, filter_size)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000056{
57 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +000058 CLTensor src = create_tensor<CLTensor>(shape, DataType::U8);
59 CLTensor dst = create_tensor<CLTensor>(shape, output_data_type);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000060
61 // Create conv matrix
62 int16_t conv[9];
63
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000064 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
65 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
66
67 // Create and configure function
68 CLConvolution3x3 convolution;
Sanghoon Leed7ba5392017-12-13 11:28:50 +000069 convolution.configure(&src, &dst, conv, 0, border_mode);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000070
71 // Validate valid region
Sanghoon Leed7ba5392017-12-13 11:28:50 +000072 const ValidRegion dst_valid_region = shape_to_valid_region(shape, (border_mode == BorderMode::UNDEFINED), BorderSize(filter_size / 2));
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000073 validate(dst.info()->valid_region(), dst_valid_region);
74
75 // Validate padding
76 PaddingCalculator calculator(shape.x(), 8);
77 calculator.set_border_size(1);
78 calculator.set_border_mode(border_mode);
79
80 const PaddingSize dst_padding = calculator.required_padding();
81
82 calculator.set_accessed_elements(16);
83 calculator.set_access_offset(-1);
84
85 const PaddingSize src_padding = calculator.required_padding();
86
87 validate(src.info()->padding(), src_padding);
88 validate(dst.info()->padding(), dst_padding);
89}
90
91template <typename T>
Sanghoon Leed7ba5392017-12-13 11:28:50 +000092using CLConvolutionFixture = ConvolutionSquareValidationFixture<CLTensor, CLAccessor, CLConvolution3x3, T>;
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000093
Sanghoon Leec8d23162018-01-12 16:19:10 +000094TEST_SUITE(CustomConvolutionSqaure3x3_U8)
Sanghoon Leed7ba5392017-12-13 11:28:50 +000095FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000096 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +000097 datasets::BorderModes()),
98 framework::dataset::make("filter_size", { 3 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000099{
100 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000101 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000102}
103
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000104FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000105 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000106 datasets::BorderModes()),
107 framework::dataset::make("filter_size", { 3 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000108{
109 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000110 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000111}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000112TEST_SUITE_END()
113
114TEST_SUITE(CustomConvolutionSqaure3x3_S16)
115FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
116 DataType::S16)),
117 datasets::BorderModes()),
118 framework::dataset::make("filter_size", { 3 })))
119{
120 // Validate output
121 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
122}
123FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
124 DataType::S16)),
125 datasets::BorderModes()),
126 framework::dataset::make("filter_size", { 3 })))
127{
128 // Validate output
129 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
130}
131TEST_SUITE_END()
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000132TEST_SUITE_END() /* Custom_Convolution 3x3 */
133
Sanghoon Leec8d23162018-01-12 16:19:10 +0000134TEST_SUITE(CustomConvolutionSquare5x5)
135DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000136 datasets::BorderModes()),
137 framework::dataset::make("filter_size", { 5 })),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000138 shape, output_data_type, border_mode, filter_size)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000139{
140 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +0000141 CLTensor src = create_tensor<CLTensor>(shape, DataType::U8);
142 CLTensor dst = create_tensor<CLTensor>(shape, output_data_type);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000143
144 // Create conv matrix
145 int16_t conv[25];
146
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000147 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
148 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
149
150 // Create and configure function
151 CLConvolution5x5 convolution;
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000152 convolution.configure(&src, &dst, conv, 0, border_mode);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000153
154 // Validate valid region
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000155 const ValidRegion dst_valid_region = shape_to_valid_region(shape, (border_mode == BorderMode::UNDEFINED), BorderSize(filter_size / 2));
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000156 validate(dst.info()->valid_region(), dst_valid_region);
157
158 // Validate padding
159 PaddingCalculator calculator(shape.x(), 8);
160 calculator.set_border_size(2);
161 calculator.set_border_mode(border_mode);
162
163 const PaddingSize dst_padding = calculator.required_padding();
164
165 calculator.set_accessed_elements(16);
166 calculator.set_access_offset(-2);
167
168 const PaddingSize src_padding = calculator.required_padding();
169
170 validate(src.info()->padding(), src_padding);
171 validate(dst.info()->padding(), dst_padding);
172}
173
174template <typename T>
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000175using CLConvolutionFixture = ConvolutionSquareValidationFixture<CLTensor, CLAccessor, CLConvolution5x5, T>;
Sanghoon Leec8d23162018-01-12 16:19:10 +0000176
177TEST_SUITE(CustomConvolutionSqaure5x5_U8)
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000178FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000179 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000180 datasets::BorderModes()),
181 framework::dataset::make("filter_size", { 5 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000182{
183 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000184 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000185}
186
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000187FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000188 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000189 datasets::BorderModes()),
190 framework::dataset::make("filter_size", { 5 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000191{
192 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000193 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000194}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000195TEST_SUITE_END()
196
197TEST_SUITE(CustomConvolutionSqaure5x5_S16)
198FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
199 DataType::S16)),
200 datasets::BorderModes()),
201 framework::dataset::make("filter_size", { 5 })))
202{
203 // Validate output
204 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
205}
206
207FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
208 DataType::S16)),
209 datasets::BorderModes()),
210 framework::dataset::make("filter_size", { 5 })))
211{
212 // Validate output
213 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
214}
215TEST_SUITE_END()
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000216TEST_SUITE_END() /* Custom Convolution 5x5 */
217
Sanghoon Leec8d23162018-01-12 16:19:10 +0000218TEST_SUITE(CustomConvolutionSquare7x7)
219DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000220 datasets::BorderModes()),
221 framework::dataset::make("filter_size", { 7 })),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000222 shape, output_data_type, border_mode, filter_size)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000223{
224 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +0000225 CLTensor src = create_tensor<CLTensor>(shape, DataType::U8);
226 CLTensor dst = create_tensor<CLTensor>(shape, output_data_type);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000227
228 // Create conv matrix
229 int16_t conv[49];
230
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000231 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
232 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
233
234 // Create and configure function
235 CLConvolution7x7 convolution;
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000236 convolution.configure(&src, &dst, conv, 0, border_mode);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000237
238 // Validate valid region
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000239 const ValidRegion dst_valid_region = shape_to_valid_region(shape, (border_mode == BorderMode::UNDEFINED), BorderSize(filter_size / 2));
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000240 validate(dst.info()->valid_region(), dst_valid_region);
241
242 // Validate padding
243 PaddingCalculator calculator(shape.x(), 8);
244 calculator.set_border_size(3);
245 calculator.set_border_mode(border_mode);
246
247 const PaddingSize dst_padding = calculator.required_padding();
248
249 calculator.set_accessed_elements(16);
250 calculator.set_access_offset(-3);
251
252 const PaddingSize src_padding = calculator.required_padding();
253
254 validate(src.info()->padding(), src_padding);
255 validate(dst.info()->padding(), dst_padding);
256}
257
258template <typename T>
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000259using CLConvolutionFixture = ConvolutionSquareValidationFixture<CLTensor, CLAccessor, CLConvolution7x7, T>;
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000260
Sanghoon Leec8d23162018-01-12 16:19:10 +0000261TEST_SUITE(CustomConvolutionSquare7x7_U8)
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000262FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000263 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000264 datasets::BorderModes()),
265 framework::dataset::make("filter_size", { 7 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000266{
267 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000268 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000269}
270
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000271FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000272 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000273 datasets::BorderModes()),
274 framework::dataset::make("filter_size", { 7 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000275{
276 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000277 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000278}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000279TEST_SUITE_END()
280
281TEST_SUITE(CustomConvolutionSquare7x7_S16)
282FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
283 DataType::S16)),
284 datasets::BorderModes()),
285 framework::dataset::make("filter_size", { 7 })))
286{
287 // Validate output
288 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
289}
290
291FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
292 DataType::S16)),
293 datasets::BorderModes()),
294 framework::dataset::make("filter_size", { 7 })))
295{
296 // Validate output
297 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
298}
299TEST_SUITE_END()
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000300TEST_SUITE_END() /* Custom Convolution 7x7 */
301
Sanghoon Leec8d23162018-01-12 16:19:10 +0000302TEST_SUITE(CustomConvolutionSquare9x9)
303DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000304 datasets::BorderModes()),
305 framework::dataset::make("filter_size", { 9 })),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000306 shape, output_data_type, border_mode, filter_size)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000307{
308 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +0000309 CLTensor src = create_tensor<CLTensor>(shape, DataType::U8);
310 CLTensor dst = create_tensor<CLTensor>(shape, output_data_type);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000311
312 // Create conv matrix
313 int16_t conv[81];
314
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000315 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
316 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
317
318 // Create and configure function
319 CLConvolution9x9 convolution;
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000320 convolution.configure(&src, &dst, conv, 0, border_mode);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000321
322 // Validate valid region
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000323 const ValidRegion dst_valid_region = shape_to_valid_region(shape, (border_mode == BorderMode::UNDEFINED), BorderSize(filter_size / 2));
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000324 validate(dst.info()->valid_region(), dst_valid_region);
325
326 // Validate padding
327 PaddingCalculator calculator(shape.x(), 8);
328 calculator.set_border_size(4);
329 calculator.set_border_mode(border_mode);
330
331 const PaddingSize dst_padding = calculator.required_padding();
332
333 calculator.set_accessed_elements(16);
334 calculator.set_access_offset(-4);
335
336 const PaddingSize src_padding = calculator.required_padding();
337
338 validate(src.info()->padding(), src_padding);
339 validate(dst.info()->padding(), dst_padding);
340}
341
342template <typename T>
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000343using CLConvolutionFixture = ConvolutionSquareValidationFixture<CLTensor, CLAccessor, CLConvolution9x9, T>;
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000344
Sanghoon Leec8d23162018-01-12 16:19:10 +0000345TEST_SUITE(CustomConvolutionSquare9x9_U8)
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000346FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000347 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000348 datasets::BorderModes()),
349 framework::dataset::make("filter_size", { 9 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000350{
351 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000352 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000353}
354
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000355FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000356 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000357 datasets::BorderModes()),
358 framework::dataset::make("filter_size", { 9 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000359{
360 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000361 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000362}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000363TEST_SUITE_END()
364
365TEST_SUITE(CustomConvolutionSquare9x9_S16)
366FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
367 DataType::S16)),
368 datasets::BorderModes()),
369 framework::dataset::make("filter_size", { 9 })))
370{
371 // Validate output
372 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
373}
374
375FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
376 DataType::S16)),
377 datasets::BorderModes()),
378 framework::dataset::make("filter_size", { 9 })))
379{
380 // Validate output
381 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
382}
383TEST_SUITE_END()
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000384TEST_SUITE_END() /* Custom Convolution 9x9 */
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000385TEST_SUITE_END() /* Custom Convolution Square */
386
387TEST_SUITE(CustomConvolutionRectangle)
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000388DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType",
Sanghoon Leec8d23162018-01-12 16:19:10 +0000389{ DataType::U8, DataType::S16 })),
390datasets::BorderModes()),
391framework::dataset::make("filter_width", { 3, 5, 7, 9 })),
392framework::dataset::make("filter_height", { 3, 5, 7, 9 })),
393shape, output_data_type, border_mode, filter_width, filter_height)
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000394{
395 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +0000396 CLTensor src = create_tensor<CLTensor>(shape, DataType::U8);
397 CLTensor dst = create_tensor<CLTensor>(shape, output_data_type);
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000398
399 // Create conv matrix
400 int16_t conv[filter_width * filter_height];
401
402 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
403 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
404
405 // Create and configure function
406 CLConvolutionRectangle convolution;
407 convolution.configure(&src, &dst, conv, filter_width, filter_height, 1, border_mode);
408
409 // Validate valid region
410 const ValidRegion dst_valid_region = shape_to_valid_region(shape, (border_mode == BorderMode::UNDEFINED), BorderSize(filter_height / 2, filter_width / 2));
411 validate(dst.info()->valid_region(), dst_valid_region);
412
413 // Validate padding
414 PaddingCalculator calculator(shape.x(), 8);
415 calculator.set_border_size(filter_width / 2);
416 calculator.set_border_mode(border_mode);
417
418 const PaddingSize dst_padding = calculator.required_padding();
419
420 calculator.set_accessed_elements(16);
421 calculator.set_access_offset(-(filter_width / 2));
422
423 const PaddingSize width_padding = calculator.required_padding();
424
425 calculator.set_border_size(filter_height / 2);
426 calculator.set_access_offset(-(filter_height / 2));
427 const PaddingSize height_padding = calculator.required_padding();
428
429 validate(src.info()->padding(), width_padding, height_padding);
430 validate(dst.info()->padding(), dst_padding);
431}
432
433template <typename T>
434using CLConvolutionFixture = ConvolutionRectangleValidationFixture<CLTensor, CLAccessor, CLConvolutionRectangle, T>;
435
Sanghoon Leec8d23162018-01-12 16:19:10 +0000436TEST_SUITE(CustomConvolutionRectangle_U8)
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000437FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
438 DataType::U8)),
439 datasets::BorderModes()),
440 framework::dataset::make("filter_width", { 3, 5, 7, 9 })),
441 framework::dataset::make("filter_height", { 3, 5, 7, 9 })))
442{
443 // Validate output
444 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
445}
446
447FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
448 DataType::U8)),
449 datasets::BorderModes()),
450 framework::dataset::make("filter_width", { 3, 5, 7, 9 })),
451 framework::dataset::make("filter_height", { 3, 5, 7, 9 })))
452{
453 // Validate output
454 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
455}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000456TEST_SUITE_END()
457
458TEST_SUITE(CustomConvolutionRectangle_S16)
459FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
460 DataType::S16)),
461 datasets::BorderModes()),
462 framework::dataset::make("filter_width", { 3, 5, 7, 9 })),
463 framework::dataset::make("filter_height", { 3, 5, 7, 9 })))
464{
465 // Validate output
466 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
467}
468
469FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
470 DataType::S16)),
471 datasets::BorderModes()),
472 framework::dataset::make("filter_width", { 3, 5, 7, 9 })),
473 framework::dataset::make("filter_height", { 3, 5, 7, 9 })))
474{
475 // Validate output
476 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
477}
478TEST_SUITE_END()
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000479TEST_SUITE_END() /* Custom Convolution Rectangle */
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000480
481TEST_SUITE(CustomConvolutionSeparable)
482TEST_SUITE(CustomConvolutionSeparable5x5)
483template <typename T>
484using CLConvolutionFixture = ConvolutionSeparableValidationFixture<CLTensor, CLAccessor, CLConvolution5x5, T>;
485
Sanghoon Leec8d23162018-01-12 16:19:10 +0000486TEST_SUITE(CustomConvolutionSeparable5x5_U8)
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000487FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
488 DataType::U8)),
489 datasets::BorderModes()),
490 framework::dataset::make("filter_size", { 5 })))
491{
492 // Validate output
493 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
494}
495
496FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
497 DataType::U8)),
498 datasets::BorderModes()),
499 framework::dataset::make("filter_size", { 5 })))
500{
501 // Validate output
502 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
503}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000504TEST_SUITE_END()
505
506TEST_SUITE(CustomConvolutionSeparable5x5_S16)
507FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
508 DataType::S16)),
509 datasets::BorderModes()),
510 framework::dataset::make("filter_size", { 5 })))
511{
512 // Validate output
513 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
514}
515
516FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
517 DataType::S16)),
518 datasets::BorderModes()),
519 framework::dataset::make("filter_size", { 5 })))
520{
521 // Validate output
522 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
523}
524TEST_SUITE_END()
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000525TEST_SUITE_END() /* Custom Convolution Separable 5x5 */
526
Sanghoon Leec8d23162018-01-12 16:19:10 +0000527TEST_SUITE(CustomConvolutionSeparable7x7)
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000528template <typename T>
529using CLConvolutionFixture = ConvolutionSeparableValidationFixture<CLTensor, CLAccessor, CLConvolution7x7, T>;
530
Sanghoon Leec8d23162018-01-12 16:19:10 +0000531TEST_SUITE(CustomConvolutionSeparable7x7_U8)
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000532FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
533 DataType::U8)),
534 datasets::BorderModes()),
535 framework::dataset::make("filter_size", { 7 })))
536{
537 // Validate output
538 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
539}
540
541FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
542 DataType::U8)),
543 datasets::BorderModes()),
544 framework::dataset::make("filter_size", { 7 })))
545{
546 // Validate output
547 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
548}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000549TEST_SUITE_END()
550
551TEST_SUITE(CustomConvolutionSeparable7x7_S16)
552FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
553 DataType::S16)),
554 datasets::BorderModes()),
555 framework::dataset::make("filter_size", { 7 })))
556{
557 // Validate output
558 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
559}
560
561FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
562 DataType::S16)),
563 datasets::BorderModes()),
564 framework::dataset::make("filter_size", { 7 })))
565{
566 // Validate output
567 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
568}
569TEST_SUITE_END()
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000570TEST_SUITE_END() /* Custom Convolution Separable 7x7 */
571
572TEST_SUITE(CustomConvolutionSeparable9x9)
573template <typename T>
574using CLConvolutionFixture = ConvolutionSeparableValidationFixture<CLTensor, CLAccessor, CLConvolution9x9, T>;
575
Sanghoon Leec8d23162018-01-12 16:19:10 +0000576TEST_SUITE(CustomConvolutionSeparable9x9_U8)
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000577FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
578 DataType::U8)),
579 datasets::BorderModes()),
580 framework::dataset::make("filter_size", { 9 })))
581{
582 // Validate output
583 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
584}
585
586FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
587 DataType::U8)),
588 datasets::BorderModes()),
589 framework::dataset::make("filter_size", { 9 })))
590{
591 // Validate output
592 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
593}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000594TEST_SUITE_END()
595
596TEST_SUITE(CustomConvolutionSeparable9x9_S16)
597FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
598 DataType::S16)),
599 datasets::BorderModes()),
600 framework::dataset::make("filter_size", { 9 })))
601{
602 // Validate output
603 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
604}
605
606FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
607 DataType::S16)),
608 datasets::BorderModes()),
609 framework::dataset::make("filter_size", { 9 })))
610{
611 // Validate output
612 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
613}
614TEST_SUITE_END()
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000615TEST_SUITE_END() /* Custom Convolution Separable 9x9 */
616
617TEST_SUITE_END() /* Custom Convolution Separable */
618TEST_SUITE_END() /* Custom Convolution */
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000619TEST_SUITE_END()
620} // namespace validation
621} // namespace test
622} // namespace arm_compute