blob: dbfe4e269fe7fdd4d0c0b96e30513c11415c05e4 [file] [log] [blame]
Sanghoon Leef47bfb92018-01-23 15:16:47 +00001/*
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 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/CL/CLTensor.h"
26#include "arm_compute/runtime/CL/CLTensorAllocator.h"
27#include "arm_compute/runtime/CL/functions/CLLocallyConnectedLayer.h"
28#include "tests/CL/CLAccessor.h"
29#include "tests/PaddingCalculator.h"
30#include "tests/datasets/LocallyConnectedDataset.h"
31#include "tests/framework/Asserts.h"
32#include "tests/framework/Macros.h"
33#include "tests/framework/datasets/Datasets.h"
34#include "tests/validation/Validation.h"
35#include "tests/validation/fixtures/LocallyConnectedFixture.h"
36
37namespace arm_compute
38{
39namespace test
40{
41namespace validation
42{
43namespace
44{
Georgios Pinitas4d0a8d62018-05-16 11:58:33 +010045constexpr AbsoluteTolerance<float> atolerance_f32(0.00001f); /**< Absolute Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
46RelativeTolerance<float> rtolerance_f32(0.05f); /**< Tolerance value for comparing reference's output against implementation's output for DataType::F32 */
Sanghoon Leef47bfb92018-01-23 15:16:47 +000047} // namespace
48
49TEST_SUITE(CL)
50TEST_SUITE(LocallyConnected)
51
Alex Gilday27c08ab2018-02-22 11:36:16 +000052// *INDENT-OFF*
53// clang-format off
54DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010055 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Mismatching data type input/weights
56 TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Mismatching data type input/bias
57 TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Mismatching data type input/output
58 TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Mismatching shape input/weights
59 TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Mismatching shape input/bias
60 TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Mismatching shape input/output
61 TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Asymmetric padding
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +010062 TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32), // Padding required
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010063 TensorInfo(TensorShape(23U, 27U, 5U), 1, DataType::F32)
Alex Gilday27c08ab2018-02-22 11:36:16 +000064 }),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010065 framework::dataset::make("WeightsInfo",{ TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F16),
66 TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F32),
67 TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F32),
68 TensorInfo(TensorShape(3U, 3U, 5U, 21U, 274U), 1, DataType::F32),
69 TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F32),
70 TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F32),
71 TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F32),
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +010072 TensorInfo(TensorShape(3U, 3U, 5U, 21U, 275U), 1, DataType::F32),
73 TensorInfo(TensorShape(1U, 3U, 5U, 21U, 575U), 1, DataType::F32)
Alex Gilday27c08ab2018-02-22 11:36:16 +000074 })),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010075 framework::dataset::make("BiasInfo", { TensorInfo(TensorShape(21U, 275U), 1, DataType::F32),
76 TensorInfo(TensorShape(21U, 275U), 1, DataType::F16),
77 TensorInfo(TensorShape(21U, 275U), 1, DataType::F32),
78 TensorInfo(TensorShape(21U, 275U), 1, DataType::F32),
79 TensorInfo(TensorShape(21U, 274U), 1, DataType::F32),
80 TensorInfo(TensorShape(21U, 275U), 1, DataType::F32),
81 TensorInfo(TensorShape(21U, 275U), 1, DataType::F32),
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +010082 TensorInfo(TensorShape(21U, 275U), 1, DataType::F32),
83 TensorInfo(TensorShape(21U, 575U), 1, DataType::F32)
Alex Gilday27c08ab2018-02-22 11:36:16 +000084 })),
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010085 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32),
86 TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32),
87 TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F16),
88 TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32),
89 TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32),
90 TensorInfo(TensorShape(11U, 25U, 22U), 1, DataType::F32),
91 TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32),
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +010092 TensorInfo(TensorShape(11U, 25U, 21U), 1, DataType::F32),
93 TensorInfo(TensorShape(23U, 25U, 21U), 1, DataType::F32)
Alex Gilday27c08ab2018-02-22 11:36:16 +000094 })),
95 framework::dataset::make("PadStride", { PadStrideInfo(2, 1, 0, 0),
96 PadStrideInfo(2, 1, 0, 0),
97 PadStrideInfo(2, 1, 0, 0),
98 PadStrideInfo(2, 1, 0, 0),
99 PadStrideInfo(2, 1, 0, 0),
100 PadStrideInfo(2, 1, 0, 0),
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100101 PadStrideInfo(2, 1, 1, 0),
102 PadStrideInfo(2, 1, 0, 0),
103 PadStrideInfo(1, 1, 0, 0)
Alex Gilday27c08ab2018-02-22 11:36:16 +0000104 })),
Gian Marco Iodice215b4ea2018-06-28 16:29:29 +0100105 framework::dataset::make("Expected", { false, false, false, false, false, false, false, false, true })),
Alex Gilday27c08ab2018-02-22 11:36:16 +0000106 input_info, weights_info, bias_info, output_info, conv_info, expected)
107{
108 bool is_valid = bool(CLLocallyConnectedLayer::validate(&input_info.clone()->set_is_resizable(false),
109 &weights_info.clone()->set_is_resizable(false),
110 &bias_info.clone()->set_is_resizable(false),
111 &output_info.clone()->set_is_resizable(false),
112 conv_info));
113 ARM_COMPUTE_EXPECT(is_valid == expected, framework::LogLevel::ERRORS);
114}
115// clang-format on
116// *INDENT-ON*
117
Sanghoon Leef47bfb92018-01-23 15:16:47 +0000118DATA_TEST_CASE(Configuration, framework::DatasetMode::ALL, combine(framework::dataset::concat(datasets::SmallLocallyConnectedDataset(), datasets::LargeLocallyConnectedDataset()),
119 framework::dataset::make("DataType", DataType::F32)),
Alex Gilday7da29b62018-03-23 14:16:00 +0000120 src_shape, weights_shape, bias_shape, dst_shape, info, dilation, data_type)
Sanghoon Leef47bfb92018-01-23 15:16:47 +0000121{
Alex Gilday7da29b62018-03-23 14:16:00 +0000122 ARM_COMPUTE_UNUSED(dilation);
123
Sanghoon Leef47bfb92018-01-23 15:16:47 +0000124 // Create tensors
125 CLTensor src = create_tensor<CLTensor>(src_shape, data_type);
126 CLTensor weights = create_tensor<CLTensor>(weights_shape, data_type);
127 CLTensor bias = create_tensor<CLTensor>(bias_shape, data_type);
128 CLTensor dst = create_tensor<CLTensor>(dst_shape, data_type);
129
130 ARM_COMPUTE_EXPECT(src.info()->is_resizable(), framework::LogLevel::ERRORS);
131 ARM_COMPUTE_EXPECT(weights.info()->is_resizable(), framework::LogLevel::ERRORS);
132 ARM_COMPUTE_EXPECT(bias.info()->is_resizable(), framework::LogLevel::ERRORS);
133 ARM_COMPUTE_EXPECT(dst.info()->is_resizable(), framework::LogLevel::ERRORS);
134
135 // Create and configure function.
136 CLLocallyConnectedLayer lc;
137 lc.configure(&src, &weights, &bias, &dst, info);
138
139 // Validate valid region
140 const ValidRegion dst_valid_region = shape_to_valid_region(dst_shape);
141 validate(dst.info()->valid_region(), dst_valid_region);
142}
143
144template <typename T>
145using CLLocallyConnectedFixture = LocallyConnectedValidationFixture<CLTensor, CLAccessor, CLLocallyConnectedLayer, T>;
146FIXTURE_DATA_TEST_CASE(RunSmall, CLLocallyConnectedFixture<float>, framework::DatasetMode::PRECOMMIT, combine(datasets::SmallLocallyConnectedDataset(),
147 framework::dataset::make("DataType",
148 DataType::F32)))
149{
150 // Validate output
Georgios Pinitas4d0a8d62018-05-16 11:58:33 +0100151 validate(CLAccessor(_target), _reference, rtolerance_f32, 0.f, atolerance_f32);
Sanghoon Leef47bfb92018-01-23 15:16:47 +0000152}
153
154FIXTURE_DATA_TEST_CASE(RunLarge, CLLocallyConnectedFixture<float>, framework::DatasetMode::NIGHTLY, combine(datasets::LargeLocallyConnectedDataset(),
155 framework::dataset::make("DataType",
156 DataType::F32)))
157{
158 // Validate output
Georgios Pinitas4d0a8d62018-05-16 11:58:33 +0100159 validate(CLAccessor(_target), _reference, rtolerance_f32, 0.f, atolerance_f32);
Sanghoon Leef47bfb92018-01-23 15:16:47 +0000160}
161TEST_SUITE_END()
162TEST_SUITE_END()
163} // namespace validation
164} // namespace test
165} // namespace arm_compute