blob: 0e5024f6d3c69053f290ab84b241ab892cf3d432 [file] [log] [blame]
Giorgio Arena44f55722019-07-12 14:49:49 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019 Arm Limited.
Giorgio Arena44f55722019-07-12 14:49:49 +01003 *
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 */
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010024#include "arm_compute/core/NEON/kernels/NEDepthwiseConvolutionLayerNativeKernel.h"
Giorgio Arena44f55722019-07-12 14:49:49 +010025#include "tests/NEON/Accessor.h"
26#include "tests/NEON/Helper.h"
27#include "tests/framework/Macros.h"
28#include "tests/framework/datasets/Datasets.h"
29#include "tests/validation/Validation.h"
30#include "tests/validation/fixtures/DepthwiseConvolutionLayerFixture.h"
31
32namespace arm_compute
33{
34namespace test
35{
36namespace validation
37{
38using namespace arm_compute::misc::shape_calculator;
39
40// Create function for NEDepthwiseConvolutionLayerKernel
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010041using NEDepthwiseConvolutionLayerNative = NESynthetizeFunctionWithZeroConstantKernelBorder<NEDepthwiseConvolutionLayerNativeKernel>;
Giorgio Arena44f55722019-07-12 14:49:49 +010042
43// Fixture for NEDepthwiseConvolutionLayerKernel
44template <typename T>
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010045using NEDepthwiseConvolutionLayerNativeFixture = DepthwiseConvolutionLayerNativeValidationFixture<Tensor, Accessor, NEDepthwiseConvolutionLayerNative, T>;
Giorgio Arena44f55722019-07-12 14:49:49 +010046
47namespace
48{
49// *INDENT-OFF*
50// clang-format off
51RelativeTolerance<float> rel_tolerance_f32(0.001f);
52constexpr float abs_tolerance_f32(0.0001f);
53
54/** Width values to test - Precommit */
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010055const auto width_values_precommit = framework::dataset::make("width", { 17U } );
56
57/** Width values to test - Nightly */
58const auto width_values_nightly = framework::dataset::make("width", { 53U, 47U } );
Giorgio Arena44f55722019-07-12 14:49:49 +010059
60/** Height values to test - Precommit */
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010061const auto height_values_precommit = framework::dataset::make("height", { 19U } );
62
63/** Height values to test - Nightly */
64const auto height_values_nightly = framework::dataset::make("height", { 39U, 43U } );
Giorgio Arena44f55722019-07-12 14:49:49 +010065
66/** Channel values to test - Precommit */
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010067const auto channel_values_precommit = framework::dataset::make("channels", { 15U });
68
69/** Channel values to test - Nightly */
70const auto channel_values_nightly = framework::dataset::make("channels", { 33U, 19U });
Giorgio Arena44f55722019-07-12 14:49:49 +010071
72/** Batch values to test - Precommit */
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010073const auto batch_values_precommit = framework::dataset::make("batch", { 1U, 2U });
Giorgio Arena44f55722019-07-12 14:49:49 +010074
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010075/** Batch values to test - Nightly */
76const auto batch_values_nightly = framework::dataset::make("batch", { 1U, 3U });
77
Giorgio Arena17203582019-08-02 16:00:41 +010078/** Kernel size values to test - Precommit */
79const auto kernel_sz_values_precommit = framework::dataset::make("kernel_size", { Size2D(1U, 1U), Size2D(1U, 3U) });
80
81/** Kernel size values to test - Nightly */
82const auto kernel_sz_values_nightly = framework::dataset::make("kernel_size", { Size2D(3U, 5U), Size2D(5U, 1U), Size2D(1U, 7U), Size2D(9U, 7U) });
Giorgio Arena44f55722019-07-12 14:49:49 +010083
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010084/** Depth multiplier values to test - All */
Giorgio Arena44f55722019-07-12 14:49:49 +010085const auto depth_multiplier_values = framework::dataset::make("depth_multiplier", { 1U, 3U });
86
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +010087/** Dilation values to test - All */
Giorgio Arena44f55722019-07-12 14:49:49 +010088const auto dilation_values = framework::dataset::make("dilation", { Size2D(1U, 1U), Size2D(3U, 3U) });
89
90/** Stride values to test - All */
91const auto stride_values = framework::dataset::make("stride", { Size2D(1U, 1U), Size2D(3U, 2U) });
92
93/** Padding values to test - All */
94const auto padding_valid_values = framework::dataset::make("padding_valid", { true, false });
95
96/** Data type values to test - All */
97const auto data_type_values = framework::dataset::make("data_type", { DataType::F32 });
98
99/** Data layout values to test - All */
100const auto data_layout_values = framework::dataset::make("data_layout", { DataLayout::NHWC });
101
102/** Configuration test */
103void validate_configuration(size_t width_value, size_t height_value, size_t channel_value, size_t batch_value, Size2D kernel_sz_value, size_t depth_multiplier_value, Size2D dilation_value, Size2D stride_value, bool padding_valid_value, DataType data_type_value, DataLayout data_layout_value)
104{
105 TensorShape src_shape(width_value, height_value, channel_value, batch_value);
106 TensorShape weights_shape(kernel_sz_value.width, kernel_sz_value.height, channel_value * depth_multiplier_value);
107 TensorShape biases_shape(channel_value * depth_multiplier_value);
108
109 if(data_layout_value == DataLayout::NHWC)
110 {
111 permute(src_shape, PermutationVector(2U, 0U, 1U, 3U));
112 permute(weights_shape, PermutationVector(2U, 0U, 1U));
113 }
114
115 TensorInfo src_info(src_shape, 1, data_type_value);
116 TensorInfo weights_info(weights_shape, 1, data_type_value);
117 TensorInfo biases_info(biases_shape, 1, data_type_value);
118
119 src_info.set_data_layout(data_layout_value);
120 weights_info.set_data_layout(data_layout_value);
121 biases_info.set_data_layout(data_layout_value);
122
123 PadStrideInfo conv_info;
124 if(padding_valid_value)
125 {
126 conv_info = PadStrideInfo();
127 }
128 else
129 {
130 conv_info = calculate_same_pad(src_shape, weights_shape, PadStrideInfo(stride_value.width, stride_value.height), data_layout_value, dilation_value);
131 }
132
133 const TensorShape dst_shape = compute_depthwise_convolution_shape(src_info, weights_info, conv_info, depth_multiplier_value, dilation_value);
134
135 // Create tensors
136 Tensor src = create_tensor<Tensor>(src_shape, data_type_value, 1, QuantizationInfo(), data_layout_value);
137 Tensor weights = create_tensor<Tensor>(weights_shape, data_type_value, 1, QuantizationInfo(), data_layout_value);
138 Tensor biases = create_tensor<Tensor>(biases_shape, data_type_value, 1, QuantizationInfo(), data_layout_value);
139 Tensor dst = create_tensor<Tensor>(dst_shape, data_type_value, 1, QuantizationInfo(), data_layout_value);
140
141 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
142 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
143 ARM_COMPUTE_EXPECT(biases.info()->is_resizable(), framework::LogLevel::ERRORS);
144 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
145
146 // Create and configure function
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +0100147 NEDepthwiseConvolutionLayerNative dwc;
Giorgio Arena44f55722019-07-12 14:49:49 +0100148 dwc.configure(&src, &weights, &biases, &dst, conv_info, depth_multiplier_value, dilation_value);
149}
150} // namespace
151
152TEST_SUITE(NEON)
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +0100153TEST_SUITE(DepthwiseConvolutionLayerNative)
Giorgio Arena44f55722019-07-12 14:49:49 +0100154TEST_SUITE(Float)
155TEST_SUITE(FP32)
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +0100156DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(width_values_precommit,
157 height_values_precommit),
158 channel_values_precommit),
159 batch_values_precommit),
Giorgio Arena17203582019-08-02 16:00:41 +0100160 kernel_sz_values_precommit),
Giorgio Arena44f55722019-07-12 14:49:49 +0100161 depth_multiplier_values),
162 dilation_values),
163 stride_values),
164 padding_valid_values),
165 data_type_values),
166 data_layout_values),
167width_value, height_value, channel_value, batch_value, kernel_sz_value, depth_multiplier_value, dilation_value, stride_value, padding_valid_value, data_type_value, data_layout_value)
168{
169 validate_configuration(width_value, height_value, channel_value, batch_value, kernel_sz_value, depth_multiplier_value, dilation_value, stride_value, padding_valid_value, data_type_value, data_layout_value);
170}
171
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +0100172FIXTURE_DATA_TEST_CASE(RunSmall, NEDepthwiseConvolutionLayerNativeFixture<float>, framework::DatasetMode::ALL,
173 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(width_values_precommit,
174 height_values_precommit),
175 channel_values_precommit),
176 batch_values_precommit),
Giorgio Arena17203582019-08-02 16:00:41 +0100177 kernel_sz_values_precommit),
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +0100178 depth_multiplier_values),
179 dilation_values),
180 stride_values),
181 padding_valid_values),
182 data_type_values),
183 data_layout_values))
184{
185 // Validate output
186 validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
187}
188
189FIXTURE_DATA_TEST_CASE(RunLarge, NEDepthwiseConvolutionLayerNativeFixture<float>, framework::DatasetMode::NIGHTLY,
190 combine(combine(combine(combine(combine(combine(combine(combine(combine(combine(width_values_nightly,
191 height_values_nightly),
192 channel_values_nightly),
193 batch_values_nightly),
Giorgio Arena17203582019-08-02 16:00:41 +0100194 kernel_sz_values_nightly),
Giorgio Arena44f55722019-07-12 14:49:49 +0100195 depth_multiplier_values),
196 dilation_values),
197 stride_values),
198 padding_valid_values),
199 data_type_values),
200 data_layout_values))
201{
202 // Validate output
203 validate(Accessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
204}
205
206TEST_SUITE_END() // FP32
207TEST_SUITE_END() // Float
Gian Marco Iodicebd9097d2019-07-26 15:31:02 +0100208TEST_SUITE_END() // DepthwiseConvolutionLayerNative
Giorgio Arena44f55722019-07-12 14:49:49 +0100209TEST_SUITE_END() // NEON
210} // namespace validation
211} // namespace test
212} // namespace arm_compute