aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/runtime
diff options
context:
space:
mode:
authorMichalis Spyrou <michalis.spyrou@arm.com>2018-08-08 12:53:05 +0100
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:54:54 +0000
commit25f45a4a0158a709d28a5207a867a9b5ce390621 (patch)
tree7d10bd3be7e2341eecef6887b5a473793bab0642 /arm_compute/runtime
parent26b22160c00d9955255015d82203c7e16f28f0c3 (diff)
downloadComputeLibrary-25f45a4a0158a709d28a5207a867a9b5ce390621.tar.gz
COMPMID-1060 LSTM FP32 NEON
Change-Id: I0bdf874e61917903c26f713ec41a7ffc29e07233 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/143892 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'arm_compute/runtime')
-rw-r--r--arm_compute/runtime/CL/functions/CLLSTMLayer.h133
-rw-r--r--arm_compute/runtime/NEON/NEFunctions.h1
-rw-r--r--arm_compute/runtime/NEON/functions/NELSTMLayer.h210
-rw-r--r--arm_compute/runtime/common/LSTMParams.h169
4 files changed, 381 insertions, 132 deletions
diff --git a/arm_compute/runtime/CL/functions/CLLSTMLayer.h b/arm_compute/runtime/CL/functions/CLLSTMLayer.h
index 6896a97e31..72e41a7aca 100644
--- a/arm_compute/runtime/CL/functions/CLLSTMLayer.h
+++ b/arm_compute/runtime/CL/functions/CLLSTMLayer.h
@@ -39,6 +39,7 @@
#include "arm_compute/runtime/CL/functions/CLGEMM.h"
#include "arm_compute/runtime/CL/functions/CLWidthConcatenateLayer.h"
#include "arm_compute/runtime/IMemoryManager.h"
+#include "arm_compute/runtime/common/LSTMParams.h"
#include <memory>
@@ -46,138 +47,6 @@ namespace arm_compute
{
class ICLTensor;
-template <typename T>
-class LSTMParams
-{
-public:
- /** Constructor */
- LSTMParams()
- : _input_to_input_weights(nullptr), _recurrent_to_input_weights(nullptr), _cell_to_input_weights(nullptr), _input_gate_bias(nullptr), _cell_to_forget_weights(nullptr),
- _cell_to_output_weights(nullptr), _projection_weights(nullptr), _projection_bias(nullptr), _has_peephole_opt(false), _has_projection(false), _has_cifg_opt(true)
- {
- }
- /** Prevent instances of this class from being copied (As this class contains pointers) */
- LSTMParams(const LSTMParams &) = delete;
- /** Prevent instances of this class from being copied (As this class contains pointers) */
- LSTMParams &operator=(const LSTMParams &) = delete;
- /** Default destructor */
- ~LSTMParams() = default;
- /** Set CIFG tensor parameters.
- *
- * @param[in] input_to_input_weights 2D weights tensor with dimensions [input_size, num_units]. Data types supported: F16/F32.
- * @param[in] recurrent_to_input_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as @p input_to_input_weights.
- * @param[in] cell_to_input_weights 1D weights tensor with dimensions [num_units]. Can be nullptr. Data type supported: Same as @p input_to_input_weights.
- * @param[in] input_gate_bias 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input_to_input_weights
- *
- * @return Reference to this LSTMParams object
- */
- LSTMParams &set_cifg_params(const T *input_to_input_weights, const T *recurrent_to_input_weights, const T *cell_to_input_weights, const T *input_gate_bias)
- {
- _input_to_input_weights = input_to_input_weights;
- _recurrent_to_input_weights = recurrent_to_input_weights;
- _cell_to_input_weights = cell_to_input_weights;
- _input_gate_bias = input_gate_bias;
- _has_cifg_opt = false;
- return *this;
- }
- /** Set projection tensor parameters.
- *
- * @param[in] projection_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Data types supported: F16/F32.
- * @param[in] projection_bias 1D weights tensor with dimensions [output_size]. Data type supported: Same as @p projection_weights.
- *
- * @return Reference to this LSTMParams object
- */
- LSTMParams &set_projection_params(const T *projection_weights, const T *projection_bias)
- {
- _projection_weights = projection_weights;
- _projection_bias = projection_bias;
- _has_projection = true;
- return *this;
- }
- /** Set peephole tensor parameters.
- *
- * @param[in] cell_to_forget_weights 1D weights tensor with dimensions [num_units]. Data type supported: Data types supported: F16/F32.
- * @param[in] cell_to_output_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p cell_to_input_weights.
- *
- * @return Reference to this LSTMParams object
- */
- LSTMParams &set_peephole_params(const T *cell_to_forget_weights, const T *cell_to_output_weights)
- {
- _cell_to_forget_weights = cell_to_forget_weights;
- _cell_to_output_weights = cell_to_output_weights;
- _has_peephole_opt = true;
- return *this;
- }
-
- const T *input_to_input_weights() const
- {
- return _input_to_input_weights;
- }
-
- const T *recurrent_to_input_weights() const
- {
- return _recurrent_to_input_weights;
- }
-
- const T *cell_to_input_weights() const
- {
- return _cell_to_input_weights;
- }
-
- const T *input_gate_bias() const
- {
- return _input_gate_bias;
- }
-
- const T *cell_to_forget_weights() const
- {
- return _cell_to_forget_weights;
- }
-
- const T *cell_to_output_weights() const
- {
- return _cell_to_output_weights;
- }
-
- const T *projection_weights() const
- {
- return _projection_weights;
- }
-
- const T *projection_bias() const
- {
- return _projection_bias;
- }
-
- bool has_peephole_opt() const
- {
- return _has_peephole_opt;
- }
-
- bool has_projection() const
- {
- return _has_projection;
- }
-
- bool has_cifg_opt() const
- {
- return _has_cifg_opt;
- }
-
-private:
- const T *_input_to_input_weights;
- const T *_recurrent_to_input_weights;
- const T *_cell_to_input_weights;
- const T *_input_gate_bias;
- const T *_cell_to_forget_weights;
- const T *_cell_to_output_weights;
- const T *_projection_weights;
- const T *_projection_bias;
- bool _has_peephole_opt;
- bool _has_projection;
- bool _has_cifg_opt;
-};
-
/** This function performs a single time step in a Long Short-Term Memory (LSTM) layer.
*
*/
diff --git a/arm_compute/runtime/NEON/NEFunctions.h b/arm_compute/runtime/NEON/NEFunctions.h
index e6d7114384..dabd78c256 100644
--- a/arm_compute/runtime/NEON/NEFunctions.h
+++ b/arm_compute/runtime/NEON/NEFunctions.h
@@ -82,6 +82,7 @@
#include "arm_compute/runtime/NEON/functions/NEIm2Col.h"
#include "arm_compute/runtime/NEON/functions/NEIntegralImage.h"
#include "arm_compute/runtime/NEON/functions/NEL2NormalizeLayer.h"
+#include "arm_compute/runtime/NEON/functions/NELSTMLayer.h"
#include "arm_compute/runtime/NEON/functions/NELaplacianPyramid.h"
#include "arm_compute/runtime/NEON/functions/NELaplacianReconstruct.h"
#include "arm_compute/runtime/NEON/functions/NELocallyConnectedLayer.h"
diff --git a/arm_compute/runtime/NEON/functions/NELSTMLayer.h b/arm_compute/runtime/NEON/functions/NELSTMLayer.h
new file mode 100644
index 0000000000..9c4ab2b068
--- /dev/null
+++ b/arm_compute/runtime/NEON/functions/NELSTMLayer.h
@@ -0,0 +1,210 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_NELSTMLAYER_H__
+#define __ARM_COMPUTE_NELSTMLAYER_H__
+
+#include "arm_compute/core/NEON/kernels/NEActivationLayerKernel.h"
+#include "arm_compute/core/NEON/kernels/NEArithmeticAdditionKernel.h"
+#include "arm_compute/core/NEON/kernels/NEArithmeticSubtractionKernel.h"
+#include "arm_compute/core/NEON/kernels/NECopyKernel.h"
+#include "arm_compute/core/NEON/kernels/NEPixelWiseMultiplicationKernel.h"
+
+#include "arm_compute/core/Types.h"
+#include "arm_compute/runtime/NEON/INESimpleFunction.h"
+#include "arm_compute/runtime/NEON/functions/NEArithmeticAddition.h"
+#include "arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h"
+#include "arm_compute/runtime/NEON/functions/NEGEMM.h"
+#include "arm_compute/runtime/NEON/functions/NEWidthConcatenateLayer.h"
+#include "arm_compute/runtime/common/LSTMParams.h"
+
+namespace arm_compute
+{
+// Forward declarations
+class ITensor;
+
+/** Basic function to run @ref NELSTMLayer */
+class NELSTMLayer : public IFunction
+{
+public:
+ /** Default constructor */
+ NELSTMLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
+ /** Initialize function's tensors.
+ *
+ * @param[in] input Source tensor. Input is a 2D tensor with dimensions [input_size, batch_size]. Data types supported: F16/F32.
+ * @param[in] input_to_forget_weights 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as @p input.
+ * @param[in] input_to_cell_weights 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as @p input.
+ * @param[in] input_to_output_weights 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as @p input.
+ * @param[in] recurrent_to_forget_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as @p input.
+ * @param[in] recurrent_to_cell_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as @p input.
+ * @param[in] recurrent_to_output_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as @p input.
+ * @param[in] forget_gate_bias 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input.
+ * @param[in] cell_bias 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input.
+ * @param[in] output_gate_bias 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input.
+ * @param[in] output_state_in 2D weights tensor with dimensions [output_size, batch_size]. Data type supported: Same as @p input.
+ * @param[in] cell_state_in 2D tensor with dimensions [num_units, batch_size]. Data type supported: Same as @p input.
+ * @param[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 @p input.
+ * @param[out] output_state_out 2D weights tensor with dimensions [output_size, batch_size]. Data type supported: Same as @p input.
+ * @param[out] cell_state_out 2D tensor with dimensions [num_units, batch_size]. Data type supported: Same as @p input.
+ * @param[out] output Destination tensor. Output is a 2D tensor with dimensions [output_size, batch_size].
+ * Data types supported: Same as @p input.
+ * @param[in] lstm_params (Optional) Weights tensors used in peephole optimization:
+ * input_to_input_weights 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as @p input.
+ * recurrent_to_input_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as @p input.
+ * cell_to_input_weights 1D weights tensor with dimensions [num_units]. Can be nullptr. Data type supported: Same as @p input.
+ * cell_to_forget_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input.
+ * cell_to_output_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input.
+ * input_gate_bias 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input
+ * projection_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as @p input.
+ * projection_bias 1D weights tensor with dimensions [output_size]. Data type supported: Same as @p input.
+ * @param[in] activation_info Contains activation information described in @ref ActivationLayerInfo.
+ * @param[in] cell_threshold The clipping threshold for the cell state, such that values are bound within [-cell_clip, cell_clip]. If set to 0.0 then clipping is disabled.
+ * @param[in] projection_threshold The clipping threshold for the output from the projection layer, such that values are bound within [-proj_clip, proj_clip]. If set to 0.0 then clipping is disabled.
+ */
+ 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);
+
+ /** Static function to check if given info will lead to a valid configuration of @ref NELSTMLayer
+ *
+ * @param[in] input Source tensor. Input is a 2D tensor with dimensions [input_size, batch_size]. Data types supported: F16/F32.
+ * @param[in] input_to_forget_weights 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as @p input.
+ * @param[in] input_to_cell_weights 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as @p input.
+ * @param[in] input_to_output_weights 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as @p input.
+ * @param[in] recurrent_to_forget_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as @p input.
+ * @param[in] recurrent_to_cell_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as @p input.
+ * @param[in] recurrent_to_output_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as @p input.
+ * @param[in] forget_gate_bias 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input.
+ * @param[in] cell_bias 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input.
+ * @param[in] output_gate_bias 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input.
+ * @param[in] output_state_in 2D weights tensor with dimensions [output_size, batch_size]. Data type supported: Same as @p input.
+ * @param[in] cell_state_in 2D tensor with dimensions [num_units, batch_size]. Data type supported: Same as @p input.
+ * @param[in] 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 @p input.
+ * @param[in] output_state_out 2D weights tensor with dimensions [output_size, batch_size]. Data type supported: Same as @p input.
+ * @param[in] cell_state_out 2D tensor with dimensions [num_units, batch_size]. Data type supported: Same as @p input.
+ * @param[in] output Destination tensor. Output is a 2D tensor with dimensions [output_size, batch_size].
+ * Data types supported: Same as @p input.
+ * @param[in] lstm_params (Optional) Weights tensors used in peephole optimization:
+ * input_to_input_weights 2D weights tensor with dimensions [input_size, num_units]. Data type supported: Same as @p input.
+ * recurrent_to_input_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as @p input.
+ * cell_to_input_weights 1D weights tensor with dimensions [num_units]. Can be nullptr. Data type supported: Same as @p input.
+ * cell_to_forget_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input.
+ * cell_to_output_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input.
+ * input_gate_bias 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input
+ * projection_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as @p input.
+ * projection_bias 1D weights tensor with dimensions [output_size]. Data type supported: Same as @p input.
+ * @param[in] activation_info Contains activation information described in @ref ActivationLayerInfo.
+ * @param[in] cell_threshold The clipping threshold for the cell state, such that values are bound within [-cell_clip, cell_clip]. If set to 0.0 then clipping is disabled.
+ * @param[in] projection_threshold The clipping threshold for the output from the projection layer, such that values are bound within [-proj_clip, proj_clip]. If set to 0.0 then clipping is disabled.
+ *
+ * @return a status
+ */
+ 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);
+
+ // Inherited methods overridden:
+ void run() override;
+
+private:
+ MemoryGroup _memory_group;
+ NEFullyConnectedLayer _fully_connected_input_gate;
+ NEGEMM _gemm_input_gate;
+ NETransposeKernel _transpose_input_gate;
+ NEArithmeticAdditionKernel _accum_input_gate1;
+ NEArithmeticAddition _accum_input_gate2;
+ NEArithmeticSubtractionKernel _subtract_input_gate;
+ NEPixelWiseMultiplicationKernel _pixelwise_mul_input_gate;
+ NEActivationLayerKernel _activation_input_gate;
+ NEFullyConnectedLayer _fully_connected_forget_gate;
+ NEGEMM _gemm_forget_gate;
+ NETransposeKernel _transpose_forget_gate;
+ NEArithmeticAdditionKernel _accum_forget_gate1;
+ NEArithmeticAddition _accum_forget_gate2;
+ NEPixelWiseMultiplicationKernel _pixelwise_mul_forget_gate;
+ NEActivationLayerKernel _activation_forget_gate;
+ NEFullyConnectedLayer _fully_connected_cell_state;
+ NEGEMM _gemm_cell_state1;
+ NEGEMM _gemm_cell_state2;
+ NETransposeKernel _transpose_cell_state;
+ NEArithmeticAdditionKernel _accum_cell_state1;
+ NEArithmeticAdditionKernel _accum_cell_state2;
+ NEPixelWiseMultiplicationKernel _pixelwise_mul_cell_state1;
+ NEActivationLayerKernel _activation_cell_state;
+ NEActivationLayerKernel _cell_clip;
+ NEPixelWiseMultiplicationKernel _pixelwise_mul_cell_state2;
+ NEFullyConnectedLayer _fully_connected_output;
+ NEGEMM _gemm_output;
+ NEPixelWiseMultiplicationKernel _pixelwise_mul_output_state1;
+ NETransposeKernel _transpose_output;
+ NEArithmeticAdditionKernel _accum_output1;
+ NEArithmeticAddition _accum_output2;
+ NEActivationLayerKernel _activation_output;
+ NEActivationLayerKernel _activation_output_state;
+ NEPixelWiseMultiplicationKernel _pixelwise_mul_output_state2;
+ NEFullyConnectedLayer _fully_connected_output_state;
+ NEGEMM _gemm_output_state;
+ NEArithmeticAdditionKernel _accum_output_state;
+ NEActivationLayerKernel _projection_clip;
+ NECopyKernel _copy_cell_state;
+ NECopyKernel _copy_output;
+ NEWidthConcatenateLayer _concat_scratch_buffer;
+ Tensor _input_gate_out1;
+ Tensor _input_gate_out2;
+ Tensor _input_gate_out3;
+ Tensor _input_gate_out4;
+ Tensor _input_gate_out5;
+ Tensor _forget_gate_out1;
+ Tensor _forget_gate_out2;
+ Tensor _forget_gate_out3;
+ Tensor _forget_gate_out4;
+ Tensor _forget_gate_out5;
+ Tensor _cell_state_out1;
+ Tensor _cell_state_out2;
+ Tensor _cell_state_out3;
+ Tensor _cell_state_out4;
+ Tensor _cell_state_out5;
+ Tensor _output1;
+ Tensor _output2;
+ Tensor _output3;
+ Tensor _output4;
+ Tensor _output5;
+ Tensor _cell_state_activation;
+ Tensor _output_state1;
+ Tensor _ones;
+ bool _run_peephole_opt;
+ bool _run_cifg_opt;
+ bool _perform_cell_clipping;
+ bool _has_projection_weights;
+ bool _perform_projection_clipping;
+};
+} // namespace arm_compute
+#endif /* __ARM_COMPUTE_NELSTMLAYER_H__ */
diff --git a/arm_compute/runtime/common/LSTMParams.h b/arm_compute/runtime/common/LSTMParams.h
new file mode 100644
index 0000000000..5b33e2e937
--- /dev/null
+++ b/arm_compute/runtime/common/LSTMParams.h
@@ -0,0 +1,169 @@
+/*
+ * Copyright (c) 2018 ARM Limited.
+ *
+ * SPDX-License-Identifier: MIT
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to
+ * deal in the Software without restriction, including without limitation the
+ * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+ * sell copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __ARM_COMPUTE_LSTMPARAMS_H__
+#define __ARM_COMPUTE_LSTMPARAMS_H__
+
+#include "arm_compute/core/IPyramid.h"
+#include "arm_compute/core/PyramidInfo.h"
+#include "arm_compute/core/Types.h"
+#include "arm_compute/runtime/Tensor.h"
+
+#include <cstddef>
+#include <memory>
+
+namespace arm_compute
+{
+template <typename T>
+class LSTMParams
+{
+public:
+ /** Constructor */
+ LSTMParams()
+ : _input_to_input_weights(nullptr), _recurrent_to_input_weights(nullptr), _cell_to_input_weights(nullptr), _input_gate_bias(nullptr), _cell_to_forget_weights(nullptr),
+ _cell_to_output_weights(nullptr), _projection_weights(nullptr), _projection_bias(nullptr), _has_peephole_opt(false), _has_projection(false), _has_cifg_opt(true)
+ {
+ }
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ LSTMParams(const LSTMParams &) = delete;
+ /** Prevent instances of this class from being copied (As this class contains pointers) */
+ LSTMParams &operator=(const LSTMParams &) = delete;
+ /** Default destructor */
+ ~LSTMParams() = default;
+ /** Set CIFG tensor parameters.
+ *
+ * @param[in] input_to_input_weights 2D weights tensor with dimensions [input_size, num_units]. Data types supported: F16/F32.
+ * @param[in] recurrent_to_input_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Same as @p input_to_input_weights.
+ * @param[in] cell_to_input_weights 1D weights tensor with dimensions [num_units]. Can be nullptr. Data type supported: Same as @p input_to_input_weights.
+ * @param[in] input_gate_bias 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input_to_input_weights
+ *
+ * @return Reference to this LSTMParams object
+ */
+ LSTMParams &set_cifg_params(const T *input_to_input_weights, const T *recurrent_to_input_weights, const T *cell_to_input_weights, const T *input_gate_bias)
+ {
+ _input_to_input_weights = input_to_input_weights;
+ _recurrent_to_input_weights = recurrent_to_input_weights;
+ _cell_to_input_weights = cell_to_input_weights;
+ _input_gate_bias = input_gate_bias;
+ _has_cifg_opt = false;
+ return *this;
+ }
+ /** Set projection tensor parameters.
+ *
+ * @param[in] projection_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Data types supported: F16/F32.
+ * @param[in] projection_bias 1D weights tensor with dimensions [output_size]. Data type supported: Same as @p projection_weights.
+ *
+ * @return Reference to this LSTMParams object
+ */
+ LSTMParams &set_projection_params(const T *projection_weights, const T *projection_bias)
+ {
+ _projection_weights = projection_weights;
+ _projection_bias = projection_bias;
+ _has_projection = true;
+ return *this;
+ }
+ /** Set peephole tensor parameters.
+ *
+ * @param[in] cell_to_forget_weights 1D weights tensor with dimensions [num_units]. Data type supported: Data types supported: F16/F32.
+ * @param[in] cell_to_output_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p cell_to_input_weights.
+ *
+ * @return Reference to this LSTMParams object
+ */
+ LSTMParams &set_peephole_params(const T *cell_to_forget_weights, const T *cell_to_output_weights)
+ {
+ _cell_to_forget_weights = cell_to_forget_weights;
+ _cell_to_output_weights = cell_to_output_weights;
+ _has_peephole_opt = true;
+ return *this;
+ }
+
+ const T *input_to_input_weights() const
+ {
+ return _input_to_input_weights;
+ }
+
+ const T *recurrent_to_input_weights() const
+ {
+ return _recurrent_to_input_weights;
+ }
+
+ const T *cell_to_input_weights() const
+ {
+ return _cell_to_input_weights;
+ }
+
+ const T *input_gate_bias() const
+ {
+ return _input_gate_bias;
+ }
+
+ const T *cell_to_forget_weights() const
+ {
+ return _cell_to_forget_weights;
+ }
+
+ const T *cell_to_output_weights() const
+ {
+ return _cell_to_output_weights;
+ }
+
+ const T *projection_weights() const
+ {
+ return _projection_weights;
+ }
+
+ const T *projection_bias() const
+ {
+ return _projection_bias;
+ }
+
+ bool has_peephole_opt() const
+ {
+ return _has_peephole_opt;
+ }
+
+ bool has_projection() const
+ {
+ return _has_projection;
+ }
+
+ bool has_cifg_opt() const
+ {
+ return _has_cifg_opt;
+ }
+
+private:
+ const T *_input_to_input_weights;
+ const T *_recurrent_to_input_weights;
+ const T *_cell_to_input_weights;
+ const T *_input_gate_bias;
+ const T *_cell_to_forget_weights;
+ const T *_cell_to_output_weights;
+ const T *_projection_weights;
+ const T *_projection_bias;
+ bool _has_peephole_opt;
+ bool _has_projection;
+ bool _has_cifg_opt;
+};
+}
+#endif /*__ARM_COMPUTE_LSTMPARAMS_H__ */