blob: b7e43b347015da4b6de3c4ac9da9360cf6fb3d60 [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#ifndef ARM_COMPUTE_TEST_LSTM_LAYER_FIXTURE
25#define ARM_COMPUTE_TEST_LSTM_LAYER_FIXTURE
26
27#include "tests/Globals.h"
28#include "tests/framework/Asserts.h"
29#include "tests/framework/Fixture.h"
30#include "tests/validation/reference/ActivationLayer.h"
31#include "tests/validation/reference/ArithmeticAddition.h"
32#include "tests/validation/reference/ArithmeticSubtraction.h"
33#include "tests/validation/reference/FullyConnectedLayer.h"
34#include "tests/validation/reference/GEMM.h"
35#include "tests/validation/reference/PixelWiseMultiplication.h"
36#include "tests/validation/reference/Transpose.h"
37
38namespace arm_compute
39{
40namespace test
41{
42namespace validation
43{
44template <typename TensorType, typename AccessorType, typename FunctionType, typename FunctionParams, typename T>
45class LSTMLayerValidationFixture : public framework::Fixture
46{
47public:
48 template <typename...>
49 void setup(TensorShape input_shape, TensorShape input_weights_shape, TensorShape recurrent_weights_shape, TensorShape cell_bias_shape, TensorShape output_cell_shape, TensorShape output_shape,
50 TensorShape scratch_shape, ActivationLayerInfo info, float cell_threshold, float projection_threshold, DataType data_type, bool projection_opt, bool peephole_opt)
51 {
52 _target = compute_target(input_shape, input_weights_shape, recurrent_weights_shape, cell_bias_shape, output_cell_shape, output_shape, scratch_shape, info, cell_threshold, projection_threshold,
53 data_type, projection_opt, peephole_opt);
54 _reference = compute_reference(input_shape, input_weights_shape, recurrent_weights_shape, cell_bias_shape, output_cell_shape, output_shape, scratch_shape, info, cell_threshold, projection_threshold,
55 data_type, projection_opt, peephole_opt);
56 }
57
58protected:
59 template <typename U>
60 void fill(U &&tensor, int i)
61 {
62 std::uniform_real_distribution<> distribution(-1.0f, 1.0f);
63 library->fill(tensor, distribution, i);
64 }
65 template <typename U>
66 void fill_custom_val(U &&tensor, float num, int i)
67 {
68 std::uniform_real_distribution<> distribution(num, num);
69 library->fill(tensor, distribution, i);
70 }
71 TensorType compute_target(const TensorShape &input_shape, const TensorShape &input_weights_shape, const TensorShape &recurrent_weights_shape, const TensorShape &cell_bias_shape,
72 const TensorShape &output_cell_shape, const TensorShape &output_shape, const TensorShape &scratch_shape, ActivationLayerInfo info, float cell_threshold,
73 float projection_threshold, DataType data_type, bool projection_opt, bool peephole_opt)
74 {
75 // Create projection bias shape
76 TensorShape projection_bias_shape{};
77 projection_bias_shape.set(0, output_shape.x());
78
79 // Create tensors
80 TensorType input = create_tensor<TensorType>(input_shape, data_type);
81 TensorType input_to_forget_w = create_tensor<TensorType>(input_weights_shape, data_type);
82 TensorType input_to_cell_w = create_tensor<TensorType>(input_weights_shape, data_type);
83 TensorType input_to_output_w = create_tensor<TensorType>(input_weights_shape, data_type);
84 TensorType recurrent_to_forget_w = create_tensor<TensorType>(recurrent_weights_shape, data_type);
85 TensorType recurrent_to_cell_w = create_tensor<TensorType>(recurrent_weights_shape, data_type);
86 TensorType recurrent_to_output_w = create_tensor<TensorType>(recurrent_weights_shape, data_type);
87 TensorType forget_gate_bias = create_tensor<TensorType>(cell_bias_shape, data_type);
88 TensorType cell_bias = create_tensor<TensorType>(cell_bias_shape, data_type);
89 TensorType output_gate_bias = create_tensor<TensorType>(cell_bias_shape, data_type);
90 TensorType output_state = create_tensor<TensorType>(output_shape, data_type);
91 TensorType cell_state = create_tensor<TensorType>(output_cell_shape, data_type);
92 TensorType scratch = create_tensor<TensorType>(scratch_shape, data_type);
93 TensorType output = create_tensor<TensorType>(output_shape, data_type);
94 TensorType input_to_input_w;
95 TensorType recurrent_to_input_w;
96 TensorType cell_to_input_w;
97 TensorType cell_to_forget_w;
98 TensorType input_gate_bias;
99 TensorType cell_to_output_w;
100 TensorType projection_w;
101 TensorType projection_bias;
102
103 bool cifg_opt = scratch_shape.x() == cell_bias_shape.x() * 4 ? true : false;
104
105 FunctionParams lstm_params;
106
107 if(!cifg_opt)
108 {
109 input_to_input_w = create_tensor<TensorType>(input_weights_shape, data_type);
110 recurrent_to_input_w = create_tensor<TensorType>(recurrent_weights_shape, data_type);
111 cell_to_input_w = create_tensor<TensorType>(cell_bias_shape, data_type);
112 input_gate_bias = create_tensor<TensorType>(cell_bias_shape, data_type);
113 lstm_params.set_cifg_params(&input_to_input_w, &recurrent_to_input_w, &cell_to_input_w, &input_gate_bias);
114 }
115
116 if(peephole_opt)
117 {
118 if(cifg_opt)
119 {
120 cell_to_input_w = create_tensor<TensorType>(cell_bias_shape, data_type);
121 }
122 cell_to_forget_w = create_tensor<TensorType>(cell_bias_shape, data_type);
123 cell_to_output_w = create_tensor<TensorType>(cell_bias_shape, data_type);
124 lstm_params.set_peephole_params(&cell_to_input_w, &cell_to_forget_w, &cell_to_output_w);
125 }
126
127 if(projection_opt)
128 {
129 projection_w = create_tensor<TensorType>(recurrent_weights_shape, data_type);
130 projection_bias = create_tensor<TensorType>(projection_bias_shape, data_type);
131 lstm_params.set_projection_params(&projection_w, &projection_bias);
132 }
133
134 // Create and configure function
135 FunctionType lstm;
136 lstm.configure(&input, &input_to_forget_w, &input_to_cell_w, &input_to_output_w, &recurrent_to_forget_w,
137 &recurrent_to_cell_w, &recurrent_to_output_w, &forget_gate_bias, &cell_bias, &output_gate_bias, &output_state, &cell_state,
138 &scratch, &output, lstm_params, info, cell_threshold, projection_threshold);
139
140 ARM_COMPUTE_EXPECT(input.info()->is_resizable(), framework::LogLevel::ERRORS);
141 ARM_COMPUTE_EXPECT(input_to_forget_w.info()->is_resizable(), framework::LogLevel::ERRORS);
142 ARM_COMPUTE_EXPECT(input_to_cell_w.info()->is_resizable(), framework::LogLevel::ERRORS);
143 ARM_COMPUTE_EXPECT(input_to_output_w.info()->is_resizable(), framework::LogLevel::ERRORS);
144 ARM_COMPUTE_EXPECT(recurrent_to_forget_w.info()->is_resizable(), framework::LogLevel::ERRORS);
145 ARM_COMPUTE_EXPECT(recurrent_to_cell_w.info()->is_resizable(), framework::LogLevel::ERRORS);
146 ARM_COMPUTE_EXPECT(recurrent_to_output_w.info()->is_resizable(), framework::LogLevel::ERRORS);
147 ARM_COMPUTE_EXPECT(forget_gate_bias.info()->is_resizable(), framework::LogLevel::ERRORS);
148 ARM_COMPUTE_EXPECT(cell_bias.info()->is_resizable(), framework::LogLevel::ERRORS);
149 ARM_COMPUTE_EXPECT(output_gate_bias.info()->is_resizable(), framework::LogLevel::ERRORS);
150 ARM_COMPUTE_EXPECT(output_state.info()->is_resizable(), framework::LogLevel::ERRORS);
151 ARM_COMPUTE_EXPECT(cell_state.info()->is_resizable(), framework::LogLevel::ERRORS);
152 ARM_COMPUTE_EXPECT(scratch.info()->is_resizable(), framework::LogLevel::ERRORS);
153 ARM_COMPUTE_EXPECT(output.info()->is_resizable(), framework::LogLevel::ERRORS);
154
155 // Allocate tensors
156 input.allocator()->allocate();
157 input_to_forget_w.allocator()->allocate();
158 input_to_cell_w.allocator()->allocate();
159 input_to_output_w.allocator()->allocate();
160 recurrent_to_forget_w.allocator()->allocate();
161 recurrent_to_cell_w.allocator()->allocate();
162 recurrent_to_output_w.allocator()->allocate();
163 forget_gate_bias.allocator()->allocate();
164 cell_bias.allocator()->allocate();
165 output_gate_bias.allocator()->allocate();
166 output_state.allocator()->allocate();
167 cell_state.allocator()->allocate();
168 scratch.allocator()->allocate();
169 output.allocator()->allocate();
170
171 ARM_COMPUTE_EXPECT(!input.info()->is_resizable(), framework::LogLevel::ERRORS);
172 ARM_COMPUTE_EXPECT(!input_to_forget_w.info()->is_resizable(), framework::LogLevel::ERRORS);
173 ARM_COMPUTE_EXPECT(!input_to_cell_w.info()->is_resizable(), framework::LogLevel::ERRORS);
174 ARM_COMPUTE_EXPECT(!input_to_output_w.info()->is_resizable(), framework::LogLevel::ERRORS);
175 ARM_COMPUTE_EXPECT(!recurrent_to_forget_w.info()->is_resizable(), framework::LogLevel::ERRORS);
176 ARM_COMPUTE_EXPECT(!recurrent_to_cell_w.info()->is_resizable(), framework::LogLevel::ERRORS);
177 ARM_COMPUTE_EXPECT(!recurrent_to_output_w.info()->is_resizable(), framework::LogLevel::ERRORS);
178 ARM_COMPUTE_EXPECT(!forget_gate_bias.info()->is_resizable(), framework::LogLevel::ERRORS);
179 ARM_COMPUTE_EXPECT(!cell_bias.info()->is_resizable(), framework::LogLevel::ERRORS);
180 ARM_COMPUTE_EXPECT(!output_gate_bias.info()->is_resizable(), framework::LogLevel::ERRORS);
181 ARM_COMPUTE_EXPECT(!output_state.info()->is_resizable(), framework::LogLevel::ERRORS);
182 ARM_COMPUTE_EXPECT(!cell_state.info()->is_resizable(), framework::LogLevel::ERRORS);
183 ARM_COMPUTE_EXPECT(!scratch.info()->is_resizable(), framework::LogLevel::ERRORS);
184 ARM_COMPUTE_EXPECT(!output.info()->is_resizable(), framework::LogLevel::ERRORS);
185
186 // Fill tensors
187 fill(AccessorType(input), 0);
188 fill(AccessorType(input_to_forget_w), 1);
189 fill(AccessorType(input_to_cell_w), 2);
190 fill(AccessorType(input_to_output_w), 3);
191 fill(AccessorType(recurrent_to_forget_w), 4);
192 fill(AccessorType(recurrent_to_cell_w), 5);
193 fill(AccessorType(recurrent_to_output_w), 6);
194 fill(AccessorType(forget_gate_bias), 7);
195 fill(AccessorType(cell_bias), 8);
196 fill(AccessorType(output_gate_bias), 9);
197 fill(AccessorType(output_state), 10);
198 fill(AccessorType(cell_state), 11);
199 fill(AccessorType(scratch), 12);
200
201 if(!cifg_opt)
202 {
203 ARM_COMPUTE_EXPECT(input_to_input_w.info()->is_resizable(), framework::LogLevel::ERRORS);
204 ARM_COMPUTE_EXPECT(recurrent_to_input_w.info()->is_resizable(), framework::LogLevel::ERRORS);
205 ARM_COMPUTE_EXPECT(cell_to_input_w.info()->is_resizable(), framework::LogLevel::ERRORS);
206 ARM_COMPUTE_EXPECT(input_gate_bias.info()->is_resizable(), framework::LogLevel::ERRORS);
207 input_to_input_w.allocator()->allocate();
208 recurrent_to_input_w.allocator()->allocate();
209 cell_to_input_w.allocator()->allocate();
210 input_gate_bias.allocator()->allocate();
211 ARM_COMPUTE_EXPECT(!input_to_input_w.info()->is_resizable(), framework::LogLevel::ERRORS);
212 ARM_COMPUTE_EXPECT(!recurrent_to_input_w.info()->is_resizable(), framework::LogLevel::ERRORS);
213 ARM_COMPUTE_EXPECT(!cell_to_input_w.info()->is_resizable(), framework::LogLevel::ERRORS);
214 ARM_COMPUTE_EXPECT(!input_gate_bias.info()->is_resizable(), framework::LogLevel::ERRORS);
215 fill(AccessorType(input_to_input_w), 13);
216 fill(AccessorType(recurrent_to_input_w), 14);
217 fill(AccessorType(cell_to_input_w), 15);
218 fill(AccessorType(recurrent_to_input_w), 16);
219 fill(AccessorType(input_gate_bias), 17);
220 }
221
222 if(peephole_opt)
223 {
224 if(cifg_opt)
225 {
226 ARM_COMPUTE_EXPECT(cell_to_input_w.info()->is_resizable(), framework::LogLevel::ERRORS);
227 cell_to_input_w.allocator()->allocate();
228 ARM_COMPUTE_EXPECT(!cell_to_input_w.info()->is_resizable(), framework::LogLevel::ERRORS);
229 fill(AccessorType(cell_to_input_w), 15);
230 }
231 ARM_COMPUTE_EXPECT(cell_to_forget_w.info()->is_resizable(), framework::LogLevel::ERRORS);
232 ARM_COMPUTE_EXPECT(cell_to_output_w.info()->is_resizable(), framework::LogLevel::ERRORS);
233 cell_to_forget_w.allocator()->allocate();
234 cell_to_output_w.allocator()->allocate();
235 ARM_COMPUTE_EXPECT(!cell_to_forget_w.info()->is_resizable(), framework::LogLevel::ERRORS);
236 ARM_COMPUTE_EXPECT(!cell_to_output_w.info()->is_resizable(), framework::LogLevel::ERRORS);
237 fill(AccessorType(cell_to_output_w), 18);
238 }
239
240 if(projection_opt)
241 {
242 ARM_COMPUTE_EXPECT(projection_w.info()->is_resizable(), framework::LogLevel::ERRORS);
243 ARM_COMPUTE_EXPECT(projection_bias.info()->is_resizable(), framework::LogLevel::ERRORS);
244
245 projection_w.allocator()->allocate();
246 projection_bias.allocator()->allocate();
247
248 ARM_COMPUTE_EXPECT(!projection_w.info()->is_resizable(), framework::LogLevel::ERRORS);
249 ARM_COMPUTE_EXPECT(!projection_bias.info()->is_resizable(), framework::LogLevel::ERRORS);
250
251 fill(AccessorType(projection_w), 19);
252 fill(AccessorType(projection_bias), 20);
253 }
254
255 // Compute function
256 lstm.run();
257
258 return output;
259 }
260
261 SimpleTensor<T> compute_reference(const TensorShape &input_shape, const TensorShape &input_weights_shape, const TensorShape &recurrent_weights_shape, const TensorShape &cell_bias_shape,
262 const TensorShape &output_cell_shape, const TensorShape &output_shape, const TensorShape &scratch_shape, ActivationLayerInfo info, float cell_threshold,
263 float projection_threshold, DataType data_type, bool projection_opt, bool peephole_opt)
264 {
265 // Create projection bias shape
266 TensorShape projection_bias_shape{};
267 projection_bias_shape.set(0, output_shape.x());
268
269 TensorShape gemm_shape{ 1, output_shape.y() };
270 SimpleTensor<T> gemm_out{ gemm_shape, data_type };
271
272 // Create reference
273 SimpleTensor<T> input{ input_shape, data_type };
274 SimpleTensor<T> input_to_input_w{ input_weights_shape, data_type };
275 SimpleTensor<T> input_to_forget_w{ input_weights_shape, data_type };
276 SimpleTensor<T> input_to_cell_w{ input_weights_shape, data_type };
277 SimpleTensor<T> input_to_output_w{ input_weights_shape, data_type };
278 SimpleTensor<T> recurrent_to_input_w{ recurrent_weights_shape, data_type };
279 SimpleTensor<T> recurrent_to_forget_w{ recurrent_weights_shape, data_type };
280 SimpleTensor<T> recurrent_to_cell_w{ recurrent_weights_shape, data_type };
281 SimpleTensor<T> recurrent_to_output_w{ recurrent_weights_shape, data_type };
282 SimpleTensor<T> cell_to_input_w{ cell_bias_shape, data_type };
283 SimpleTensor<T> cell_to_forget_w{ cell_bias_shape, data_type };
284 SimpleTensor<T> cell_to_output_w{ cell_bias_shape, data_type };
285 SimpleTensor<T> input_gate_bias{ cell_bias_shape, data_type };
286 SimpleTensor<T> forget_gate_bias{ cell_bias_shape, data_type };
287 SimpleTensor<T> cell_bias{ cell_bias_shape, data_type };
288 SimpleTensor<T> output_gate_bias{ cell_bias_shape, data_type };
289 SimpleTensor<T> projection_w{ recurrent_weights_shape, data_type };
290 SimpleTensor<T> projection_bias{ projection_bias_shape, data_type };
291 SimpleTensor<T> output_state{ output_shape, data_type };
292 SimpleTensor<T> cell_state{ output_cell_shape, data_type };
293 SimpleTensor<T> scratch{ scratch_shape, data_type };
294 SimpleTensor<T> output{ output_shape, data_type };
295
296 // Fill reference
297 fill(input, 0);
298 fill(input_to_forget_w, 1);
299 fill(input_to_cell_w, 2);
300 fill(input_to_output_w, 3);
301 fill(recurrent_to_forget_w, 4);
302 fill(recurrent_to_cell_w, 5);
303 fill(recurrent_to_output_w, 6);
304 fill(forget_gate_bias, 7);
305 fill(cell_bias, 8);
306 fill(output_gate_bias, 9);
307 fill(output_state, 10);
308 fill(cell_state, 11);
309 fill(scratch, 12);
310 fill(input_to_input_w, 13);
311 fill(recurrent_to_input_w, 14);
312 fill(cell_to_input_w, 15);
313 fill(recurrent_to_input_w, 16);
314 fill(input_gate_bias, 17);
315 fill(cell_to_output_w, 18);
316 fill(projection_w, 19);
317 fill(projection_bias, 20);
318
319 bool cifg_opt = scratch_shape.x() == cell_bias_shape.x() * 4 ? true : false;
320
321 // Compute forget_gate
322 SimpleTensor<T> fully_connected_forget = reference::fully_connected_layer(input, input_to_forget_w, forget_gate_bias, output_cell_shape);
323 SimpleTensor<T> transposed_weights = reference::transpose(recurrent_to_forget_w);
324 SimpleTensor<T> gemm = reference::gemm(output_state, transposed_weights, cell_state, 1.f, 0.f);
325 SimpleTensor<T> forget_gate = reference::arithmetic_addition(fully_connected_forget, gemm, data_type, ConvertPolicy::SATURATE);
326
327 if(peephole_opt)
328 {
329 transposed_weights = reference::transpose(cell_to_forget_w);
330 gemm = reference::gemm(cell_state, transposed_weights, gemm_out, 1.f, 0.f);
331 forget_gate = reference::arithmetic_addition(forget_gate, gemm, data_type, ConvertPolicy::SATURATE);
332 }
333
334 forget_gate = reference::activation_layer(forget_gate, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC));
335
336 // Compute input_gate
337 SimpleTensor<T> input_gate;
338 if(cifg_opt)
339 {
340 SimpleTensor<T> ones{ cell_bias_shape, data_type };
341 fill_custom_val(ones, 1.f, 0);
342 input_gate = reference::arithmetic_subtraction<T, T, T>(ones, forget_gate, data_type, ConvertPolicy::SATURATE);
343 }
344 else
345 {
346 SimpleTensor<T> fully_connected_input = reference::fully_connected_layer(input, input_to_input_w, input_gate_bias, output_cell_shape);
347 transposed_weights = reference::transpose(recurrent_to_input_w);
348 gemm = reference::gemm(output_state, transposed_weights, cell_state, 1.f, 0.f);
349 input_gate = reference::arithmetic_addition(fully_connected_input, gemm, data_type, ConvertPolicy::SATURATE);
350 transposed_weights = reference::transpose(cell_to_input_w);
351 gemm = reference::gemm(cell_state, transposed_weights, gemm_out, 1.f, 0.f);
352 input_gate = reference::arithmetic_addition(input_gate, gemm, data_type, ConvertPolicy::SATURATE);
353 input_gate = reference::activation_layer(input_gate, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC));
354 }
355
356 // Compute cell_state
357 SimpleTensor<T> fully_connected_cell_state = reference::fully_connected_layer(input, input_to_cell_w, cell_bias, output_cell_shape);
358 transposed_weights = reference::transpose(recurrent_to_cell_w);
359 gemm = reference::gemm(output_state, transposed_weights, cell_state, 1.f, 0.f);
360 SimpleTensor<T> pixelwise_mul = reference::pixel_wise_multiplication(cell_state, forget_gate, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN);
361 cell_state = reference::arithmetic_addition(fully_connected_cell_state, gemm, data_type, ConvertPolicy::SATURATE);
362 cell_state = reference::activation_layer(cell_state, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC));
363 cell_state = reference::pixel_wise_multiplication(cell_state, input_gate, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN);
364 cell_state = reference::arithmetic_addition(cell_state, pixelwise_mul, data_type, ConvertPolicy::SATURATE);
365 if(cell_threshold != 0.f)
366 {
367 cell_state = reference::activation_layer(cell_state, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -cell_threshold, cell_threshold));
368 }
369
370 // Compute output
371 SimpleTensor<T> fully_connected_output = reference::fully_connected_layer(input, input_to_output_w, output_gate_bias, output_cell_shape);
372 transposed_weights = reference::transpose(recurrent_to_output_w);
373 gemm = reference::gemm(output_state, transposed_weights, cell_state, 1.f, 0.f);
374 output = reference::arithmetic_addition(fully_connected_output, gemm, data_type, ConvertPolicy::SATURATE);
375 if(peephole_opt)
376 {
377 transposed_weights = reference::transpose(cell_to_output_w);
378 gemm = reference::gemm(cell_state, transposed_weights, gemm_out, 1.f, 0.f);
379 output = reference::arithmetic_addition(output, gemm, data_type, ConvertPolicy::SATURATE);
380 }
381 output = reference::activation_layer(output, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC));
382
383 // Compute output state
384 SimpleTensor<T> cell_state_activation = reference::activation_layer(cell_state, info);
385 output_state = reference::pixel_wise_multiplication(output, cell_state_activation, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN);
386
387 if(projection_opt)
388 {
389 SimpleTensor<T> fully_connected_projection = reference::fully_connected_layer(output_state, projection_w, projection_bias, output_cell_shape);
390 if(projection_threshold != 0.f)
391 {
392 output_state = reference::activation_layer(fully_connected_projection, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -projection_threshold, projection_threshold));
393 }
394 }
395 return output_state;
396 }
397
398 TensorType _target{};
399 SimpleTensor<T> _reference{};
400};
401} // namespace validation
402} // namespace test
403} // namespace arm_compute
404#endif /* ARM_COMPUTE_TEST_LSTM_LAYER_FIXTURE */