1*c217d954SCole Faust /*
2*c217d954SCole Faust * Copyright (c) 2018-2020 Arm Limited.
3*c217d954SCole Faust *
4*c217d954SCole Faust * SPDX-License-Identifier: MIT
5*c217d954SCole Faust *
6*c217d954SCole Faust * Permission is hereby granted, free of charge, to any person obtaining a copy
7*c217d954SCole Faust * of this software and associated documentation files (the "Software"), to
8*c217d954SCole Faust * deal in the Software without restriction, including without limitation the
9*c217d954SCole Faust * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10*c217d954SCole Faust * sell copies of the Software, and to permit persons to whom the Software is
11*c217d954SCole Faust * furnished to do so, subject to the following conditions:
12*c217d954SCole Faust *
13*c217d954SCole Faust * The above copyright notice and this permission notice shall be included in all
14*c217d954SCole Faust * copies or substantial portions of the Software.
15*c217d954SCole Faust *
16*c217d954SCole Faust * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17*c217d954SCole Faust * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*c217d954SCole Faust * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19*c217d954SCole Faust * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20*c217d954SCole Faust * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21*c217d954SCole Faust * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22*c217d954SCole Faust * SOFTWARE.
23*c217d954SCole Faust */
24*c217d954SCole Faust #include "arm_compute/core/Types.h"
25*c217d954SCole Faust #include "arm_compute/runtime/CL/CLTensor.h"
26*c217d954SCole Faust #include "arm_compute/runtime/CL/CLTensorAllocator.h"
27*c217d954SCole Faust #include "arm_compute/runtime/CL/functions/CLConvolutionLayer.h"
28*c217d954SCole Faust #include "arm_compute/runtime/CL/functions/CLGEMMConvolutionLayer.h"
29*c217d954SCole Faust #include "tests/CL/CLAccessor.h"
30*c217d954SCole Faust #include "tests/PaddingCalculator.h"
31*c217d954SCole Faust #include "tests/datasets/DilatedConvolutionLayerDataset.h"
32*c217d954SCole Faust #include "tests/framework/Asserts.h"
33*c217d954SCole Faust #include "tests/framework/Macros.h"
34*c217d954SCole Faust #include "tests/framework/datasets/Datasets.h"
35*c217d954SCole Faust #include "tests/validation/Validation.h"
36*c217d954SCole Faust #include "tests/validation/fixtures/ConvolutionLayerFixture.h"
37*c217d954SCole Faust
38*c217d954SCole Faust namespace arm_compute
39*c217d954SCole Faust {
40*c217d954SCole Faust namespace test
41*c217d954SCole Faust {
42*c217d954SCole Faust namespace validation
43*c217d954SCole Faust {
44*c217d954SCole Faust namespace
45*c217d954SCole Faust {
46*c217d954SCole Faust RelativeTolerance<float> rel_tolerance_f32(0.05f); /**< Relative tolerance value for comparing reference's output against implementation's output for DataType::F32 */
47*c217d954SCole Faust RelativeTolerance<half_float::half> rel_tolerance_f16(half_float::half(0.2)); /**< Relative tolerance value for comparing reference's output against implementation's output for DataType::F16 */
48*c217d954SCole Faust constexpr AbsoluteTolerance<float> abs_tolerance_qasymm8(1); /**< Relative tolerance value for comparing reference's output against implementation's output for quantized data types */
49*c217d954SCole Faust constexpr float abs_tolerance_f32 = 0.001f; /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F32 */
50*c217d954SCole Faust constexpr float abs_tolerance_f16 = 0.3f; /**< Absolute tolerance value for comparing reference's output against implementation's output for DataType::F16 */
51*c217d954SCole Faust constexpr float tolerance_num_f16 = 0.07f; /**< Tolerance number for FP16 */
52*c217d954SCole Faust
53*c217d954SCole Faust /** CNN data types */
54*c217d954SCole Faust const auto CNNDataTypes = framework::dataset::make("DataType",
55*c217d954SCole Faust {
56*c217d954SCole Faust DataType::F16,
57*c217d954SCole Faust DataType::F32,
58*c217d954SCole Faust DataType::QASYMM8,
59*c217d954SCole Faust });
60*c217d954SCole Faust } // namespace
61*c217d954SCole Faust
62*c217d954SCole Faust TEST_SUITE(CL)
TEST_SUITE(DilatedConvolutionLayer)63*c217d954SCole Faust TEST_SUITE(DilatedConvolutionLayer)
64*c217d954SCole Faust
65*c217d954SCole Faust DATA_TEST_CASE(ValidateConvolutionMethod, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(
66*c217d954SCole Faust framework::dataset::make("InputInfo", { TensorInfo(TensorShape(17U, 31U, 2U), 1, DataType::F32),
67*c217d954SCole Faust TensorInfo(TensorShape(17U, 31U, 2U), 1, DataType::F32),
68*c217d954SCole Faust TensorInfo(TensorShape(23U, 27U, 23U, 4U), 1, DataType::F32),
69*c217d954SCole Faust TensorInfo(TensorShape(3U, 3U, 2U, 1U), 1, DataType::F32),
70*c217d954SCole Faust TensorInfo(TensorShape(33U, 27U, 7U, 4U), 1, DataType::F32)
71*c217d954SCole Faust }),
72*c217d954SCole Faust framework::dataset::make("WeightsInfo", { TensorInfo(TensorShape(5U, 5U, 2U, 19U), 1, DataType::F32),
73*c217d954SCole Faust TensorInfo(TensorShape(5U, 5U, 2U, 19U), 1, DataType::F32),
74*c217d954SCole Faust TensorInfo(TensorShape(3U, 3U, 23U, 21U), 1, DataType::F32),
75*c217d954SCole Faust TensorInfo(TensorShape(3U, 3U, 5U, 21U), 1, DataType::F32),
76*c217d954SCole Faust TensorInfo(TensorShape(5U, 5U, 7U, 16U), 1, DataType::F16)
77*c217d954SCole Faust })),
78*c217d954SCole Faust framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(15U, 15U, 19U), 1, DataType::F32),
79*c217d954SCole Faust TensorInfo(TensorShape(15U, 15U, 19U), 1, DataType::F32),
80*c217d954SCole Faust TensorInfo(TensorShape(21U, 25U, 21U, 4U), 1, DataType::F32),
81*c217d954SCole Faust TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32),
82*c217d954SCole Faust TensorInfo(TensorShape(11U, 12U, 16U, 4U), 1, DataType::F32)
83*c217d954SCole Faust })),
84*c217d954SCole Faust framework::dataset::make("ConvInfo", { PadStrideInfo(1, 2, 1, 1),
85*c217d954SCole Faust PadStrideInfo(1, 2, 1, 1),
86*c217d954SCole Faust PadStrideInfo(1, 1, 0, 0),
87*c217d954SCole Faust PadStrideInfo(2, 1, 0, 0),
88*c217d954SCole Faust PadStrideInfo(3, 2, 1, 0)
89*c217d954SCole Faust })),
90*c217d954SCole Faust framework::dataset::make("GpuTarget", { GPUTarget::BIFROST,
91*c217d954SCole Faust GPUTarget::MIDGARD,
92*c217d954SCole Faust GPUTarget::G71,
93*c217d954SCole Faust GPUTarget::MIDGARD,
94*c217d954SCole Faust GPUTarget::BIFROST
95*c217d954SCole Faust })),
96*c217d954SCole Faust framework::dataset::make("Dilation", { Size2D(1U, 1U),
97*c217d954SCole Faust Size2D(1U, 1U),
98*c217d954SCole Faust Size2D(1U, 1U),
99*c217d954SCole Faust Size2D(2U, 2U),
100*c217d954SCole Faust Size2D(3U, 3U)
101*c217d954SCole Faust })),
102*c217d954SCole Faust
103*c217d954SCole Faust framework::dataset::make("Expected", { ConvolutionMethod::GEMM, ConvolutionMethod::GEMM, ConvolutionMethod::WINOGRAD, ConvolutionMethod::GEMM, ConvolutionMethod::GEMM })),
104*c217d954SCole Faust input_info, weights_info, output_info, conv_info, gpu_target, dilation, expected)
105*c217d954SCole Faust {
106*c217d954SCole Faust ConvolutionMethod is_valid = CLConvolutionLayer::get_convolution_method(&input_info.clone()->set_is_resizable(true),
107*c217d954SCole Faust &weights_info.clone()->set_is_resizable(true),
108*c217d954SCole Faust &output_info.clone()->set_is_resizable(true), conv_info, WeightsInfo(), ActivationLayerInfo(), gpu_target, dilation);
109*c217d954SCole Faust ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
110*c217d954SCole Faust }
111*c217d954SCole Faust
112*c217d954SCole Faust TEST_SUITE_END()
113*c217d954SCole Faust
114*c217d954SCole Faust TEST_SUITE(GEMMDilatedConvolutionLayer)
115*c217d954SCole Faust
116*c217d954SCole Faust template <typename T>
117*c217d954SCole Faust using CLGEMMDilatedConvolutionLayerFixture = ConvolutionValidationFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>;
118*c217d954SCole Faust
119*c217d954SCole Faust TEST_SUITE(Float)
TEST_SUITE(FP16)120*c217d954SCole Faust TEST_SUITE(FP16)
121*c217d954SCole Faust FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
122*c217d954SCole Faust framework::dataset::make("ReshapeWeights", { true })),
123*c217d954SCole Faust framework::dataset::make("DataType", DataType::F16)),
124*c217d954SCole Faust framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
125*c217d954SCole Faust framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
126*c217d954SCole Faust {
127*c217d954SCole Faust // Validate output
128*c217d954SCole Faust validate(CLAccessor(_target), _reference, rel_tolerance_f16, 0.0f, abs_tolerance_f16);
129*c217d954SCole Faust }
130*c217d954SCole Faust
131*c217d954SCole Faust FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
132*c217d954SCole Faust framework::dataset::make("ReshapeWeights", { true })),
133*c217d954SCole Faust framework::dataset::make("DataType", DataType::F16)),
134*c217d954SCole Faust framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
135*c217d954SCole Faust framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
136*c217d954SCole Faust {
137*c217d954SCole Faust // Validate output
138*c217d954SCole Faust validate(CLAccessor(_target), _reference, rel_tolerance_f16, tolerance_num_f16);
139*c217d954SCole Faust }
140*c217d954SCole Faust
141*c217d954SCole Faust TEST_SUITE_END()
142*c217d954SCole Faust
TEST_SUITE(FP32)143*c217d954SCole Faust TEST_SUITE(FP32)
144*c217d954SCole Faust FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
145*c217d954SCole Faust framework::dataset::make("ReshapeWeights", { true })),
146*c217d954SCole Faust framework::dataset::make("DataType", DataType::F32)),
147*c217d954SCole Faust framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
148*c217d954SCole Faust framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
149*c217d954SCole Faust {
150*c217d954SCole Faust // Validate output
151*c217d954SCole Faust validate(CLAccessor(_target), _reference, rel_tolerance_f32);
152*c217d954SCole Faust }
153*c217d954SCole Faust
154*c217d954SCole Faust FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
155*c217d954SCole Faust framework::dataset::make("ReshapeWeights", { true })),
156*c217d954SCole Faust framework::dataset::make("DataType", DataType::F32)),
157*c217d954SCole Faust framework::dataset::make("DataLayout", { DataLayout::NCHW, DataLayout::NHWC })),
158*c217d954SCole Faust framework::dataset::make("ActivationLayerInfo", ActivationLayerInfo())))
159*c217d954SCole Faust {
160*c217d954SCole Faust // Validate output
161*c217d954SCole Faust validate(CLAccessor(_target), _reference, rel_tolerance_f32, 0.f, abs_tolerance_f32);
162*c217d954SCole Faust }
163*c217d954SCole Faust TEST_SUITE_END()
164*c217d954SCole Faust TEST_SUITE_END()
165*c217d954SCole Faust
166*c217d954SCole Faust template <typename T>
167*c217d954SCole Faust using CLGEMMDilatedConvolutionLayerQuantizedFixture = ConvolutionValidationQuantizedFixture<CLTensor, CLAccessor, CLGEMMConvolutionLayer, T>;
168*c217d954SCole Faust
169*c217d954SCole Faust TEST_SUITE(Quantized)
TEST_SUITE(QASYMM8)170*c217d954SCole Faust TEST_SUITE(QASYMM8)
171*c217d954SCole Faust FIXTURE_DATA_TEST_CASE(RunSmall, CLGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::PRECOMMIT,
172*c217d954SCole Faust combine(combine(combine(combine(combine(datasets::SmallDilatedConvolutionLayerDataset(),
173*c217d954SCole Faust framework::dataset::make("ReshapeWeights", { true })),
174*c217d954SCole Faust framework::dataset::make("DataType", DataType::QASYMM8)),
175*c217d954SCole Faust framework::dataset::make("DataLayout", { DataLayout::NCHW })),
176*c217d954SCole Faust framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 10) })),
177*c217d954SCole Faust framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() })))
178*c217d954SCole Faust {
179*c217d954SCole Faust // Validate output
180*c217d954SCole Faust validate(CLAccessor(_target), _reference, abs_tolerance_qasymm8);
181*c217d954SCole Faust }
182*c217d954SCole Faust
183*c217d954SCole Faust FIXTURE_DATA_TEST_CASE(RunLarge, CLGEMMDilatedConvolutionLayerQuantizedFixture<uint8_t>, framework::DatasetMode::NIGHTLY,
184*c217d954SCole Faust combine(combine(combine(combine(combine(datasets::LargeDilatedConvolutionLayerDataset(),
185*c217d954SCole Faust framework::dataset::make("ReshapeWeights", { true })),
186*c217d954SCole Faust framework::dataset::make("DataType", DataType::QASYMM8)),
187*c217d954SCole Faust framework::dataset::make("DataLayout", { DataLayout::NCHW })),
188*c217d954SCole Faust framework::dataset::make("QuantizationInfo", { QuantizationInfo(2.f / 255.f, 0) })),
189*c217d954SCole Faust framework::dataset::make("ActivationLayerInfo", { ActivationLayerInfo() })))
190*c217d954SCole Faust {
191*c217d954SCole Faust // Validate output
192*c217d954SCole Faust validate(CLAccessor(_target), _reference, abs_tolerance_qasymm8);
193*c217d954SCole Faust }
194*c217d954SCole Faust TEST_SUITE_END()
195*c217d954SCole Faust TEST_SUITE_END()
196*c217d954SCole Faust
197*c217d954SCole Faust TEST_SUITE_END()
198*c217d954SCole Faust TEST_SUITE_END()
199*c217d954SCole Faust } // namespace validation
200*c217d954SCole Faust } // namespace test
201*c217d954SCole Faust } // namespace arm_compute
202