blob: f4b2cc78359641637ec612aa54fd5974357ee39c [file] [log] [blame]
Georgios Pinitasd912fd82017-11-27 21:00:13 +00001/*
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +00002 * Copyright (c) 2017-2019 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"
25#include "arm_compute/runtime/NEON/functions/NEIm2Col.h"
Giorgio Arena156fcf32018-03-09 15:30:43 +000026#include "tests/NEON/Accessor.h"
27#include "tests/datasets/ShapeDatasets.h"
Georgios Pinitasd912fd82017-11-27 21:00:13 +000028#include "tests/framework/Asserts.h"
29#include "tests/framework/Macros.h"
30#include "tests/framework/datasets/Datasets.h"
31#include "tests/validation/Validation.h"
Giorgio Arena156fcf32018-03-09 15:30:43 +000032#include "tests/validation/fixtures/Im2ColFixture.h"
Georgios Pinitasd912fd82017-11-27 21:00:13 +000033
34namespace arm_compute
35{
36namespace test
37{
38namespace validation
39{
Giorgio Arena156fcf32018-03-09 15:30:43 +000040namespace
41{
Pablo Tello4a626a72018-04-04 10:01:14 +010042const 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 +010043const 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) })),
44 framework::dataset::make("QuantizationInfo", QuantizationInfo(0.5f, 10))),
45 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
46 framework::dataset::make("NumGroups", { 1 }));
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000047
48const auto conv_filter_sizes_small = framework::dataset::make("KernelDims", { Size2D(3U, 3U), Size2D(3U, 1U), Size2D(1U, 5U) });
49const 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) })),
50 framework::dataset::make("QuantizationInfo", QuantizationInfo(0.5f, 10))),
51 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
52 framework::dataset::make("NumGroups", { 1 }));
Giorgio Arena156fcf32018-03-09 15:30:43 +000053} // namespace
Georgios Pinitasd912fd82017-11-27 21:00:13 +000054TEST_SUITE(NEON)
55TEST_SUITE(Im2Col)
56
57// *INDENT-OFF*
58// clang-format off
59DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(
60 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(10U, 12U, 2U), 1, DataType::U8), // Unsupported data type
61 TensorInfo(TensorShape(10U, 12U, 2U), 1, DataType::F32), // Mismatching data type
Georgios Pinitasd912fd82017-11-27 21:00:13 +000062 TensorInfo(TensorShape(10U, 12U, 2U), 1, DataType::QASYMM8), // Bias not supported with QASYMM8
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000063 TensorInfo(TensorShape(10U, 12U, 2U), 1, DataType::QASYMM8), // Mismatching shapes
Giorgio Arena156fcf32018-03-09 15:30:43 +000064 TensorInfo(TensorShape(10U, 12U, 2U, 2U), 1, DataType::QASYMM8),
Georgios Pinitasd912fd82017-11-27 21:00:13 +000065 }),
66 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(3U, 4U, 10U, 2U), 1, DataType::F16),
67 TensorInfo(TensorShape(3U, 4U, 10U, 2U), 1, DataType::F16),
Georgios Pinitasd912fd82017-11-27 21:00:13 +000068 TensorInfo(TensorShape(3U, 3U, 10U, 2U), 1, DataType::QASYMM8),
69 TensorInfo(TensorShape(3U, 4U, 10U, 2U), 1, DataType::QASYMM8),
Ioan-Cristian Szabob4e3e1c2017-11-30 17:17:17 +000070 TensorInfo(TensorShape(18U, 80U, 1U, 2U), 1, DataType::QASYMM8),
Georgios Pinitasd912fd82017-11-27 21:00:13 +000071 })),
Vidhya Sudhan Loganathan0fc25452018-06-18 14:40:56 +010072 framework::dataset::make("HasBias", { true, true, true, false, false })),
73 framework::dataset::make("Expected", { false, false, false, false, true })),
Georgios Pinitasd912fd82017-11-27 21:00:13 +000074 input_info, output_info, has_bias, expected)
75{
Giorgio Arena0f170392018-07-18 16:13:12 +010076 bool status = bool(NEIm2Col::validate(&input_info, &output_info, Size2D(3U, 3U), PadStrideInfo(), has_bias));
Georgios Pinitas358ca202017-12-07 16:47:52 +000077 ARM_COMPUTE_EXPECT(status == expected, framework::LogLevel::ERRORS);
Georgios Pinitasd912fd82017-11-27 21:00:13 +000078}
79// clang-format on
80// *INDENT-ON*
81
Giorgio Arena156fcf32018-03-09 15:30:43 +000082template <typename T>
Gian Marco Iodice597a8562018-08-01 15:06:06 +010083using NEIm2ColFixture = Im2ColValidationFixture<Tensor, Accessor, NEIm2Col, T, false>;
Giorgio Arena156fcf32018-03-09 15:30:43 +000084
85TEST_SUITE(Float)
86TEST_SUITE(FP32)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000087FIXTURE_DATA_TEST_CASE(RunSmall, NEIm2ColFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F32)),
88 conv_args_small))
Giorgio Arena156fcf32018-03-09 15:30:43 +000089{
90 // Validate output
91 validate(Accessor(_target), _reference);
92}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +000093FIXTURE_DATA_TEST_CASE(RunLarge, NEIm2ColFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType",
94 DataType::F32)),
Giorgio Arenafb629082018-08-20 18:03:27 +010095 conv_args))
Pablo Tello4a626a72018-04-04 10:01:14 +010096{
97 // Validate output
98 validate(Accessor(_target), _reference);
99}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000100TEST_SUITE_END() // FP32
Giorgio Arena156fcf32018-03-09 15:30:43 +0000101
102#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
103
104TEST_SUITE(FP16)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000105FIXTURE_DATA_TEST_CASE(RunSmall, NEIm2ColFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::F16)),
106 conv_args_small))
Giorgio Arena156fcf32018-03-09 15:30:43 +0000107{
108 // Validate output
109 validate(Accessor(_target), _reference);
110}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000111FIXTURE_DATA_TEST_CASE(RunLarge, NEIm2ColFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()), framework::dataset::make("DataType",
112 DataType::F16)),
Giorgio Arenafb629082018-08-20 18:03:27 +0100113 conv_args))
Pablo Tello4a626a72018-04-04 10:01:14 +0100114{
115 // Validate output
116 validate(Accessor(_target), _reference);
117}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000118TEST_SUITE_END() // FP16
Giorgio Arena156fcf32018-03-09 15:30:43 +0000119
120#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
121
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000122TEST_SUITE_END() // Float
Giorgio Arena156fcf32018-03-09 15:30:43 +0000123
124TEST_SUITE(QASYMM8)
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000125FIXTURE_DATA_TEST_CASE(RunSmall, NEIm2ColFixture<uint8_t>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallShapes(), framework::dataset::make("DataType", DataType::QASYMM8)),
126 conv_args_small))
Giorgio Arena156fcf32018-03-09 15:30:43 +0000127{
128 // Validate output
129 validate(Accessor(_target), _reference);
130}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000131FIXTURE_DATA_TEST_CASE(RunLarge, NEIm2ColFixture<uint8_t>, framework::DatasetMode::NIGHTLY, combine(combine(concat(datasets::SmallShapes(), datasets::LargeShapes()),
132 framework::dataset::make("DataType", DataType::QASYMM8)),
Giorgio Arenafb629082018-08-20 18:03:27 +0100133 conv_args))
Pablo Tello4a626a72018-04-04 10:01:14 +0100134{
135 // Validate output
136 validate(Accessor(_target), _reference);
137}
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000138TEST_SUITE_END() // QASYMM8
Giorgio Arena156fcf32018-03-09 15:30:43 +0000139
Georgios Pinitas75bde5e2019-06-07 11:52:01 +0100140TEST_SUITE(SpecialCases)
141TEST_CASE(PaddedChannelNHWC, framework::DatasetMode::PRECOMMIT)
142{
143 // Const data
144 const TensorShape src_shape = TensorShape(7U, 27U, 13U);
145 const DataType data_type = DataType::F32;
146 const DataLayout data_layout = DataLayout::NHWC;
147 const bool has_bias = false;
148 const unsigned int num_groups = 1;
149 const Size2D spatial_kernel(3, 3);
150 const QuantizationInfo qinfo{};
151 const PadStrideInfo conv_info(1U, 1U, 0U, 0U);
152
153 // Calculate destination shape
154 TensorInfo src_info(src_shape, 1, data_type);
155 src_info.set_data_layout(data_layout);
156 const TensorShape dst_shape = compute_im2col_conv_shape(&src_info, spatial_kernel, conv_info, has_bias, Size2D(1U, 1U), false, num_groups);
157
158 // Compute target
159 Tensor src_target = create_tensor<Tensor>(src_shape, data_type, 1, qinfo, data_layout);
160 Tensor dst_target = create_tensor<Tensor>(dst_shape, data_type, 1, qinfo);
161
162 // Configure target function
163 NEIm2Col im2col_func;
164 im2col_func.configure(&src_target, &dst_target, spatial_kernel, conv_info, has_bias);
165
166 // Extend padding
167 src_target.info()->extend_padding(PaddingSize(3, 5, 9, 1));
168 dst_target.info()->extend_padding(PaddingSize(8, 1, 1, 3));
169
170 // Validate and allocate tensors
171 ARM_COMPUTE_EXPECT(src_target.info()->is_resizable(), framework::LogLevel::ERRORS);
172 ARM_COMPUTE_EXPECT(dst_target.info()->is_resizable(), framework::LogLevel::ERRORS);
173
174 src_target.allocator()->allocate();
175 dst_target.allocator()->allocate();
176
177 ARM_COMPUTE_EXPECT(!src_target.info()->is_resizable(), framework::LogLevel::ERRORS);
178 ARM_COMPUTE_EXPECT(!dst_target.info()->is_resizable(), framework::LogLevel::ERRORS);
179
180 // Fill target source
181 library->fill_tensor_uniform(Accessor(src_target), 0);
182
183 // Run target function
184 im2col_func.run();
185
186 // Calculate Reference
187 SimpleTensor<float> src_ref{ src_shape, data_type, 1, qinfo, data_layout };
188 SimpleTensor<float> dst_ref{ dst_shape, data_type, 1, qinfo, DataLayout::NCHW };
189
190 // Fill reference source
191 library->fill_tensor_uniform(src_ref, 0);
192
193#ifndef DOXYGEN_SKIP_THIS
194 // Run reference function
195 reference::im2col(src_ref, dst_ref, spatial_kernel, conv_info, has_bias, num_groups);
196#endif // DOXYGEN_SKIP_THIS
197
198 // Validate
199 validate(Accessor(dst_target), dst_ref);
200}
201TEST_SUITE_END() // Special Cases
Michalis Spyrouaeebe4a2019-01-09 14:21:03 +0000202TEST_SUITE_END() // Im2Col
203TEST_SUITE_END() // NEON
Georgios Pinitasd912fd82017-11-27 21:00:13 +0000204} // namespace validation
205} // namespace test
206} // namespace arm_compute