blob: b942ddc40832776cc5941956ea5843a7c4c782f0 [file] [log] [blame]
Sanghoon Leec8a85ba2017-11-29 11:23:14 +00001/*
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +00002 * Copyright (c) 2017-2019 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/NEON/functions/NEConvolution.h"
26#include "arm_compute/runtime/Tensor.h"
27#include "arm_compute/runtime/TensorAllocator.h"
28#include "tests/NEON/Accessor.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{
Georgios Pinitasacacc322017-12-13 12:48:44 +000046/** Tolerance value for comparing reference's output against implementation
47 *
48 * This is due to the fact that NEON target performs multiplication with reciprocal of scale,
49 * while reference performs direct division with scale.
50 */
51constexpr AbsoluteTolerance<uint8_t> tolerance_u8(1);
Sanghoon Leec8d23162018-01-12 16:19:10 +000052constexpr AbsoluteTolerance<int16_t> tolerance_s16(1);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000053} // namespace
54
55TEST_SUITE(NEON)
56TEST_SUITE(CustomConvolution)
Sanghoon Leec0079e92018-01-29 17:28:49 +000057TEST_SUITE(Square3x3)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000058
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000059DATA_TEST_CASE(Configuration, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
60 datasets::BorderModes()),
61 framework::dataset::make("filter_size", { 3 })),
Sanghoon Leec8d23162018-01-12 16:19:10 +000062 shape, output_data_type, border_mode, filter_size)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000063{
64 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +000065 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
66 Tensor dst = create_tensor<Tensor>(shape, output_data_type);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000067
68 // Create conv matrix
Michalis Spyrou299fdd32019-05-01 13:03:59 +010069 std::array<int16_t, 9> conv = { 0 };
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000070
71 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
72 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
73
74 // Create and configure function
75 NEConvolution3x3 convolution;
Michalis Spyrou299fdd32019-05-01 13:03:59 +010076 convolution.configure(&src, &dst, conv.data(), 0, border_mode);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +000077
78 // Validate valid region
Sanghoon Leed7ba5392017-12-13 11:28:50 +000079 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 +000080 validate(dst.info()->valid_region(), dst_valid_region);
81
82 // Validate padding
83 PaddingCalculator calculator(shape.x(), 8);
84 calculator.set_border_size(1);
85 calculator.set_border_mode(border_mode);
86
87 const PaddingSize dst_padding = calculator.required_padding();
88
89 calculator.set_accessed_elements(16);
90 calculator.set_access_offset(-1);
91
92 const PaddingSize src_padding = calculator.required_padding();
93
94 validate(src.info()->padding(), src_padding);
95 validate(dst.info()->padding(), dst_padding);
96}
97
98template <typename T>
Sanghoon Leed7ba5392017-12-13 11:28:50 +000099using NEConvolutionFixture = ConvolutionSquareValidationFixture<Tensor, Accessor, NEConvolution3x3, T>;
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000100
Sanghoon Leec0079e92018-01-29 17:28:49 +0000101TEST_SUITE(U8)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000102FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
103 framework::dataset::make("DataType",
104 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000105 datasets::BorderModes()),
106 framework::dataset::make("filter_size", { 3 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000107{
108 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000109 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_u8);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000110}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000111TEST_SUITE_END() // U8
Sanghoon Leec8d23162018-01-12 16:19:10 +0000112
Sanghoon Leec0079e92018-01-29 17:28:49 +0000113TEST_SUITE(S16)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000114FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
115 framework::dataset::make("DataType",
116 DataType::S16)),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000117 datasets::BorderModes()),
118 framework::dataset::make("filter_size", { 3 })))
119{
120 // Validate output
121 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_s16);
122}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000123TEST_SUITE_END() // S16
124TEST_SUITE_END() // Square3x3
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000125
Sanghoon Leec0079e92018-01-29 17:28:49 +0000126TEST_SUITE(Square5x5)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000127DATA_TEST_CASE(Configuration, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
128 datasets::BorderModes()),
129 framework::dataset::make("filter_size", { 5 })),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000130 shape, output_data_type, border_mode, filter_size)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000131{
132 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +0000133 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
134 Tensor dst = create_tensor<Tensor>(shape, output_data_type);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000135
136 // Create conv matrix
Michalis Spyrou299fdd32019-05-01 13:03:59 +0100137 std::array<int16_t, 25> conv = { 0 };
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000138
139 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
140 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
141
142 // Create and configure function
143 NEConvolution5x5 convolution;
Michalis Spyrou299fdd32019-05-01 13:03:59 +0100144 convolution.configure(&src, &dst, conv.data(), 0, border_mode);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000145
146 // Validate valid region
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000147 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 +0000148 validate(dst.info()->valid_region(), dst_valid_region);
149
150 // Validate padding
151 PaddingCalculator calculator(shape.x(), 8);
152 calculator.set_border_size(2);
153 calculator.set_border_mode(border_mode);
154
155 const PaddingSize dst_padding = calculator.required_padding();
156
157 calculator.set_accessed_elements(16);
158 calculator.set_access_offset(-2);
159
160 const PaddingSize src_padding = calculator.required_padding();
161
162 validate(src.info()->padding(), src_padding);
163 validate(dst.info()->padding(), dst_padding);
164}
165
166template <typename T>
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000167using NEConvolutionFixture = ConvolutionSquareValidationFixture<Tensor, Accessor, NEConvolution5x5, T>;
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000168
Sanghoon Leec0079e92018-01-29 17:28:49 +0000169TEST_SUITE(U8)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000170FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
171 framework::dataset::make("DataType",
172 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000173 datasets::BorderModes()),
174 framework::dataset::make("filter_size", { 5 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000175{
176 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000177 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_u8);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000178}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000179TEST_SUITE_END() // U8
Sanghoon Leec8d23162018-01-12 16:19:10 +0000180
Sanghoon Leec0079e92018-01-29 17:28:49 +0000181TEST_SUITE(S16)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000182FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
183 framework::dataset::make("DataType",
184 DataType::S16)),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000185 datasets::BorderModes()),
186 framework::dataset::make("filter_size", { 5 })))
187{
188 // Validate output
189 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_s16);
190}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000191TEST_SUITE_END() // S16
192TEST_SUITE_END() // Square5x5
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000193
Sanghoon Leec0079e92018-01-29 17:28:49 +0000194TEST_SUITE(Square7x7)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000195DATA_TEST_CASE(Configuration, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
196 datasets::BorderModes()),
197 framework::dataset::make("filter_size", { 7 })),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000198 shape, output_data_type, border_mode, filter_size)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000199{
200 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +0000201 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
202 Tensor dst = create_tensor<Tensor>(shape, output_data_type);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000203
204 // Create conv matrix
Michalis Spyrou299fdd32019-05-01 13:03:59 +0100205 std::array<int16_t, 49> conv = { 0 };
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000206
207 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
208 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
209
210 // Create and configure function
211 NEConvolution7x7 convolution;
Michalis Spyrou299fdd32019-05-01 13:03:59 +0100212 convolution.configure(&src, &dst, conv.data(), 0, border_mode);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000213
214 // Validate valid region
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000215 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 +0000216 validate(dst.info()->valid_region(), dst_valid_region);
217
218 // Validate padding
219 PaddingCalculator calculator(shape.x(), 8);
220 calculator.set_border_size(3);
221 calculator.set_border_mode(border_mode);
222
223 const PaddingSize dst_padding = calculator.required_padding();
224
225 calculator.set_accessed_elements(16);
226 calculator.set_access_offset(-3);
227
228 const PaddingSize src_padding = calculator.required_padding();
229
230 validate(src.info()->padding(), src_padding);
231 validate(dst.info()->padding(), dst_padding);
232}
233
234template <typename T>
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000235using NEConvolutionFixture = ConvolutionSquareValidationFixture<Tensor, Accessor, NEConvolution7x7, T>;
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000236
Sanghoon Leec0079e92018-01-29 17:28:49 +0000237TEST_SUITE(U8)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000238FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
239 framework::dataset::make("DataType",
240 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000241 datasets::BorderModes()),
242 framework::dataset::make("filter_size", { 7 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000243{
244 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000245 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_u8);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000246}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000247TEST_SUITE_END() // U8
Sanghoon Leec8d23162018-01-12 16:19:10 +0000248
Sanghoon Leec0079e92018-01-29 17:28:49 +0000249TEST_SUITE(S16)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000250FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
251 framework::dataset::make("DataType",
252 DataType::S16)),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000253 datasets::BorderModes()),
254 framework::dataset::make("filter_size", { 7 })))
255{
256 // Validate output
257 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_s16);
258}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000259TEST_SUITE_END() // S16
260TEST_SUITE_END() // Square7x7
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000261
Sanghoon Leec0079e92018-01-29 17:28:49 +0000262TEST_SUITE(Square9x9)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000263DATA_TEST_CASE(Configuration, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType", { DataType::U8, DataType::S16 })),
264 datasets::BorderModes()),
265 framework::dataset::make("filter_size", { 9 })),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000266 shape, output_data_type, border_mode, filter_size)
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000267{
268 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +0000269 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
270 Tensor dst = create_tensor<Tensor>(shape, output_data_type);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000271
272 // Create conv matrix
Michalis Spyrou299fdd32019-05-01 13:03:59 +0100273 std::array<int16_t, 81> conv = { 0 };
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000274
275 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
276 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
277
278 // Create and configure function
279 NEConvolution9x9 convolution;
Michalis Spyrou299fdd32019-05-01 13:03:59 +0100280 convolution.configure(&src, &dst, conv.data(), 0, border_mode);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000281
282 // Validate valid region
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000283 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 +0000284 validate(dst.info()->valid_region(), dst_valid_region);
285
286 // Validate padding
287 PaddingCalculator calculator(shape.x(), 8);
288 calculator.set_border_size(4);
289 calculator.set_border_mode(border_mode);
290
291 const PaddingSize dst_padding = calculator.required_padding();
292
293 calculator.set_accessed_elements(16);
294 calculator.set_access_offset(-4);
295
296 const PaddingSize src_padding = calculator.required_padding();
297
298 validate(src.info()->padding(), src_padding);
299 validate(dst.info()->padding(), dst_padding);
300}
301
302template <typename T>
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000303using NEConvolutionFixture = ConvolutionSquareValidationFixture<Tensor, Accessor, NEConvolution9x9, T>;
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000304
Sanghoon Leec0079e92018-01-29 17:28:49 +0000305TEST_SUITE(U8)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000306FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
307 framework::dataset::make("DataType",
308 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000309 datasets::BorderModes()),
310 framework::dataset::make("filter_size", { 9 })))
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000311{
312 // Validate output
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000313 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_u8);
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000314}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000315TEST_SUITE_END() // U8
Sanghoon Leec8d23162018-01-12 16:19:10 +0000316
Sanghoon Leec0079e92018-01-29 17:28:49 +0000317TEST_SUITE(S16)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000318FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
319 framework::dataset::make("DataType",
320 DataType::S16)),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000321 datasets::BorderModes()),
322 framework::dataset::make("filter_size", { 9 })))
323{
324 // Validate output
325 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_s16);
326}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000327TEST_SUITE_END() // S16
328TEST_SUITE_END() // Square9x9
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000329
Sanghoon Leec0079e92018-01-29 17:28:49 +0000330TEST_SUITE(Rectangle)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000331DATA_TEST_CASE(Configuration, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType",
Sanghoon Leec8d23162018-01-12 16:19:10 +0000332{ DataType::U8, DataType::S16 })),
333datasets::BorderModes()),
334framework::dataset::make("filter_width", { 3, 5, 7, 9 })),
335framework::dataset::make("filter_height", { 3, 5, 7, 9 })),
336shape, output_data_type, border_mode, filter_width, filter_height)
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000337{
338 // Create tensors
Sanghoon Leec8d23162018-01-12 16:19:10 +0000339 Tensor src = create_tensor<Tensor>(shape, DataType::U8);
340 Tensor dst = create_tensor<Tensor>(shape, output_data_type);
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000341
342 // Create conv matrix
Michalis Spyrou5ae9b692018-02-05 14:59:54 +0000343 std::vector<int16_t> conv(filter_height * filter_width);
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000344
345 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
346 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
347
348 // Create and configure function
349 NEConvolutionRectangle convolution;
Michalis Spyrou5ae9b692018-02-05 14:59:54 +0000350 convolution.configure(&src, &dst, conv.data(), filter_width, filter_height, 1, border_mode);
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000351
352 // Validate valid region
353 const ValidRegion dst_valid_region = shape_to_valid_region(shape, (border_mode == BorderMode::UNDEFINED), BorderSize(filter_height / 2, filter_width / 2));
354 validate(dst.info()->valid_region(), dst_valid_region);
355
356 // Validate padding
357 PaddingCalculator calculator(shape.x(), 8);
358 calculator.set_border_size(filter_width / 2);
359 calculator.set_border_mode(border_mode);
360
361 const PaddingSize dst_padding = calculator.required_padding();
362
363 calculator.set_accessed_elements(16);
364 calculator.set_access_offset(-(filter_width / 2));
365
366 const PaddingSize width_padding = calculator.required_padding();
367
368 calculator.set_border_size(filter_height / 2);
369 calculator.set_access_offset(-(filter_height / 2));
370 const PaddingSize height_padding = calculator.required_padding();
371
372 validate(src.info()->padding(), width_padding, height_padding);
373 validate(dst.info()->padding(), dst_padding);
374}
375
376template <typename T>
377using NEConvolutionFixture = ConvolutionRectangleValidationFixture<Tensor, Accessor, NEConvolutionRectangle, T>;
378
Sanghoon Leec0079e92018-01-29 17:28:49 +0000379TEST_SUITE(U8)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000380FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
381 framework::dataset::make("DataType",
382 DataType::U8)),
Sanghoon Leed7ba5392017-12-13 11:28:50 +0000383 datasets::BorderModes()),
384 framework::dataset::make("filter_width", { 3, 5, 7, 9 })),
385 framework::dataset::make("filter_height", { 3, 5, 7, 9 })))
386{
387 // Validate output
388 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_u8);
389}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000390TEST_SUITE_END() // U8
Sanghoon Leec8d23162018-01-12 16:19:10 +0000391
Sanghoon Leec0079e92018-01-29 17:28:49 +0000392TEST_SUITE(S16)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000393FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
394 framework::dataset::make("DataType",
395 DataType::S16)),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000396 datasets::BorderModes()),
397 framework::dataset::make("filter_width", { 3, 5, 7, 9 })),
398 framework::dataset::make("filter_height", { 3, 5, 7, 9 })))
399{
400 // Validate output
401 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_s16);
402}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000403TEST_SUITE_END() // S16
404TEST_SUITE_END() // Rectangle
Sanghoon Leec8d23162018-01-12 16:19:10 +0000405
Sanghoon Leec0079e92018-01-29 17:28:49 +0000406TEST_SUITE(Separable5x5)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000407template <typename T>
408using NEConvolutionFixture = ConvolutionSeparableValidationFixture<Tensor, Accessor, NEConvolution5x5, T>;
409
Sanghoon Leec0079e92018-01-29 17:28:49 +0000410TEST_SUITE(U8)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000411FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
412 framework::dataset::make("DataType",
413 DataType::U8)),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000414 datasets::BorderModes()),
415 framework::dataset::make("filter_size", { 5 })))
416{
417 // Validate output
418 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_u8);
419}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000420TEST_SUITE_END() // U8
Sanghoon Leec8d23162018-01-12 16:19:10 +0000421
Sanghoon Leec0079e92018-01-29 17:28:49 +0000422TEST_SUITE(S16)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000423FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
424 framework::dataset::make("DataType",
425 DataType::S16)),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000426 datasets::BorderModes()),
427 framework::dataset::make("filter_size", { 5 })))
428{
429 // Validate output
430 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_s16);
431}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000432TEST_SUITE_END() // S16
433TEST_SUITE_END() // Separable5x5
Sanghoon Leec8d23162018-01-12 16:19:10 +0000434
Sanghoon Leec0079e92018-01-29 17:28:49 +0000435TEST_SUITE(Separable7x7)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000436template <typename T>
437using NEConvolutionFixture = ConvolutionSeparableValidationFixture<Tensor, Accessor, NEConvolution7x7, T>;
438
Sanghoon Leec0079e92018-01-29 17:28:49 +0000439TEST_SUITE(U8)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000440FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
441 framework::dataset::make("DataType",
442 DataType::U8)),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000443 datasets::BorderModes()),
444 framework::dataset::make("filter_size", { 7 })))
445{
446 // Validate output
447 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_u8);
448}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000449TEST_SUITE_END() // U8
Sanghoon Leec8d23162018-01-12 16:19:10 +0000450
Sanghoon Leec0079e92018-01-29 17:28:49 +0000451TEST_SUITE(S16)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000452FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
453 framework::dataset::make("DataType",
454 DataType::S16)),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000455 datasets::BorderModes()),
456 framework::dataset::make("filter_size", { 7 })))
457{
458 // Validate output
459 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_s16);
460}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000461TEST_SUITE_END() // S16
462TEST_SUITE_END() // Separable7x7
Sanghoon Leec8d23162018-01-12 16:19:10 +0000463
Sanghoon Leec0079e92018-01-29 17:28:49 +0000464TEST_SUITE(Separable9x9)
Sanghoon Leec8d23162018-01-12 16:19:10 +0000465template <typename T>
466using NEConvolutionFixture = ConvolutionSeparableValidationFixture<Tensor, Accessor, NEConvolution9x9, T>;
467
Sanghoon Leec0079e92018-01-29 17:28:49 +0000468TEST_SUITE(U8)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000469FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
470 framework::dataset::make("DataType",
471 DataType::U8)),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000472 datasets::BorderModes()),
473 framework::dataset::make("filter_size", { 9 })))
474{
475 // Validate output
476 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_u8);
477}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000478TEST_SUITE_END() // U8
Sanghoon Leec8d23162018-01-12 16:19:10 +0000479
Sanghoon Leec0079e92018-01-29 17:28:49 +0000480TEST_SUITE(S16)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000481FIXTURE_DATA_TEST_CASE(RunLarge, NEConvolutionFixture<int16_t>, framework::DatasetMode::NIGHTLY, combine(combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
482 framework::dataset::make("DataType",
483 DataType::S16)),
Sanghoon Leec8d23162018-01-12 16:19:10 +0000484 datasets::BorderModes()),
485 framework::dataset::make("filter_size", { 9 })))
486{
487 // Validate output
488 validate(Accessor(_target), _reference, shape_to_valid_region(_reference.shape(), (_border_mode == BorderMode::UNDEFINED), BorderSize(_height / 2, _width / 2)), tolerance_s16);
489}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000490TEST_SUITE_END() // S16
491TEST_SUITE_END() // Separable9x9
Sanghoon Leec0079e92018-01-29 17:28:49 +0000492
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000493TEST_SUITE_END() // CustomConvolution
494TEST_SUITE_END() // NEON
Sanghoon Leec8a85ba2017-11-29 11:23:14 +0000495} // namespace validation
496} // namespace test
497} // namespace arm_compute