blob: 8808d82d348f527bf5a9cb411b2eeb563a253667 [file] [log] [blame]
Stephen Lie855c232018-01-04 14:13:22 +08001/*
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 CONCLCTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * 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 */
48constexpr float tolerance_num = 0.07f; /**< Tolerance number */
49
50/** CNN data types */
51const auto CNNDataTypes = framework::dataset::make("DataType",
52{
53 DataType::F16,
54 // DataType::F32,
55});
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000056const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo",
57{
58 ActivationLayerInfo(),
59 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
60 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::BOUNDED_RELU, 0.5f)
61});
Stephen Lie855c232018-01-04 14:13:22 +080062} // namespace
63
64TEST_SUITE(GC)
65TEST_SUITE(ConvolutionLayer)
66
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000067DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallConvolutionLayerDataset(), datasets::LargeConvolutionLayerDataset()),
68 CNNDataTypes),
69 ActivationFunctionsDataset),
70 input_shape, weights_shape, bias_shape, output_shape, info, dilation, data_type, act_info)
Stephen Lie855c232018-01-04 14:13:22 +080071{
72 // Set fixed point position data type allowed
73 int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
74
75 auto bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type;
76
77 // Create tensors
78 GCTensor src = create_tensor<GCTensor>(input_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
79 GCTensor weights = create_tensor<GCTensor>(weights_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
80 GCTensor bias = create_tensor<GCTensor>(bias_shape, bias_data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
81 GCTensor dst = create_tensor<GCTensor>(output_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
82
83 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
84 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
85 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
86 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
87
88 const QuantizationInfo src_quantization_info = src.info()->quantization_info();
89 const QuantizationInfo weights_quantization_info = weights.info()->quantization_info();
90
91 // Create and configure function
92 GCConvolutionLayer conv;
Isabella Gottardi3f217ec2018-02-12 14:59:19 +000093 conv.configure(&src, &weights, &bias, &dst, info, WeightsInfo(), dilation, act_info);
Stephen Lie855c232018-01-04 14:13:22 +080094
95 // Validate valid region
96 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
97 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
98 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
99 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
100
101 validate(src.info()->valid_region(), src_valid_region);
102 validate(weights.info()->valid_region(), weights_valid_region);
103 validate(bias.info()->valid_region(), bias_valid_region);
104 validate(dst.info()->valid_region(), dst_valid_region);
105
106 // Validate QuantizationInfo
107 ARM_COMPUTE_EXPECT(src.info()->quantization_info() == src_quantization_info, framework::LogLevel::ERRORS);
108 ARM_COMPUTE_EXPECT(weights.info()->quantization_info() == weights_quantization_info, framework::LogLevel::ERRORS);
109
110 //Validate padding
111 //TODO(COMPMID-415) Need to validate padding?
112}
113
114template <typename T>
115using GCConvolutionLayerFixture = ConvolutionValidationFixture<GCTensor, GCAccessor, GCConvolutionLayer, T>;
116
117TEST_SUITE(Float)
118TEST_SUITE(FP16)
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000119FIXTURE_DATA_TEST_CASE(RunSmall, GCConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallConvolutionLayerDataset(),
Stephen Lie855c232018-01-04 14:13:22 +0800120 framework::dataset::make("ReshapeWeights", { true, false })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000121 framework::dataset::make("DataType",
122 DataType::F16)),
123 ActivationFunctionsDataset))
Stephen Lie855c232018-01-04 14:13:22 +0800124{
125 // Validate output
126 validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num);
127}
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000128FIXTURE_DATA_TEST_CASE(RunLarge, GCConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeConvolutionLayerDataset(),
Stephen Lie855c232018-01-04 14:13:22 +0800129 framework::dataset::make("ReshapeWeights", { true, false })),
Isabella Gottardi3f217ec2018-02-12 14:59:19 +0000130 framework::dataset::make("DataType",
131 DataType::F16)),
132 ActivationFunctionsDataset))
Stephen Lie855c232018-01-04 14:13:22 +0800133{
134 // Validate output
135 validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num);
136}
137TEST_SUITE_END()
Anthony Barbier51b074a2018-02-20 12:09:07 +0000138TEST_SUITE_END()
Stephen Lie855c232018-01-04 14:13:22 +0800139
140TEST_SUITE_END()
141TEST_SUITE_END()
Stephen Lie855c232018-01-04 14:13:22 +0800142} // namespace validation
143} // namespace test
144} // namespace arm_compute