blob: 1ef2fb9559630dccbd888bc276ceff63068857b9 [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Giorgio Arena1856ff72020-02-07 13:46:45 +00002 * Copyright (c) 2017-2020 ARM Limited.
Anthony Barbier7068f992017-10-26 15:23:08 +01003 *
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 */
Michele Di Giorgiob71d2242019-11-25 14:22:31 +000047constexpr RelativeTolerance<float> rel_tolerance_f32(0.05f);
48constexpr AbsoluteTolerance<float> abs_tolerance_f32(0.0001f);
Anthony Barbier7068f992017-10-26 15:23:08 +010049RelativeTolerance<half_float::half> tolerance_f16(half(0.2));
50constexpr float tolerance_num = 0.07f; /**< Tolerance number */
51
52/** CNN data types */
53const auto CNNDataTypes = framework::dataset::make("DataType",
54{
55 DataType::F16,
56 DataType::F32,
57});
58
Giorgio Arena1856ff72020-02-07 13:46:45 +000059const auto FullyConnectedParameters = combine(framework::dataset::make("TransposeWeights", { false, true }), framework::dataset::make("ReshapeWeights", { false, true }));
60const auto ActivationFunctionsDataset = framework::dataset::make("ActivationInfo", ActivationLayerInfo());
Anthony Barbier7068f992017-10-26 15:23:08 +010061} // namespace
62
63TEST_SUITE(GC)
64TEST_SUITE(FullyConnectedLayer)
65
66DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(combine(framework::dataset::concat(datasets::SmallFullyConnectedLayerDataset(), datasets::LargeFullyConnectedLayerDataset()),
67 FullyConnectedParameters),
68 CNNDataTypes),
69 src_shape, weights_shape, bias_shape, dst_shape, transpose_weights, reshape_weights, data_type)
70{
Anthony Barbier7068f992017-10-26 15:23:08 +010071 TensorShape ws(weights_shape);
72
73 // Transpose weights if not done in the function
74 if(!reshape_weights || !transpose_weights)
75 {
76 const size_t shape_x = ws.x();
77 ws.set(0, ws.y());
78 ws.set(1, shape_x);
79 }
80
81 // Create tensors
Vidhya Sudhan Loganathan014333d2018-07-02 09:13:49 +010082 GCTensor src = create_tensor<GCTensor>(src_shape, data_type, 1);
83 GCTensor weights = create_tensor<GCTensor>(ws, data_type, 1);
84 GCTensor bias = create_tensor<GCTensor>(bias_shape, data_type, 1);
85 GCTensor dst = create_tensor<GCTensor>(dst_shape, data_type, 1);
Anthony Barbier7068f992017-10-26 15:23:08 +010086
87 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
88 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
89 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
90 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
91
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +010092 // Create Fully Connected layer info
93 FullyConnectedLayerInfo fc_info;
94 fc_info.transpose_weights = transpose_weights;
95 fc_info.are_weights_reshaped = !reshape_weights;
96
Anthony Barbier7068f992017-10-26 15:23:08 +010097 // Create and configure function.
98 GCFullyConnectedLayer fc;
Georgios Pinitas7d66a8e2018-07-17 12:28:42 +010099 fc.configure(&src, &weights, &bias, &dst, fc_info);
Anthony Barbier7068f992017-10-26 15:23:08 +0100100
101 // Validate valid region
102 const ValidRegion dst_valid_region = shape_to_valid_region(dst_shape);
103 validate(dst.info()->valid_region(), dst_valid_region);
104}
105
106template <typename T>
Giorgio Arenaa855af12018-07-16 17:20:38 +0100107using GCFullyConnectedLayerFixture = FullyConnectedLayerValidationFixture<GCTensor, GCAccessor, GCFullyConnectedLayer, T>;
Anthony Barbier7068f992017-10-26 15:23:08 +0100108
109TEST_SUITE(Float)
110TEST_SUITE(FP16)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000111FIXTURE_DATA_TEST_CASE(RunSmall, GCFullyConnectedLayerFixture<half_float::half>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(),
Anthony Barbier7068f992017-10-26 15:23:08 +0100112 FullyConnectedParameters),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000113 framework::dataset::make("DataType", DataType::F16)),
114 ActivationFunctionsDataset))
Anthony Barbier7068f992017-10-26 15:23:08 +0100115{
116 // Validate output
117 validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num);
118}
Giorgio Arena1856ff72020-02-07 13:46:45 +0000119FIXTURE_DATA_TEST_CASE(RunLarge, GCFullyConnectedLayerFixture<half_float::half>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeFullyConnectedLayerDataset(),
Anthony Barbier7068f992017-10-26 15:23:08 +0100120 FullyConnectedParameters),
Giorgio Arena1856ff72020-02-07 13:46:45 +0000121 framework::dataset::make("DataType", DataType::F16)),
122 ActivationFunctionsDataset))
Anthony Barbier7068f992017-10-26 15:23:08 +0100123{
124 // Validate output
125 validate(GCAccessor(_target), _reference, tolerance_f16, tolerance_num);
126}
127TEST_SUITE_END()
128
129TEST_SUITE(FP32)
Giorgio Arena1856ff72020-02-07 13:46:45 +0000130FIXTURE_DATA_TEST_CASE(RunSmall, GCFullyConnectedLayerFixture<float>, framework::DatasetMode::PRECOMMIT, combine(combine(combine(datasets::SmallFullyConnectedLayerDataset(), FullyConnectedParameters),
131 framework::dataset::make("DataType", DataType::F32)),
132 ActivationFunctionsDataset))
Anthony Barbier7068f992017-10-26 15:23:08 +0100133{
134 // Validate output
Michele Di Giorgiob71d2242019-11-25 14:22:31 +0000135 validate(GCAccessor(_target), _reference, rel_tolerance_f32);
Anthony Barbier7068f992017-10-26 15:23:08 +0100136}
Giorgio Arena1856ff72020-02-07 13:46:45 +0000137FIXTURE_DATA_TEST_CASE(RunLarge, GCFullyConnectedLayerFixture<float>, framework::DatasetMode::NIGHTLY, combine(combine(combine(datasets::LargeFullyConnectedLayerDataset(), FullyConnectedParameters),
138 framework::dataset::make("DataType", DataType::F32)),
139 ActivationFunctionsDataset))
Anthony Barbier7068f992017-10-26 15:23:08 +0100140{
141 // Validate output
Michele Di Giorgiob71d2242019-11-25 14:22:31 +0000142 validate(GCAccessor(_target), _reference, rel_tolerance_f32, 0, abs_tolerance_f32);
Anthony Barbier7068f992017-10-26 15:23:08 +0100143}
144TEST_SUITE_END()
145TEST_SUITE_END()
146
147TEST_SUITE_END()
148TEST_SUITE_END()
149} // namespace validation
150} // namespace test
151} // namespace arm_compute