blob: 364eb6e6d23ef2960b8e098460457d96ab50d8a6 [file] [log] [blame]
Stephen Lie855c232018-01-04 14:13:22 +08001/*
Gian Marco Iodice1e6c9152019-08-20 11:27:20 +01002 * Copyright (c) 2017-2019 ARM Limited.
Stephen Lie855c232018-01-04 14:13:22 +08003 *
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,
Gian Marco Iodice1e6c9152019-08-20 11:27:20 +010021 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Stephen Lie855c232018-01-04 14:13:22 +080022 * SOFTWARE.
23 */
24
25#include "arm_compute/core/Types.h"
26#include "arm_compute/runtime/GLES_COMPUTE/GCTensor.h"
27#include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h"
28#include "arm_compute/runtime/GLES_COMPUTE/functions/GCConvolutionLayer.h"
29#include "tests/GLES_COMPUTE/GCAccessor.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/LargeConvolutionLayerDataset.h"
32#include "tests/datasets/SmallConvolutionLayerDataset.h"
33#include "tests/framework/Asserts.h"
34#include "tests/framework/Macros.h"
35#include "tests/framework/datasets/Datasets.h"
36#include "tests/validation/Validation.h"
37#include "tests/validation/fixtures/ConvolutionLayerFixture.h"
38
39namespace arm_compute
40{
41namespace test
42{
43namespace validation
44{
45namespace
46{
47RelativeTolerance<half_float::half> tolerance_f16(half_float::half(0.2)); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F16 */
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010048RelativeTolerance<float> tolerance_f32(0.00001f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
Stephen Lie855c232018-01-04 14:13:22 +080049constexpr float tolerance_num = 0.07f; /**< Tolerance number */
50
51/** CNN data types */
52const auto CNNDataTypes = framework::dataset::make("DataType",
53{
54 DataType::F16,
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010055 DataType::F32,
Stephen Lie855c232018-01-04 14:13:22 +080056});
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000057const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
58{
59 ActivationLayerInfo(),
60 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
61 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f)
62});
Stephen Lie855c232018-01-04 14:13:22 +080063} // namespace
64
65TEST_SUITE(GC)
66TEST_SUITE(ConvolutionLayer)
67
Gian Marco Iodice1e6c9152019-08-20 11:27:20 +010068DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(datasets::SmallConvolutionLayerReducedDataset(),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000069 CNNDataTypes),
70 ActivationFunctionsDataset),
71 input_shape, weights_shape, bias_shape, output_shape, info, dilation, data_type, act_info)
Stephen Lie855c232018-01-04 14:13:22 +080072{
Stephen Lie855c232018-01-04 14:13:22 +080073 auto bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type;
74
75 // Create tensors
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010076 GCTensor src = create_tensor<GCTensor>(input_shape, data_type, 1, QuantizationInfo(2.f / 255.f, 127));
77 GCTensor weights = create_tensor<GCTensor>(weights_shape, data_type, 1, QuantizationInfo(2.f / 255.f, 127));
78 GCTensor bias = create_tensor<GCTensor>(bias_shape, bias_data_type, 1, QuantizationInfo(2.f / 255.f, 127));
79 GCTensor dst = create_tensor<GCTensor>(output_shape, data_type, 1, QuantizationInfo(2.f / 255.f, 127));
Stephen Lie855c232018-01-04 14:13:22 +080080
81 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
82 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
83 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
84 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
85
86 const QuantizationInfo src_quantization_info = src.info()->quantization_info();
87 const QuantizationInfo weights_quantization_info = weights.info()->quantization_info();
88
89 // Create and configure function
90 GCConvolutionLayer conv;
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000091 conv.configure(&src, &weights, &bias, &dst, info, WeightsInfo(), dilation, act_info);
Stephen Lie855c232018-01-04 14:13:22 +080092
93 // Validate valid region
94 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
95 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
96 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
97 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
98
99 validate(src.info()->valid_region(), src_valid_region);
100 validate(weights.info()->valid_region(), weights_valid_region);
101 validate(bias.info()->valid_region(), bias_valid_region);
102 validate(dst.info()->valid_region(), dst_valid_region);
103
104 // Validate QuantizationInfo
105 ARM_COMPUTE_EXPECT(src.info()->quantization_info() == src_quantization_info, framework::LogLevel::ERRORS);
106 ARM_COMPUTE_EXPECT(weights.info()->quantization_info() == weights_quantization_info, framework::LogLevel::ERRORS);
107
108 //Validate padding
109 //TODO(COMPMID-415) Need to validate padding?
110}
111
112template <typename T>
113using GCConvolutionLayerFixture = ConvolutionValidationFixture<GCTensor, GCAccessor, GCConvolutionLayer, T>;
114
115TEST_SUITE(Float)
116TEST_SUITE(FP16)
Gian Marco Iodice3139f032018-11-05 14:26:32 +0000117FIXTURE_DATA_TEST_CASE(RunSmall, GCConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallConvolutionLayerReducedDataset(),
Michele Di Giorgio164b65d2018-04-13 14:28:08 +0100118 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000119 framework::dataset::make("DataType",
120 DataType::F16)),
Michalis Spyroue2503892018-04-23 15:17:31 +0100121 framework::dataset::make("DataLayout",
122 DataLayout::NCHW)),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000123 ActivationFunctionsDataset))
Stephen Lie855c232018-01-04 14:13:22 +0800124{
125 // Validate output
126 validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num);
127}
Michalis Spyroue2503892018-04-23 15:17:31 +0100128FIXTURE_DATA_TEST_CASE(RunLarge, GCConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
Michele Di Giorgio164b65d2018-04-13 14:28:08 +0100129 framework::dataset::make("ReshapeWeights", { true })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000130 framework::dataset::make("DataType",
131 DataType::F16)),
Michalis Spyroue2503892018-04-23 15:17:31 +0100132 framework::dataset::make("DataLayout",
133 DataLayout::NCHW)),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000134 ActivationFunctionsDataset))
Stephen Lie855c232018-01-04 14:13:22 +0800135{
136 // Validate output
137 validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num);
138}
139TEST_SUITE_END()
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +0100140
141TEST_SUITE(FP32)
Gian Marco Iodice3139f032018-11-05 14:26:32 +0000142FIXTURE_DATA_TEST_CASE(RunSmall, GCConvolutionLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(combine(datasets::SmallConvolutionLayerReducedDataset(),
Michele Di Giorgio164b65d2018-04-13 14:28:08 +0100143 framework::dataset::make("ReshapeWeights", { true })),
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +0100144 framework::dataset::make("DataType", DataType::F32)),
Michalis Spyroue2503892018-04-23 15:17:31 +0100145 framework::dataset::make("DataLayout",
146 DataLayout::NCHW)),
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +0100147 ActivationFunctionsDataset))
148{
149 // Validate output
150 validate(GCAccessor(_target), _reference, tolerance_f32, tolerance_num);
151}
Michalis Spyroue2503892018-04-23 15:17:31 +0100152FIXTURE_DATA_TEST_CASE(RunLarge, GCConvolutionLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
Michele Di Giorgio164b65d2018-04-13 14:28:08 +0100153 framework::dataset::make("ReshapeWeights", { true })),
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +0100154 framework::dataset::make("DataType", DataType::F32)),
Michalis Spyroue2503892018-04-23 15:17:31 +0100155 framework::dataset::make("DataLayout",
156 DataLayout::NCHW)),
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +0100157 ActivationFunctionsDataset))
158{
159 // Validate output
160 validate(GCAccessor(_target), _reference, tolerance_f32, tolerance_num);
161}
162TEST_SUITE_END()
Anthony Barbier51b074a2018-02-20 12:09:07 +0000163TEST_SUITE_END()
Stephen Lie855c232018-01-04 14:13:22 +0800164
165TEST_SUITE_END()
166TEST_SUITE_END()
Stephen Lie855c232018-01-04 14:13:22 +0800167} // namespace validation
168} // namespace test
169} // namespace arm_compute