blob: bd43678844d96201f5a7c3e7ff6fb964ef042f59 [file] [log] [blame]
Michalis Spyroubcedf512018-03-22 14:55:08 +00001/*
2 * Copyright (c) 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/runtime/CL/functions/CLLSTMLayer.h"
25#include "tests/CL/CLAccessor.h"
26#include "tests/PaddingCalculator.h"
27#include "tests/datasets/LSTMLayerDataset.h"
28#include "tests/framework/Asserts.h"
29#include "tests/framework/Macros.h"
30#include "tests/framework/datasets/Datasets.h"
31#include "tests/validation/Validation.h"
32#include "tests/validation/fixtures/LSTMLayerFixture.h"
33
34namespace arm_compute
35{
36namespace test
37{
38namespace validation
39{
40namespace
41{
42RelativeTolerance<float> tolerance_f32(0.001f);
43RelativeTolerance<half> tolerance_f16(half(0.1));
44} // namespace
45
46TEST_SUITE(CL)
47TEST_SUITE(LSTMLayer)
48
49// *INDENT-OFF*
50// clang-format off
51DATA_TEST_CASE(Validate, framework::DatasetMode::ALL, zip(zip(zip(zip(zip(zip(zip(zip(zip(
52 framework::dataset::make("InputInfo", { TensorInfo(TensorShape(8U, 2U), 1, DataType::U8, 0), // Wrong data type
53 TensorInfo(TensorShape(27U, 13U, 2U), 1, DataType::F32, 0), // Wrong input size
54 TensorInfo(TensorShape(8U, 2U), 1, DataType::F32, 0), // Wrong input weights size
55 TensorInfo(TensorShape(8U, 2U), 1, DataType::F32, 0), // Wrong recurrent weights size
56 TensorInfo(TensorShape(8U, 2U), 1, DataType::F32, 0), // Wrong cell bias size
57 TensorInfo(TensorShape(8U, 2U), 1, DataType::F32, 0), // Wrong cell state size
58 TensorInfo(TensorShape(8U, 2U), 1, DataType::F32, 0), // Wrong output size
59 TensorInfo(TensorShape(8U, 2U), 1, DataType::F32, 0), // Wrong scratch size
60 }),
61 framework::dataset::make("InputWeightsInfo", { TensorInfo(TensorShape(8U, 16U), 1, DataType::F32, 0),
62 TensorInfo(TensorShape(8U, 16U), 1, DataType::F32, 0),
63 TensorInfo(TensorShape(27U, 11U, 2U), 1, DataType::F32, 0),
64 TensorInfo(TensorShape(8U, 16U), 1, DataType::F32, 0),
65 TensorInfo(TensorShape(8U, 16U), 1, DataType::F32, 0),
66 TensorInfo(TensorShape(8U, 16U), 1, DataType::F32, 0),
67 TensorInfo(TensorShape(8U, 16U), 1, DataType::F32, 0),
68 TensorInfo(TensorShape(8U, 16U), 1, DataType::F32, 0),
69 })),
70 framework::dataset::make("RecurrentWeightsInfo", { TensorInfo(TensorShape(16U, 16U), 1, DataType::F32, 0),
71 TensorInfo(TensorShape(16U, 16U), 1, DataType::F32, 0),
72 TensorInfo(TensorShape(16U, 16U), 1, DataType::F32, 0),
73 TensorInfo(TensorShape(25U, 11U, 2U), 1, DataType::F32, 0),
74 TensorInfo(TensorShape(16U, 16U), 1, DataType::F32, 0),
75 TensorInfo(TensorShape(16U, 16U), 1, DataType::F32, 0),
76 TensorInfo(TensorShape(16U, 16U), 1, DataType::F32, 0),
77 TensorInfo(TensorShape(16U, 16U), 1, DataType::F32, 0),
78 })),
79 framework::dataset::make("CellBiasInfo", { TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
80 TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
81 TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
82 TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
83 TensorInfo(TensorShape(30U), 1, DataType::F32, 0),
84 TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
85 TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
86 TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
87 })),
88 framework::dataset::make("ProjectionBiasInfo", { TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
89 TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
90 TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
91 TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
92 TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
93 TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
94 TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
95 TensorInfo(TensorShape(16U), 1, DataType::F32, 0),
96 })),
97 framework::dataset::make("CellStateInfo", { TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
98 TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
99 TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
100 TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
101 TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
102 TensorInfo(TensorShape(11U), 1, DataType::F32, 0),
103 TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
104 TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
105 })),
106 framework::dataset::make("OutputInfo", { TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
107 TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
108 TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
109 TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
110 TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
111 TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
112 TensorInfo(TensorShape(11U, 13U), 1, DataType::F32, 0),
113 TensorInfo(TensorShape(16U, 2U), 1, DataType::F32, 0),
114 })),
115 framework::dataset::make("ScratchInfo", { TensorInfo(TensorShape(64U, 2U), 1, DataType::F32, 0),
116 TensorInfo(TensorShape(64U, 2U), 1, DataType::F32, 0),
117 TensorInfo(TensorShape(64U, 2U), 1, DataType::F32, 0),
118 TensorInfo(TensorShape(64U, 2U), 1, DataType::F32, 0),
119 TensorInfo(TensorShape(64U, 2U), 1, DataType::F32, 0),
120 TensorInfo(TensorShape(64U, 2U), 1, DataType::F32, 0),
121 TensorInfo(TensorShape(64U, 2U), 1, DataType::F32, 0),
122 TensorInfo(TensorShape(12U, 2U), 1, DataType::F32, 0),
123 })),
124 framework::dataset::make("ActivationInfo", { ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
125 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
126 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
127 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
128 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
129 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
130 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
131 ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::RELU),
132 })),
133 framework::dataset::make("Expected", { false, false, false, false, false, false, false, false })),
134 input_info, input_weights_info, recurrent_weights_info, cell_bias_info, projection_bias_info, cell_state_info, output_info, scratch_info, info, expected)
135{
136 LSTMParams<ITensorInfo> lstm_params_info;
137 lstm_params_info.set_peephole_params(&cell_bias_info, &cell_bias_info, &cell_bias_info)
138 .set_projection_params(&recurrent_weights_info, &projection_bias_info)
139 .set_cifg_params(&input_weights_info, &recurrent_weights_info, &cell_bias_info, &cell_bias_info);
140
141 ARM_COMPUTE_EXPECT(bool(CLLSTMLayer::validate(&input_info.clone()->set_is_resizable(false), &input_weights_info.clone()->set_is_resizable(false), &input_weights_info.clone()->set_is_resizable(false),
142 &input_weights_info.clone()->set_is_resizable(false), &recurrent_weights_info.clone()->set_is_resizable(false), &recurrent_weights_info.clone()->set_is_resizable(false),
143 &recurrent_weights_info.clone()->set_is_resizable(false), &cell_bias_info.clone()->set_is_resizable(false), &cell_bias_info.clone()->set_is_resizable(false),
144 &cell_bias_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), &cell_state_info.clone()->set_is_resizable(false),
145 &scratch_info.clone()->set_is_resizable(false), &output_info.clone()->set_is_resizable(false), lstm_params_info, info, 0.05, 0.9)) == expected, framework::LogLevel::ERRORS);
146}
147// clang-format on
148// *INDENT-ON*
149
150template <typename T>
151using CLLSTMLayerFixture = LSTMLayerValidationFixture<CLTensor, CLAccessor, CLLSTMLayer, LSTMParams<ICLTensor>, T>;
152
153TEST_SUITE(FP32)
154FIXTURE_DATA_TEST_CASE(RunSmall, CLLSTMLayerFixture<float>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallLSTMLayerDataset(), framework::dataset::make("DataType",
155 DataType::F32)),
156 framework::dataset::make("ProjectionOpt", { true, false })),
157 framework::dataset::make("PeepholeOpt", { true, false })))
158{
159 // Validate output
160 validate(CLAccessor(_target), _reference, tolerance_f32);
161}
162TEST_SUITE_END() // FP32
163
164TEST_SUITE(FP16)
165FIXTURE_DATA_TEST_CASE(RunSmall, CLLSTMLayerFixture<half>, framework::DatasetMode::ALL, combine(combine(combine(datasets::SmallLSTMLayerDataset(), framework::dataset::make("DataType", DataType::F16)),
166 framework::dataset::make("ProjectionOpt", { true, false })),
167 framework::dataset::make("PeepholeOpt", { true, false })))
168{
169 // Validate output
170 validate(CLAccessor(_target), _reference, tolerance_f16);
171}
172TEST_SUITE_END() // FP16
173TEST_SUITE_END() // LSTMLayer
174TEST_SUITE_END() // CL
175} // namespace validation
176} // namespace test
177} // namespace arm_compute