23.08
|
This function performs a single time step in a Long Short-Term Memory (LSTM) layer. More...
#include <CLLSTMLayer.h>
Public Member Functions | |
CLLSTMLayer (std::shared_ptr< IMemoryManager > memory_manager=nullptr) | |
Default constructor. More... | |
CLLSTMLayer (const CLLSTMLayer &)=delete | |
Prevent instances of this class from being copied. More... | |
CLLSTMLayer & | operator= (const CLLSTMLayer &)=delete |
Prevent instances of this class from being copied. More... | |
CLLSTMLayer (CLLSTMLayer &&)=delete | |
Prevent instances of this class to be moved. More... | |
CLLSTMLayer & | operator= (CLLSTMLayer &&)=delete |
Prevent instances of this class to be moved. More... | |
~CLLSTMLayer () | |
Default destructor. More... | |
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. More... | |
void | configure (const CLCompileContext &compile_context, 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. More... | |
void | run () override |
Run the kernels contained in the function. More... | |
void | prepare () override |
Prepare the function for executing. More... | |
![]() | |
virtual | ~IFunction ()=default |
Destructor. More... | |
Static Public Member Functions | |
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. More... | |
This function performs a single time step in a Long Short-Term Memory (LSTM) layer.
Definition at line 61 of file CLLSTMLayer.h.
CLLSTMLayer | ( | std::shared_ptr< IMemoryManager > | memory_manager = nullptr | ) |
Default constructor.
Definition at line 42 of file CLLSTMLayer.cpp.
|
delete |
Prevent instances of this class from being copied.
|
delete |
Prevent instances of this class to be moved.
|
default |
Default destructor.
void configure | ( | const CLCompileContext & | compile_context, |
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.
[in] | compile_context | The compile context to be used. |
[in] | input | Source tensor. Input is a 2D tensor with dimensions [input_size, batch_size]. Data types supported: F16/F32. |
[in] | input_to_forget_weights | 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as input . |
[in] | input_to_cell_weights | 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as input . |
[in] | input_to_output_weights | 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as input . |
[in] | recurrent_to_forget_weights | 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as input . |
[in] | recurrent_to_cell_weights | 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as input . |
[in] | recurrent_to_output_weights | 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as input . |
[in] | forget_gate_bias | 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . |
[in] | cell_bias | 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . |
[in] | output_gate_bias | 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . |
[in] | output_state_in | 2D weights tensor with dimensions [output_size, batch_size]. Data type supported: Same as input . |
[in] | cell_state_in | 2D tensor with dimensions [num_units, batch_size]. Data type supported: Same as input . |
[out] | scratch_buffer | 2D tensor with dimensions [num_units * 4, batch_size] with CIFG or [num_units * 3, batch_size] without CIGF. Data type supported: Same as input . |
[out] | output_state_out | 2D weights tensor with dimensions [output_size, batch_size]. Data type supported: Same as input . |
[out] | cell_state_out | 2D tensor with dimensions [num_units, batch_size]. Data type supported: Same as input . |
[out] | output | Destination tensor. Output is a 2D tensor with dimensions [output_size, batch_size]. Data types supported: Same as input . |
[in] | lstm_params | Weights tensors used in peephole optimization: input_to_input_weights 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as input . recurrent_to_input_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as input . cell_to_input_weights 1D weights tensor with dimensions [num_units]. Can be nullptr. Data type supported: Same as input . cell_to_forget_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . cell_to_output_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . input_gate_bias 1D weights tensor with dimensions [num_units]. Data type supported: Same as input projection_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as input . projection_bias 1D weights tensor with dimensions [output_size]. Data type supported: Same as input . input_layer_norm_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . forget_layer_norm_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . cell_layer_norm_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . output_layer_norm_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . |
[in] | activation_info | Contains activation information described in ActivationLayerInfo. |
[in] | cell_threshold | (Optional) The clipping threshold for the cell state, such that values are bound within [-cell_clip, cell_clip]. If set to 0.0f then clipping is disabled. |
[in] | projection_threshold | (Optional) The clipping threshold for the output from the projection layer, such that values are bound within [-proj_clip, proj_clip]. If set to 0.0f then clipping is disabled. |
lstm_res = PixelwiseMul(output, Activation(cell_state))
-- Clip(lstm_res * projection_weights + projection_bias, projection_threshold) , if there is a projection /
output_state = – \ – lstm_res , otherwise
Definition at line 73 of file CLLSTMLayer.cpp.
References CLTensorAllocator::allocate(), CLTensor::allocator(), ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, ARM_COMPUTE_LOG_PARAMS, arm_compute::utils::info_helpers::build_lstm_params_tensor_info(), arm_compute::misc::shape_calculator::calculate_concatenate_shape(), LSTMParams< T >::cell_layer_norm_weights(), LSTMParams< T >::cell_to_forget_weights(), LSTMParams< T >::cell_to_input_weights(), LSTMParams< T >::cell_to_output_weights(), arm_compute::misc::shape_calculator::compute_transposed_shape(), CLMeanStdDevNormalizationLayer::configure(), CLFill::configure(), CLCopy::configure(), CLActivationLayer::configure(), CLArithmeticAddition::configure(), CLConcatenateLayer::configure(), CLFullyConnectedLayer::configure(), CLPixelWiseMultiplication::configure(), CLGEMM::configure(), CLArithmeticSubtraction::configure(), TensorInfo::data_type(), Window::DimX, arm_compute::test::validation::forget_gate_bias, LSTMParams< T >::forget_layer_norm_weights(), LSTMParams< T >::has_cifg_opt(), LSTMParams< T >::has_peephole_opt(), LSTMParams< T >::has_projection(), ITensor::info(), CLTensor::info(), ITensorAllocator::init(), arm_compute::test::validation::input, LSTMParams< T >::input_gate_bias(), LSTMParams< T >::input_layer_norm_weights(), arm_compute::test::validation::input_to_cell_weights, arm_compute::test::validation::input_to_forget_weights, LSTMParams< T >::input_to_input_weights(), arm_compute::test::validation::input_to_output_weights, MemoryGroup::manage(), arm_compute::test::validation::output_gate_bias, LSTMParams< T >::output_layer_norm_weights(), LSTMParams< T >::projection_bias(), LSTMParams< T >::projection_weights(), arm_compute::test::validation::recurrent_to_cell_weights, arm_compute::test::validation::recurrent_to_forget_weights, LSTMParams< T >::recurrent_to_input_weights(), arm_compute::test::validation::recurrent_to_output_weights, arm_compute::SATURATE, ITensorInfo::tensor_shape(), TensorInfo::tensor_shape(), arm_compute::TO_NEAREST_EVEN, LSTMParams< T >::use_layer_norm(), and CLLSTMLayer::validate().
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.
Valid data layouts:
Valid data type configurations:
src0 - src13 | dst0 - dst3 |
---|---|
F16 | F16 |
F32 | F32 |
[in] | input | Source tensor. Input is a 2D tensor with dimensions [input_size, batch_size]. Data types supported: F16/F32. |
[in] | input_to_forget_weights | 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as input . |
[in] | input_to_cell_weights | 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as input . |
[in] | input_to_output_weights | 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as input . |
[in] | recurrent_to_forget_weights | 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as input . |
[in] | recurrent_to_cell_weights | 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as input . |
[in] | recurrent_to_output_weights | 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as input . |
[in] | forget_gate_bias | 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . |
[in] | cell_bias | 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . |
[in] | output_gate_bias | 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . |
[in] | output_state_in | 2D weights tensor with dimensions [output_size, batch_size]. Data type supported: Same as input . |
[in] | cell_state_in | 2D tensor with dimensions [num_units, batch_size]. Data type supported: Same as input . |
[out] | scratch_buffer | 2D tensor with dimensions [num_units * 4, batch_size] with CIFG or [num_units * 3, batch_size] without CIGF. Data type supported: Same as input . |
[out] | output_state_out | 2D weights tensor with dimensions [output_size, batch_size]. Data type supported: Same as input . |
[out] | cell_state_out | 2D tensor with dimensions [num_units, batch_size]. Data type supported: Same as input . |
[out] | output | Destination tensor. Output is a 2D tensor with dimensions [output_size, batch_size]. Data types supported: Same as input . |
[in] | lstm_params | Weights tensors used in peephole optimization: input_to_input_weights 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as input . recurrent_to_input_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as input . cell_to_input_weights 1D weights tensor with dimensions [num_units]. Can be nullptr. Data type supported: Same as input . cell_to_forget_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . cell_to_output_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . input_gate_bias 1D weights tensor with dimensions [num_units]. Data type supported: Same as input projection_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as input . projection_bias 1D weights tensor with dimensions [output_size]. Data type supported: Same as input . input_layer_norm_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . forget_layer_norm_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . cell_layer_norm_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . output_layer_norm_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as input . |
[in] | activation_info | Contains activation information described in ActivationLayerInfo. |
[in] | cell_threshold | (Optional) The clipping threshold for the cell state, such that values are bound within [-cell_clip, cell_clip]. If set to 0.0f then clipping is disabled. |
[in] | projection_threshold | (Optional) The clipping threshold for the output from the projection layer, such that values are bound within [-proj_clip, proj_clip]. If set to 0.0f then clipping is disabled. |
Definition at line 60 of file CLLSTMLayer.cpp.
References arm_compute::test::validation::forget_gate_bias, CLKernelLibrary::get(), arm_compute::test::validation::input, arm_compute::test::validation::input_to_cell_weights, arm_compute::test::validation::input_to_forget_weights, arm_compute::test::validation::input_to_output_weights, arm_compute::test::validation::output_gate_bias, arm_compute::test::validation::recurrent_to_cell_weights, arm_compute::test::validation::recurrent_to_forget_weights, and arm_compute::test::validation::recurrent_to_output_weights.
|
delete |
Prevent instances of this class to be moved.
|
delete |
Prevent instances of this class from being copied.
|
overridevirtual |
Prepare the function for executing.
Any one off pre-processing step required by the function is handled here
Reimplemented from IFunction.
Definition at line 736 of file CLLSTMLayer.cpp.
References CLConcatenateLayer::run().
Referenced by CLLSTMLayer::run().
|
overridevirtual |
Run the kernels contained in the function.
For CPU kernels:
For OpenCL kernels:
Implements IFunction.
Definition at line 631 of file CLLSTMLayer.cpp.
References arm_compute::ACL_DST, arm_compute::ACL_SRC, ITensorPack::add_tensor(), CLScheduler::enqueue_op(), CLScheduler::get(), arm_compute::test::validation::pack, CLLSTMLayer::prepare(), ICLSimpleFunction::run(), CLFill::run(), CLCopy::run(), CLFullyConnectedLayer::run(), CLActivationLayer::run(), CLGEMM::run(), CLConcatenateLayer::run(), CLPixelWiseMultiplication::run(), CLArithmeticAddition::run(), and CLArithmeticSubtraction::run().
|
static |
Static function to check if given info will lead to a valid configuration of CLLSTMLayer.
[in] | input | Source tensor info. Input is a 2D tensor with dimensions [input_size, batch_size]. Data types supported: F16/F32. |
[in] | input_to_forget_weights | 2D weights tensor info with dimensions [input_size, num_units]. Data type supported: Same as input . |
[in] | input_to_cell_weights | 2D weights tensor info with dimensions [input_size, num_units]. Data type supported: Same as input . |
[in] | input_to_output_weights | 2D weights tensor info with dimensions [input_size, num_units]. Data type supported: Same as input . |
[in] | recurrent_to_forget_weights | 2D weights tensor info with dimensions [output_size, num_units]. Data type supported: Same as input . |
[in] | recurrent_to_cell_weights | 2D weights tensor info with dimensions [output_size, num_units]. Data type supported: Same as input . |
[in] | recurrent_to_output_weights | 2D weights tensor info with dimensions [output_size, num_units]. Data type supported: Same as input . |
[in] | forget_gate_bias | 1D weights tensor info with dimensions [num_units]. Data type supported: Same as input . |
[in] | cell_bias | 1D weights tensor info with dimensions [num_units]. Data type supported: Same as input . |
[in] | output_gate_bias | 1D weights tensor info with dimensions [num_units]. Data type supported: Same as input . |
[in] | output_state_in | 2D weights tensor info with dimensions [output_size, batch_size]. Data type supported: Same as input . |
[in] | cell_state_in | 2D tensor info with dimensions [num_units, batch_size]. Data type supported: Same as input . |
[in] | scratch_buffer | 2D tensor info with dimensions [num_units * 4, batch_size] with CIFG or [num_units * 3, batch_size] without CIGF. Data type supported: Same as input . |
[in] | output_state_out | 2D weights tensor info with dimensions [output_size, batch_size]. Data type supported: Same as input . |
[in] | cell_state_out | 2D tensor info with dimensions [num_units, batch_size]. Data type supported: Same as input . |
[in] | output | Destination tensor info. Output is a 2D tensor with dimensions [output_size, batch_size]. Data types supported: Same as input . |
[in] | lstm_params | Weights tensors info used in peephole optimization: input_to_input_weights 2D weights tensor info with dimensions [input_size, num_units]. Data type supported: Same as input . recurrent_to_input_weights 2D weights tensor info with dimensions [output_size, num_units]. Data type supported: Same as input . cell_to_input_weights 1D weights tensor info with dimensions [num_units]. Can be nullptr. Data type supported: Same as input . cell_to_forget_weights 1D weights tensor info with dimensions [num_units]. Data type supported: Same as input . cell_to_output_weights 1D weights tensor info with dimensions [num_units]. Data type supported: Same as input . input_gate_bias 1D weights tensor info with dimensions [num_units]. Data type supported: Same as input projection_weights 2D weights tensor info with dimensions [output_size, num_units]. Data type supported: Same as input . projection_bias 1D weights tensor info with dimensions [output_size]. Data type supported: Same as input . input_layer_norm_weights 1D weights tensor info with dimensions [num_units]. Data type supported: Same as input . forget_layer_norm_weights 1D weights tensor info with dimensions [num_units]. Data type supported: Same as input . cell_layer_norm_weights 1D weights tensor info with dimensions [num_units]. Data type supported: Same as input . output_layer_norm_weights 1D weights tensor info with dimensions [num_units]. Data type supported: Same as input . |
[in] | activation_info | Contains activation information described in ActivationLayerInfo. |
[in] | cell_threshold | (Optional) The clipping threshold for the cell state, such that values are bound within [-cell_clip, cell_clip]. If set to 0.0f then clipping is disabled. |
[in] | projection_threshold | (Optional) The clipping threshold for the output from the projection layer, such that values are bound within [-proj_clip, proj_clip]. If set to 0.0f then clipping is disabled. |
Definition at line 400 of file CLLSTMLayer.cpp.
References ARM_COMPUTE_RETURN_ERROR_ON, ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR, ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::misc::shape_calculator::calculate_concatenate_shape(), LSTMParams< T >::cell_layer_norm_weights(), LSTMParams< T >::cell_to_forget_weights(), LSTMParams< T >::cell_to_input_weights(), LSTMParams< T >::cell_to_output_weights(), arm_compute::misc::shape_calculator::compute_transposed_shape(), ITensorInfo::dimension(), Window::DimX, arm_compute::F16, arm_compute::F32, arm_compute::test::validation::forget_gate_bias, LSTMParams< T >::forget_layer_norm_weights(), LSTMParams< T >::has_cifg_opt(), LSTMParams< T >::has_peephole_opt(), LSTMParams< T >::has_projection(), arm_compute::test::validation::input, LSTMParams< T >::input_gate_bias(), LSTMParams< T >::input_layer_norm_weights(), arm_compute::test::validation::input_to_cell_weights, arm_compute::test::validation::input_to_forget_weights, LSTMParams< T >::input_to_input_weights(), arm_compute::test::validation::input_to_output_weights, ITensorInfo::num_dimensions(), arm_compute::test::validation::output_gate_bias, LSTMParams< T >::output_layer_norm_weights(), LSTMParams< T >::projection_bias(), LSTMParams< T >::projection_weights(), arm_compute::test::validation::recurrent_to_cell_weights, arm_compute::test::validation::recurrent_to_forget_weights, LSTMParams< T >::recurrent_to_input_weights(), arm_compute::test::validation::recurrent_to_output_weights, arm_compute::SATURATE, arm_compute::TO_NEAREST_EVEN, LSTMParams< T >::use_layer_norm(), CLMeanStdDevNormalizationLayer::validate(), CLCopy::validate(), CLFullyConnectedLayer::validate(), CLActivationLayer::validate(), CLGEMM::validate(), CLConcatenateLayer::validate(), CLPixelWiseMultiplication::validate(), CLArithmeticAddition::validate(), and CLArithmeticSubtraction::validate().
Referenced by CLLSTMLayer::configure().