blob: d7642eb1728aba71c027c68fcb20c7b8518ae645 [file] [log] [blame]
Alex Gilday7da29b62018-03-23 14:16:00 +00001/*
2 * Copyright (c) 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 CONCLCTION 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/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLConvolutionLayer.h"
28#include "arm_compute/runtime/CL/functions/CLGEMMConvolutionLayer.h"
29#include "tests/CL/CLAccessor.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/DilatedConvolutionLayerDataset.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/ConvolutionLayerFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
Gian Marco Iodicebcafc4d2018-08-17 11:02:54 +010046RelativeTolerance<float> rel_tolerance_f32(0.05f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
47RelativeTolerance<half_float::half> rel_tolerance_f16(half_float::half(0.2)); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */
48constexpr AbsoluteTolerance<float> abs_tolerance_qasymm8(0.0); /**< Tolerance value for comparing reference's output against implementation's output for quantized data types */
49constexpr float abs_tolerance_f32 = 0.001f; /**< Tolerance number */
50constexpr float abs_tolerance_f16 = 0.07f; /**< Tolerance number */
Alex Gilday7da29b62018-03-23 14:16:00 +000051
52/** CNN data types */
53const auto CNNDataTypes = framework::dataset::make("DataType",
54{
55 DataType::F16,
56 DataType::F32,
Alex Gilday7da29b62018-03-23 14:16:00 +000057 DataType::QASYMM8,
58});
59} // namespace
60
61TEST_SUITE(CL)
62TEST_SUITE(DilatedConvolutionLayer)
63
Gian Marco Iodicee52a3002018-04-11 15:59:10 +010064DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010065 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(17U, 31U, 2U), 1, DataType::F32),
66 TensorInfo(TensorShape(17U, 31U, 2U), 1, DataType::F32),
67 TensorInfo(TensorShape(23U, 27U, 23U, 4U), 1, DataType::F32),
68 TensorInfo(TensorShape(3U, 3U, 2U, 1U), 1, DataType::F32),
69 TensorInfo(TensorShape(33U, 27U, 7U, 4U), 1, DataType::F32)
Gian Marco Iodicee52a3002018-04-11 15:59:10 +010070 }),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010071 framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(5U, 5U, 2U, 19U), 1, DataType::F32),
72 TensorInfo(TensorShape(5U, 5U, 2U, 19U), 1, DataType::F32),
73 TensorInfo(TensorShape(3U, 3U, 23U, 21U), 1, DataType::F32),
74 TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32),
75 TensorInfo(TensorShape(5U, 5U, 7U, 16U), 1, DataType::F16)
Gian Marco Iodicee52a3002018-04-11 15:59:10 +010076 })),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010077 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(15U, 15U, 19U), 1, DataType::F32),
78 TensorInfo(TensorShape(15U, 15U, 19U), 1, DataType::F32),
79 TensorInfo(TensorShape(21U, 25U, 21U, 4U), 1, DataType::F32),
80 TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32),
81 TensorInfo(TensorShape(11U, 12U, 16U, 4U), 1, DataType::F32)
Alex Gilday7da29b62018-03-23 14:16:00 +000082 })),
83 framework::dataset::make("ConvInfo", { PadStrideInfo(1, 2, 1, 1),
84 PadStrideInfo(1, 2, 1, 1),
85 PadStrideInfo(1, 1, 0, 0),
86 PadStrideInfo(2, 1, 0, 0),
87 PadStrideInfo(3, 2, 1, 0)
88 })),
89 framework::dataset::make("GpuTarget", { GPUTarget::BIFROST,
90 GPUTarget::MIDGARD,
91 GPUTarget::G71,
92 GPUTarget::MIDGARD,
93 GPUTarget::BIFROST
94 })),
95 framework::dataset::make("Dilation", { Size2D(1U, 1U),
96 Size2D(1U, 1U),
97 Size2D(1U, 1U),
98 Size2D(2U, 2U),
99 Size2D(3U, 3U)
100 })),
101
Gian Marco Iodicee52a3002018-04-11 15:59:10 +0100102 framework::dataset::make("Expected", { ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::WINOGRAD, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM })),
103 input_info, weights_info, output_info, conv_info, gpu_target, dilation, expected)
Alex Gilday7da29b62018-03-23 14:16:00 +0000104{
Gian Marco Iodice2213d4b2018-04-27 10:39:06 +0100105 ConvolutionMethod is_valid = CLConvolutionLayer::get_convolution_method(&input_info.clone()->set_is_resizable(true),
106 &weights_info.clone()->set_is_resizable(true),
107 &output_info.clone()->set_is_resizable(true), conv_info, WeightsInfo(), ActivationLayerInfo(), gpu_target, dilation);
Alex Gilday7da29b62018-03-23 14:16:00 +0000108 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
109}
Gian Marco Iodicebcafc4d2018-08-17 11:02:54 +0100110
Alex Gilday7da29b62018-03-23 14:16:00 +0000111TEST_SUITE_END()
112
113TEST_SUITE(GEMMDilatedConvolutionLayer)
114
115DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallDilatedConvolutionLayerDataset(), datasets::LargeDilatedConvolutionLayerDataset()),
116 CNNDataTypes),
117 input_shape, weights_shape, bias_shape, output_shape, info, dilation, data_type)
118{
Alex Gilday7da29b62018-03-23 14:16:00 +0000119 auto bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type;
120
121 // Create tensors
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +0100122 CLTensor src = create_tensor<CLTensor>(input_shape, data_type, 1, QuantizationInfo(2.f / 255.f, 127));
123 CLTensor weights = create_tensor<CLTensor>(weights_shape, data_type, 1, QuantizationInfo(2.f / 255.f, 127));
124 CLTensor bias = create_tensor<CLTensor>(bias_shape, bias_data_type, 1, QuantizationInfo(2.f / 255.f, 127));
125 CLTensor dst = create_tensor<CLTensor>(output_shape, data_type, 1, QuantizationInfo(2.f / 255.f, 127));
Alex Gilday7da29b62018-03-23 14:16:00 +0000126
127 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
128 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
129 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
130 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
131
132 const QuantizationInfo src_quantization_info = src.info()->quantization_info();
133 const QuantizationInfo weights_quantization_info = weights.info()->quantization_info();
134
135 // Create and configure function
136 CLGEMMConvolutionLayer conv;
137 conv.configure(&src, &weights, &bias, &dst, info, WeightsInfo(), dilation);
138
139 // Validate valid region
140 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
141 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
142 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
143 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
144
145 validate(src.info()->valid_region(), src_valid_region);
146 validate(weights.info()->valid_region(), weights_valid_region);
147 validate(bias.info()->valid_region(), bias_valid_region);
148 validate(dst.info()->valid_region(), dst_valid_region);
149
150 // Validate QuantizationInfo
151 ARM_COMPUTE_EXPECT(src.info()->quantization_info() == src_quantization_info, framework::LogLevel::ERRORS);
152 ARM_COMPUTE_EXPECT(weights.info()->quantization_info() == weights_quantization_info, framework::LogLevel::ERRORS);
153
154 // Validate padding
155 //TODO(COMPMID-415) Need to validate padding?
156}
157
158template <typename T>
159using CLGEMMDilatedConvolutionLayerFixture = ConvolutionValidationFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>;
160
161TEST_SUITE(Float)
162TEST_SUITE(FP16)
Michalis Spyroue2503892018-04-23 15:17:31 +0100163FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
Alex Gilday7da29b62018-03-23 14:16:00 +0000164 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000165 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitas19ea4192018-06-19 13:09:53 +0100166 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000167 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000168{
169 // Validate output
Gian Marco Iodicebcafc4d2018-08-17 11:02:54 +0100170 validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.0f, abs_tolerance_f16);
Alex Gilday7da29b62018-03-23 14:16:00 +0000171}
Gian Marco Iodicebcafc4d2018-08-17 11:02:54 +0100172
Michalis Spyroue2503892018-04-23 15:17:31 +0100173FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
Alex Gilday7da29b62018-03-23 14:16:00 +0000174 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000175 framework::dataset::make("DataType", DataType::F16)),
Georgios Pinitas19ea4192018-06-19 13:09:53 +0100176 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000177 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000178{
179 // Validate output
Gian Marco Iodicebcafc4d2018-08-17 11:02:54 +0100180 validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.0f, abs_tolerance_f16);
Alex Gilday7da29b62018-03-23 14:16:00 +0000181}
Gian Marco Iodicebcafc4d2018-08-17 11:02:54 +0100182
Alex Gilday7da29b62018-03-23 14:16:00 +0000183TEST_SUITE_END()
184
185TEST_SUITE(FP32)
Michalis Spyroue2503892018-04-23 15:17:31 +0100186FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
Alex Gilday7da29b62018-03-23 14:16:00 +0000187 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000188 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitas19ea4192018-06-19 13:09:53 +0100189 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000190 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000191{
192 // Validate output
Gian Marco Iodicebcafc4d2018-08-17 11:02:54 +0100193 validate(CLAccessor(_target), _reference, rel_tolerance_f32);
Alex Gilday7da29b62018-03-23 14:16:00 +0000194}
Gian Marco Iodicebcafc4d2018-08-17 11:02:54 +0100195
Michalis Spyroue2503892018-04-23 15:17:31 +0100196FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
Alex Gilday7da29b62018-03-23 14:16:00 +0000197 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000198 framework::dataset::make("DataType", DataType::F32)),
Georgios Pinitas19ea4192018-06-19 13:09:53 +0100199 framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000200 framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
Alex Gilday7da29b62018-03-23 14:16:00 +0000201{
202 // Validate output
Gian Marco Iodicebcafc4d2018-08-17 11:02:54 +0100203 validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
Alex Gilday7da29b62018-03-23 14:16:00 +0000204}
205TEST_SUITE_END()
206TEST_SUITE_END()
207
208template <typename T>
Alex Gilday7da29b62018-03-23 14:16:00 +0000209using CLGEMMDilatedConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>;
210
211TEST_SUITE(Quantized)
212TEST_SUITE(QASYMM8)
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000213FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
Georgios Pinitas19ea4192018-06-19 13:09:53 +0100214 combine(combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
215 framework::dataset::make("ReshapeWeights", { true })),
216 framework::dataset::make("DataType", DataType::QASYMM8)),
217 framework::dataset::make("DataLayout", { DataLayout::NCHW })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000218 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
219 framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() })))
Alex Gilday7da29b62018-03-23 14:16:00 +0000220{
221 // Validate output
Gian Marco Iodicebcafc4d2018-08-17 11:02:54 +0100222 validate(CLAccessor(_target), _reference, abs_tolerance_qasymm8);
Alex Gilday7da29b62018-03-23 14:16:00 +0000223}
Gian Marco Iodicebcafc4d2018-08-17 11:02:54 +0100224
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000225FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
Georgios Pinitas19ea4192018-06-19 13:09:53 +0100226 combine(combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
227 framework::dataset::make("ReshapeWeights", { true })),
228 framework::dataset::make("DataType", DataType::QASYMM8)),
229 framework::dataset::make("DataLayout", { DataLayout::NCHW })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000230 framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 0) })),
231 framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() })))
Alex Gilday7da29b62018-03-23 14:16:00 +0000232{
233 // Validate output
Gian Marco Iodicebcafc4d2018-08-17 11:02:54 +0100234 validate(CLAccessor(_target), _reference, abs_tolerance_qasymm8);
Alex Gilday7da29b62018-03-23 14:16:00 +0000235}
236TEST_SUITE_END()
237TEST_SUITE_END()
238
239TEST_SUITE_END()
240TEST_SUITE_END()
241} // namespace validation
242} // namespace test
243} // namespace arm_compute