Compute Library
 21.05
CLLSTMLayer.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2021 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"
45 
46 namespace arm_compute
47 {
49 using namespace arm_compute::utils::info_helpers;
50 
51 CLLSTMLayer::CLLSTMLayer(std::shared_ptr<IMemoryManager> memory_manager)
52  : _memory_group(std::move(memory_manager)), _fully_connected_input_gate(), _accum_input_gate1(), _subtract_input_gate(), _pixelwise_mul_input_gate(), _activation_input_gate(),
53  _fully_connected_forget_gate(), _accum_forget_gate1(), _pixelwise_mul_forget_gate(), _activation_forget_gate(), _fully_connected_cell_state(), _gemm_cell_state1(),
54  _transpose_cell_state(std::make_unique<opencl::kernels::ClTransposeKernel>()), _accum_cell_state1(), _accum_cell_state2(), _pixelwise_mul_cell_state1(), _activation_cell_state(), _cell_clip(),
55  _pixelwise_mul_cell_state2(), _fully_connected_output(), _pixelwise_mul_output_state1(), _accum_output1(), _activation_output(), _activation_output_state(), _pixelwise_mul_output_state2(),
56  _fully_connected_output_state(), _projection_clip(), _copy_cell_state(), _copy_output(), _concat_scratch_buffer(), _concat_inputs_forget_gate(), _concat_weights_forget_gate(),
57  _concat_weights_input_gate(), _concat_weights_output(), _ones_fill(), _mean_std_norm_input_gate(), _pixelwise_mul_input_gate_coeff(), _accum_input_gate_bias(), _mean_std_norm_forget_gate(),
58  _pixelwise_mul_forget_gate_coeff(), _accum_forget_gate_bias(), _mean_std_norm_cell_gate(), _pixelwise_mul_cell_gate_coeff(), _accum_cell_gate_bias(), _mean_std_norm_output_gate(),
59  _pixelwise_mul_output_gate_coeff(), _accum_output_gate_bias(), _input_gate_out1(), _input_gate_out2(), _input_gate_out3(), _input_gate_out4(), _forget_gate_out1(), _forget_gate_out2(),
60  _forget_gate_out3(), _forget_gate_out4(), _forget_gate_out5(), _forget_gate_out6(), _cell_state_out1(), _cell_state_out2(), _cell_state_out3(), _cell_state_out4(), _cell_state_out5(), _output1(),
61  _output2(), _output3(), _output4(), _cell_state_activation(), _output_state1(), _ones(), _input_layer_norm_out1(), _input_layer_norm_out2(), _forget_layer_norm_out1(), _forget_layer_norm_out2(),
62  _cell_layer_norm_out1(), _cell_layer_norm_out2(), _output_layer_norm_out1(), _output_layer_norm_out2(), _run_peephole_opt(false), _run_cifg_opt(false), _perform_cell_clipping(false),
63  _has_projection_weights(false), _perform_projection_clipping(false), _is_prepared(false), _is_layer_norm_lstm(false)
64 {
65 }
66 
67 CLLSTMLayer::~CLLSTMLayer() = default;
68 
72  const ICLTensor *forget_gate_bias, const ICLTensor *cell_bias, const ICLTensor *output_gate_bias,
73  const ICLTensor *output_state_in, ICLTensor *cell_state_in,
74  ICLTensor *scratch_buffer, ICLTensor *output_state_out, ICLTensor *cell_state_out, ICLTensor *output,
75  const LSTMParams<ICLTensor> &lstm_params, const ActivationLayerInfo &activation_info, float cell_threshold, float projection_threshold)
76 {
78  recurrent_to_output_weights, forget_gate_bias, cell_bias, output_gate_bias, output_state_in, cell_state_in, scratch_buffer, output_state_out, cell_state_out, output, lstm_params, activation_info,
79  cell_threshold, projection_threshold);
80 }
81 
82 void CLLSTMLayer::configure(const CLCompileContext &compile_context, const ICLTensor *input,
85  const ICLTensor *forget_gate_bias, const ICLTensor *cell_bias, const ICLTensor *output_gate_bias,
86  const ICLTensor *output_state_in, ICLTensor *cell_state_in,
87  ICLTensor *scratch_buffer, ICLTensor *output_state_out, ICLTensor *cell_state_out, ICLTensor *output,
88  const LSTMParams<ICLTensor> &lstm_params, const ActivationLayerInfo &activation_info, float cell_threshold, float projection_threshold)
89 {
94  output_state_in, cell_state_in,
95  scratch_buffer, output_state_out, cell_state_out, output);
96 
97  _is_layer_norm_lstm = lstm_params.use_layer_norm();
98 
99  // Set lstm parameters
100  LSTMParams<ITensorInfo> lstm_params_info{};
101  build_lstm_params_tensor_info(lstm_params, &lstm_params_info);
102 
103  // Validate
107  forget_gate_bias->info(), cell_bias->info(), output_gate_bias->info(),
108  output_state_in->info(), cell_state_in->info(),
109  scratch_buffer->info(), output_state_out->info(), cell_state_out->info(), output->info(),
110  lstm_params_info, activation_info, cell_threshold, projection_threshold));
111 
112  const TensorShape cell_state_shape = cell_state_in->info()->tensor_shape();
113  // Configure block that calculates the forget gate
114  // 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)
115  // We optimize this as follows:
116  // 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
117  _forget_gate_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
118  _forget_gate_out3.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
119  _forget_gate_out5.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
120 
121  std::vector<const ICLTensor *> inputs_vector;
122  inputs_vector.emplace_back(input);
123  inputs_vector.emplace_back(output_state_in);
125  _forget_gate_out2.allocator()->init(TensorInfo(concat_shape, 1, input->info()->data_type()));
126 
127  _memory_group.manage(&_forget_gate_out2);
128  _concat_inputs_forget_gate.configure(compile_context, inputs_vector, &_forget_gate_out2, Window::DimX);
129 
130  std::vector<const ICLTensor *> weights_vector;
131 
132  weights_vector.emplace_back(input_to_forget_weights);
133  weights_vector.emplace_back(recurrent_to_forget_weights);
134  const TensorShape weights_concat_shape = arm_compute::misc::shape_calculator::calculate_concatenate_shape(weights_vector, 0);
135  _forget_gate_out6.allocator()->init(TensorInfo(weights_concat_shape, 1, input->info()->data_type()));
136 
137  _concat_weights_forget_gate.configure(compile_context, weights_vector, &_forget_gate_out6, Window::DimX);
138 
139  _memory_group.manage(&_forget_gate_out5);
140  _fully_connected_forget_gate.configure(compile_context, &_forget_gate_out2, &_forget_gate_out6, (_is_layer_norm_lstm) ? nullptr : forget_gate_bias, &_forget_gate_out5);
141  _memory_group.manage(&_forget_gate_out1);
142  _memory_group.manage(&_forget_gate_out3);
143  _forget_gate_out6.allocator()->allocate();
144 
145  CLTensor *forget_gate_out = &_forget_gate_out5;
146  if(lstm_params.has_peephole_opt())
147  {
148  _forget_gate_out4.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
149 
150  _run_peephole_opt = true;
151  _memory_group.manage(&_forget_gate_out4);
152  _pixelwise_mul_forget_gate.configure(compile_context, cell_state_in, lstm_params.cell_to_forget_weights(), &_forget_gate_out4, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN);
153  _accum_forget_gate1.configure(compile_context, &_forget_gate_out5, &_forget_gate_out4, &_forget_gate_out3, ConvertPolicy::SATURATE);
154  _forget_gate_out4.allocator()->allocate();
155  _forget_gate_out5.allocator()->allocate();
156  forget_gate_out = &_forget_gate_out3;
157  }
158  else
159  {
160  _forget_gate_out3.allocator()->allocate();
161  }
162  if(_is_layer_norm_lstm)
163  {
164  _forget_layer_norm_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
165  _forget_layer_norm_out2.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
166  _memory_group.manage(&_forget_layer_norm_out1);
167  _memory_group.manage(&_forget_layer_norm_out2);
168  _mean_std_norm_forget_gate.configure(compile_context, forget_gate_out);
169  _pixelwise_mul_forget_gate_coeff.configure(compile_context, forget_gate_out, lstm_params.forget_layer_norm_weights(), &_forget_layer_norm_out1, 1, ConvertPolicy::SATURATE,
171  // forget_gate_out is going to be reassigned, so allocate the tensor that it was assigned to before
172  forget_gate_out->allocator()->allocate();
173  _accum_forget_gate_bias.configure(compile_context, &_forget_layer_norm_out1, forget_gate_bias, &_forget_layer_norm_out2, ConvertPolicy::SATURATE);
174  _forget_layer_norm_out1.allocator()->allocate();
175  forget_gate_out = &_forget_layer_norm_out2;
176  }
177  _activation_forget_gate.configure(compile_context, forget_gate_out, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC));
178 
179  // Configure block that calculates the input gate
180  // 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
181  // input_gate = 1 - forget_gate, with CIFG
182  // We optimize this as follows:
183  // 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
184  _input_gate_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
185  CLTensor *input_gate_out = &_input_gate_out1;
186  if(lstm_params.has_cifg_opt())
187  {
188  _memory_group.manage(&_input_gate_out1);
189  _ones.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
190  _ones_fill.configure(compile_context, &_ones, PixelValue(1, _ones.info()->data_type()));
191  _subtract_input_gate.configure(compile_context, &_ones, forget_gate_out, &_input_gate_out1, ConvertPolicy::SATURATE);
192  _ones.allocator()->allocate();
193  _run_cifg_opt = true;
194  }
195  else
196  {
197  _input_gate_out3.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
198  _input_gate_out4.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
199 
200  std::vector<const ICLTensor *> lstm_weights;
201  lstm_weights.emplace_back(lstm_params.input_to_input_weights());
202  lstm_weights.emplace_back(lstm_params.recurrent_to_input_weights());
203  TensorShape lstm_weights_concat_shape = arm_compute::misc::shape_calculator::calculate_concatenate_shape(lstm_weights, 0);
204  _input_gate_out2.allocator()->init(TensorInfo(lstm_weights_concat_shape, 1, input->info()->data_type()));
205 
206  _concat_weights_input_gate.configure(compile_context, lstm_weights, &_input_gate_out2, Window::DimX);
207 
208  _memory_group.manage(&_input_gate_out1);
209 
210  _memory_group.manage(&_input_gate_out3);
211  _fully_connected_input_gate.configure(compile_context, &_forget_gate_out2, &_input_gate_out2, (_is_layer_norm_lstm) ? nullptr : lstm_params.input_gate_bias(), &_input_gate_out3);
212  _input_gate_out2.allocator()->allocate();
213 
214  input_gate_out = &_input_gate_out3;
215  if(_run_peephole_opt)
216  {
217  _memory_group.manage(&_input_gate_out4);
218  _pixelwise_mul_input_gate.configure(compile_context, cell_state_in, lstm_params.cell_to_input_weights(), &_input_gate_out4, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN);
219  _accum_input_gate1.configure(compile_context, &_input_gate_out3, &_input_gate_out4, &_input_gate_out1, ConvertPolicy::SATURATE);
220  _input_gate_out3.allocator()->allocate();
221  _input_gate_out4.allocator()->allocate();
222  input_gate_out = &_input_gate_out1;
223  }
224  else
225  {
226  _input_gate_out1.allocator()->allocate();
227  }
228 
229  if(_is_layer_norm_lstm)
230  {
231  _input_layer_norm_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
232  _input_layer_norm_out2.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
233  _memory_group.manage(&_input_layer_norm_out1);
234  _memory_group.manage(&_input_layer_norm_out2);
235  _mean_std_norm_input_gate.configure(compile_context, input_gate_out);
236  _pixelwise_mul_input_gate_coeff.configure(compile_context, input_gate_out, lstm_params.input_layer_norm_weights(), &_input_layer_norm_out1, 1, ConvertPolicy::SATURATE,
238  // input_gate_out is going to be reassigned, so allocate the tensor that it was assigned to before
239  input_gate_out->allocator()->allocate();
240  _accum_input_gate_bias.configure(compile_context, &_input_layer_norm_out1, lstm_params.input_gate_bias(), &_input_layer_norm_out2, ConvertPolicy::SATURATE);
241  _input_layer_norm_out1.allocator()->allocate();
242  input_gate_out = &_input_layer_norm_out2;
243  }
244  _activation_input_gate.configure(compile_context, input_gate_out, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC));
245  }
246 
247  // Configure block that calculates the cell state
248  // 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)
250  _cell_state_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
251  _cell_state_out2.allocator()->init(TensorInfo(cell_state1_shape, 1, input->info()->data_type()));
252  _cell_state_out3.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
253  _cell_state_out4.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
254  _cell_state_out5.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
255 
256  _memory_group.manage(&_cell_state_out1);
257  _fully_connected_cell_state.configure(compile_context, input, input_to_cell_weights, (_is_layer_norm_lstm) ? nullptr : cell_bias, &_cell_state_out1);
258  _memory_group.manage(&_cell_state_out2);
259  _transpose_cell_state->configure(compile_context, recurrent_to_cell_weights->info(), _cell_state_out2.info());
260  _recurrent_to_cell_weights = recurrent_to_cell_weights;
261  _memory_group.manage(&_cell_state_out3);
262  _gemm_cell_state1.configure(compile_context, output_state_in, &_cell_state_out2, nullptr, &_cell_state_out3, 1.f, 0.f);
263  _cell_state_out2.allocator()->allocate();
264  _memory_group.manage(&_cell_state_out4);
265  _accum_cell_state1.configure(compile_context, &_cell_state_out1, &_cell_state_out3, &_cell_state_out4, ConvertPolicy::SATURATE);
266  CLTensor *cell_state_out_ptr = &_cell_state_out4;
267  if(_is_layer_norm_lstm)
268  {
269  _cell_layer_norm_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
270  _cell_layer_norm_out2.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
271  _memory_group.manage(&_cell_layer_norm_out1);
272  _memory_group.manage(&_cell_layer_norm_out2);
273  _mean_std_norm_cell_gate.configure(compile_context, cell_state_out_ptr);
274  _pixelwise_mul_cell_gate_coeff.configure(compile_context, cell_state_out_ptr, lstm_params.cell_layer_norm_weights(), &_cell_layer_norm_out1, 1, ConvertPolicy::SATURATE,
276  // cell_state_out_ptr is going to be reassigned, so allocate the tensor that it was assigned to before
277  cell_state_out_ptr->allocator()->allocate();
278  _accum_cell_gate_bias.configure(compile_context, &_cell_layer_norm_out1, cell_bias, &_cell_layer_norm_out2, ConvertPolicy::SATURATE);
279  _cell_layer_norm_out1.allocator()->allocate();
280  cell_state_out_ptr = &_cell_layer_norm_out2;
281  }
282  _activation_cell_state.configure(compile_context, cell_state_out_ptr, nullptr, activation_info);
283  _memory_group.manage(&_cell_state_out5);
284  _pixelwise_mul_cell_state1.configure(compile_context, cell_state_out_ptr, input_gate_out, &_cell_state_out5, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN);
285  cell_state_out_ptr->allocator()->allocate();
286  _pixelwise_mul_cell_state2.configure(compile_context, forget_gate_out, cell_state_in, &_cell_state_out3, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN);
287  _accum_cell_state2.configure(compile_context, &_cell_state_out5, &_cell_state_out3, &_cell_state_out1, ConvertPolicy::SATURATE);
288  _cell_state_out3.allocator()->allocate();
289  _cell_state_out5.allocator()->allocate();
290  // Perform clipping
291  if(cell_threshold != 0.f)
292  {
293  _perform_cell_clipping = true;
294  _cell_clip.configure(compile_context, &_cell_state_out1, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -cell_threshold, cell_threshold));
295  }
296 
297  // Configure block that calculates the output
298  // 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)
299  // We optimize this as follows:
300  // 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)
301  _output1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
302  _output4.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
303  std::vector<const ICLTensor *> in_out_weights;
304  in_out_weights.emplace_back(input_to_output_weights);
305  in_out_weights.emplace_back(recurrent_to_output_weights);
306  TensorShape in_out_weights_concat_shape = arm_compute::misc::shape_calculator::calculate_concatenate_shape(in_out_weights, 0);
307  _output2.allocator()->init(TensorInfo(in_out_weights_concat_shape, 1, input->info()->data_type()));
308 
309  _concat_weights_output.configure(compile_context, in_out_weights, &_output2, Window::DimX);
310 
311  _memory_group.manage(&_output1);
312  _memory_group.manage(&_output4);
313 
314  _fully_connected_output.configure(compile_context, &_forget_gate_out2, &_output2, (_is_layer_norm_lstm) ? nullptr : output_gate_bias, &_output4);
315 
316  _output2.allocator()->allocate();
317  _forget_gate_out2.allocator()->allocate();
318 
319  CLTensor *output_gate_out = &_output4;
320  if(lstm_params.has_peephole_opt())
321  {
322  _output3.allocator()->init(TensorInfo(_cell_state_out1.info()->tensor_shape(), 1, input->info()->data_type()));
323 
324  _memory_group.manage(&_output3);
325  _pixelwise_mul_output_state1.configure(compile_context, &_cell_state_out1, lstm_params.cell_to_output_weights(), &_output3, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN);
326  _accum_output1.configure(compile_context, &_output4, &_output3, &_output1, ConvertPolicy::SATURATE);
327  _output4.allocator()->allocate();
328  output_gate_out = &_output1;
329 
330  // Allocate intermediate buffers
331  _output3.allocator()->allocate();
332  }
333  else
334  {
335  _output1.allocator()->allocate();
336  }
337  if(_is_layer_norm_lstm)
338  {
339  _output_layer_norm_out1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
340  _output_layer_norm_out2.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
341  _memory_group.manage(&_output_layer_norm_out1);
342  _memory_group.manage(&_output_layer_norm_out2);
343  _mean_std_norm_output_gate.configure(compile_context, output_gate_out);
344  _pixelwise_mul_output_gate_coeff.configure(compile_context, output_gate_out, lstm_params.output_layer_norm_weights(), &_output_layer_norm_out1, 1, ConvertPolicy::SATURATE,
346  // output_gate_out is going to be reassigned, so allocate the tensor that it was assigned to before
347  output_gate_out->allocator()->allocate();
348  _accum_output_gate_bias.configure(compile_context, &_output_layer_norm_out1, output_gate_bias, &_output_layer_norm_out2, ConvertPolicy::SATURATE);
349  _output_layer_norm_out1.allocator()->allocate();
350  output_gate_out = &_output_layer_norm_out2;
351  }
352  _activation_output.configure(compile_context, output_gate_out, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LOGISTIC));
353 
354  // Configure block that calculates the output state
355  /** lstm_res = PixelwiseMul(output, Activation(cell_state))
356  *
357  * -- Clip(lstm_res * projection_weights + projection_bias, projection_threshold) , if there is a projection
358  * /
359  * output_state = --
360  * \
361  * -- lstm_res , otherwise
362  */
363  ICLTensor *output_state_out_tmp = lstm_params.has_projection() ? &_output_state1 : output_state_out;
364  _cell_state_activation.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
365  _output_state1.allocator()->init(TensorInfo(cell_state_shape, 1, input->info()->data_type()));
366 
367  _memory_group.manage(&_cell_state_activation);
368  _activation_output_state.configure(compile_context, &_cell_state_out1, &_cell_state_activation, activation_info);
369  _pixelwise_mul_output_state2.configure(compile_context, &_cell_state_activation, output_gate_out, output_state_out_tmp, 1, ConvertPolicy::SATURATE, RoundingPolicy::TO_NEAREST_EVEN);
370  _cell_state_activation.allocator()->allocate();
371 
372  if(lstm_params.has_projection())
373  {
374  _has_projection_weights = true;
375  _fully_connected_output_state.configure(compile_context, output_state_out_tmp, lstm_params.projection_weights(), lstm_params.projection_bias(), output_state_out);
376  _output_state1.allocator()->allocate();
377  // Perform clipping
378  if(projection_threshold != 0.f)
379  {
380  _perform_projection_clipping = true;
381  _projection_clip.configure(compile_context, output_state_out, nullptr, ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -projection_threshold, projection_threshold));
382  }
383  }
384 
385  // Copy cell state and output
386  _copy_cell_state.configure(compile_context, &_cell_state_out1, cell_state_out);
387  _copy_output.configure(compile_context, output_state_out, output);
388 
389  // Vector for holding the tensors to store in scratch buffer
390  std::vector<const ICLTensor *> scratch_inputs;
391  if(!lstm_params.has_cifg_opt())
392  {
393  scratch_inputs.emplace_back(input_gate_out);
394  }
395  scratch_inputs.emplace_back(&_cell_state_out1);
396  scratch_inputs.emplace_back(forget_gate_out);
397  scratch_inputs.emplace_back(output_gate_out);
398  _concat_scratch_buffer.configure(compile_context, scratch_inputs, scratch_buffer, Window::DimX);
399  input_gate_out->allocator()->allocate();
400  _cell_state_out1.allocator()->allocate();
401  forget_gate_out->allocator()->allocate();
402  output_gate_out->allocator()->allocate();
403 }
404 
408  const ITensorInfo *forget_gate_bias, const ITensorInfo *cell_bias, const ITensorInfo *output_gate_bias,
409  const ITensorInfo *output_state_in, const ITensorInfo *cell_state_in,
410  const ITensorInfo *scratch_buffer, const ITensorInfo *output_state_out, const ITensorInfo *cell_state_out, const ITensorInfo *output,
411  const LSTMParams<ITensorInfo> &lstm_params, const ActivationLayerInfo &activation_info, float cell_threshold, float projection_threshold)
412 {
417  output_state_in, cell_state_in,
418  scratch_buffer, output_state_out, cell_state_out, output);
419 
420  // Check data types
426  output_state_in, cell_state_in,
427  scratch_buffer, output_state_out, cell_state_out, output);
428 
429  // Check dimensions
430  ARM_COMPUTE_RETURN_ERROR_ON(input->num_dimensions() > 2);
432  ARM_COMPUTE_RETURN_ERROR_ON(input_to_cell_weights->num_dimensions() > 2);
437  ARM_COMPUTE_RETURN_ERROR_ON(forget_gate_bias->num_dimensions() > 1);
439  ARM_COMPUTE_RETURN_ERROR_ON(output_gate_bias->num_dimensions() > 1);
440  ARM_COMPUTE_RETURN_ERROR_ON(output_state_in->num_dimensions() > 2);
441  ARM_COMPUTE_RETURN_ERROR_ON(cell_state_in->num_dimensions() > 2);
442  ARM_COMPUTE_RETURN_ERROR_ON(scratch_buffer->num_dimensions() > 2);
443  ARM_COMPUTE_RETURN_ERROR_ON(output_state_out->num_dimensions() > 2);
444  ARM_COMPUTE_RETURN_ERROR_ON(cell_state_out->num_dimensions() > 2);
446  ARM_COMPUTE_RETURN_ERROR_ON(cell_bias->dimension(0) * 4 != scratch_buffer->dimension(0)
447  && cell_bias->dimension(0) * 3 != scratch_buffer->dimension(0));
448 
449  const unsigned int num_batches = input->dimension(1);
450  const unsigned int num_cells = input_to_output_weights->dimension(1);
451 
452  if(lstm_params.use_layer_norm())
453  {
454  // If CIFG is used, input layer normalization weights tensor is omitted
455  if(lstm_params.has_cifg_opt())
456  {
457  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.input_layer_norm_weights() != nullptr);
458  }
459  else
460  {
462  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.input_layer_norm_weights()->num_dimensions() > 1);
463  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.input_layer_norm_weights()->dimension(0) != num_cells);
465  }
466 
469  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.forget_layer_norm_weights()->num_dimensions() > 1);
470  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.cell_layer_norm_weights()->num_dimensions() > 1);
471  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.output_layer_norm_weights()->num_dimensions() > 1);
472  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.forget_layer_norm_weights()->dimension(0) != num_cells);
473  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.cell_layer_norm_weights()->dimension(0) != num_cells);
474  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.output_layer_norm_weights()->dimension(0) != num_cells);
475  }
476 
477  // Check peephole optimization
478  if(lstm_params.has_peephole_opt())
479  {
481  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.cell_to_forget_weights()->num_dimensions() > 1);
482  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.cell_to_output_weights()->num_dimensions() > 1);
483  }
484 
486  TensorShape num_units_transposed_shape = compute_transposed_shape(*forget_gate_bias);
487  const TensorInfo units_out_transposed_info = TensorInfo(units_out_transposed_shape, 1, input->data_type());
488  const TensorInfo num_units_transposed_info = TensorInfo(num_units_transposed_shape, 1, input->data_type());
489 
490  TensorInfo input_gate = TensorInfo(TensorShape(num_cells, num_batches), 1, input->data_type());
491  TensorInfo forget_gate = TensorInfo(TensorShape(num_cells, num_batches), 1, input->data_type());
492  TensorInfo output_gate_tmp = TensorInfo(TensorShape(num_cells, num_batches), 1, input->data_type());
493  TensorInfo cell_state_tmp = TensorInfo(TensorShape(num_cells, num_batches), 1, input->data_type());
494 
495  // Validate forget gate
497 
498  std::vector<const ITensorInfo *> inputs_vector;
499  inputs_vector.emplace_back(input);
500  inputs_vector.emplace_back(output_state_in);
502  TensorInfo forget_gate_concat = TensorInfo(concat_shape, 1, input->data_type());
503 
504  ARM_COMPUTE_RETURN_ON_ERROR(CLConcatenateLayer::validate(inputs_vector, &forget_gate_concat, Window::DimX));
505 
506  if(lstm_params.has_peephole_opt())
507  {
509  ARM_COMPUTE_RETURN_ON_ERROR(CLArithmeticAddition::validate(&forget_gate, &forget_gate, &forget_gate, ConvertPolicy::SATURATE));
510  }
511  if(lstm_params.use_layer_norm())
512  {
517  }
519 
520  // Validate input gate
521  if(!lstm_params.has_cifg_opt())
522  {
524  lstm_params.recurrent_to_input_weights(),
525  lstm_params.input_gate_bias());
526  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.input_to_input_weights()->num_dimensions() > 2);
527  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.recurrent_to_input_weights()->num_dimensions() > 2);
528  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.input_gate_bias()->num_dimensions() > 1);
529 
530  std::vector<const ITensorInfo *> lstm_weights;
531  lstm_weights.emplace_back(lstm_params.input_to_input_weights());
532  lstm_weights.emplace_back(lstm_params.recurrent_to_input_weights());
533  TensorShape lstm_weights_concat_shape = arm_compute::misc::shape_calculator::calculate_concatenate_shape(lstm_weights, 0);
534  TensorInfo lstm_gate_concat = TensorInfo(lstm_weights_concat_shape, 1, input->data_type());
535  ARM_COMPUTE_RETURN_ON_ERROR(CLConcatenateLayer::validate(lstm_weights, &lstm_gate_concat, Window::DimX));
536 
537  ARM_COMPUTE_RETURN_ON_ERROR(CLFullyConnectedLayer::validate(input, lstm_params.input_to_input_weights(), (lstm_params.use_layer_norm()) ? nullptr : lstm_params.input_gate_bias(), &input_gate));
538 
539  if(lstm_params.has_peephole_opt())
540  {
542  ARM_COMPUTE_RETURN_ERROR_ON(lstm_params.cell_to_input_weights()->num_dimensions() > 1);
545  }
546 
547  if(lstm_params.use_layer_norm())
548  {
552  }
554  }
555  else
556  {
558  }
559 
560  // Validate cell state
561  ARM_COMPUTE_RETURN_ON_ERROR(CLFullyConnectedLayer::validate(input, input_to_cell_weights, (lstm_params.use_layer_norm()) ? nullptr : cell_bias, &cell_state_tmp));
562  ARM_COMPUTE_RETURN_ON_ERROR(CLGEMM::validate(output_state_in, &units_out_transposed_info, nullptr, &cell_state_tmp, 1.f, 0.f, GEMMInfo()));
563  ARM_COMPUTE_RETURN_ON_ERROR(CLArithmeticAddition::validate(&cell_state_tmp, &cell_state_tmp, &cell_state_tmp, ConvertPolicy::SATURATE));
564  if(lstm_params.use_layer_norm())
565  {
569  ARM_COMPUTE_RETURN_ON_ERROR(CLArithmeticAddition::validate(&cell_state_tmp, cell_bias, &cell_state_tmp, ConvertPolicy::SATURATE));
570  }
571  ARM_COMPUTE_RETURN_ON_ERROR(CLActivationLayer::validate(&cell_state_tmp, nullptr, activation_info));
574  ARM_COMPUTE_RETURN_ON_ERROR(CLArithmeticAddition::validate(&cell_state_tmp, &cell_state_tmp, &cell_state_tmp, ConvertPolicy::SATURATE));
575  if(cell_threshold != 0.f)
576  {
578  cell_threshold)));
579  }
580 
581  std::vector<const ITensorInfo *> in_out_weights;
582  in_out_weights.emplace_back(input_to_output_weights);
583  in_out_weights.emplace_back(recurrent_to_output_weights);
584  TensorShape in_out_weights_concat_shape = arm_compute::misc::shape_calculator::calculate_concatenate_shape(in_out_weights, 0);
585  TensorInfo in_out_gate_concat = TensorInfo(in_out_weights_concat_shape, 1, input->data_type());
586  ARM_COMPUTE_RETURN_ON_ERROR(CLConcatenateLayer::validate(in_out_weights, &in_out_gate_concat, Window::DimX));
587  // Validate output gate tmp
589 
590  if(lstm_params.has_peephole_opt())
591  {
594  ARM_COMPUTE_RETURN_ON_ERROR(CLArithmeticAddition::validate(&output_gate_tmp, &output_gate_tmp, &output_gate_tmp, ConvertPolicy::SATURATE));
595  }
596  if(lstm_params.use_layer_norm())
597  {
602  }
604 
605  // Validate output state
606  ARM_COMPUTE_RETURN_ON_ERROR(CLActivationLayer::validate(&cell_state_tmp, &cell_state_tmp, activation_info));
608  if(lstm_params.has_projection())
609  {
610  ARM_COMPUTE_RETURN_ON_ERROR(CLFullyConnectedLayer::validate(&output_gate_tmp, lstm_params.projection_weights(), lstm_params.projection_bias(), output_state_out));
611  if(projection_threshold != 0.f)
612  {
613  ARM_COMPUTE_RETURN_ON_ERROR(CLActivationLayer::validate(output_state_out, output_state_out,
614  ActivationLayerInfo(ActivationLayerInfo::ActivationFunction::LU_BOUNDED_RELU, -projection_threshold, projection_threshold)));
615  }
616  }
617 
618  // Validate copy kernel
619  ARM_COMPUTE_RETURN_ON_ERROR(CLCopy::validate(&cell_state_tmp, cell_state_out));
620  ARM_COMPUTE_RETURN_ON_ERROR(CLCopy::validate(output_state_out, output));
621 
622  // Validate scratch concatenation
623  std::vector<const ITensorInfo *> inputs_vector_info_raw;
624  if(!lstm_params.has_cifg_opt())
625  {
626  inputs_vector_info_raw.push_back(&input_gate);
627  }
628  inputs_vector_info_raw.push_back(&cell_state_tmp);
629  inputs_vector_info_raw.push_back(&forget_gate);
630  inputs_vector_info_raw.push_back(&output_gate_tmp);
631 
632  ARM_COMPUTE_RETURN_ON_ERROR(CLConcatenateLayer::validate(inputs_vector_info_raw, scratch_buffer, Window::DimX));
633  return Status{};
634 }
635 
637 {
638  prepare();
639 
640  MemoryGroupResourceScope scope_mg(_memory_group);
641 
642  _concat_inputs_forget_gate.run();
643 
644  _fully_connected_forget_gate.run();
645 
646  if(_run_peephole_opt)
647  {
648  _pixelwise_mul_forget_gate.run();
649  _accum_forget_gate1.run();
650  }
651  if(_is_layer_norm_lstm)
652  {
653  _mean_std_norm_forget_gate.run();
654  _pixelwise_mul_forget_gate_coeff.run();
655  _accum_forget_gate_bias.run();
656  }
657  _activation_forget_gate.run();
658 
659  if(_run_cifg_opt)
660  {
661  _ones_fill.run();
662  _subtract_input_gate.run();
663  }
664  else
665  {
666  _fully_connected_input_gate.run();
667 
668  if(_run_peephole_opt)
669  {
670  _pixelwise_mul_input_gate.run();
671  _accum_input_gate1.run();
672  }
673 
674  if(_is_layer_norm_lstm)
675  {
676  _mean_std_norm_input_gate.run();
677  _pixelwise_mul_input_gate_coeff.run();
678  _accum_input_gate_bias.run();
679  }
680  _activation_input_gate.run();
681  }
682 
683  _fully_connected_cell_state.run();
684  ITensorPack pack;
685  pack.add_tensor(TensorType::ACL_SRC, _recurrent_to_cell_weights);
686  pack.add_tensor(TensorType::ACL_DST, &_cell_state_out2);
687  CLScheduler::get().enqueue_op(*_transpose_cell_state,
688  pack,
689  false);
690  _gemm_cell_state1.run();
691  _accum_cell_state1.run();
692  if(_is_layer_norm_lstm)
693  {
694  _mean_std_norm_cell_gate.run();
695  _pixelwise_mul_cell_gate_coeff.run();
696  _accum_cell_gate_bias.run();
697  }
698  _activation_cell_state.run();
699  _pixelwise_mul_cell_state1.run();
700  _pixelwise_mul_cell_state2.run();
701  _accum_cell_state2.run();
702 
703  if(_perform_cell_clipping)
704  {
705  _cell_clip.run();
706  }
707 
708  _fully_connected_output.run();
709 
710  if(_run_peephole_opt)
711  {
712  _pixelwise_mul_output_state1.run();
713  _accum_output1.run();
714  }
715  if(_is_layer_norm_lstm)
716  {
717  _mean_std_norm_output_gate.run();
718  _pixelwise_mul_output_gate_coeff.run();
719  _accum_output_gate_bias.run();
720  }
721  _activation_output.run();
722 
723  _activation_output_state.run();
724  _pixelwise_mul_output_state2.run();
725 
726  if(_has_projection_weights)
727  {
728  _fully_connected_output_state.run();
729  if(_perform_projection_clipping)
730  {
731  _projection_clip.run();
732  }
733  }
734 
735  _copy_cell_state.run();
736  _copy_output.run();
737 
738  _concat_scratch_buffer.run();
739 }
740 
742 {
743  if(!_is_prepared)
744  {
745  _concat_weights_forget_gate.run();
746  if(!_run_cifg_opt)
747  {
748  _concat_weights_input_gate.run();
749  }
750  _concat_weights_output.run();
751  _is_prepared = true;
752  }
753 }
754 } // namespace arm_compute
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ActivationLayerInfo &act_info)
Static function to check if given info will lead to a valid configuration of CLActivationLayer.
const T * projection_weights() const
Definition: LSTMParams.h:225
const T * input_to_input_weights() const
Definition: LSTMParams.h:195
Shape of a tensor.
Definition: TensorShape.h:39
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.
void configure(const ICLTensor *input, const ICLTensor *input_to_forget_weights, const ICLTensor *input_to_cell_weights, const ICLTensor *input_to_output_weights, const ICLTensor *recurrent_to_forget_weights, const ICLTensor *recurrent_to_cell_weights, const ICLTensor *recurrent_to_output_weights, const ICLTensor *forget_gate_bias, const ICLTensor *cell_bias, const ICLTensor *output_gate_bias, const ICLTensor *output_state_in, ICLTensor *cell_state_in, ICLTensor *scratch_buffer, ICLTensor *output_state_out, ICLTensor *cell_state_out, ICLTensor *output, const LSTMParams< ICLTensor > &lstm_params, const ActivationLayerInfo &activation_info, float cell_threshold=0.f, float projection_threshold=0.f)
Initialize function's tensors.
Definition: CLLSTMLayer.cpp:69
bool use_layer_norm() const
Definition: LSTMParams.h:310
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor's metadata.
Definition: CLTensor.cpp:41
void run() override
Run the kernels contained in the function.
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 CLMeanStdDevNormalizatio...
void run() override
Run the kernels contained in the function.
Definition: CLGEMM.cpp:778
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
bool has_peephole_opt() const
Definition: LSTMParams.h:295
static CLScheduler & get()
Access the scheduler singleton.
T * forget_layer_norm_weights() const
Definition: LSTMParams.h:240
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
void run() override
Run the kernels contained in the function.
Definition: CLCopy.cpp:73
1 channel, 1 F32 per channel
void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Initialise the kernel's inputs, output and convertion policy.
bool has_cifg_opt() const
Definition: LSTMParams.h:305
void configure(std::vector< const ICLTensor * > &inputs_vector, ICLTensor *output, size_t axis)
Initialise the kernel's inputs vector and output.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor's metadata.
Definition: ITensorInfo.h:40
void run() override
Run the kernels contained in the function.
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: CLTensor.cpp:61
void configure(ICLTensor *input, ICLTensor *output=nullptr, float epsilon=1e-8f)
Initialise the function's input and outputs.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
CLLSTMLayer(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Default constructor.
Definition: CLLSTMLayer.cpp:51
T * cell_to_input_weights() const
Definition: LSTMParams.h:205
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:1478
void run() override
Run the kernels contained in the function.
void init(const TensorInfo &input, size_t alignment=0)
Initialize a tensor based on the passed TensorInfo.
Copyright (c) 2017-2021 Arm Limited.
~CLLSTMLayer()
Default destructor.
1 channel, 1 F16 per channel
TensorShape compute_transposed_shape(const ITensorInfo &input)
Calculate the transposed shape of a tensor.
DataType data_type() const override
Data type used for each element of the tensor.
Definition: TensorInfo.h:242
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Definition: Validate.h:159
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
const T * recurrent_to_input_weights() const
Definition: LSTMParams.h:200
const T * projection_bias() const
Definition: LSTMParams.h:230
Interface to enqueue OpenCL kernels and get/set the OpenCL CommandQueue and ICLTuner.
void configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, FullyConnectedLayerInfo fc_info=FullyConnectedLayerInfo())
Set the input and output tensors.
void run() override
Run the kernels contained in the function.
Definition: CLFill.cpp:72
T * output_layer_norm_weights() const
Definition: LSTMParams.h:250
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
Definition: Window.h:43
void run() override final
Run the kernels contained in the function.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
void configure(ICLTensor *input, ICLTensor *output, Window *dst_window=nullptr)
Initialise the function's source and destination.
Definition: CLCopy.cpp:52
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 CLFullyConnectedLayer.
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 opencl::kernels::ClSatur...
void enqueue_op(ICLKernel &kernel, ITensorPack &tensors, bool flush=true)
Schedule the execution of the passed kernel if possible.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void configure(ICLTensor *input1, ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Initialise the kernel's inputs, output and conversion policy.
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 CLLSTMLayer.
void run() override
Run the kernels contained in the function.
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 opencl::kernels::ClSatur...
void configure(ICLTensor *tensor, const PixelValue &constant_value, Window *window=nullptr)
Initialize the kernel's tensor and filling value.
Definition: CLFill.cpp:52
CLCompileContext class.
T * cell_to_forget_weights() const
Definition: LSTMParams.h:215
static Status validate(const ITensorInfo *input, const ITensorInfo *output, Window *dst_window=nullptr)
Static function to check if given info will lead to a valid configuration of CLCopy.
Definition: CLCopy.cpp:68
bool has_projection() const
Definition: LSTMParams.h:300
void configure(const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, ConvertPolicy policy, const ActivationLayerInfo &act_info=ActivationLayerInfo())
Initialise the kernel's inputs, output and conversion policy.
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
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 CLConcatenateLayer.
T * cell_to_output_weights() const
Definition: LSTMParams.h:220
Rounds to nearest value; half rounds to nearest even.
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
T * input_layer_norm_weights() const
Definition: LSTMParams.h:235
void configure(const ICLTensor *a, const ICLTensor *b, const ICLTensor *c, ICLTensor *output, float alpha, float beta, const GEMMInfo &gemm_info=GEMMInfo())
Initialise the kernel's inputs and output.
Definition: CLGEMM.cpp:666
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:541
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:788
const T * input_gate_bias() const
Definition: LSTMParams.h:210
void configure(ICLTensor *input, ICLTensor *output, ActivationLayerInfo act_info)
Set the input and output tensor.
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 CLGEMM.
Definition: CLGEMM.cpp:727
Tensor packing service.
Definition: ITensorPack.h:37
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:157
Store the tensor's metadata.
Definition: TensorInfo.h:43
GEMM information class.
Definition: Types.h:1938
T * cell_layer_norm_weights() const
Definition: LSTMParams.h:245
const TensorShape & tensor_shape() const override
Size for each dimension of the tensor.
Definition: TensorInfo.h:234
void run() override
Run the kernels contained in the function.
void run() override
Run the kernels contained in the function.
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 CLPixelWiseMultiplicatio...
void add_tensor(int id, ITensor *tensor)
Add tensor to the pack.
Definition: ITensorPack.cpp:30
void prepare() override
Prepare the function for executing.
Basic implementation of the OpenCL tensor interface.
Definition: CLTensor.h:41