blob: 4c1bb80a5011c337f55c9018e898c3c5f64426b6 [file] [log] [blame]
Georgios Pinitasd912fd82017-11-27 21:00:13 +00001/*
Georgios Pinitasf7c5a412020-12-03 14:38:33 +00002 * Copyright (c) 2017-2020 Arm Limited.
Georgios Pinitasd912fd82017-11-27 21:00:13 +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"
Georgios Pinitasf7c5a412020-12-03 14:38:33 +000025#include "src/core/NEON/kernels/NEIm2ColKernel.h"
Giorgio Arena156fcf32018-03-09 15:30:43 +000026#include "tests/NEON/Accessor.h"
Georgios Pinitasf7c5a412020-12-03 14:38:33 +000027#include "tests/NEON/Helper.h"
Giorgio Arena156fcf32018-03-09 15:30:43 +000028#include "tests/datasets/ShapeDatasets.h"
Georgios Pinitasd912fd82017-11-27 21:00:13 +000029#include "tests/framework/Asserts.h"
30#include "tests/framework/Macros.h"
31#include "tests/framework/datasets/Datasets.h"
32#include "tests/validation/Validation.h"
Giorgio Arena156fcf32018-03-09 15:30:43 +000033#include "tests/validation/fixtures/Im2ColFixture.h"
Georgios Pinitasd912fd82017-11-27 21:00:13 +000034
35namespace arm_compute
36{
37namespace test
38{
39namespace validation
40{
Giorgio Arena156fcf32018-03-09 15:30:43 +000041namespace
42{
Pablo Tello4a626a72018-04-04 10:01:14 +010043const auto conv_filter_sizes = framework::dataset::make("KernelDims", { Size2D(3U, 3U), Size2D(3U, 1U), Size2D(1U, 5U), Size2D(5U, 5U), Size2D(7U, 7U) });
Giorgio Arena0f170392018-07-18 16:13:12 +010044const auto conv_args = combine(combine(combine(combine(conv_filter_sizes, framework::dataset::make("PadStride", { PadStrideInfo(1U, 1U, 0U, 0U), PadStrideInfo(1U, 1U, 1U, 1U), PadStrideInfo(2U, 2U, 0U, 2U) })),
45 framework::dataset::make("QuantizationInfo", QuantizationInfo(0.5f, 10))),
46 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
47 framework::dataset::make("NumGroups", { 1 }));
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000048
49const auto conv_filter_sizes_small = framework::dataset::make("KernelDims", { Size2D(3U, 3U), Size2D(3U, 1U), Size2D(1U, 5U) });
50const auto conv_args_small = combine(combine(combine(combine(conv_filter_sizes_small, framework::dataset::make("PadStride", { PadStrideInfo(1U, 1U, 0U, 0U), PadStrideInfo(1U, 1U, 1U, 1U) })),
51 framework::dataset::make("QuantizationInfo", QuantizationInfo(0.5f, 10))),
52 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
53 framework::dataset::make("NumGroups", { 1 }));
Giorgio Arena156fcf32018-03-09 15:30:43 +000054} // namespace
Georgios Pinitasd912fd82017-11-27 21:00:13 +000055TEST_SUITE(NEON)
56TEST_SUITE(Im2Col)
57
Georgios Pinitasf7c5a412020-12-03 14:38:33 +000058using NEIm2Col = NESynthetizeFunction<NEIm2ColKernel>;
59
Georgios Pinitasd912fd82017-11-27 21:00:13 +000060// *INDENT-OFF*
61// clang-format off
62DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
63 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(10U, 12U, 2U), 1, DataType::U8), // Unsupported data type
64 TensorInfo(TensorShape(10U, 12U, 2U), 1, DataType::F32), // Mismatching data type
Georgios Pinitasd912fd82017-11-27 21:00:13 +000065 TensorInfo(TensorShape(10U, 12U, 2U), 1, DataType::QASYMM8), // Bias not supported with QASYMM8
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000066 TensorInfo(TensorShape(10U, 12U, 2U), 1, DataType::QASYMM8), // Mismatching shapes
Giorgio Arena156fcf32018-03-09 15:30:43 +000067 TensorInfo(TensorShape(10U, 12U, 2U, 2U), 1, DataType::QASYMM8),
Georgios Pinitasd912fd82017-11-27 21:00:13 +000068 }),
69 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(3U, 4U, 10U, 2U), 1, DataType::F16),
70 TensorInfo(TensorShape(3U, 4U, 10U, 2U), 1, DataType::F16),
Georgios Pinitasd912fd82017-11-27 21:00:13 +000071 TensorInfo(TensorShape(3U, 3U, 10U, 2U), 1, DataType::QASYMM8),
72 TensorInfo(TensorShape(3U, 4U, 10U, 2U), 1, DataType::QASYMM8),
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000073 TensorInfo(TensorShape(18U, 80U, 1U, 2U), 1, DataType::QASYMM8),
Georgios Pinitasd912fd82017-11-27 21:00:13 +000074 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +010075 framework::dataset::make("HasBias", { true, true, true, false, false })),
76 framework::dataset::make("Expected", { false, false, false, false, true })),
Georgios Pinitasd912fd82017-11-27 21:00:13 +000077 input_info, output_info, has_bias, expected)
78{
Giorgio Arena0f170392018-07-18 16:13:12 +010079 bool status = bool(NEIm2Col::validate(&input_info, &output_info, Size2D(3U, 3U), PadStrideInfo(), has_bias));
Georgios Pinitas358ca202017-12-07 16:47:52 +000080 ARM_COMPUTE_EXPECT(status == expected, framework::LogLevel::ERRORS);
Georgios Pinitasd912fd82017-11-27 21:00:13 +000081}
82// clang-format on
83// *INDENT-ON*
84
Giorgio Arena156fcf32018-03-09 15:30:43 +000085template <typename T>
Gian Marco Iodice597a8562018-08-01 15:06:06 +010086using NEIm2ColFixture = Im2ColValidationFixture<Tensor, Accessor, NEIm2Col, T, false>;
Giorgio Arena156fcf32018-03-09 15:30:43 +000087
88TEST_SUITE(Float)
89TEST_SUITE(FP32)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000090FIXTURE_DATA_TEST_CASE(RunSmall, NEIm2ColFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)),
91 conv_args_small))
Giorgio Arena156fcf32018-03-09 15:30:43 +000092{
93 // Validate output
94 validate(Accessor(_target), _reference);
95}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000096FIXTURE_DATA_TEST_CASE(RunLarge, NEIm2ColFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType",
97 DataType::F32)),
Giorgio Arenafb629082018-08-20 18:03:27 +010098 conv_args))
Pablo Tello4a626a72018-04-04 10:01:14 +010099{
100 // Validate output
101 validate(Accessor(_target), _reference);
102}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000103TEST_SUITE_END() // FP32
Giorgio Arena156fcf32018-03-09 15:30:43 +0000104
105#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
106
107TEST_SUITE(FP16)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000108FIXTURE_DATA_TEST_CASE(RunSmall, NEIm2ColFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)),
109 conv_args_small))
Giorgio Arena156fcf32018-03-09 15:30:43 +0000110{
111 // Validate output
112 validate(Accessor(_target), _reference);
113}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000114FIXTURE_DATA_TEST_CASE(RunLarge, NEIm2ColFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType",
115 DataType::F16)),
Giorgio Arenafb629082018-08-20 18:03:27 +0100116 conv_args))
Pablo Tello4a626a72018-04-04 10:01:14 +0100117{
118 // Validate output
119 validate(Accessor(_target), _reference);
120}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000121TEST_SUITE_END() // FP16
Giorgio Arena156fcf32018-03-09 15:30:43 +0000122
123#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
124
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000125TEST_SUITE_END() // Float
Giorgio Arena156fcf32018-03-09 15:30:43 +0000126
127TEST_SUITE(QASYMM8)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000128FIXTURE_DATA_TEST_CASE(RunSmall, NEIm2ColFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::QASYMM8)),
129 conv_args_small))
Giorgio Arena156fcf32018-03-09 15:30:43 +0000130{
131 // Validate output
132 validate(Accessor(_target), _reference);
133}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000134FIXTURE_DATA_TEST_CASE(RunLarge, NEIm2ColFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
135 framework::dataset::make("DataType", DataType::QASYMM8)),
Giorgio Arenafb629082018-08-20 18:03:27 +0100136 conv_args))
Pablo Tello4a626a72018-04-04 10:01:14 +0100137{
138 // Validate output
139 validate(Accessor(_target), _reference);
140}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000141TEST_SUITE_END() // QASYMM8
Giorgio Arena156fcf32018-03-09 15:30:43 +0000142
Georgios Pinitas75bde5e2019-06-07 11:52:01 +0100143TEST_SUITE(SpecialCases)
144TEST_CASE(PaddedChannelNHWC, framework::DatasetMode::PRECOMMIT)
145{
146 // Const data
147 const TensorShape src_shape = TensorShape(7U, 27U, 13U);
148 const DataType data_type = DataType::F32;
149 const DataLayout data_layout = DataLayout::NHWC;
150 const bool has_bias = false;
151 const unsigned int num_groups = 1;
152 const Size2D spatial_kernel(3, 3);
153 const QuantizationInfo qinfo{};
154 const PadStrideInfo conv_info(1U, 1U, 0U, 0U);
155
156 // Calculate destination shape
157 TensorInfo src_info(src_shape, 1, data_type);
158 src_info.set_data_layout(data_layout);
159 const TensorShape dst_shape = compute_im2col_conv_shape(&src_info, spatial_kernel, conv_info, has_bias, Size2D(1U, 1U), false, num_groups);
160
161 // Compute target
162 Tensor src_target = create_tensor<Tensor>(src_shape, data_type, 1, qinfo, data_layout);
163 Tensor dst_target = create_tensor<Tensor>(dst_shape, data_type, 1, qinfo);
164
165 // Configure target function
166 NEIm2Col im2col_func;
167 im2col_func.configure(&src_target, &dst_target, spatial_kernel, conv_info, has_bias);
168
169 // Extend padding
170 src_target.info()->extend_padding(PaddingSize(3, 5, 9, 1));
171 dst_target.info()->extend_padding(PaddingSize(8, 1, 1, 3));
172
173 // Validate and allocate tensors
174 ARM_COMPUTE_EXPECT(src_target.info()->is_resizable(), framework::LogLevel::ERRORS);
175 ARM_COMPUTE_EXPECT(dst_target.info()->is_resizable(), framework::LogLevel::ERRORS);
176
177 src_target.allocator()->allocate();
178 dst_target.allocator()->allocate();
179
180 ARM_COMPUTE_EXPECT(!src_target.info()->is_resizable(), framework::LogLevel::ERRORS);
181 ARM_COMPUTE_EXPECT(!dst_target.info()->is_resizable(), framework::LogLevel::ERRORS);
182
183 // Fill target source
184 library->fill_tensor_uniform(Accessor(src_target), 0);
185
186 // Run target function
187 im2col_func.run();
188
189 // Calculate Reference
190 SimpleTensor<float> src_ref{ src_shape, data_type, 1, qinfo, data_layout };
191 SimpleTensor<float> dst_ref{ dst_shape, data_type, 1, qinfo, DataLayout::NCHW };
192
193 // Fill reference source
194 library->fill_tensor_uniform(src_ref, 0);
195
196#ifndef DOXYGEN_SKIP_THIS
197 // Run reference function
198 reference::im2col(src_ref, dst_ref, spatial_kernel, conv_info, has_bias, num_groups);
199#endif // DOXYGEN_SKIP_THIS
200
201 // Validate
202 validate(Accessor(dst_target), dst_ref);
203}
204TEST_SUITE_END() // Special Cases
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000205TEST_SUITE_END() // Im2Col
206TEST_SUITE_END() // NEON
Georgios Pinitasd912fd82017-11-27 21:00:13 +0000207} // namespace validation
208} // namespace test
209} // namespace arm_compute