blob: 59e85537e51ad702b1603f8b7b9eb51ead7a92e3 [file] [log] [blame]
Anthony Barbierf45d5a92018-01-24 16:23:15 +00001/*
2 * Copyright (c) 2017, 2018 ARM Limited.
3 *
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{
46constexpr AbsoluteTolerance<float> tolerance_fp32(0.001f); /**< Tolerance for floating point tests */
47
48const auto data3x3 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 2)
49 * framework::dataset::make("PadY", 0, 2) * framework::dataset::make("ax", 0) * framework::dataset::make("ay", 0) * framework::dataset::make("NumKernels", { 1, 3 });
50
51const auto data1x1 = datasets::SmallDeconvolutionShapes() * framework::dataset::make("StrideX", 1, 4) * framework::dataset::make("StrideY", 1, 4) * framework::dataset::make("PadX", 0, 1)
52 * framework::dataset::make("PadY", 0, 1) * framework::dataset::make("ax", 0) * framework::dataset::make("ay", 0) * framework::dataset::make("NumKernels", { 1, 3 });
53
54} // namespace
55
56TEST_SUITE(CL)
57TEST_SUITE(DeconvolutionLayer)
58
59DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, (combine(datasets::SmallDeconvolutionShapes(), framework::dataset::make("DataType", DataType::F32))),
60 input_shape, data_type)
61{
62 // Create shapes
63 const unsigned int kernel_size_x = 3;
64 const unsigned int kernel_size_y = 3;
65 const unsigned int num_kernels = 1;
66 const TensorShape weights_shape(kernel_size_x, kernel_size_y, input_shape.z(), num_kernels);
67 const TensorShape bias_shape(num_kernels);
68 auto out_dim = deconvolution_output_dimensions(input_shape.x(), input_shape.y(), kernel_size_x, kernel_size_y, 1, 1, 0, 0, 1, 1);
69 TensorShape output_shape = deconvolution_output_shape(out_dim, input_shape, weights_shape);
70
71 // Create tensors
72 CLTensor src = create_tensor<CLTensor>(input_shape, data_type, 1);
73 CLTensor weights = create_tensor<CLTensor>(weights_shape, data_type, 1);
74 CLTensor bias = create_tensor<CLTensor>(bias_shape, data_type, 1);
75 CLTensor dst = create_tensor<CLTensor>(output_shape, data_type, 1);
76
77 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
78 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
79 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
80 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
81
82 // Create and configure function
83 CLDeconvolutionLayer deconv;
84 deconv.configure(&src, &weights, &bias, &dst, PadStrideInfo(1, 1, 1, 1, DimensionRoundingType::CEIL), 0, 0);
85
86 // Validate valid region
87 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
88 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
89 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
90 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
91
92 validate(src.info()->valid_region(), src_valid_region);
93 validate(weights.info()->valid_region(), weights_valid_region);
94 validate(bias.info()->valid_region(), bias_valid_region);
95 validate(dst.info()->valid_region(), dst_valid_region);
96}
97
98// *INDENT-OFF*
99// clang-format off
100DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip(
101 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Mismatching data type
102 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Invalid weights shape
103 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::QS8, 4), // Non supported data type
104 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 11), // Invalid bias shape
105 TensorInfo(TensorShape(13U, 11U, 4U, 3U), 1, DataType::F32, 0), // Window shrink
106 TensorInfo(TensorShape(32U, 16U, 2U), 1, DataType::F32, 0),
107 }),
108 framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::F16, 0),
109 TensorInfo(TensorShape(3U, 3U, 2U, 4U), 1, DataType::F32, 0),
110 TensorInfo(TensorShape(3U, 3U, 2U, 2U), 1, DataType::QS8, 5),
111 TensorInfo(TensorShape(3U, 2U, 2U, 2U), 1, DataType::F32, 11),
112 TensorInfo(TensorShape(3U, 3U, 4U), 1, DataType::F32, 0),
113 TensorInfo(TensorShape(1U, 1U, 2U, 4U), 1, DataType::F32, 0),
114 })),
115 framework::dataset::make("BiasInfo", { TensorInfo(TensorShape(1U), 1, DataType::F16, 0),
116 TensorInfo(TensorShape(1U), 1, DataType::F32, 0),
117 TensorInfo(TensorShape(1U), 1, DataType::F32, 5),
118 TensorInfo(TensorShape(25U, 11U), 1, DataType::F32, 11),
119 TensorInfo(TensorShape(1U), 1, DataType::F32, 0),
120 TensorInfo(TensorShape(4U), 1, DataType::F32, 0),
121 })),
122 framework::dataset::make("OutputInfo",{ TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F16, 0),
123 TensorInfo(TensorShape(25U, 10U, 2U), 1, DataType::F32, 0),
124 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32, 5),
125 TensorInfo(TensorShape(13U, 13U, 2U), 1, DataType::F32, 0),
126 TensorInfo(TensorShape(11U, 9U, 1U, 3U), 1, DataType::F32, 0),
127 TensorInfo(TensorShape(32U, 16U, 4U), 1, DataType::F32, 0),
128 })),
129 framework::dataset::make("PadStrideInfo", { PadStrideInfo(1, 1, 0, 0),
130 PadStrideInfo(1, 1, 0, 0),
131 PadStrideInfo(1, 1, 0, 0),
132 PadStrideInfo(1, 1, 0, 0),
133 PadStrideInfo(1, 1, 1, 1),
134 PadStrideInfo(1, 1, 0, 0),
135 })),
136 framework::dataset::make("ax", { 1U,
137 1U,
138 1U,
139 1U,
140 0U,
141 0U,
142 })),
143 framework::dataset::make("ay", { 1U,
144 1U,
145 1U,
146 1U,
147 0U,
148 0U,
149 })),
150 framework::dataset::make("Expected", { false, false, false, false, false, true })),
151 input_info, weights_info, bias_info, output_info, pad_info, ax, ay, expected)
152{
153 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));
154 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
155}
156// clang-format on
157// *INDENT-ON*
158
159template <typename T>
160using CLDeconvolutionLayerFixture3x3 = DeconvolutionValidationFixture<CLTensor, CLAccessor, CLDeconvolutionLayer, T, 3, 3>;
161
162template <typename T>
163using CLDeconvolutionLayerFixture1x1 = DeconvolutionValidationFixture<CLTensor, CLAccessor, CLDeconvolutionLayer, T, 1, 1>;
164
165TEST_SUITE(Float)
166
167TEST_SUITE(FP32)
168TEST_SUITE(W3x3)
169
170FIXTURE_DATA_TEST_CASE(Run, CLDeconvolutionLayerFixture3x3<float>, framework::DatasetMode::ALL, combine(data3x3, framework::dataset::make("DataType", DataType::F32)))
171{
172 // Validate output
173 validate(CLAccessor(_target), _reference, tolerance_fp32);
174}
175TEST_SUITE_END()
176
177TEST_SUITE(W1x1)
178FIXTURE_DATA_TEST_CASE(Run, CLDeconvolutionLayerFixture1x1<float>, framework::DatasetMode::ALL, combine(data1x1, framework::dataset::make("DataType", DataType::F32)))
179{
180 // Validate output
181 validate(CLAccessor(_target), _reference, tolerance_fp32);
182}
183TEST_SUITE_END()
184
185TEST_SUITE_END()
186TEST_SUITE_END()
187
188TEST_SUITE_END()
189TEST_SUITE_END()
190} // namespace validation
191} // namespace test
192} // namespace arm_compute