blob: 4040f468f458477591bbee158672f58a93630446 [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
2 * Copyright (c) 2017 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 CONNECTION 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/GLES_COMPUTE/GCTensor.h"
26#include "arm_compute/runtime/GLES_COMPUTE/GCTensorAllocator.h"
27#include "arm_compute/runtime/GLES_COMPUTE/functions/GCFullyConnectedLayer.h"
28#include "tests/GLES_COMPUTE/GCAccessor.h"
29#include "tests/GLES_COMPUTE/Helper.h"
30#include "tests/PaddingCalculator.h"
31#include "tests/datasets/FullyConnectedLayerDataset.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/FullyConnectedLayerFixture.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44namespace
45{
46/** Tolerance for float operations */
47RelativeTolerance<float> tolerance_f32(0.05f);
48RelativeTolerance<half_float::half> tolerance_f16(half(0.2));
49constexpr float tolerance_num = 0.07f; /**< Tolerance number */
50
51/** CNN data types */
52const auto CNNDataTypes = framework::dataset::make("DataType",
53{
54 DataType::F16,
55 DataType::F32,
56});
57
58const auto FullyConnectedParameters = combine(framework::dataset::make("TransposeWeights", { false, true }), framework::dataset::make("ReshapeWeights", { false, true }));
59} // namespace
60
61TEST_SUITE(GC)
62TEST_SUITE(FullyConnectedLayer)
63
64DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallFullyConnectedLayerDataset(), datasets::LargeFullyConnectedLayerDataset()),
65 FullyConnectedParameters),
66 CNNDataTypes),
67 src_shape, weights_shape, bias_shape, dst_shape, transpose_weights, reshape_weights, data_type)
68{
69 // Set fixed point position data type allowed
70 int fixed_point_position = is_data_type_fixed_point(data_type) ? 3 : 0;
71
72 TensorShape ws(weights_shape);
73
74 // Transpose weights if not done in the function
75 if(!reshape_weights || !transpose_weights)
76 {
77 const size_t shape_x = ws.x();
78 ws.set(0, ws.y());
79 ws.set(1, shape_x);
80 }
81
82 // Create tensors
83 GCTensor src = create_tensor<GCTensor>(src_shape, data_type, 1, fixed_point_position);
84 GCTensor weights = create_tensor<GCTensor>(ws, data_type, 1, fixed_point_position);
85 GCTensor bias = create_tensor<GCTensor>(bias_shape, data_type, 1, fixed_point_position);
86 GCTensor dst = create_tensor<GCTensor>(dst_shape, data_type, 1, fixed_point_position);
87
88 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
89 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
90 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
91 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
92
93 // Create and configure function.
94 GCFullyConnectedLayer fc;
95 fc.configure(&src, &weights, &bias, &dst, transpose_weights, !reshape_weights);
96
97 // Validate valid region
98 const ValidRegion dst_valid_region = shape_to_valid_region(dst_shape);
99 validate(dst.info()->valid_region(), dst_valid_region);
100}
101
102template <typename T>
103using GCFullyConnectedLayerFixture = FullyConnectedLayerValidationFixture<GCTensor, GCAccessor, GCFullyConnectedLayer, T, false>;
104
105TEST_SUITE(Float)
106TEST_SUITE(FP16)
107FIXTURE_DATA_TEST_CASE(RunSmall, GCFullyConnectedLayerFixture<half_float::half>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallFullyConnectedLayerDataset(),
108 FullyConnectedParameters),
109 framework::dataset::make("DataType", DataType::F16)))
110{
111 // Validate output
112 validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num);
113}
114FIXTURE_DATA_TEST_CASE(RunLarge, GCFullyConnectedLayerFixture<half_float::half>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeFullyConnectedLayerDataset(),
115 FullyConnectedParameters),
116 framework::dataset::make("DataType", DataType::F16)))
117{
118 // Validate output
119 validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num);
120}
121TEST_SUITE_END()
122
123TEST_SUITE(FP32)
124FIXTURE_DATA_TEST_CASE(RunSmall, GCFullyConnectedLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(datasets::SmallFullyConnectedLayerDataset(), FullyConnectedParameters),
125 framework::dataset::make("DataType", DataType::F32)))
126{
127 // Validate output
128 validate(GCAccessor(_target), _reference, tolerance_f32);
129}
130FIXTURE_DATA_TEST_CASE(RunLarge, GCFullyConnectedLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(datasets::LargeFullyConnectedLayerDataset(), FullyConnectedParameters),
131 framework::dataset::make("DataType", DataType::F32)))
132{
133 // Validate output
134 validate(GCAccessor(_target), _reference, tolerance_f32);
135}
136TEST_SUITE_END()
137TEST_SUITE_END()
138
139TEST_SUITE_END()
140TEST_SUITE_END()
141} // namespace validation
142} // namespace test
143} // namespace arm_compute