blob: 0fd7ed4ddc84976c7de468a89a56d9e0510454af [file] [log] [blame]
Anthony Barbierf45d5a92018-01-24 16:23:15 +00001/*
Anthony Barbier06ea0482018-02-22 15:45:35 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbierf45d5a92018-01-24 16:23:15 +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/CL/kernels/CLFillBorderKernel.h"
25#include "arm_compute/core/Types.h"
26#include "arm_compute/runtime/CL/CLTensor.h"
27#include "arm_compute/runtime/CL/CLTensorAllocator.h"
28#include "arm_compute/runtime/CL/functions/CLDeconvolutionLayer.h"
29#include "tests/CL/CLAccessor.h"
30#include "tests/PaddingCalculator.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/DeconvolutionLayerFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
Jenkins52ba29e2018-08-29 15:32:11 +000046constexpr AbsoluteTolerance<float> tolerance_fp32(0.001f); /**< Tolerance for floating point tests */
47RelativeTolerance<half_float::half> tolerance_f16(half_float::half(0.2)); /**< Tolerance value for comparing reference's for DataType::F16 */
48constexpr float tolerance_num = 0.07f; /**< Tolerance number */
Anthony Barbierf45d5a92018-01-24 16:23:15 +000049
Anthony Barbier06ea0482018-02-22 15:45:35 +000050const auto data4x4 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 3)
51 * framework::dataset::make("PadY", 0, 3) * framework::dataset::make("ax", 0) * framework::dataset::make("ay", 0) * framework::dataset::make("NumKernels", { 1, 3 });
52
Anthony Barbierf45d5a92018-01-24 16:23:15 +000053const auto data3x3 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 2)
54 * framework::dataset::make("PadY", 0, 2) * framework::dataset::make("ax", 0) * framework::dataset::make("ay", 0) * framework::dataset::make("NumKernels", { 1, 3 });
55
56const auto data1x1 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 1)
57 * framework::dataset::make("PadY", 0, 1) * framework::dataset::make("ax", 0) * framework::dataset::make("ay", 0) * framework::dataset::make("NumKernels", { 1, 3 });
58
59} // namespace
60
61TEST_SUITE(CL)
62TEST_SUITE(DeconvolutionLayer)
63
64DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, (combine(datasets::SmallDeconvolutionShapes(), framework::dataset::make("DataType", DataType::F32))),
65 input_shape, data_type)
66{
67 // Create shapes
68 const unsigned int kernel_size_x = 3;
69 const unsigned int kernel_size_y = 3;
70 const unsigned int num_kernels = 1;
71 const TensorShape weights_shape(kernel_size_x, kernel_size_y, input_shape.z(), num_kernels);
72 const TensorShape bias_shape(num_kernels);
73 auto out_dim = deconvolution_output_dimensions(input_shape.x(), input_shape.y(), kernel_size_x, kernel_size_y, 1, 1, 0, 0, 1, 1);
74 TensorShape output_shape = deconvolution_output_shape(out_dim, input_shape, weights_shape);
75
76 // Create tensors
77 CLTensor src = create_tensor<CLTensor>(input_shape, data_type, 1);
78 CLTensor weights = create_tensor<CLTensor>(weights_shape, data_type, 1);
79 CLTensor bias = create_tensor<CLTensor>(bias_shape, data_type, 1);
80 CLTensor dst = create_tensor<CLTensor>(output_shape, data_type, 1);
81
82 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
83 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
84 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
85 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
86
87 // Create and configure function
88 CLDeconvolutionLayer deconv;
89 deconv.configure(&src, &weights, &bias, &dst, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), 0, 0);
90
91 // Validate valid region
92 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
93 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
94 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
95 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
96
97 validate(src.info()->valid_region(), src_valid_region);
98 validate(weights.info()->valid_region(), weights_valid_region);
99 validate(bias.info()->valid_region(), bias_valid_region);
100 validate(dst.info()->valid_region(), dst_valid_region);
101}
102
103// *INDENT-OFF*
104// clang-format off
105DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip(
Jenkins52ba29e2018-08-29 15:32:11 +0000106 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Mismatching data type
107 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid weights shape
108 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QASYMM8), // Non supported data type
109 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32), // Invalid bias shape
110 TensorInfo(TensorShape(13U, 11U, 4U, 3U), 1, DataType::F32), // Window shrink
111 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32),
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000112 }),
Jenkins52ba29e2018-08-29 15:32:11 +0000113 framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F16),
114 TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32),
115 TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::QASYMM8),
116 TensorInfo(TensorShape(3U, 2U, 2U, 2U), 1, DataType::F32),
117 TensorInfo(TensorShape(3U, 3U, 4U), 1, DataType::F32),
118 TensorInfo(TensorShape(1U, 1U, 2U, 4U), 1, DataType::F32),
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000119 })),
Jenkins52ba29e2018-08-29 15:32:11 +0000120 framework::dataset::make("BiasInfo", { TensorInfo(TensorShape(1U), 1, DataType::F16),
121 TensorInfo(TensorShape(1U), 1, DataType::F32),
122 TensorInfo(TensorShape(1U), 1, DataType::F32),
123 TensorInfo(TensorShape(25U, 11U), 1, DataType::F32),
124 TensorInfo(TensorShape(1U), 1, DataType::F32),
125 TensorInfo(TensorShape(4U), 1, DataType::F32),
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000126 })),
Jenkins52ba29e2018-08-29 15:32:11 +0000127 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16),
128 TensorInfo(TensorShape(25U, 10U, 2U), 1, DataType::F32),
129 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32),
130 TensorInfo(TensorShape(13U, 13U, 2U), 1, DataType::F32),
131 TensorInfo(TensorShape(11U, 9U, 1U, 3U), 1, DataType::F32),
132 TensorInfo(TensorShape(32U, 16U, 4U), 1, DataType::F32),
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000133 })),
134 framework::dataset::make("PadStrideInfo", { PadStrideInfo(1, 1, 0, 0),
135 PadStrideInfo(1, 1, 0, 0),
136 PadStrideInfo(1, 1, 0, 0),
137 PadStrideInfo(1, 1, 0, 0),
138 PadStrideInfo(1, 1, 1, 1),
139 PadStrideInfo(1, 1, 0, 0),
140 })),
141 framework::dataset::make("ax", { 1U,
142 1U,
143 1U,
144 1U,
145 0U,
146 0U,
147 })),
148 framework::dataset::make("ay", { 1U,
149 1U,
150 1U,
151 1U,
152 0U,
153 0U,
154 })),
155 framework::dataset::make("Expected", { false, false, false, false, false, true })),
156 input_info, weights_info, bias_info, output_info, pad_info, ax, ay, expected)
157{
158 bool is_valid = bool(CLDeconvolutionLayer::validate(&input_info.clone()->set_is_resizable(false), &weights_info.clone()->set_is_resizable(false), &bias_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), pad_info, ax, ay));
159 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
160}
161// clang-format on
162// *INDENT-ON*
163
164template <typename T>
Anthony Barbier06ea0482018-02-22 15:45:35 +0000165using CLDeconvolutionLayerFixture4x4 = DeconvolutionValidationFixture<CLTensor, CLAccessor, CLDeconvolutionLayer, T, 4, 4>;
166
167template <typename T>
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000168using CLDeconvolutionLayerFixture3x3 = DeconvolutionValidationFixture<CLTensor, CLAccessor, CLDeconvolutionLayer, T, 3, 3>;
169
170template <typename T>
171using CLDeconvolutionLayerFixture1x1 = DeconvolutionValidationFixture<CLTensor, CLAccessor, CLDeconvolutionLayer, T, 1, 1>;
172
173TEST_SUITE(Float)
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000174TEST_SUITE(FP32)
Anthony Barbier06ea0482018-02-22 15:45:35 +0000175
Jenkins52ba29e2018-08-29 15:32:11 +0000176TEST_SUITE(W4x4)
Anthony Barbier06ea0482018-02-22 15:45:35 +0000177FIXTURE_DATA_TEST_CASE(Run, CLDeconvolutionLayerFixture4x4<float>, framework::DatasetMode::ALL, combine(data4x4, framework::dataset::make("DataType", DataType::F32)))
178{
179 // Validate output
180 validate(CLAccessor(_target), _reference, tolerance_fp32);
181}
182TEST_SUITE_END()
183
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000184TEST_SUITE(W3x3)
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000185FIXTURE_DATA_TEST_CASE(Run, CLDeconvolutionLayerFixture3x3<float>, framework::DatasetMode::ALL, combine(data3x3, framework::dataset::make("DataType", DataType::F32)))
186{
187 // Validate output
188 validate(CLAccessor(_target), _reference, tolerance_fp32);
189}
190TEST_SUITE_END()
191
192TEST_SUITE(W1x1)
193FIXTURE_DATA_TEST_CASE(Run, CLDeconvolutionLayerFixture1x1<float>, framework::DatasetMode::ALL, combine(data1x1, framework::dataset::make("DataType", DataType::F32)))
194{
195 // Validate output
196 validate(CLAccessor(_target), _reference, tolerance_fp32);
197}
198TEST_SUITE_END()
199
200TEST_SUITE_END()
Jenkins52ba29e2018-08-29 15:32:11 +0000201
202TEST_SUITE(FP16)
203
204TEST_SUITE(W4x4)
205FIXTURE_DATA_TEST_CASE(Run, CLDeconvolutionLayerFixture4x4<half>, framework::DatasetMode::ALL, combine(data4x4, framework::dataset::make("DataType", DataType::F16)))
206{
207 // Validate output
208 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
209}
210TEST_SUITE_END()
211
212TEST_SUITE(W3x3)
213FIXTURE_DATA_TEST_CASE(Run, CLDeconvolutionLayerFixture3x3<half>, framework::DatasetMode::ALL, combine(data3x3, framework::dataset::make("DataType", DataType::F16)))
214{
215 // Validate output
216 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
217}
218TEST_SUITE_END()
219
220TEST_SUITE(W1x1)
221FIXTURE_DATA_TEST_CASE(Run, CLDeconvolutionLayerFixture1x1<half>, framework::DatasetMode::ALL, combine(data1x1, framework::dataset::make("DataType", DataType::F16)))
222{
223 // Validate output
224 validate(CLAccessor(_target), _reference, tolerance_f16, tolerance_num);
225}
226TEST_SUITE_END()
227
228TEST_SUITE_END()
Anthony Barbierf45d5a92018-01-24 16:23:15 +0000229TEST_SUITE_END()
230
231TEST_SUITE_END()
232TEST_SUITE_END()
233} // namespace validation
234} // namespace test
235} // namespace arm_compute