blob: ef5e75c5db1a834b0134a61b0b5f71bfebb3470a [file] [log] [blame]
Georgios Pinitasd912fd82017-11-27 21:00:13 +00001/*
Georgios Pinitasdff29352020-12-31 15:35:17 +00002 * Copyright (c) 2017-2021 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 Pinitas7891a732021-08-20 21:39:25 +010025#include "src/cpu/kernels/CpuIm2ColKernel.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{
Georgios Pinitasdff29352020-12-31 15:35:17 +000043const auto im2col_shapes = framework::dataset::make("Shape", { TensorShape{ 11U, 11U, 11U }, TensorShape{ 16U, 16U, 16U }, TensorShape{ 27U, 13U, 7U }, TensorShape{ 31U, 27U, 17U, 2U }, TensorShape{ 27U, 13U, 5U, 4U }, TensorShape{ 11U, 11U, 5U, 5U } });
44
Pablo Tello4a626a72018-04-04 10:01:14 +010045const 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 +010046const 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) })),
47 framework::dataset::make("QuantizationInfo", QuantizationInfo(0.5f, 10))),
48 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
49 framework::dataset::make("NumGroups", { 1 }));
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000050
51const auto conv_filter_sizes_small = framework::dataset::make("KernelDims", { Size2D(3U, 3U), Size2D(3U, 1U), Size2D(1U, 5U) });
52const 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) })),
53 framework::dataset::make("QuantizationInfo", QuantizationInfo(0.5f, 10))),
54 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
55 framework::dataset::make("NumGroups", { 1 }));
Giorgio Arena156fcf32018-03-09 15:30:43 +000056} // namespace
Georgios Pinitasd912fd82017-11-27 21:00:13 +000057TEST_SUITE(NEON)
58TEST_SUITE(Im2Col)
59
Manuel Bottini90028992021-06-30 18:29:18 +010060using CpuIm2Col = NESynthetizeFunctionWithZeroConstantKernelBorder<cpu::kernels::CpuIm2ColKernel>;
Georgios Pinitasf7c5a412020-12-03 14:38:33 +000061
Georgios Pinitasd912fd82017-11-27 21:00:13 +000062// *INDENT-OFF*
63// clang-format off
64DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
65 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(10U, 12U, 2U), 1, DataType::U8), // Unsupported data type
66 TensorInfo(TensorShape(10U, 12U, 2U), 1, DataType::F32), // Mismatching data type
Georgios Pinitasd912fd82017-11-27 21:00:13 +000067 TensorInfo(TensorShape(10U, 12U, 2U), 1, DataType::QASYMM8), // Bias not supported with QASYMM8
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000068 TensorInfo(TensorShape(10U, 12U, 2U), 1, DataType::QASYMM8), // Mismatching shapes
Giorgio Arena156fcf32018-03-09 15:30:43 +000069 TensorInfo(TensorShape(10U, 12U, 2U, 2U), 1, DataType::QASYMM8),
Georgios Pinitasd912fd82017-11-27 21:00:13 +000070 }),
71 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(3U, 4U, 10U, 2U), 1, DataType::F16),
72 TensorInfo(TensorShape(3U, 4U, 10U, 2U), 1, DataType::F16),
Georgios Pinitasd912fd82017-11-27 21:00:13 +000073 TensorInfo(TensorShape(3U, 3U, 10U, 2U), 1, DataType::QASYMM8),
74 TensorInfo(TensorShape(3U, 4U, 10U, 2U), 1, DataType::QASYMM8),
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000075 TensorInfo(TensorShape(18U, 80U, 1U, 2U), 1, DataType::QASYMM8),
Georgios Pinitasd912fd82017-11-27 21:00:13 +000076 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +010077 framework::dataset::make("HasBias", { true, true, true, false, false })),
78 framework::dataset::make("Expected", { false, false, false, false, true })),
Georgios Pinitasd912fd82017-11-27 21:00:13 +000079 input_info, output_info, has_bias, expected)
80{
Manuel Bottini90028992021-06-30 18:29:18 +010081 bool status = bool(cpu::kernels::CpuIm2ColKernel::validate(&input_info, &output_info, Size2D(3U, 3U), PadStrideInfo(), has_bias));
Georgios Pinitas358ca202017-12-07 16:47:52 +000082 ARM_COMPUTE_EXPECT(status == expected, framework::LogLevel::ERRORS);
Georgios Pinitasd912fd82017-11-27 21:00:13 +000083}
84// clang-format on
85// *INDENT-ON*
86
Giorgio Arena156fcf32018-03-09 15:30:43 +000087template <typename T>
Manuel Bottini90028992021-06-30 18:29:18 +010088using CpuIm2ColFixture = Im2ColOpValidationFixture<Tensor, Accessor, CpuIm2Col, T, false>;
Giorgio Arena156fcf32018-03-09 15:30:43 +000089
90TEST_SUITE(Float)
91TEST_SUITE(FP32)
Manuel Bottini90028992021-06-30 18:29:18 +010092FIXTURE_DATA_TEST_CASE(RunSmall, CpuIm2ColFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(im2col_shapes, framework::dataset::make("DataType", DataType::F32)),
93 conv_args_small))
Giorgio Arena156fcf32018-03-09 15:30:43 +000094{
95 // Validate output
96 validate(Accessor(_target), _reference);
97}
Manuel Bottini90028992021-06-30 18:29:18 +010098FIXTURE_DATA_TEST_CASE(RunLarge, CpuIm2ColFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(concat(im2col_shapes, datasets::LargeShapes()), framework::dataset::make("DataType",
99 DataType::F32)),
100 conv_args))
Pablo Tello4a626a72018-04-04 10:01:14 +0100101{
102 // Validate output
103 validate(Accessor(_target), _reference);
104}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000105TEST_SUITE_END() // FP32
Giorgio Arena156fcf32018-03-09 15:30:43 +0000106
107#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
108
109TEST_SUITE(FP16)
Manuel Bottini90028992021-06-30 18:29:18 +0100110FIXTURE_DATA_TEST_CASE(RunSmall, CpuIm2ColFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(im2col_shapes, framework::dataset::make("DataType", DataType::F16)),
111 conv_args_small))
Giorgio Arena156fcf32018-03-09 15:30:43 +0000112{
113 // Validate output
114 validate(Accessor(_target), _reference);
115}
Manuel Bottini90028992021-06-30 18:29:18 +0100116FIXTURE_DATA_TEST_CASE(RunLarge, CpuIm2ColFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(concat(im2col_shapes, datasets::LargeShapes()), framework::dataset::make("DataType",
117 DataType::F16)),
118 conv_args))
Pablo Tello4a626a72018-04-04 10:01:14 +0100119{
120 // Validate output
121 validate(Accessor(_target), _reference);
122}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000123TEST_SUITE_END() // FP16
Giorgio Arena156fcf32018-03-09 15:30:43 +0000124
125#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
126
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000127TEST_SUITE_END() // Float
Giorgio Arena156fcf32018-03-09 15:30:43 +0000128
129TEST_SUITE(QASYMM8)
Manuel Bottini90028992021-06-30 18:29:18 +0100130FIXTURE_DATA_TEST_CASE(RunSmall, CpuIm2ColFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(im2col_shapes, framework::dataset::make("DataType", DataType::QASYMM8)),
131 conv_args_small))
Giorgio Arena156fcf32018-03-09 15:30:43 +0000132{
133 // Validate output
134 validate(Accessor(_target), _reference);
135}
Manuel Bottini90028992021-06-30 18:29:18 +0100136FIXTURE_DATA_TEST_CASE(RunLarge, CpuIm2ColFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(concat(im2col_shapes, datasets::LargeShapes()),
137 framework::dataset::make("DataType", DataType::QASYMM8)),
138 conv_args))
Pablo Tello4a626a72018-04-04 10:01:14 +0100139{
140 // Validate output
141 validate(Accessor(_target), _reference);
142}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000143TEST_SUITE_END() // QASYMM8
Giorgio Arena156fcf32018-03-09 15:30:43 +0000144
Georgios Pinitas75bde5e2019-06-07 11:52:01 +0100145TEST_SUITE(SpecialCases)
146TEST_CASE(PaddedChannelNHWC, framework::DatasetMode::PRECOMMIT)
147{
148 // Const data
149 const TensorShape src_shape = TensorShape(7U, 27U, 13U);
150 const DataType data_type = DataType::F32;
151 const DataLayout data_layout = DataLayout::NHWC;
152 const bool has_bias = false;
153 const unsigned int num_groups = 1;
154 const Size2D spatial_kernel(3, 3);
155 const QuantizationInfo qinfo{};
156 const PadStrideInfo conv_info(1U, 1U, 0U, 0U);
157
158 // Calculate destination shape
159 TensorInfo src_info(src_shape, 1, data_type);
160 src_info.set_data_layout(data_layout);
161 const TensorShape dst_shape = compute_im2col_conv_shape(&src_info, spatial_kernel, conv_info, has_bias, Size2D(1U, 1U), false, num_groups);
162
163 // Compute target
164 Tensor src_target = create_tensor<Tensor>(src_shape, data_type, 1, qinfo, data_layout);
165 Tensor dst_target = create_tensor<Tensor>(dst_shape, data_type, 1, qinfo);
166
167 // Configure target function
Manuel Bottini90028992021-06-30 18:29:18 +0100168 CpuIm2Col im2col_func;
169 im2col_func.configure(src_target.info(), dst_target.info(), spatial_kernel, conv_info, has_bias);
Georgios Pinitas75bde5e2019-06-07 11:52:01 +0100170
171 // Extend padding
172 src_target.info()->extend_padding(PaddingSize(3, 5, 9, 1));
173 dst_target.info()->extend_padding(PaddingSize(8, 1, 1, 3));
174
175 // Validate and allocate tensors
176 ARM_COMPUTE_EXPECT(src_target.info()->is_resizable(), framework::LogLevel::ERRORS);
177 ARM_COMPUTE_EXPECT(dst_target.info()->is_resizable(), framework::LogLevel::ERRORS);
178
179 src_target.allocator()->allocate();
180 dst_target.allocator()->allocate();
181
182 ARM_COMPUTE_EXPECT(!src_target.info()->is_resizable(), framework::LogLevel::ERRORS);
183 ARM_COMPUTE_EXPECT(!dst_target.info()->is_resizable(), framework::LogLevel::ERRORS);
184
185 // Fill target source
186 library->fill_tensor_uniform(Accessor(src_target), 0);
187
Manuel Bottini90028992021-06-30 18:29:18 +0100188 ITensorPack pack =
189 {
190 { TensorType::ACL_SRC, &src_target },
191 { TensorType::ACL_DST, &dst_target }
192 };
Georgios Pinitas75bde5e2019-06-07 11:52:01 +0100193 // Run target function
Manuel Bottini90028992021-06-30 18:29:18 +0100194 im2col_func.run(pack);
Georgios Pinitas75bde5e2019-06-07 11:52:01 +0100195
196 // Calculate Reference
197 SimpleTensor<float> src_ref{ src_shape, data_type, 1, qinfo, data_layout };
198 SimpleTensor<float> dst_ref{ dst_shape, data_type, 1, qinfo, DataLayout::NCHW };
199
200 // Fill reference source
201 library->fill_tensor_uniform(src_ref, 0);
202
203#ifndef DOXYGEN_SKIP_THIS
204 // Run reference function
205 reference::im2col(src_ref, dst_ref, spatial_kernel, conv_info, has_bias, num_groups);
206#endif // DOXYGEN_SKIP_THIS
207
208 // Validate
209 validate(Accessor(dst_target), dst_ref);
210}
211TEST_SUITE_END() // Special Cases
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000212TEST_SUITE_END() // Im2Col
Sheri Zhangac6499a2021-02-10 15:32:38 +0000213TEST_SUITE_END() // Neon
Georgios Pinitasd912fd82017-11-27 21:00:13 +0000214} // namespace validation
215} // namespace test
216} // namespace arm_compute