| 1 |
/* |
| 2 |
* Copyright (c) 2020-2022, 2024 Arm Limited. |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
* |
| 6 |
* Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
* of this software and associated documentation files (the "Software"), to |
| 8 |
* deal in the Software without restriction, including without limitation the |
| 9 |
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 |
* sell copies of the Software, and to permit persons to whom the Software is |
| 11 |
* furnished to do so, subject to the following conditions: |
| 12 |
* |
| 13 |
* The above copyright notice and this permission notice shall be included in all |
| 14 |
* copies or substantial portions of the Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 |
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 |
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 |
* SOFTWARE. |
| 23 |
*/ |
| 24 |
#ifndef ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEQLSTMLAYER_H |
| 25 |
#define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEQLSTMLAYER_H |
| 26 |
|
| 27 |
#include "arm_compute/core/Types.h" |
| 28 |
#include "arm_compute/runtime/common/LSTMParams.h" |
| 29 |
#include "arm_compute/runtime/NEON/functions/NEActivationLayer.h" |
| 30 |
#include "arm_compute/runtime/NEON/functions/NEArithmeticAddition.h" |
| 31 |
#include "arm_compute/runtime/NEON/functions/NEArithmeticSubtraction.h" |
| 32 |
#include "arm_compute/runtime/NEON/functions/NECopy.h" |
| 33 |
#include "arm_compute/runtime/NEON/functions/NEDequantizationLayer.h" |
| 34 |
#include "arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCore.h" |
| 35 |
#include "arm_compute/runtime/NEON/functions/NEGEMMLowpOutputStage.h" |
| 36 |
#include "arm_compute/runtime/NEON/functions/NEPixelWiseMultiplication.h" |
| 37 |
#include "arm_compute/runtime/NEON/functions/NEQuantizationLayer.h" |
| 38 |
#include "arm_compute/runtime/NEON/functions/NETranspose.h" |
| 39 |
|
| 40 |
#include <memory> |
| 41 |
|
| 42 |
namespace arm_compute |
| 43 |
{ |
| 44 |
// Forward declarations |
| 45 |
class ITensor; |
| 46 |
class ITensorInfo; |
| 47 |
class NEQLSTMLayerNormalizationKernel; |
| 48 |
namespace cpu |
| 49 |
{ |
| 50 |
namespace kernels |
| 51 |
{ |
| 52 |
class CpuGemmLowpMatrixAReductionKernel; |
| 53 |
} // namespace kernels |
| 54 |
} // namespace cpu |
| 55 |
/** Basic function to run @ref NEQLSTMLayer |
| 56 |
* |
| 57 |
* This function calls the following kernels: |
| 58 |
* |
| 59 |
* -# @ref NEActivationLayer Activation functions (tanh and logistic) |
| 60 |
* -# @ref NEArithmeticAddition Elementwise addition |
| 61 |
* -# @ref NEArithmeticSubtraction Elementwise subtraction |
| 62 |
* -# @ref NECopy Copy kernel for copying output_state_out to output |
| 63 |
* -# @ref NEGEMMLowpMatrixMultiplyCore Quantized matrix multiplication core. Accumulators are 32-bit integers |
| 64 |
* -# @ref NEGEMMLowpOutputStage Convert 32-bit integers into QSYMM16 |
| 65 |
* -# cpu::kernels::CpuGemmLowpMatrixAReductionKernel For precomputing effective biases to use |
| 66 |
* -# @ref NEPixelWiseMultiplication Elementwise multiplication |
| 67 |
* -# @ref NETranspose Transpose function for reshaping the weights |
| 68 |
* */ |
| 69 |
class NEQLSTMLayer : public IFunction |
| 70 |
{ |
| 71 |
public: |
| 72 |
/** Default constructor */ |
| 73 |
NEQLSTMLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
| 74 |
/** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 75 |
NEQLSTMLayer(const NEQLSTMLayer &) = delete; |
| 76 |
/** Prevent instances of this class from being moved (As this class contains pointers) */ |
| 77 |
NEQLSTMLayer(NEQLSTMLayer &&) = delete; |
| 78 |
/** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 79 |
NEQLSTMLayer &operator=(const NEQLSTMLayer &) = delete; |
| 80 |
/** Prevent instances of this class from being moved (As this class contains pointers) */ |
| 81 |
NEQLSTMLayer &operator=(NEQLSTMLayer &&) = delete; |
| 82 |
/** Default destructor */ |
| 83 |
~NEQLSTMLayer(); |
| 84 |
/** Initialize function's tensors. |
| 85 |
* |
| 86 |
* Valid data layouts: |
| 87 |
* - All |
| 88 |
* |
| 89 |
* Valid data type configurations: |
| 90 |
* |src0 |src1 - src6 |src7 -src9 |src10 |src11 |dst0 |dst1 - dst2 | |
| 91 |
* |:-------------|:------------|:------------|:------|:-------------|:------|:-----------------| |
| 92 |
* |QASYMM8_SIGNED|QASYMM8 |S32 |QSYMM16|QASYMM8_SIGNED|QSYMM16|QASYMM8_SIGNED | |
| 93 |
* |
| 94 |
* @param[in] input Source tensor. Input is a 2D tensor with dimensions [input_size, batch_size]. Data types supported: QASYMM8_SIGNED. |
| 95 |
* @param[in] input_to_forget_weights 2D weights tensor with dimensions [input_size, num_units]. Data type supported: QSYMM8. |
| 96 |
* @param[in] input_to_cell_weights 2D weights tensor with dimensions [input_size, num_units]. Data type supported: QSYMM8. |
| 97 |
* @param[in] input_to_output_weights 2D weights tensor with dimensions [input_size, num_units]. Data type supported: QSYMM8. |
| 98 |
* @param[in] recurrent_to_forget_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: QSYMM8. |
| 99 |
* @param[in] recurrent_to_cell_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: QSYMM8. |
| 100 |
* @param[in] recurrent_to_output_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: QSYMM8. |
| 101 |
* @param[in] forget_gate_bias 1D weights tensor with dimensions [num_units]. Data type supported: S32. |
| 102 |
* @param[in] cell_bias 1D weights tensor with dimensions [num_units]. Data type supported: S32. |
| 103 |
* @param[in] output_gate_bias 1D weights tensor with dimensions [num_units]. Data type supported: S32. |
| 104 |
* @param[in] cell_state_in 2D tensor with dimensions [num_units, batch_size]. Data type supported: QSYMM16. |
| 105 |
* @param[in] output_state_in 2D tensor with dimensions [output_size, batch_size]. Data type supported: Same as @p input. |
| 106 |
* @param[out] cell_state_out Destination tensor. Output is a 2D tensor with dimensions [num_units, batch_size]. Data type supported: QSYMM16. |
| 107 |
* @param[out] output_state_out Destination tensor. Output is a 2D tensor with dimensions [output_size, batch_size].Data types supported: Same as @p input. |
| 108 |
* @param[out] output Destination tensor. Output is a 2D tensor with dimensions [output_size, batch_size].Data types supported: Same as @p input. |
| 109 |
* @param[in] lstm_params Weights tensors used in peephole, CIFG and layer normalization optimizations: |
| 110 |
* input_intermediate_scale Scale of the intermediate result of matmul, i.e. input to layer normalization, at input gate. |
| 111 |
* forget_intermediate_scale Scale of the intermediate result of matmul, i.e. input to layer normalization, at forget gate. |
| 112 |
* cell_intermediate_scale Scale of the intermediate result of matmul, i.e. input to layer normalization, at cell gate. |
| 113 |
* output_intermediate_scale Scale of the intermediate result of matmul, i.e. input to layer normalization, at output gate. |
| 114 |
* hidden_state_zero The zero point of the hidden state. |
| 115 |
* hidden_state_scale The scale of the hidden state. |
| 116 |
* input_to_input_weights (Optional) 2D weights tensor with dimensions [input_size, num_units]. Data type supported: QSYMM8. |
| 117 |
* recurrent_to_input_weights (Optional) 2D weights tensor with dimensions [output_size, num_units]. Data type supported: QSYMM8. |
| 118 |
* cell_to_input_weights (Optional) 1D weights tensor with dimensions [num_units]. Can be nullptr. Data type supported: QSYMM16. |
| 119 |
* cell_to_forget_weights (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: QSYMM16. |
| 120 |
* cell_to_output_weights (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: QSYMM16. |
| 121 |
* input_gate_bias (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: S32. |
| 122 |
* projection_weights (Optional) 2D weights tensor with dimensions [output_size, num_units]. Data type supported: QSYMM8. |
| 123 |
* projection_bias (Optional) 1D weights tensor with dimensions [output_size]. S32. |
| 124 |
* input_layer_norm_weights (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: QSYMM16. |
| 125 |
* forget_layer_norm_weights (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: QSYMM16. |
| 126 |
* cell_layer_norm_weights (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: QSYMM16. |
| 127 |
* output_layer_norm_weights (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: QSYMM16. |
| 128 |
* cell_threshold (Optional) The clipping threshold for the cell state, such that values are bound within [-cell_clip, cell_clip]. |
| 129 |
* If set to 0.0 then clipping is disabled. |
| 130 |
* projection_threshold (Optional) The clipping threshold for the output from the projection layer, such that values are bound within |
| 131 |
* [-proj_clip, proj_clip]. If set to 0.0 then clipping is disabled. |
| 132 |
*/ |
| 133 |
void configure(const ITensor *input, |
| 134 |
const ITensor *input_to_forget_weights, |
| 135 |
const ITensor *input_to_cell_weights, |
| 136 |
const ITensor *input_to_output_weights, |
| 137 |
const ITensor *recurrent_to_forget_weights, |
| 138 |
const ITensor *recurrent_to_cell_weights, |
| 139 |
const ITensor *recurrent_to_output_weights, |
| 140 |
const ITensor *forget_gate_bias, |
| 141 |
const ITensor *cell_bias, |
| 142 |
const ITensor *output_gate_bias, |
| 143 |
const ITensor *cell_state_in, |
| 144 |
ITensor *output_state_in, |
| 145 |
ITensor *cell_state_out, |
| 146 |
ITensor *output_state_out, |
| 147 |
ITensor *output, |
| 148 |
const LSTMParams<ITensor> &lstm_params); |
| 149 |
|
| 150 |
/** Static function to check if given info will lead to a valid configuration of @ref NEQLSTMLayer |
| 151 |
* |
| 152 |
* @param[in] input Source tensor info. Input is a 2D tensor info with dimensions [input_size, batch_size]. Data types supported: QASYMM8_SIGNED. |
| 153 |
* @param[in] input_to_forget_weights 2D weights tensor info with dimensions [input_size, num_units]. Data type supported: QSYMM8. |
| 154 |
* @param[in] input_to_cell_weights 2D weights tensor info with dimensions [input_size, num_units]. Data type supported: QSYMM8. |
| 155 |
* @param[in] input_to_output_weights 2D weights tensor info with dimensions [input_size, num_units]. Data type supported: QSYMM8. |
| 156 |
* @param[in] recurrent_to_forget_weights 2D weights tensor info with dimensions [output_size, num_units]. Data type supported: QSYMM8. |
| 157 |
* @param[in] recurrent_to_cell_weights 2D weights tensor info with dimensions [output_size, num_units]. Data type supported: QSYMM8. |
| 158 |
* @param[in] recurrent_to_output_weights 2D weights tensor info with dimensions [output_size, num_units]. Data type supported: QSYMM8. |
| 159 |
* @param[in] forget_gate_bias 1D weights tensor info with dimensions [num_units]. Data type supported: S32. |
| 160 |
* @param[in] cell_bias 1D weights tensor info with dimensions [num_units]. Data type supported: S32. |
| 161 |
* @param[in] output_gate_bias 1D weights tensor info with dimensions [num_units]. Data type supported: S32. |
| 162 |
* @param[in] cell_state_in 2D tensor info with dimensions [num_units, batch_size]. Data type supported: QSYMM16. |
| 163 |
* @param[in] output_state_in 2D tensor info with dimensions [output_size, batch_size]. Data type supported: Same as @p input. |
| 164 |
* @param[in] cell_state_out Destination tensor info. Output is a 2D tensor info with dimensions [num_units, batch_size]. Data type supported: QSYMM16. |
| 165 |
* @param[in] output_state_out Destination tensor info. Output is a 2D tensor info with dimensions [output_size, batch_size].Data types supported: Same as @p input. |
| 166 |
* @param[in] output Destination tensor info. Output is a 2D tensor info with dimensions [output_size, batch_size].Data types supported: Same as @p input. |
| 167 |
* @param[in] lstm_params Weights tensors info used in peephole, CIFG and layer normalization optimizations: |
| 168 |
* input_intermediate_scale Scale of the intermediate result of matmul, i.e. input to layer normalization, at input gate. |
| 169 |
* forget_intermediate_scale Scale of the intermediate result of matmul, i.e. input to layer normalization, at forget gate. |
| 170 |
* cell_intermediate_scale Scale of the intermediate result of matmul, i.e. input to layer normalization, at cell gate. |
| 171 |
* output_intermediate_scale Scale of the intermediate result of matmul, i.e. input to layer normalization, at output gate. |
| 172 |
* hidden_state_zero The zero point of the hidden state. |
| 173 |
* hidden_state_scale The scale of the hidden state. |
| 174 |
* input_to_input_weights (Optional) 2D weights tensor with dimensions [input_size, num_units]. Data type supported: QSYMM8. |
| 175 |
* recurrent_to_input_weights (Optional) 2D weights tensor with dimensions [output_size, num_units]. Data type supported: QSYMM8. |
| 176 |
* cell_to_input_weights (Optional) 1D weights tensor with dimensions [num_units]. Can be nullptr. Data type supported: QSYMM16. |
| 177 |
* cell_to_forget_weights (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: QSYMM16. |
| 178 |
* cell_to_output_weights (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: QSYMM16. |
| 179 |
* input_gate_bias (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: S32. |
| 180 |
* projection_weights (Optional) 2D weights tensor with dimensions [output_size, num_units]. Data type supported: QSYMM8. |
| 181 |
* projection_bias (Optional) 1D weights tensor with dimensions [output_size]. S32. |
| 182 |
* input_layer_norm_weights (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: QSYMM16. |
| 183 |
* forget_layer_norm_weights (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: QSYMM16. |
| 184 |
* cell_layer_norm_weights (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: QSYMM16. |
| 185 |
* output_layer_norm_weights (Optional) 1D weights tensor with dimensions [num_units]. Data type supported: QSYMM16. |
| 186 |
* cell_threshold (Optional) The clipping threshold for the cell state, such that values are bound within [-cell_clip, cell_clip]. |
| 187 |
* If set to 0.0 then clipping is disabled. |
| 188 |
* projection_threshold (Optional) The clipping threshold for the output from the projection layer, such that values are bound within |
| 189 |
* [-proj_clip, proj_clip]. If set to 0.0 then clipping is disabled. |
| 190 |
* @return a status |
| 191 |
*/ |
| 192 |
static Status validate(const ITensorInfo *input, |
| 193 |
const ITensorInfo *input_to_forget_weights, |
| 194 |
const ITensorInfo *input_to_cell_weights, |
| 195 |
const ITensorInfo *input_to_output_weights, |
| 196 |
const ITensorInfo *recurrent_to_forget_weights, |
| 197 |
const ITensorInfo *recurrent_to_cell_weights, |
| 198 |
const ITensorInfo *recurrent_to_output_weights, |
| 199 |
const ITensorInfo *forget_gate_bias, |
| 200 |
const ITensorInfo *cell_bias, |
| 201 |
const ITensorInfo *output_gate_bias, |
| 202 |
const ITensorInfo *cell_state_in, |
| 203 |
const ITensorInfo *output_state_in, |
| 204 |
const ITensorInfo *cell_state_out, |
| 205 |
const ITensorInfo *output_state_out, |
| 206 |
const ITensorInfo *output, |
| 207 |
const LSTMParams<ITensorInfo> &lstm_params); |
| 208 |
|
| 209 |
// Inherited methods overridden: |
| 210 |
void run() override; |
| 211 |
void prepare() override; |
| 212 |
|
| 213 |
private: |
| 214 |
enum class LayerNormGate : uint8_t |
| 215 |
{ |
| 216 |
Forget, |
| 217 |
Cell, |
| 218 |
Input, |
| 219 |
Output, |
| 220 |
Count |
| 221 |
}; |
| 222 |
static constexpr uint8_t _layer_norm_count = static_cast<uint8_t>(LayerNormGate::Count); |
| 223 |
static constexpr uint32_t _out_state_output_size_dimension_idx = 0; |
| 224 |
|
| 225 |
/** Internal method to configure matrix multiplication plus output stage of each gate. |
| 226 |
* |
| 227 |
* @param[in] mm Matrix multiplication function to use. |
| 228 |
* @param[in] outstage Output stage function to use. |
| 229 |
* @param[in] gemmlowp_info GEMMLowp metadata to be used by the output stage. |
| 230 |
* @param[in] mm_input Input tensor to matrix multiplication function. |
| 231 |
* @param[in] mm_weights Weights tensor to matrix multiplication function. |
| 232 |
* @param[in] bias Bias tensor to matrix multiplication function. |
| 233 |
* @param[in] outstage_res Tensor to be used for storing the result of the output stage. |
| 234 |
* @param[in] gemmlowp_scale Real multiplier to be used computing multiplier and shift for requantization. |
| 235 |
* @param[in] mm_res_info Tensor info to be used to initialize matrix multiplication result tensor. |
| 236 |
* @param[in] mm_res_info Tensor info to be used to initialize output stage result tensor. |
| 237 |
* |
| 238 |
*/ |
| 239 |
void configure_mm(NEGEMMLowpMatrixMultiplyCore &mm, |
| 240 |
NEGEMMLowpOutputStage &outstage, |
| 241 |
GEMMLowpOutputStageInfo &gemmlowp_info, |
| 242 |
const ITensor *mm_input, |
| 243 |
const ITensor *mm_weights, |
| 244 |
const ITensor *bias, |
| 245 |
Tensor *mm_res, |
| 246 |
Tensor *outstage_res, |
| 247 |
float gemmlowp_scale, |
| 248 |
const TensorInfo &mm_res_info, |
| 249 |
const TensorInfo &outstage_tensor_info); |
| 250 |
|
| 251 |
MemoryGroup _memory_group; |
| 252 |
|
| 253 |
/** A small internel kernel do the copy between two tensors */ |
| 254 |
class TensorCopyKernel |
| 255 |
{ |
| 256 |
static constexpr uint32_t max_dimension_supported = 2; |
| 257 |
|
| 258 |
ITensor *_src{nullptr}; |
| 259 |
ITensor *_dst{nullptr}; |
| 260 |
size_t _row_size{}; |
| 261 |
Window _window{}; |
| 262 |
|
| 263 |
public: |
| 264 |
/** Destructor */ |
| 265 |
~TensorCopyKernel(); |
| 266 |
/** Static function to check if given info will lead to a valid configuration of @ref NEQLSTMLayer::TensorCopyKernel |
| 267 |
* |
| 268 |
* @param[in] src Source tensor info. |
| 269 |
* @param[in] dst Destination tensor info |
| 270 |
* |
| 271 |
* @return a status |
| 272 |
*/ |
| 273 |
static Status validate(const ITensorInfo &src, const ITensorInfo &dst); |
| 274 |
/** Set the input and output tensors. |
| 275 |
* |
| 276 |
* @param[in] src Source tensor |
| 277 |
* @param[out] dst Destination tensor |
| 278 |
*/ |
| 279 |
void configure(ITensor &src, ITensor &dst); |
| 280 |
/** run the kernel */ |
| 281 |
void run(); |
| 282 |
}; |
| 283 |
|
| 284 |
// Functions used |
| 285 |
|
| 286 |
NEDequantizationLayer _dequantize_input_to_forget_weights; |
| 287 |
NEQuantizationLayer _quantize_input_to_forget_weights; |
| 288 |
NETranspose _transpose_input_to_forget_weights; |
| 289 |
NETranspose _transpose_input_to_cell_weights; |
| 290 |
NETranspose _transpose_input_to_output_weights; |
| 291 |
NETranspose _transpose_input_to_input_weights; |
| 292 |
NETranspose _transpose_recurrent_to_forget_weights; |
| 293 |
NETranspose _transpose_recurrent_to_cell_weights; |
| 294 |
NETranspose _transpose_recurrent_to_output_weights; |
| 295 |
NETranspose _transpose_recurrent_to_input_weights; |
| 296 |
NETranspose _transpose_projection_weights; |
| 297 |
std::unique_ptr<cpu::kernels::CpuGemmLowpMatrixAReductionKernel> _input_to_input_reduction; |
| 298 |
std::unique_ptr<cpu::kernels::CpuGemmLowpMatrixAReductionKernel> _recurrent_to_input_reduction; |
| 299 |
std::unique_ptr<cpu::kernels::CpuGemmLowpMatrixAReductionKernel> _input_to_forget_reduction; |
| 300 |
std::unique_ptr<cpu::kernels::CpuGemmLowpMatrixAReductionKernel> _recurrent_to_forget_reduction; |
| 301 |
std::unique_ptr<cpu::kernels::CpuGemmLowpMatrixAReductionKernel> _input_to_cell_reduction; |
| 302 |
std::unique_ptr<cpu::kernels::CpuGemmLowpMatrixAReductionKernel> _recurrent_to_cell_reduction; |
| 303 |
std::unique_ptr<cpu::kernels::CpuGemmLowpMatrixAReductionKernel> _input_to_output_reduction; |
| 304 |
std::unique_ptr<cpu::kernels::CpuGemmLowpMatrixAReductionKernel> _recurrent_to_output_reduction; |
| 305 |
std::unique_ptr<cpu::kernels::CpuGemmLowpMatrixAReductionKernel> _projection_reduction; |
| 306 |
NEArithmeticAddition _projection_bias_add; |
| 307 |
NEGEMMLowpMatrixMultiplyCore _mm_input_to_forget; |
| 308 |
NEGEMMLowpMatrixMultiplyCore _mm_recurrent_to_forget; |
| 309 |
NEPixelWiseMultiplication _pixelwise_mul_cell_to_forget; |
| 310 |
NEGEMMLowpOutputStage _input_to_forget_outstage; |
| 311 |
NEGEMMLowpOutputStage _recurrent_to_forget_outstage; |
| 312 |
NEGEMMLowpOutputStage _cell_to_forget_outstage; |
| 313 |
NEArithmeticAddition _accumulate_input_recurrent_forget; |
| 314 |
NEArithmeticAddition _accumulate_cell_forget; |
| 315 |
NEActivationLayer _forget_gate_sigmoid; |
| 316 |
NEGEMMLowpMatrixMultiplyCore _mm_input_to_cell; |
| 317 |
NEGEMMLowpOutputStage _input_to_cell_outstage; |
| 318 |
NEGEMMLowpMatrixMultiplyCore _mm_recurrent_to_cell; |
| 319 |
NEGEMMLowpOutputStage _recurrent_to_cell_outstage; |
| 320 |
NEArithmeticAddition _accumulate_input_recurrent_modulation; |
| 321 |
NEActivationLayer _cell_gate_tanh; |
| 322 |
NEArithmeticSubtraction _input_gate_sub; |
| 323 |
NEGEMMLowpMatrixMultiplyCore _mm_input_to_input; |
| 324 |
NEGEMMLowpOutputStage _input_to_input_outstage; |
| 325 |
NEGEMMLowpMatrixMultiplyCore _mm_recurrent_to_input; |
| 326 |
NEGEMMLowpOutputStage _recurrent_to_input_outstage; |
| 327 |
NEArithmeticAddition _accumulate_input_recurrent_input; |
| 328 |
NEPixelWiseMultiplication _pixelwise_mul_cell_to_input; |
| 329 |
NEGEMMLowpOutputStage _cell_to_input_outstage; |
| 330 |
NEArithmeticAddition _accumulate_cell_input; |
| 331 |
NEActivationLayer _input_gate_sigmoid; |
| 332 |
NEPixelWiseMultiplication _pixelwise_mul_forget_cell; |
| 333 |
NEPixelWiseMultiplication _pixelwise_mul_input_cell; |
| 334 |
NEArithmeticAddition _add_forget_cell; |
| 335 |
NEActivationLayer _cell_clip; |
| 336 |
NEGEMMLowpMatrixMultiplyCore _mm_input_to_output; |
| 337 |
NEGEMMLowpOutputStage _input_to_output_outstage; |
| 338 |
NEGEMMLowpMatrixMultiplyCore _mm_recurrent_to_output; |
| 339 |
NEGEMMLowpOutputStage _recurrent_to_output_outstage; |
| 340 |
NEArithmeticAddition _accumulate_input_recurrent_output; |
| 341 |
NEPixelWiseMultiplication _pixelwise_mul_cell_to_output; |
| 342 |
NEGEMMLowpOutputStage _cell_to_output_outstage; |
| 343 |
NEArithmeticAddition _accumulate_cell_to_output; |
| 344 |
NEActivationLayer _output_gate_sigmoid; |
| 345 |
NEActivationLayer _hidden_tanh; |
| 346 |
NEPixelWiseMultiplication _pixelwise_mul_hidden; |
| 347 |
NEGEMMLowpOutputStage _hidden_outstage; |
| 348 |
NEGEMMLowpMatrixMultiplyCore _mm_projection; |
| 349 |
NEGEMMLowpOutputStage _projection_outstage; |
| 350 |
NEArithmeticAddition _accumulate_projection; |
| 351 |
NEActivationLayer _projection_clip; |
| 352 |
|
| 353 |
TensorCopyKernel _projection_bias_copy; |
| 354 |
TensorCopyKernel _projection_output_to_accumulate_copy; |
| 355 |
TensorCopyKernel _projection_accumulate_to_output_copy; |
| 356 |
TensorCopyKernel _hidden_to_output_copy; |
| 357 |
|
| 358 |
std::array<std::unique_ptr<NEQLSTMLayerNormalizationKernel>, _layer_norm_count> _layer_norms; |
| 359 |
|
| 360 |
NECopy _copy_output; |
| 361 |
|
| 362 |
// Tensor pointers |
| 363 |
const ITensor *_input_to_input_weights{nullptr}; |
| 364 |
const ITensor *_recurrent_to_input_weights{nullptr}; |
| 365 |
const ITensor *_projection_bias{nullptr}; |
| 366 |
const ITensor *_input_to_forget_weights{nullptr}; |
| 367 |
const ITensor *_input_to_cell_weights{nullptr}; |
| 368 |
const ITensor *_input_to_output_weights{nullptr}; |
| 369 |
const ITensor *_recurrent_to_forget_weights{nullptr}; |
| 370 |
const ITensor *_recurrent_to_cell_weights{nullptr}; |
| 371 |
const ITensor *_recurrent_to_output_weights{nullptr}; |
| 372 |
const ITensor *_projection_weights{nullptr}; |
| 373 |
std::array<const ITensor *, _layer_norm_count> _layer_norm_weights{}; |
| 374 |
std::array<const ITensor *, _layer_norm_count> _layer_norm_bias{}; |
| 375 |
|
| 376 |
using LayerNormIndexType = typename std::underlying_type<LayerNormGate>::type; |
| 377 |
inline LayerNormIndexType getGateIndex(LayerNormGate g) |
| 378 |
{ |
| 379 |
return static_cast<LayerNormIndexType>(g); |
| 380 |
} |
| 381 |
|
| 382 |
inline void set_layer_norm_weight(const ITensor *t, LayerNormGate g) |
| 383 |
{ |
| 384 |
_layer_norm_weights[getGateIndex(g)] = t; |
| 385 |
} |
| 386 |
|
| 387 |
inline void set_layer_norm_bias(const ITensor *t, LayerNormGate g) |
| 388 |
{ |
| 389 |
_layer_norm_bias[getGateIndex(g)] = t; |
| 390 |
} |
| 391 |
|
| 392 |
inline const ITensor *get_layer_norm_weight(LayerNormGate g) |
| 393 |
{ |
| 394 |
return _layer_norm_weights[getGateIndex(g)]; |
| 395 |
} |
| 396 |
|
| 397 |
inline const ITensor *get_layer_norm_bias(LayerNormGate g) |
| 398 |
{ |
| 399 |
return _layer_norm_bias[getGateIndex(g)]; |
| 400 |
} |
| 401 |
|
| 402 |
inline std::unique_ptr<NEQLSTMLayerNormalizationKernel> &get_layer_norm(LayerNormGate g) |
| 403 |
{ |
| 404 |
return _layer_norms[getGateIndex(g)]; |
| 405 |
} |
| 406 |
|
| 407 |
void configure_layer_norm(LayerNormGate g, const ITensor *in); |
| 408 |
static Status validate_layer_norm(const ITensorInfo &in, const ITensorInfo &weight, const ITensorInfo &bias); |
| 409 |
|
| 410 |
// Temporary tensors |
| 411 |
Tensor _input_to_forget_weights_f32{nullptr}; |
| 412 |
Tensor _input_to_forget_weights_symm8{nullptr}; |
| 413 |
|
| 414 |
Tensor _input_to_forget_weights_transposed{nullptr}; |
| 415 |
Tensor _input_to_cell_weights_transposed{nullptr}; |
| 416 |
Tensor _input_to_output_weights_transposed{nullptr}; |
| 417 |
Tensor _input_to_input_weights_transposed{nullptr}; |
| 418 |
Tensor _recurrent_to_forget_weights_transposed{nullptr}; |
| 419 |
Tensor _recurrent_to_cell_weights_transposed{nullptr}; |
| 420 |
Tensor _recurrent_to_output_weights_transposed{nullptr}; |
| 421 |
Tensor _recurrent_to_input_weights_transposed{nullptr}; |
| 422 |
Tensor _projection_weights_transposed{nullptr}; |
| 423 |
Tensor _input_to_input_eff_bias{nullptr}; |
| 424 |
Tensor _recurrent_to_input_eff_bias{nullptr}; |
| 425 |
Tensor _input_to_forget_eff_bias{nullptr}; |
| 426 |
Tensor _recurrent_to_forget_eff_bias{nullptr}; |
| 427 |
Tensor _input_to_cell_eff_bias{nullptr}; |
| 428 |
Tensor _recurrent_to_cell_eff_bias{nullptr}; |
| 429 |
Tensor _input_to_output_eff_bias{nullptr}; |
| 430 |
Tensor _recurrent_to_output_eff_bias{nullptr}; |
| 431 |
Tensor _projection_reduction_res{nullptr}; |
| 432 |
Tensor _projection_eff_bias{nullptr}; |
| 433 |
Tensor _mm_input_to_forget_res{nullptr}; |
| 434 |
Tensor _mm_recurrent_to_forget_res{nullptr}; |
| 435 |
Tensor _mul_cell_to_forget_res{nullptr}; |
| 436 |
Tensor _input_to_forget_outstage_res{nullptr}; |
| 437 |
Tensor _cell_to_forget_outstage_res{nullptr}; |
| 438 |
Tensor _recurrent_to_forget_outstage_res{nullptr}; |
| 439 |
Tensor _forget_gate{nullptr}; |
| 440 |
Tensor _mm_input_to_cell_res{nullptr}; |
| 441 |
Tensor _input_to_cell_outstage_res{nullptr}; |
| 442 |
Tensor _mm_recurrent_to_cell_res{nullptr}; |
| 443 |
Tensor _recurrent_to_cell_outstage_res{nullptr}; |
| 444 |
Tensor _cell_gate{nullptr}; |
| 445 |
Tensor _mul_input_cell_res{nullptr}; |
| 446 |
Tensor _mm_input_to_input_res{nullptr}; |
| 447 |
Tensor _input_to_input_outstage_res{nullptr}; |
| 448 |
Tensor _mm_recurrent_to_input_res{nullptr}; |
| 449 |
Tensor _mul_cell_to_input_res{nullptr}; |
| 450 |
Tensor _cell_to_input_outstage_res{nullptr}; |
| 451 |
Tensor _recurrent_to_input_outstage_res{nullptr}; |
| 452 |
Tensor _input_gate{nullptr}; |
| 453 |
Tensor _mm_input_to_output_res{nullptr}; |
| 454 |
Tensor _input_to_output_outstage_res{nullptr}; |
| 455 |
Tensor _mm_recurrent_to_output_res{nullptr}; |
| 456 |
Tensor _mul_cell_to_output_res{nullptr}; |
| 457 |
Tensor _cell_to_output_outstage_res{nullptr}; |
| 458 |
Tensor _recurrent_to_output_outstage_res{nullptr}; |
| 459 |
Tensor _output_gate{nullptr}; |
| 460 |
Tensor _hidden_mul_res{nullptr}; |
| 461 |
Tensor _hidden_gate{nullptr}; |
| 462 |
Tensor _mm_projection_res{nullptr}; |
| 463 |
Tensor _projection_outstage_res{nullptr}; |
| 464 |
Tensor _projection_out_res{nullptr}; |
| 465 |
Tensor _projection_accumulate_res{nullptr}; |
| 466 |
Tensor _ones{nullptr}; |
| 467 |
std::array<Tensor, _layer_norm_count> _layer_norm_output{}; |
| 468 |
|
| 469 |
inline Tensor &get_layer_norm_output(LayerNormGate g) |
| 470 |
{ |
| 471 |
return _layer_norm_output[getGateIndex(g)]; |
| 472 |
} |
| 473 |
|
| 474 |
bool _is_prepared{false}; |
| 475 |
bool _has_cifg{false}; |
| 476 |
bool _has_cell_clipping{false}; |
| 477 |
bool _has_projection{false}; |
| 478 |
bool _has_projection_clipping{false}; |
| 479 |
bool _has_peephole{false}; |
| 480 |
bool _has_layer_norm{false}; |
| 481 |
bool _projection_tensor_copy_required{false}; |
| 482 |
bool _convert_input_to_forget_weights_to_qsymm8{false}; |
| 483 |
}; |
| 484 |
} // namespace arm_compute |
| 485 |
#endif // ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEQLSTMLAYER_H |