blob: a5d1b6992f1b738ab3f68414e1b81a6f2f633503 [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});
56} // namespace
57
58TEST_SUITE(GC)
59TEST_SUITE(ConvolutionLayer)
60
61DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallConvolutionLayerDataset(), datasets::LargeConvolutionLayerDataset()), CNNDataTypes),
62 input_shape, weights_shape, bias_shape, output_shape, info, data_type)
63{
64 // Set fixed point position data type allowed
65 int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
66
67 auto bias_data_type = is_data_type_quantized_asymmetric(data_type) ? DataType::S32 : data_type;
68
69 // Create tensors
70 GCTensor src = create_tensor<GCTensor>(input_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
71 GCTensor weights = create_tensor<GCTensor>(weights_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
72 GCTensor bias = create_tensor<GCTensor>(bias_shape, bias_data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
73 GCTensor dst = create_tensor<GCTensor>(output_shape, data_type, 1, fixed_point_position, QuantizationInfo(2.f / 255.f, 127));
74
75 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
76 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
77 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
78 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
79
80 const QuantizationInfo src_quantization_info = src.info()->quantization_info();
81 const QuantizationInfo weights_quantization_info = weights.info()->quantization_info();
82
83 // Create and configure function
84 GCConvolutionLayer conv;
85 conv.configure(&src, &weights, &bias, &dst, info);
86
87 // Validate valid region
88 const ValidRegion src_valid_region = shape_to_valid_region(input_shape);
89 const ValidRegion weights_valid_region = shape_to_valid_region(weights_shape);
90 const ValidRegion bias_valid_region = shape_to_valid_region(bias_shape);
91 const ValidRegion dst_valid_region = shape_to_valid_region(output_shape);
92
93 validate(src.info()->valid_region(), src_valid_region);
94 validate(weights.info()->valid_region(), weights_valid_region);
95 validate(bias.info()->valid_region(), bias_valid_region);
96 validate(dst.info()->valid_region(), dst_valid_region);
97
98 // Validate QuantizationInfo
99 ARM_COMPUTE_EXPECT(src.info()->quantization_info() == src_quantization_info, framework::LogLevel::ERRORS);
100 ARM_COMPUTE_EXPECT(weights.info()->quantization_info() == weights_quantization_info, framework::LogLevel::ERRORS);
101
102 //Validate padding
103 //TODO(COMPMID-415) Need to validate padding?
104}
105
106template <typename T>
107using GCConvolutionLayerFixture = ConvolutionValidationFixture<GCTensor, GCAccessor, GCConvolutionLayer, T>;
108
109TEST_SUITE(Float)
110TEST_SUITE(FP16)
111FIXTURE_DATA_TEST_CASE(RunSmall, GCConvolutionLayerFixture<half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallConvolutionLayerDataset(),
112 framework::dataset::make("ReshapeWeights", { true, false })),
113 framework::dataset::make("DataType",
114 DataType::F16)))
115{
116 // Validate output
117 validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num);
118}
119FIXTURE_DATA_TEST_CASE(RunLarge, GCConvolutionLayerFixture<half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeConvolutionLayerDataset(),
120 framework::dataset::make("ReshapeWeights", { true, false })),
121 framework::dataset::make("DataType",
122 DataType::F16)))
123{
124 // Validate output
125 validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num);
126}
127TEST_SUITE_END()
128
129TEST_SUITE_END()
130TEST_SUITE_END()
131}
132} // namespace validation
133} // namespace test
134} // namespace arm_compute