blob: eb95d1a29520695207c484b12d233f4076e9bbbb [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{
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000044TEST_SUITE(CL)
45TEST_SUITE(CustomConvolution)
Sanghoon Leec0079e92018-01-29 17:28:49 +000046TEST_SUITE(Square3x3)
Sanghoon Leec8d23162018-01-12 16:19:10 +000047DATA_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 +000048 datasets::BorderModes()),
49 framework::dataset::make("filter_size", { 3 })),
Sanghoon Leec8d23162018-01-12 16:19:10 +000050 shape, output_data_type, border_mode, filter_size)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000051{
52 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +000053 CLTensor src = create_tensor<CLTensor>(shape, DataType::U8);
54 CLTensor dst = create_tensor<CLTensor>(shape, output_data_type);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000055
56 // Create conv matrix
57 int16_t conv[9];
58
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000059 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
60 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
61
62 // Create and configure function
63 CLConvolution3x3 convolution;
Sanghoon Leed7ba5392017-12-13 11:28:50 +000064 convolution.configure(&src, &dst, conv, 0, border_mode);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000065
66 // Validate valid region
Sanghoon Leed7ba5392017-12-13 11:28:50 +000067 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 +000068 validate(dst.info()->valid_region(), dst_valid_region);
69
70 // Validate padding
71 PaddingCalculator calculator(shape.x(), 8);
72 calculator.set_border_size(1);
73 calculator.set_border_mode(border_mode);
74
75 const PaddingSize dst_padding = calculator.required_padding();
76
77 calculator.set_accessed_elements(16);
78 calculator.set_access_offset(-1);
79
80 const PaddingSize src_padding = calculator.required_padding();
81
82 validate(src.info()->padding(), src_padding);
83 validate(dst.info()->padding(), dst_padding);
84}
85
86template <typename T>
Sanghoon Leed7ba5392017-12-13 11:28:50 +000087using CLConvolutionFixture = ConvolutionSquareValidationFixture<CLTensor, CLAccessor, CLConvolution3x3, T>;
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000088
Sanghoon Leec0079e92018-01-29 17:28:49 +000089TEST_SUITE(U8)
Sanghoon Leed7ba5392017-12-13 11:28:50 +000090FIXTURE_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 +000091 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +000092 datasets::BorderModes()),
93 framework::dataset::make("filter_size", { 3 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000094{
95 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +000096 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 +000097}
98
Sanghoon Leed7ba5392017-12-13 11:28:50 +000099FIXTURE_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 +0000100 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000101 datasets::BorderModes()),
102 framework::dataset::make("filter_size", { 3 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000103{
104 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000105 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 +0000106}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000107TEST_SUITE_END()
108
Sanghoon Leec0079e92018-01-29 17:28:49 +0000109TEST_SUITE(S16)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000110FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
111 DataType::S16)),
112 datasets::BorderModes()),
113 framework::dataset::make("filter_size", { 3 })))
114{
115 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000116 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000117}
118FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
119 DataType::S16)),
120 datasets::BorderModes()),
121 framework::dataset::make("filter_size", { 3 })))
122{
123 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000124 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000125}
126TEST_SUITE_END()
Sanghoon Leec0079e92018-01-29 17:28:49 +0000127TEST_SUITE_END() /* Square 3x3 */
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000128
Sanghoon Leec0079e92018-01-29 17:28:49 +0000129TEST_SUITE(Square5x5)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000130DATA_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 +0000131 datasets::BorderModes()),
132 framework::dataset::make("filter_size", { 5 })),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000133 shape, output_data_type, border_mode, filter_size)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000134{
135 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +0000136 CLTensor src = create_tensor<CLTensor>(shape, DataType::U8);
137 CLTensor dst = create_tensor<CLTensor>(shape, output_data_type);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000138
139 // Create conv matrix
140 int16_t conv[25];
141
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000142 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
143 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
144
145 // Create and configure function
146 CLConvolution5x5 convolution;
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000147 convolution.configure(&src, &dst, conv, 0, border_mode);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000148
149 // Validate valid region
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000150 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 +0000151 validate(dst.info()->valid_region(), dst_valid_region);
152
153 // Validate padding
154 PaddingCalculator calculator(shape.x(), 8);
155 calculator.set_border_size(2);
156 calculator.set_border_mode(border_mode);
157
158 const PaddingSize dst_padding = calculator.required_padding();
159
160 calculator.set_accessed_elements(16);
161 calculator.set_access_offset(-2);
162
163 const PaddingSize src_padding = calculator.required_padding();
164
165 validate(src.info()->padding(), src_padding);
166 validate(dst.info()->padding(), dst_padding);
167}
168
169template <typename T>
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000170using CLConvolutionFixture = ConvolutionSquareValidationFixture<CLTensor, CLAccessor, CLConvolution5x5, T>;
Sanghoon Leec8d23162018-01-12 16:19:10 +0000171
Sanghoon Leec0079e92018-01-29 17:28:49 +0000172TEST_SUITE(U8)
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000173FIXTURE_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 +0000174 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000175 datasets::BorderModes()),
176 framework::dataset::make("filter_size", { 5 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000177{
178 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000179 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 +0000180}
181
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000182FIXTURE_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 +0000183 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000184 datasets::BorderModes()),
185 framework::dataset::make("filter_size", { 5 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000186{
187 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000188 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 +0000189}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000190TEST_SUITE_END()
191
Sanghoon Leec0079e92018-01-29 17:28:49 +0000192TEST_SUITE(S16)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000193FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
194 DataType::S16)),
195 datasets::BorderModes()),
196 framework::dataset::make("filter_size", { 5 })))
197{
198 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000199 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000200}
201
Georgios Pinitasc5694af2018-02-09 10:30:41 +0000202FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
Sanghoon Leec8d23162018-01-12 16:19:10 +0000203 DataType::S16)),
204 datasets::BorderModes()),
205 framework::dataset::make("filter_size", { 5 })))
206{
207 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000208 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000209}
210TEST_SUITE_END()
Sanghoon Leec0079e92018-01-29 17:28:49 +0000211TEST_SUITE_END() /* Square5x5 */
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000212
Sanghoon Leec0079e92018-01-29 17:28:49 +0000213TEST_SUITE(Square7x7)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000214DATA_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 +0000215 datasets::BorderModes()),
216 framework::dataset::make("filter_size", { 7 })),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000217 shape, output_data_type, border_mode, filter_size)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000218{
219 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +0000220 CLTensor src = create_tensor<CLTensor>(shape, DataType::U8);
221 CLTensor dst = create_tensor<CLTensor>(shape, output_data_type);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000222
223 // Create conv matrix
224 int16_t conv[49];
225
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000226 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
227 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
228
229 // Create and configure function
230 CLConvolution7x7 convolution;
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000231 convolution.configure(&src, &dst, conv, 0, border_mode);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000232
233 // Validate valid region
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000234 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 +0000235 validate(dst.info()->valid_region(), dst_valid_region);
236
237 // Validate padding
238 PaddingCalculator calculator(shape.x(), 8);
239 calculator.set_border_size(3);
240 calculator.set_border_mode(border_mode);
241
242 const PaddingSize dst_padding = calculator.required_padding();
243
244 calculator.set_accessed_elements(16);
245 calculator.set_access_offset(-3);
246
247 const PaddingSize src_padding = calculator.required_padding();
248
249 validate(src.info()->padding(), src_padding);
250 validate(dst.info()->padding(), dst_padding);
251}
252
253template <typename T>
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000254using CLConvolutionFixture = ConvolutionSquareValidationFixture<CLTensor, CLAccessor, CLConvolution7x7, T>;
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000255
Sanghoon Leec0079e92018-01-29 17:28:49 +0000256TEST_SUITE(U8)
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000257FIXTURE_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 +0000258 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000259 datasets::BorderModes()),
260 framework::dataset::make("filter_size", { 7 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000261{
262 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000263 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 +0000264}
265
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000266FIXTURE_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 +0000267 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000268 datasets::BorderModes()),
269 framework::dataset::make("filter_size", { 7 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000270{
271 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000272 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 +0000273}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000274TEST_SUITE_END()
275
Sanghoon Leec0079e92018-01-29 17:28:49 +0000276TEST_SUITE(S16)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000277FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
278 DataType::S16)),
279 datasets::BorderModes()),
280 framework::dataset::make("filter_size", { 7 })))
281{
282 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000283 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000284}
285
286FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
287 DataType::S16)),
288 datasets::BorderModes()),
289 framework::dataset::make("filter_size", { 7 })))
290{
291 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000292 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000293}
294TEST_SUITE_END()
Sanghoon Leec0079e92018-01-29 17:28:49 +0000295TEST_SUITE_END() /* Square7x7 */
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000296
Sanghoon Leec0079e92018-01-29 17:28:49 +0000297TEST_SUITE(Square9x9)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000298DATA_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 +0000299 datasets::BorderModes()),
300 framework::dataset::make("filter_size", { 9 })),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000301 shape, output_data_type, border_mode, filter_size)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000302{
303 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +0000304 CLTensor src = create_tensor<CLTensor>(shape, DataType::U8);
305 CLTensor dst = create_tensor<CLTensor>(shape, output_data_type);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000306
307 // Create conv matrix
308 int16_t conv[81];
309
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000310 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
311 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
312
313 // Create and configure function
314 CLConvolution9x9 convolution;
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000315 convolution.configure(&src, &dst, conv, 0, border_mode);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000316
317 // Validate valid region
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000318 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 +0000319 validate(dst.info()->valid_region(), dst_valid_region);
320
321 // Validate padding
322 PaddingCalculator calculator(shape.x(), 8);
323 calculator.set_border_size(4);
324 calculator.set_border_mode(border_mode);
325
326 const PaddingSize dst_padding = calculator.required_padding();
327
328 calculator.set_accessed_elements(16);
329 calculator.set_access_offset(-4);
330
331 const PaddingSize src_padding = calculator.required_padding();
332
333 validate(src.info()->padding(), src_padding);
334 validate(dst.info()->padding(), dst_padding);
335}
336
337template <typename T>
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000338using CLConvolutionFixture = ConvolutionSquareValidationFixture<CLTensor, CLAccessor, CLConvolution9x9, T>;
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000339
Sanghoon Leec0079e92018-01-29 17:28:49 +0000340TEST_SUITE(U8)
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000341FIXTURE_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 +0000342 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000343 datasets::BorderModes()),
344 framework::dataset::make("filter_size", { 9 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000345{
346 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000347 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 +0000348}
349
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000350FIXTURE_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 +0000351 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000352 datasets::BorderModes()),
353 framework::dataset::make("filter_size", { 9 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000354{
355 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000356 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 +0000357}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000358TEST_SUITE_END()
359
Sanghoon Leec0079e92018-01-29 17:28:49 +0000360TEST_SUITE(S16)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000361FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
362 DataType::S16)),
363 datasets::BorderModes()),
364 framework::dataset::make("filter_size", { 9 })))
365{
366 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000367 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000368}
369
370FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
371 DataType::S16)),
372 datasets::BorderModes()),
373 framework::dataset::make("filter_size", { 9 })))
374{
375 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000376 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000377}
378TEST_SUITE_END()
Sanghoon Leec0079e92018-01-29 17:28:49 +0000379TEST_SUITE_END() /* Square9x9 */
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000380
Sanghoon Leec0079e92018-01-29 17:28:49 +0000381TEST_SUITE(Rectangle)
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000382DATA_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 +0000383{ DataType::U8, DataType::S16 })),
384datasets::BorderModes()),
385framework::dataset::make("filter_width", { 3, 5, 7, 9 })),
386framework::dataset::make("filter_height", { 3, 5, 7, 9 })),
387shape, output_data_type, border_mode, filter_width, filter_height)
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000388{
389 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +0000390 CLTensor src = create_tensor<CLTensor>(shape, DataType::U8);
391 CLTensor dst = create_tensor<CLTensor>(shape, output_data_type);
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000392
393 // Create conv matrix
394 int16_t conv[filter_width * filter_height];
395
396 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
397 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
398
399 // Create and configure function
400 CLConvolutionRectangle convolution;
401 convolution.configure(&src, &dst, conv, filter_width, filter_height, 1, border_mode);
402
403 // Validate valid region
404 const ValidRegion dst_valid_region = shape_to_valid_region(shape, (border_mode == BorderMode::UNDEFINED), BorderSize(filter_height / 2, filter_width / 2));
405 validate(dst.info()->valid_region(), dst_valid_region);
406
407 // Validate padding
408 PaddingCalculator calculator(shape.x(), 8);
409 calculator.set_border_size(filter_width / 2);
410 calculator.set_border_mode(border_mode);
411
412 const PaddingSize dst_padding = calculator.required_padding();
413
414 calculator.set_accessed_elements(16);
415 calculator.set_access_offset(-(filter_width / 2));
416
417 const PaddingSize width_padding = calculator.required_padding();
418
419 calculator.set_border_size(filter_height / 2);
420 calculator.set_access_offset(-(filter_height / 2));
421 const PaddingSize height_padding = calculator.required_padding();
422
423 validate(src.info()->padding(), width_padding, height_padding);
424 validate(dst.info()->padding(), dst_padding);
425}
426
427template <typename T>
428using CLConvolutionFixture = ConvolutionRectangleValidationFixture<CLTensor, CLAccessor, CLConvolutionRectangle, T>;
429
Sanghoon Leec0079e92018-01-29 17:28:49 +0000430TEST_SUITE(U8)
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000431FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
432 DataType::U8)),
433 datasets::BorderModes()),
434 framework::dataset::make("filter_width", { 3, 5, 7, 9 })),
435 framework::dataset::make("filter_height", { 3, 5, 7, 9 })))
436{
437 // Validate output
438 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
439}
440
441FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
442 DataType::U8)),
443 datasets::BorderModes()),
444 framework::dataset::make("filter_width", { 3, 5, 7, 9 })),
445 framework::dataset::make("filter_height", { 3, 5, 7, 9 })))
446{
447 // Validate output
448 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
449}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000450TEST_SUITE_END()
451
Sanghoon Leec0079e92018-01-29 17:28:49 +0000452TEST_SUITE(S16)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000453FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
454 DataType::S16)),
455 datasets::BorderModes()),
456 framework::dataset::make("filter_width", { 3, 5, 7, 9 })),
457 framework::dataset::make("filter_height", { 3, 5, 7, 9 })))
458{
459 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000460 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000461}
462
463FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
464 DataType::S16)),
465 datasets::BorderModes()),
466 framework::dataset::make("filter_width", { 3, 5, 7, 9 })),
467 framework::dataset::make("filter_height", { 3, 5, 7, 9 })))
468{
469 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000470 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000471}
472TEST_SUITE_END()
Sanghoon Leec0079e92018-01-29 17:28:49 +0000473TEST_SUITE_END() /* Rectangle */
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000474
Sanghoon Leec0079e92018-01-29 17:28:49 +0000475TEST_SUITE(Separable5x5)
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000476template <typename T>
477using CLConvolutionFixture = ConvolutionSeparableValidationFixture<CLTensor, CLAccessor, CLConvolution5x5, T>;
478
Sanghoon Leec0079e92018-01-29 17:28:49 +0000479TEST_SUITE(U8)
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000480FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
481 DataType::U8)),
482 datasets::BorderModes()),
483 framework::dataset::make("filter_size", { 5 })))
484{
485 // Validate output
486 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
487}
488
489FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
490 DataType::U8)),
491 datasets::BorderModes()),
492 framework::dataset::make("filter_size", { 5 })))
493{
494 // Validate output
495 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
496}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000497TEST_SUITE_END()
498
Sanghoon Leec0079e92018-01-29 17:28:49 +0000499TEST_SUITE(S16)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000500FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
501 DataType::S16)),
502 datasets::BorderModes()),
503 framework::dataset::make("filter_size", { 5 })))
504{
505 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000506 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000507}
508
509FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
510 DataType::S16)),
511 datasets::BorderModes()),
512 framework::dataset::make("filter_size", { 5 })))
513{
514 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000515 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000516}
517TEST_SUITE_END()
Sanghoon Leec0079e92018-01-29 17:28:49 +0000518TEST_SUITE_END() /* Separable5x5 */
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000519
Sanghoon Leec0079e92018-01-29 17:28:49 +0000520TEST_SUITE(Separable7x7)
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000521template <typename T>
522using CLConvolutionFixture = ConvolutionSeparableValidationFixture<CLTensor, CLAccessor, CLConvolution7x7, T>;
523
Sanghoon Leec0079e92018-01-29 17:28:49 +0000524TEST_SUITE(U8)
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000525FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
526 DataType::U8)),
527 datasets::BorderModes()),
528 framework::dataset::make("filter_size", { 7 })))
529{
530 // Validate output
531 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
532}
533
534FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
535 DataType::U8)),
536 datasets::BorderModes()),
537 framework::dataset::make("filter_size", { 7 })))
538{
539 // Validate output
540 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
541}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000542TEST_SUITE_END()
543
Sanghoon Leec0079e92018-01-29 17:28:49 +0000544TEST_SUITE(S16)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000545FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
546 DataType::S16)),
547 datasets::BorderModes()),
548 framework::dataset::make("filter_size", { 7 })))
549{
550 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000551 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000552}
553
554FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
555 DataType::S16)),
556 datasets::BorderModes()),
557 framework::dataset::make("filter_size", { 7 })))
558{
559 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000560 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000561}
562TEST_SUITE_END()
Sanghoon Leec0079e92018-01-29 17:28:49 +0000563TEST_SUITE_END() /* Separable7x7 */
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000564
Sanghoon Leec0079e92018-01-29 17:28:49 +0000565TEST_SUITE(Separable9x9)
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000566template <typename T>
567using CLConvolutionFixture = ConvolutionSeparableValidationFixture<CLTensor, CLAccessor, CLConvolution9x9, T>;
568
Sanghoon Leec0079e92018-01-29 17:28:49 +0000569TEST_SUITE(U8)
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000570FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
571 DataType::U8)),
572 datasets::BorderModes()),
573 framework::dataset::make("filter_size", { 9 })))
574{
575 // Validate output
576 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
577}
578
579FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
580 DataType::U8)),
581 datasets::BorderModes()),
582 framework::dataset::make("filter_size", { 9 })))
583{
584 // Validate output
585 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
586}
Sanghoon Leec8d23162018-01-12 16:19:10 +0000587TEST_SUITE_END()
588
Sanghoon Leec0079e92018-01-29 17:28:49 +0000589TEST_SUITE(S16)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000590FIXTURE_DATA_TEST_CASE(RunSmall, CLConvolutionFixture<int16_t>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType",
591 DataType::S16)),
592 datasets::BorderModes()),
593 framework::dataset::make("filter_size", { 9 })))
594{
595 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000596 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000597}
598
599FIXTURE_DATA_TEST_CASE(RunLarge, CLConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeShapes(), framework::dataset::make("DataType",
600 DataType::S16)),
601 datasets::BorderModes()),
602 framework::dataset::make("filter_size", { 9 })))
603{
604 // Validate output
Georgios Pinitase9146ed2018-02-07 16:05:47 +0000605 validate(CLAccessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)));
Sanghoon Leec8d23162018-01-12 16:19:10 +0000606}
607TEST_SUITE_END()
Sanghoon Leec0079e92018-01-29 17:28:49 +0000608TEST_SUITE_END() /* Separable9x9 */
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000609
Sanghoon Lee571b18a2017-12-22 16:20:11 +0000610TEST_SUITE_END() /* Custom Convolution */
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000611TEST_SUITE_END()
612} // namespace validation
613} // namespace test
614} // namespace arm_compute