Compute Library
 21.02
NELSTMLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2020 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  */
25 
26 #include "arm_compute/core/Utils.h"
42 
43 namespace arm_compute
44 {
46 using namespace arm_compute::utils::info_helpers;
47 
48 NELSTMLayer::~NELSTMLayer() = default;
49 
50 NELSTMLayer::NELSTMLayer(std::shared_ptr<IMemoryManager> memory_manager)
51  : _memory_group(std::move(memory_manager)), _fully_connected_input_gate(), _accum_input_gate1(), _subtract_input_gate(), _pixelwise_mul_input_gate(), _activation_input_gate(),
52  _fully_connected_forget_gate(), _accum_forget_gate1(), _pixelwise_mul_forget_gate(), _activation_forget_gate(), _fully_connected_cell_state(), _gemm_cell_state1(), _transpose_cell_state(),
53  _accum_cell_state1(), _accum_cell_state2(), _pixelwise_mul_cell_state1(), _activation_cell_state(), _cell_clip(), _pixelwise_mul_cell_state2(), _fully_connected_output(),
54  _pixelwise_mul_output_state1(), _accum_output1(), _activation_output(), _activation_output_state(), _pixelwise_mul_output_state2(), _fully_connected_output_state(), _projection_clip(),
55  _copy_cell_state(), _copy_output(), _concat_scratch_buffer(), _concat_inputs_forget_gate(), _concat_weights_forget_gate(), _concat_weights_input_gate(), _concat_weights_output(),
56  _mean_std_norm_input_gate(), _pixelwise_mul_input_gate_coeff(), _accum_input_gate_bias(), _mean_std_norm_forget_gate(), _pixelwise_mul_forget_gate_coeff(), _accum_forget_gate_bias(),
57  _mean_std_norm_cell_gate(), _pixelwise_mul_cell_gate_coeff(), _accum_cell_gate_bias(), _mean_std_norm_output_gate(), _pixelwise_mul_output_gate_coeff(), _accum_output_gate_bias(), _input_gate_out1(),
58  _input_gate_out2(), _input_gate_out3(), _input_gate_out4(), _forget_gate_out1(), _forget_gate_out2(), _forget_gate_out3(), _forget_gate_out4(), _forget_gate_out5(), _forget_gate_out6(),
59  _cell_state_out1(), _cell_state_out2(), _cell_state_out3(), _cell_state_out4(), _cell_state_out5(), _output1(), _output2(), _output3(), _output4(), _cell_state_activation(), _output_state1(), _ones(),
60  _input_layer_norm_out1(), _input_layer_norm_out2(), _forget_layer_norm_out1(), _forget_layer_norm_out2(), _cell_layer_norm_out1(), _cell_layer_norm_out2(), _output_layer_norm_out1(),
61  _output_layer_norm_out2(), _run_peephole_opt(false), _run_cifg_opt(false), _perform_cell_clipping(false), _has_projection_weights(false), _perform_projection_clipping(false), _is_prepared(false),
62  _is_layer_norm_lstm(false)
63 {
64 }
65 
69  const ITensor *forget_gate_bias, const ITensor *cell_bias, const ITensor *output_gate_bias,
70  const ITensor *output_state_in, const ITensor *cell_state_in,
71  ITensor *scratch_buffer, ITensor *output_state_out, ITensor *cell_state_out, ITensor *output,
72  const LSTMParams<ITensor> &lstm_params, const ActivationLayerInfo &activation_info, float cell_threshold, float projection_threshold)
73 {
75  input_to_forget_weights, input_to_cell_weights, input_to_output_weights,
76  recurrent_to_forget_weights, recurrent_to_cell_weights, recurrent_to_output_weights,
77  forget_gate_bias, cell_bias, output_gate_bias,
78  output_state_in, cell_state_in,
79  scratch_buffer, output_state_out, cell_state_out, output);
80 
81  _is_layer_norm_lstm = lstm_params.use_layer_norm();
82 
83  // Set lstm parameters
84  LSTMParams<ITensorInfo> lstm_params_info{};
85  build_lstm_params_tensor_info(lstm_params, &lstm_params_info);
86 
87  // Validate
88  ARM_COMPUTE_ERROR_THROW_ON(NELSTMLayer::validate(input->info(), input_to_forget_weights->info(),
89  input_to_cell_weights->info(), input_to_output_weights->info(),
90  recurrent_to_forget_weights->info(), recurrent_to_cell_weights->info(), recurrent_to_output_weights->info(),
91  forget_gate_bias->info(), cell_bias->info(), output_gate_bias->info(),
92  output_state_in->info(), cell_state_in->info(),
93  scratch_buffer->info(), output_state_out->info(), cell_state_out->info(), output->info(),
94  lstm_params_info, activation_info, cell_threshold, projection_threshold));
95 
96  const TensorShape cell_state_shape = cell_state_in->info()->tensor_shape();
97 
98  // Configure block that calculates the forget gate
99  // forget_gate = Activation(input * input_to_forget_weights + output_state_in * recurrent_to_forget_weights + PixelWiseMul(cell_state, cell_to_forget_weights) + forget_gate_bias)
100  // We optimize this as follows:
101  // forget_gate = Activation( (input,output_state_in) * (input_to_forget_weights,recurrent_to_forget_weights) + PixelWiseMul(cell_state, cell_to_forget_weights) + forget_gate_bias)
102  _forget_gate_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
103  _forget_gate_out3.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
104  _forget_gate_out5.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
105 
106  std::vector<const ITensor *> inputs_vector;
107  inputs_vector.emplace_back(input);
108  inputs_vector.emplace_back(output_state_in);
109 
110  _memory_group.manage(&_forget_gate_out2);
111  _concat_inputs_forget_gate.configure(inputs_vector, &_forget_gate_out2, Window::DimX);
112 
113  std::vector<const ITensor *> weights_vector;
114 
115  weights_vector.emplace_back(input_to_forget_weights);
116  weights_vector.emplace_back(recurrent_to_forget_weights);
117 
118  _concat_weights_forget_gate.configure(weights_vector, &_forget_gate_out6, Window::DimX);
119 
120  _memory_group.manage(&_forget_gate_out5);
121  _fully_connected_forget_gate.configure(&_forget_gate_out2, &_forget_gate_out6, (_is_layer_norm_lstm) ? nullptr : forget_gate_bias, &_forget_gate_out5);
122  _memory_group.manage(&_forget_gate_out1);
123  _memory_group.manage(&_forget_gate_out3);
124  _forget_gate_out6.allocator()->allocate();
125 
126  Tensor *forget_gate_out = &_forget_gate_out5;
127  if(lstm_params.has_peephole_opt())
128  {
129  _forget_gate_out4.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
130 
131  _run_peephole_opt = true;
132  _memory_group.manage(&_forget_gate_out4);
133  _pixelwise_mul_forget_gate.configure(cell_state_in, lstm_params.cell_to_forget_weights(), &_forget_gate_out4, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO);
134  _accum_forget_gate1.configure(&_forget_gate_out5, &_forget_gate_out4, &_forget_gate_out3, ConvertPolicy::SATURATE);
135  _forget_gate_out4.allocator()->allocate();
136  _forget_gate_out5.allocator()->allocate();
137  forget_gate_out = &_forget_gate_out3;
138  }
139  else
140  {
141  _forget_gate_out3.allocator()->allocate();
142  }
143  if(_is_layer_norm_lstm)
144  {
145  _forget_layer_norm_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
146  _forget_layer_norm_out2.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
147  _memory_group.manage(&_forget_layer_norm_out1);
148  _memory_group.manage(&_forget_layer_norm_out2);
149  _mean_std_norm_forget_gate.configure(forget_gate_out);
150  _pixelwise_mul_forget_gate_coeff.configure(forget_gate_out, lstm_params.forget_layer_norm_weights(), &_forget_layer_norm_out1, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO);
151  // forget_gate_out is going to be reassigned, so allocate the tensor that it was assigned to before
152  forget_gate_out->allocator()->allocate();
153  _accum_forget_gate_bias.configure(&_forget_layer_norm_out1, forget_gate_bias, &_forget_layer_norm_out2, ConvertPolicy::SATURATE);
154  _forget_layer_norm_out1.allocator()->allocate();
155  forget_gate_out = &_forget_layer_norm_out2;
156  }
157  _activation_forget_gate.configure(forget_gate_out, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC));
158 
159  // Configure block that calculates the input gate
160  // input_gate = Activation(input * input_to_input_weights + output_state * recurrent_to_input_weights + PixelWiseMul(cell_state, cell_to_input_weights) + input_gate_bias), without CIFG
161  // input_gate = 1 - forget_gate, with CIFG
162  // We optimize this as follows:
163  // input_gate = Activation((input,output_state) * (input_to_input_weights,recurrent_to_input_weights) + PixelWiseMul(cell_state, cell_to_input_weights) + input_gate_bias), without CIFG
164  _input_gate_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
165  Tensor *input_gate_out = &_input_gate_out1;
166  if(lstm_params.has_cifg_opt())
167  {
168  _memory_group.manage(&_input_gate_out1);
169  _ones.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
170  _subtract_input_gate.configure(&_ones, forget_gate_out, &_input_gate_out1, ConvertPolicy::SATURATE);
171  _ones.allocator()->allocate();
172  _run_cifg_opt = true;
173  }
174  else
175  {
176  _input_gate_out3.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
177  _input_gate_out4.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
178 
179  std::vector<const ITensor *> lstm_weights;
180  lstm_weights.emplace_back(lstm_params.input_to_input_weights());
181  lstm_weights.emplace_back(lstm_params.recurrent_to_input_weights());
182 
183  _concat_weights_input_gate.configure(lstm_weights, &_input_gate_out2, Window::DimX);
184 
185  _memory_group.manage(&_input_gate_out1);
186  _memory_group.manage(&_input_gate_out4);
187 
188  _fully_connected_input_gate.configure(&_forget_gate_out2, &_input_gate_out2, (_is_layer_norm_lstm) ? nullptr : lstm_params.input_gate_bias(), &_input_gate_out3);
189  _input_gate_out2.allocator()->allocate();
190  input_gate_out = &_input_gate_out3;
191 
192  if(_run_peephole_opt)
193  {
194  _memory_group.manage(&_input_gate_out4);
195  _pixelwise_mul_input_gate.configure(cell_state_in, lstm_params.cell_to_input_weights(), &_input_gate_out4, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO);
196  _accum_input_gate1.configure(&_input_gate_out3, &_input_gate_out4, &_input_gate_out1, ConvertPolicy::SATURATE);
197  _input_gate_out3.allocator()->allocate();
198  _input_gate_out4.allocator()->allocate();
199  input_gate_out = &_input_gate_out1;
200  }
201  else
202  {
203  _input_gate_out1.allocator()->allocate();
204  }
205 
206  if(_is_layer_norm_lstm)
207  {
208  _input_layer_norm_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
209  _input_layer_norm_out2.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
210  _memory_group.manage(&_input_layer_norm_out1);
211  _memory_group.manage(&_input_layer_norm_out2);
212  _mean_std_norm_input_gate.configure(input_gate_out);
213  _pixelwise_mul_input_gate_coeff.configure(input_gate_out, lstm_params.input_layer_norm_weights(), &_input_layer_norm_out1, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO);
214  // input_gate_out is going to be reassigned, so allocate the tensor that it was assigned to before
215  input_gate_out->allocator()->allocate();
216  _accum_input_gate_bias.configure(&_input_layer_norm_out1, lstm_params.input_gate_bias(), &_input_layer_norm_out2, ConvertPolicy::SATURATE);
217  _input_layer_norm_out1.allocator()->allocate();
218  input_gate_out = &_input_layer_norm_out2;
219  }
220  _activation_input_gate.configure(input_gate_out, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC));
221  }
222 
223  // Configure block that calculates the cell state
224  // cell_state = Clip((PixelwiseMul(input_gate, Activation(input * input_to_cell_weights + output_state_in * recurrent_to_cell_weights + cell_bias)) + PixelwiseMul(forget_gate, cell_state)), cell_threshold)
225  TensorShape cell_state1_shape = compute_transposed_shape(*recurrent_to_output_weights->info());
226  _cell_state_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
227  _cell_state_out2.allocator()->init(TensorInfo(cell_state1_shape, 1, input->info()->data_type()));
228  _cell_state_out3.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
229  _cell_state_out4.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
230  _cell_state_out5.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
231 
232  _memory_group.manage(&_cell_state_out1);
233  _fully_connected_cell_state.configure(input, input_to_cell_weights, (_is_layer_norm_lstm) ? nullptr : cell_bias, &_cell_state_out1);
234  _memory_group.manage(&_cell_state_out2);
235  _transpose_cell_state.configure(recurrent_to_cell_weights, &_cell_state_out2);
236  _memory_group.manage(&_cell_state_out3);
237  _gemm_cell_state1.configure(output_state_in, &_cell_state_out2, nullptr, &_cell_state_out3, 1.f, 0.f);
238  _cell_state_out2.allocator()->allocate();
239  _memory_group.manage(&_cell_state_out4);
240  _accum_cell_state1.configure(&_cell_state_out1, &_cell_state_out3, &_cell_state_out4, ConvertPolicy::SATURATE);
241  Tensor *cell_state_out_ptr = &_cell_state_out4;
242  if(_is_layer_norm_lstm)
243  {
244  _cell_layer_norm_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
245  _cell_layer_norm_out2.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
246  _memory_group.manage(&_cell_layer_norm_out1);
247  _memory_group.manage(&_cell_layer_norm_out2);
248  _mean_std_norm_cell_gate.configure(cell_state_out_ptr);
249  _pixelwise_mul_cell_gate_coeff.configure(cell_state_out_ptr, lstm_params.cell_layer_norm_weights(), &_cell_layer_norm_out1, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO);
250  // cell_state_out_ptr is going to be reassigned, so allocate the tensor that it was assigned to before
251  cell_state_out_ptr->allocator()->allocate();
252  _accum_cell_gate_bias.configure(&_cell_layer_norm_out1, cell_bias, &_cell_layer_norm_out2, ConvertPolicy::SATURATE);
253  _cell_layer_norm_out1.allocator()->allocate();
254  cell_state_out_ptr = &_cell_layer_norm_out2;
255  }
256  _activation_cell_state.configure(cell_state_out_ptr, nullptr, activation_info);
257  _memory_group.manage(&_cell_state_out5);
258  _pixelwise_mul_cell_state1.configure(cell_state_out_ptr, input_gate_out, &_cell_state_out5, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO);
259  cell_state_out_ptr->allocator()->allocate();
260  _pixelwise_mul_cell_state2.configure(forget_gate_out, cell_state_in, &_cell_state_out3, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO);
261  _accum_cell_state2.configure(&_cell_state_out5, &_cell_state_out3, &_cell_state_out1, ConvertPolicy::SATURATE);
262  _cell_state_out3.allocator()->allocate();
263  _cell_state_out5.allocator()->allocate();
264  // Perform clipping
265  if(cell_threshold != 0.f)
266  {
267  _perform_cell_clipping = true;
268  _cell_clip.configure(&_cell_state_out1, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -cell_threshold, cell_threshold));
269  }
270 
271  // Configure block that calculates the output
272  // output_state_out = Activation(input * input_to_output_weights + output_state_in * recurrent_to_output_weights + PixelWiseMul(cell_state, cell_to_output_weights) + output_gate_bias)
273  // We optimize this as follows:
274  // output_state_out = Activation( (input,output_state_in) * (input_to_output_weights, recurrent_to_output_weights) + PixelWiseMul(cell_state, cell_to_output_weights) + output_gate_bias)
275  _output1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
276  _output4.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
277 
278  std::vector<const ITensor *> in_out_weights;
279  in_out_weights.emplace_back(input_to_output_weights);
280  in_out_weights.emplace_back(recurrent_to_output_weights);
281 
282  _concat_weights_output.configure(in_out_weights, &_output2, Window::DimX);
283  _memory_group.manage(&_output1);
284  _memory_group.manage(&_output4);
285 
286  _fully_connected_output.configure(&_forget_gate_out2, &_output2, (_is_layer_norm_lstm) ? nullptr : output_gate_bias, &_output4);
287 
288  _output2.allocator()->allocate();
289  _forget_gate_out2.allocator()->allocate();
290 
291  Tensor *output_gate_out = &_output4;
292  if(lstm_params.has_peephole_opt())
293  {
294  _output3.allocator()->init(TensorInfo(_cell_state_out1.info()->tensor_shape(), 1, input->info()->data_type()));
295 
296  _memory_group.manage(&_output3);
297  _pixelwise_mul_output_state1.configure(&_cell_state_out1, lstm_params.cell_to_output_weights(), &_output3, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO);
298  _accum_output1.configure(&_output4, &_output3, &_output1, ConvertPolicy::SATURATE);
299  _output4.allocator()->allocate();
300  output_gate_out = &_output1;
301 
302  // Allocate intermediate buffers
303  _output3.allocator()->allocate();
304  }
305  else
306  {
307  _output1.allocator()->allocate();
308  }
309  if(_is_layer_norm_lstm)
310  {
311  _output_layer_norm_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
312  _output_layer_norm_out2.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
313  _memory_group.manage(&_output_layer_norm_out1);
314  _memory_group.manage(&_output_layer_norm_out2);
315  _mean_std_norm_output_gate.configure(output_gate_out);
316  _pixelwise_mul_output_gate_coeff.configure(output_gate_out, lstm_params.output_layer_norm_weights(), &_output_layer_norm_out1, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO);
317  // output_gate_out is going to be reassigned, so allocate the tensor that it was assigned to before
318  output_gate_out->allocator()->allocate();
319  _accum_output_gate_bias.configure(&_output_layer_norm_out1, output_gate_bias, &_output_layer_norm_out2, ConvertPolicy::SATURATE);
320  _output_layer_norm_out1.allocator()->allocate();
321  output_gate_out = &_output_layer_norm_out2;
322  }
323  _activation_output.configure(output_gate_out, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC));
324 
325  // Configure block that calculates the output state
326  /** lstm_res = PixelwiseMul(output, Activation(cell_state))
327  *
328  * -- Clip(lstm_res * projection_weights + projection_bias, projection_threshold) , if there is a projection
329  * /
330  * output_state = --
331  * \
332  * -- lstm_res , otherwise
333  */
334  ITensor *output_state_out_tmp = lstm_params.has_projection() ? &_output_state1 : output_state_out;
335  _cell_state_activation.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
336  _output_state1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
337 
338  _memory_group.manage(&_cell_state_activation);
339  _activation_output_state.configure(&_cell_state_out1, &_cell_state_activation, activation_info);
340  _pixelwise_mul_output_state2.configure(&_cell_state_activation, output_gate_out, output_state_out_tmp, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_ZERO);
341  _cell_state_activation.allocator()->allocate();
342  output_gate_out->allocator()->allocate();
343 
344  if(lstm_params.has_projection())
345  {
346  _has_projection_weights = true;
347  _fully_connected_output_state.configure(output_state_out_tmp, lstm_params.projection_weights(), lstm_params.projection_bias(), output_state_out);
348  _output_state1.allocator()->allocate();
349  // Perform clipping
350  if(projection_threshold != 0.f)
351  {
352  _perform_projection_clipping = true;
353  _projection_clip.configure(output_state_out, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -projection_threshold, projection_threshold));
354  }
355  }
356 
357  // Copy cell state and output
358  _copy_cell_state.configure(&_cell_state_out1, cell_state_out);
359  _copy_output.configure(output_state_out, output);
360 
361  // Vector for holding the tensors to store in scratch buffer
362  std::vector<const ITensor *> scratch_inputs;
363  if(!lstm_params.has_cifg_opt())
364  {
365  scratch_inputs.emplace_back(input_gate_out);
366  }
367  scratch_inputs.emplace_back(&_cell_state_out1);
368  scratch_inputs.emplace_back(forget_gate_out);
369  scratch_inputs.emplace_back(output_gate_out);
370  _concat_scratch_buffer.configure(scratch_inputs, scratch_buffer, Window::DimX);
371  input_gate_out->allocator()->allocate();
372  _cell_state_out1.allocator()->allocate();
373  forget_gate_out->allocator()->allocate();
374  output_gate_out->allocator()->allocate();
375 }
376 
380  const ITensorInfo *forget_gate_bias, const ITensorInfo *cell_bias, const ITensorInfo *output_gate_bias,
381  const ITensorInfo *output_state_in, const ITensorInfo *cell_state_in,
382  const ITensorInfo *scratch_buffer, const ITensorInfo *output_state_out, const ITensorInfo *cell_state_out, const ITensorInfo *output,
383  const LSTMParams<ITensorInfo> &lstm_params, const ActivationLayerInfo &activation_info, float cell_threshold, float projection_threshold)
384 {
386  input_to_forget_weights, input_to_cell_weights, input_to_output_weights,
387  recurrent_to_forget_weights, recurrent_to_cell_weights, recurrent_to_output_weights,
388  forget_gate_bias, cell_bias, output_gate_bias,
389  output_state_in, cell_state_in,
390  scratch_buffer, output_state_out, cell_state_out, output);
391 
392  // Check data types
395  input_to_forget_weights, input_to_cell_weights, input_to_output_weights,
396  recurrent_to_forget_weights, recurrent_to_cell_weights, recurrent_to_output_weights,
397  forget_gate_bias, cell_bias, output_gate_bias,
398  output_state_in, cell_state_in,
399  scratch_buffer, output_state_out, cell_state_out, output);
400 
401  // Check dimensions
403  ARM_COMPUTE_RETURN_ERROR_ON(input_to_forget_weights->num_dimensions() > 2);
404  ARM_COMPUTE_RETURN_ERROR_ON(input_to_cell_weights->num_dimensions() > 2);
405  ARM_COMPUTE_RETURN_ERROR_ON(input_to_output_weights->num_dimensions() > 2);
406  ARM_COMPUTE_RETURN_ERROR_ON(recurrent_to_forget_weights->num_dimensions() > 2);
407  ARM_COMPUTE_RETURN_ERROR_ON(recurrent_to_cell_weights->num_dimensions() > 2);
408  ARM_COMPUTE_RETURN_ERROR_ON(recurrent_to_output_weights->num_dimensions() > 2);
409  ARM_COMPUTE_RETURN_ERROR_ON(forget_gate_bias->num_dimensions() > 1);
411  ARM_COMPUTE_RETURN_ERROR_ON(output_gate_bias->num_dimensions() > 1);
412  ARM_COMPUTE_RETURN_ERROR_ON(output_state_in->num_dimensions() > 2);
413  ARM_COMPUTE_RETURN_ERROR_ON(cell_state_in->num_dimensions() > 2);
414  ARM_COMPUTE_RETURN_ERROR_ON(scratch_buffer->num_dimensions() > 2);
415  ARM_COMPUTE_RETURN_ERROR_ON(output_state_out->num_dimensions() > 2);
416  ARM_COMPUTE_RETURN_ERROR_ON(cell_state_out->num_dimensions() > 2);
418  ARM_COMPUTE_RETURN_ERROR_ON(cell_bias->dimension(0) * 4 != scratch_buffer->dimension(0)
419  && cell_bias->dimension(0) * 3 != scratch_buffer->dimension(0));
420 
421  const unsigned int num_batches = input->dimension(1);
422  const unsigned int num_cells = input_to_output_weights->dimension(1);
423 
424  if(lstm_params.use_layer_norm())
425  {
426  // If CIFG is used, input layer normalization weights tensor is omitted
427  if(lstm_params.has_cifg_opt())
428  {
429  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.input_layer_norm_weights() != nullptr);
430  }
431  else
432  {
434  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.input_layer_norm_weights()->num_dimensions() > 1);
435  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.input_layer_norm_weights()->dimension(0) != num_cells);
437  }
438 
441  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.forget_layer_norm_weights()->num_dimensions() > 1);
442  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.cell_layer_norm_weights()->num_dimensions() > 1);
443  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.output_layer_norm_weights()->num_dimensions() > 1);
444  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.forget_layer_norm_weights()->dimension(0) != num_cells);
445  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.cell_layer_norm_weights()->dimension(0) != num_cells);
446  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.output_layer_norm_weights()->dimension(0) != num_cells);
447  }
448 
449  // Check peephole optimization
450  if(lstm_params.has_peephole_opt())
451  {
453  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.cell_to_forget_weights()->num_dimensions() > 1);
454  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.cell_to_output_weights()->num_dimensions() > 1);
455  }
456 
457  TensorShape units_out_transposed_shape = compute_transposed_shape(*recurrent_to_output_weights);
458  TensorShape num_units_transposed_shape = compute_transposed_shape(*forget_gate_bias);
459  const TensorInfo units_out_transposed_info = TensorInfo(units_out_transposed_shape, 1, input->data_type());
460  const TensorInfo num_units_transposed_info = TensorInfo(num_units_transposed_shape, 1, input->data_type());
461 
462  TensorInfo input_gate = TensorInfo(TensorShape(num_cells, num_batches), 1, input->data_type());
463  TensorInfo forget_gate = TensorInfo(TensorShape(num_cells, num_batches), 1, input->data_type());
464  TensorInfo output_gate_tmp = TensorInfo(TensorShape(num_cells, num_batches), 1, input->data_type());
465  TensorInfo cell_state_tmp = TensorInfo(TensorShape(num_cells, num_batches), 1, input->data_type());
466 
467  std::vector<const ITensorInfo *> inputs_vector;
468  inputs_vector.emplace_back(input);
469  inputs_vector.emplace_back(output_state_in);
471  TensorInfo forget_gate_concat = TensorInfo(concat_shape, 1, input->data_type());
472  ARM_COMPUTE_RETURN_ON_ERROR(NEConcatenateLayer::validate(inputs_vector, &forget_gate_concat, Window::DimX));
473 
474  // Validate forget gate
475  ARM_COMPUTE_RETURN_ON_ERROR(NEFullyConnectedLayer::validate(input, input_to_forget_weights, (lstm_params.use_layer_norm()) ? nullptr : forget_gate_bias, &forget_gate));
476 
477  if(lstm_params.has_peephole_opt())
478  {
480  ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAddition::validate(&forget_gate, &forget_gate, &forget_gate, ConvertPolicy::SATURATE));
481  }
482  if(lstm_params.use_layer_norm())
483  {
487  ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAddition::validate(&forget_gate, forget_gate_bias, &forget_gate, ConvertPolicy::SATURATE));
488  }
490 
491  // Validate input gate
492  if(!lstm_params.has_cifg_opt())
493  {
495  lstm_params.recurrent_to_input_weights(),
496  lstm_params.input_gate_bias());
497  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.input_to_input_weights()->num_dimensions() > 2);
498  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.recurrent_to_input_weights()->num_dimensions() > 2);
499  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.input_gate_bias()->num_dimensions() > 1);
500 
501  std::vector<const ITensorInfo *> lstm_weights;
502  lstm_weights.emplace_back(lstm_params.input_to_input_weights());
503  lstm_weights.emplace_back(lstm_params.recurrent_to_input_weights());
504  TensorShape lstm_weights_concat_shape = arm_compute::misc::shape_calculator::calculate_concatenate_shape(lstm_weights, 0);
505  TensorInfo lstm_gate_concat = TensorInfo(lstm_weights_concat_shape, 1, input->data_type());
506  ARM_COMPUTE_RETURN_ON_ERROR(NEConcatenateLayer::validate(lstm_weights, &lstm_gate_concat, Window::DimX));
507  ARM_COMPUTE_RETURN_ON_ERROR(NEFullyConnectedLayer::validate(input, lstm_params.input_to_input_weights(), (lstm_params.use_layer_norm()) ? nullptr : lstm_params.input_gate_bias(), &input_gate));
508 
509  if(lstm_params.has_peephole_opt())
510  {
512  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.cell_to_input_weights()->num_dimensions() > 1);
514  ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAddition::validate(&input_gate, &input_gate, &input_gate, ConvertPolicy::SATURATE));
515  }
516 
517  if(lstm_params.use_layer_norm())
518  {
522  }
524  }
525  else
526  {
528  }
529 
530  // Validate cell state
531  ARM_COMPUTE_RETURN_ON_ERROR(NEFullyConnectedLayer::validate(input, input_to_cell_weights, (lstm_params.use_layer_norm()) ? nullptr : cell_bias, &cell_state_tmp));
532  ARM_COMPUTE_RETURN_ON_ERROR(NEGEMM::validate(output_state_in, &units_out_transposed_info, nullptr, &cell_state_tmp, 1.f, 0.f, GEMMInfo()));
533  ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAddition::validate(&cell_state_tmp, &cell_state_tmp, &cell_state_tmp, ConvertPolicy::SATURATE));
534  if(lstm_params.use_layer_norm())
535  {
539  ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAddition::validate(&cell_state_tmp, cell_bias, &cell_state_tmp, ConvertPolicy::SATURATE));
540  }
541  ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayer::validate(&cell_state_tmp, nullptr, activation_info));
544  ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAddition::validate(&cell_state_tmp, &cell_state_tmp, &cell_state_tmp, ConvertPolicy::SATURATE));
545  if(cell_threshold != 0.f)
546  {
548  cell_threshold)));
549  }
550 
551  // Validate output gate tmp
552  std::vector<const ITensorInfo *> in_out_weights;
553  in_out_weights.emplace_back(input_to_output_weights);
554  in_out_weights.emplace_back(recurrent_to_output_weights);
555  TensorShape in_out_weights_concat_shape = arm_compute::misc::shape_calculator::calculate_concatenate_shape(in_out_weights, 0);
556  TensorInfo in_out_gate_concat = TensorInfo(in_out_weights_concat_shape, 1, input->data_type());
557  ARM_COMPUTE_RETURN_ON_ERROR(NEConcatenateLayer::validate(in_out_weights, &in_out_gate_concat, Window::DimX));
558 
559  ARM_COMPUTE_RETURN_ON_ERROR(NEFullyConnectedLayer::validate(input, input_to_output_weights, (lstm_params.use_layer_norm()) ? nullptr : output_gate_bias, &output_gate_tmp));
560 
561  if(lstm_params.has_peephole_opt())
562  {
565  ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAddition::validate(&output_gate_tmp, &output_gate_tmp, &output_gate_tmp, ConvertPolicy::SATURATE));
566  }
567  if(lstm_params.use_layer_norm())
568  {
572  ARM_COMPUTE_RETURN_ON_ERROR(NEArithmeticAddition::validate(&output_gate_tmp, output_gate_bias, &output_gate_tmp, ConvertPolicy::SATURATE));
573  }
575 
576  // Validate output state
577  ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayer::validate(&cell_state_tmp, &cell_state_tmp, activation_info));
579  if(lstm_params.has_projection())
580  {
581  ARM_COMPUTE_RETURN_ON_ERROR(NEFullyConnectedLayer::validate(&output_gate_tmp, lstm_params.projection_weights(), lstm_params.projection_bias(), output_state_out));
582  if(projection_threshold != 0.f)
583  {
584  ARM_COMPUTE_RETURN_ON_ERROR(NEActivationLayer::validate(output_state_out, output_state_out,
585  ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -projection_threshold, projection_threshold)));
586  }
587  }
588 
589  // Validate copy kernel
590  ARM_COMPUTE_RETURN_ON_ERROR(NECopy::validate(&cell_state_tmp, cell_state_out));
591  ARM_COMPUTE_RETURN_ON_ERROR(NECopy::validate(output_state_out, output));
592 
593  // Validate scratch concatenation
594  std::vector<const ITensorInfo *> inputs_vector_info_raw;
595  if(!lstm_params.has_cifg_opt())
596  {
597  inputs_vector_info_raw.push_back(&input_gate);
598  }
599  inputs_vector_info_raw.push_back(&cell_state_tmp);
600  inputs_vector_info_raw.push_back(&forget_gate);
601  inputs_vector_info_raw.push_back(&output_gate_tmp);
602 
603  ARM_COMPUTE_RETURN_ON_ERROR(NEConcatenateLayer::validate(inputs_vector_info_raw, scratch_buffer, Window::DimX));
604  return Status{};
605 }
606 
608 {
609  prepare();
610 
611  MemoryGroupResourceScope scope_mg(_memory_group);
612 
613  _concat_inputs_forget_gate.run();
614  _fully_connected_forget_gate.run();
615 
616  if(_run_peephole_opt)
617  {
618  _pixelwise_mul_forget_gate.run();
619  _accum_forget_gate1.run();
620  }
621  if(_is_layer_norm_lstm)
622  {
623  _mean_std_norm_forget_gate.run();
624  _pixelwise_mul_forget_gate_coeff.run();
625  _accum_forget_gate_bias.run();
626  }
627  _activation_forget_gate.run();
628 
629  if(_run_cifg_opt)
630  {
631  if(_ones.info()->data_type() == DataType::F16)
632  {
633  std::fill_n(reinterpret_cast<half *>(_ones.buffer()), _ones.info()->total_size() / _ones.info()->element_size(), 1);
634  }
635  else
636  {
637  std::fill_n(reinterpret_cast<float *>(_ones.buffer()), _ones.info()->total_size() / _ones.info()->element_size(), 1);
638  }
639  _subtract_input_gate.run();
640  }
641  else
642  {
643  _fully_connected_input_gate.run();
644 
645  if(_run_peephole_opt)
646  {
647  _pixelwise_mul_input_gate.run();
648  _accum_input_gate1.run();
649  }
650 
651  if(_is_layer_norm_lstm)
652  {
653  _mean_std_norm_input_gate.run();
654  _pixelwise_mul_input_gate_coeff.run();
655  _accum_input_gate_bias.run();
656  }
657  _activation_input_gate.run();
658  }
659 
660  _fully_connected_cell_state.run();
661  _transpose_cell_state.run();
662  _gemm_cell_state1.run();
663  _accum_cell_state1.run();
664  if(_is_layer_norm_lstm)
665  {
666  _mean_std_norm_cell_gate.run();
667  _pixelwise_mul_cell_gate_coeff.run();
668  _accum_cell_gate_bias.run();
669  }
670  _activation_cell_state.run();
671  _pixelwise_mul_cell_state1.run();
672  _pixelwise_mul_cell_state2.run();
673  _accum_cell_state2.run();
674 
675  if(_perform_cell_clipping)
676  {
677  _cell_clip.run();
678  }
679 
680  _fully_connected_output.run();
681  if(_run_peephole_opt)
682  {
683  _pixelwise_mul_output_state1.run();
684  _accum_output1.run();
685  }
686  if(_is_layer_norm_lstm)
687  {
688  _mean_std_norm_output_gate.run();
689  _pixelwise_mul_output_gate_coeff.run();
690  _accum_output_gate_bias.run();
691  }
692  _activation_output.run();
693 
694  _activation_output_state.run();
695  _pixelwise_mul_output_state2.run();
696 
697  if(_has_projection_weights)
698  {
699  _fully_connected_output_state.run();
700  if(_perform_projection_clipping)
701  {
702  _projection_clip.run();
703  }
704  }
705 
706  _copy_cell_state.run();
707  _copy_output.run();
708 
709  _concat_scratch_buffer.run();
710 }
711 
713 {
714  if(!_is_prepared)
715  {
716  _concat_weights_forget_gate.run();
717  if(!_run_cifg_opt)
718  {
719  _concat_weights_input_gate.run();
720  }
721  _concat_weights_output.run();
722  _is_prepared = true;
723  }
724 }
725 } // namespace arm_compute
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
const T * projection_weights() const
Definition: LSTMParams.h:227
void run() override
Run the kernels contained in the function.
const T * input_to_input_weights() const
Definition: LSTMParams.h:197
void run() override
Run the kernels contained in the function.
Shape of a tensor.
Definition: TensorShape.h:39
void run() override final
Run the kernels contained in the function.
bool use_layer_norm() const
Definition: LSTMParams.h:312
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of NEArithmeticAddition.
void init(const TensorAllocator &allocator, const Coordinates &coords, TensorInfo &sub_info)
Shares the same backing memory with another tensor allocator, while the tensor info might be differen...
static Status validate(const ITensorInfo *input, const ITensorInfo *input_to_forget_weights, const ITensorInfo *input_to_cell_weights, const ITensorInfo *input_to_output_weights, const ITensorInfo *recurrent_to_forget_weights, const ITensorInfo *recurrent_to_cell_weights, const ITensorInfo *recurrent_to_output_weights, const ITensorInfo *forget_gate_bias, const ITensorInfo *cell_bias, const ITensorInfo *output_gate_bias, const ITensorInfo *output_state_in, const ITensorInfo *cell_state_in, const ITensorInfo *scratch_buffer, const ITensorInfo *output_state_out, const ITensorInfo *cell_state_out, const ITensorInfo *output, const LSTMParams< ITensorInfo > &lstm_params, const ActivationLayerInfo &activation_info, float cell_threshold=0.f, float projection_threshold=0.f)
Static function to check if given info will lead to a valid configuration of NELSTMLayer.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
bool has_peephole_opt() const
Definition: LSTMParams.h:297
T * forget_layer_norm_weights() const
Definition: LSTMParams.h:242
void build_lstm_params_tensor_info(const LSTMParams< T > &lstm_params, LSTMParams< ITensorInfo > *lstm_params_info)
Build LSTMParams<ITensorInfo> object by extracting the metadata from each tensor. ...
Definition: InfoHelpers.h:71
void run() override
Run the kernels contained in the function.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204
virtual DataType data_type() const =0
Data type used for each element of the tensor.
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info)
[NEActivationLayer snippet]
void run() override
Run the kernels contained in the function.
1 channel, 1 F32 per channel
bool has_cifg_opt() const
Definition: LSTMParams.h:307
void configure(const ITensor *input, const ITensor *input_to_forget_weights, const ITensor *input_to_cell_weights, const ITensor *input_to_output_weights, const ITensor *recurrent_to_forget_weights, const ITensor *recurrent_to_cell_weights, const ITensor *recurrent_to_output_weights, const ITensor *forget_gate_bias, const ITensor *cell_bias, const ITensor *output_gate_bias, const ITensor *output_state_in, const ITensor *cell_state_in, ITensor *scratch_buffer, ITensor *output_state_out, ITensor *cell_state_out, ITensor *output, const LSTMParams< ITensor > &lstm_params, const ActivationLayerInfo &activation_info, float cell_threshold=0.f, float projection_threshold=0.f)
Initialize function&#39;s tensors.
Definition: NELSTMLayer.cpp:66
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
T * cell_to_input_weights() const
Definition: LSTMParams.h:207
Status class.
Definition: Error.h:52
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Definition: Error.h:296
Activation Layer Information class.
Definition: Types.h:1550
Interface for Neon tensor.
Definition: ITensor.h:36
void configure(const ITensor *input1, const ITensor *input2, ITensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Initialise the kernel&#39;s inputs, output and conversion policy.
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
TensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: Tensor.cpp:48
ITensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: Tensor.cpp:33
TensorShape compute_transposed_shape(const ITensorInfo &input)
Calculate the transposed shape of a tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:163
void configure(ITensor *input, ITensor *output=nullptr, float epsilon=1e-8f)
Initialise the function&#39;s input and outputs.
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
void configure(const ITensor *input, ITensor *output)
Initialise the kernel&#39;s inputs and output.
Definition: NETranspose.cpp:32
const T * recurrent_to_input_weights() const
Definition: LSTMParams.h:202
void run() override
Run the kernels contained in the function.
const T * projection_bias() const
Definition: LSTMParams.h:232
static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *output, float alpha, float beta, const GEMMInfo &gemm_info=GEMMInfo())
Static function to check if given info will lead to a valid configuration of NEGEMM.
Definition: NEGEMM.cpp:190
void run() override
Run the kernels contained in the function.
Definition: NEGEMM.cpp:309
T * output_layer_norm_weights() const
Definition: LSTMParams.h:252
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
void run() override
Run the kernels contained in the function.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
void configure(const ITensor *input1, const ITensor *input2, ITensor *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Initialise the kernel&#39;s inputs, output and convertion policy.
static Status validate(const ITensorInfo *input, const ITensorInfo *output)
Static function to check if given info will lead to a valid configuration of NECopy.
Definition: NECopy.cpp:58
void configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, FullyConnectedLayerInfo fc_info=FullyConnectedLayerInfo())
Set the input and output tensors.
void allocate() override
Allocate size specified by TensorInfo of CPU memory.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Basic implementation of the tensor interface.
Definition: Tensor.h:37
virtual size_t element_size() const =0
Element size in bytes calculated as data_size() * num_channels()
NELSTMLayer(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Default constructor.
Definition: NELSTMLayer.cpp:50
void prepare() override
Prepare the function for executing.
T * cell_to_forget_weights() const
Definition: LSTMParams.h:217
bool has_projection() const
Definition: LSTMParams.h:302
T * cell_to_output_weights() const
Definition: LSTMParams.h:222
void configure(const ITensor *input1, const ITensor *input2, ITensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Initialise the kernel&#39;s inputs, output and conversion policy.
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of NEPixelWiseMultiplicatio...
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.
T * input_layer_norm_weights() const
Definition: LSTMParams.h:237
void run() override
Run the kernels contained in the function.
static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, FullyConnectedLayerInfo fc_info=FullyConnectedLayerInfo())
Static function to check if given info will lead to a valid configuration of NEFullyConnectedLayer.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:545
void run() override
Run the kernels contained in the function.
Definition: NECopy.cpp:66
void configure(const ITensor *a, const ITensor *b, const ITensor *c, ITensor *d, float alpha, float beta, const GEMMInfo &gemm_info=GEMMInfo())
Initialise the kernel&#39;s inputs, output.
Definition: NEGEMM.cpp:72
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:792
void configure(ITensor *input, ITensor *output, ActivationLayerInfo activation_info)
[NEActivationLayer snippet]
const T * input_gate_bias() const
Definition: LSTMParams.h:212
uint8_t * buffer() const override
Interface to be implemented by the child class to return a pointer to CPU memory. ...
Definition: Tensor.cpp:43
~NELSTMLayer()
Default destructor.
static Status validate(const ITensorInfo *input, const ITensorInfo *output=nullptr, float epsilon=1e-8f)
Static function to check if given info will lead to a valid configuration of NEMeanStdDevNormalizatio...
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:45
GEMM information class.
Definition: Types.h:2003
T * cell_layer_norm_weights() const
Definition: LSTMParams.h:247
void configure(ITensor *input, ITensor *output)
Initialise the function&#39;s source and destination.
Definition: NECopy.cpp:48
static Status validate(const std::vector< const ITensorInfo *> &inputs_vector, const ITensorInfo *output, size_t axis)
Static function to check if given info will lead to a valid configuration of NEConcatenateLayer.
void configure(std::vector< const ITensor *> inputs_vector, ITensor *output, size_t axis)
Initialise the kernel&#39;s inputs vector and output.
TensorShape calculate_concatenate_shape(const std::vector< T *> &input, size_t axis)
Calculate the concatenate output shape of the concatenate operation along a single axis...
Truncates the least significant values that are lost in operations.
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ConvertPolicy policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Static function to check if given info will lead to a valid configuration of NEArithmeticSubtraction...