Michalis Spyrou | 25f45a4 | 2018-08-08 12:53:05 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2018 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 __ARM_COMPUTE_LSTMPARAMS_H__ |
| 25 | #define __ARM_COMPUTE_LSTMPARAMS_H__ |
| 26 | |
| 27 | #include "arm_compute/core/IPyramid.h" |
| 28 | #include "arm_compute/core/PyramidInfo.h" |
| 29 | #include "arm_compute/core/Types.h" |
| 30 | #include "arm_compute/runtime/Tensor.h" |
| 31 | |
| 32 | #include <cstddef> |
| 33 | #include <memory> |
| 34 | |
| 35 | namespace arm_compute |
| 36 | { |
| 37 | template <typename T> |
| 38 | class LSTMParams |
| 39 | { |
| 40 | public: |
| 41 | /** Constructor */ |
| 42 | LSTMParams() |
| 43 | : _input_to_input_weights(nullptr), _recurrent_to_input_weights(nullptr), _cell_to_input_weights(nullptr), _input_gate_bias(nullptr), _cell_to_forget_weights(nullptr), |
| 44 | _cell_to_output_weights(nullptr), _projection_weights(nullptr), _projection_bias(nullptr), _has_peephole_opt(false), _has_projection(false), _has_cifg_opt(true) |
| 45 | { |
| 46 | } |
| 47 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 48 | LSTMParams(const LSTMParams &) = delete; |
| 49 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 50 | LSTMParams &operator=(const LSTMParams &) = delete; |
| 51 | /** Default destructor */ |
| 52 | ~LSTMParams() = default; |
| 53 | /** Set CIFG tensor parameters. |
| 54 | * |
| 55 | * @param[in] input_to_input_weights 2D weights tensor with dimensions [input_size, num_units]. Data types supported: F16/F32. |
| 56 | * @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. |
| 57 | * @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. |
| 58 | * @param[in] input_gate_bias 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p input_to_input_weights |
| 59 | * |
| 60 | * @return Reference to this LSTMParams object |
| 61 | */ |
| 62 | 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) |
| 63 | { |
| 64 | _input_to_input_weights = input_to_input_weights; |
| 65 | _recurrent_to_input_weights = recurrent_to_input_weights; |
| 66 | _cell_to_input_weights = cell_to_input_weights; |
| 67 | _input_gate_bias = input_gate_bias; |
| 68 | _has_cifg_opt = false; |
| 69 | return *this; |
| 70 | } |
| 71 | /** Set projection tensor parameters. |
| 72 | * |
| 73 | * @param[in] projection_weights 2D weights tensor with dimensions [output_size, num_units]. Data type supported: Data types supported: F16/F32. |
| 74 | * @param[in] projection_bias 1D weights tensor with dimensions [output_size]. Data type supported: Same as @p projection_weights. |
| 75 | * |
| 76 | * @return Reference to this LSTMParams object |
| 77 | */ |
| 78 | LSTMParams &set_projection_params(const T *projection_weights, const T *projection_bias) |
| 79 | { |
| 80 | _projection_weights = projection_weights; |
| 81 | _projection_bias = projection_bias; |
| 82 | _has_projection = true; |
| 83 | return *this; |
| 84 | } |
| 85 | /** Set peephole tensor parameters. |
| 86 | * |
| 87 | * @param[in] cell_to_forget_weights 1D weights tensor with dimensions [num_units]. Data type supported: Data types supported: F16/F32. |
| 88 | * @param[in] cell_to_output_weights 1D weights tensor with dimensions [num_units]. Data type supported: Same as @p cell_to_input_weights. |
| 89 | * |
| 90 | * @return Reference to this LSTMParams object |
| 91 | */ |
| 92 | LSTMParams &set_peephole_params(const T *cell_to_forget_weights, const T *cell_to_output_weights) |
| 93 | { |
| 94 | _cell_to_forget_weights = cell_to_forget_weights; |
| 95 | _cell_to_output_weights = cell_to_output_weights; |
| 96 | _has_peephole_opt = true; |
| 97 | return *this; |
| 98 | } |
| 99 | |
| 100 | const T *input_to_input_weights() const |
| 101 | { |
| 102 | return _input_to_input_weights; |
| 103 | } |
| 104 | |
| 105 | const T *recurrent_to_input_weights() const |
| 106 | { |
| 107 | return _recurrent_to_input_weights; |
| 108 | } |
| 109 | |
| 110 | const T *cell_to_input_weights() const |
| 111 | { |
| 112 | return _cell_to_input_weights; |
| 113 | } |
| 114 | |
| 115 | const T *input_gate_bias() const |
| 116 | { |
| 117 | return _input_gate_bias; |
| 118 | } |
| 119 | |
| 120 | const T *cell_to_forget_weights() const |
| 121 | { |
| 122 | return _cell_to_forget_weights; |
| 123 | } |
| 124 | |
| 125 | const T *cell_to_output_weights() const |
| 126 | { |
| 127 | return _cell_to_output_weights; |
| 128 | } |
| 129 | |
| 130 | const T *projection_weights() const |
| 131 | { |
| 132 | return _projection_weights; |
| 133 | } |
| 134 | |
| 135 | const T *projection_bias() const |
| 136 | { |
| 137 | return _projection_bias; |
| 138 | } |
| 139 | |
| 140 | bool has_peephole_opt() const |
| 141 | { |
| 142 | return _has_peephole_opt; |
| 143 | } |
| 144 | |
| 145 | bool has_projection() const |
| 146 | { |
| 147 | return _has_projection; |
| 148 | } |
| 149 | |
| 150 | bool has_cifg_opt() const |
| 151 | { |
| 152 | return _has_cifg_opt; |
| 153 | } |
| 154 | |
| 155 | private: |
| 156 | const T *_input_to_input_weights; |
| 157 | const T *_recurrent_to_input_weights; |
| 158 | const T *_cell_to_input_weights; |
| 159 | const T *_input_gate_bias; |
| 160 | const T *_cell_to_forget_weights; |
| 161 | const T *_cell_to_output_weights; |
| 162 | const T *_projection_weights; |
| 163 | const T *_projection_bias; |
| 164 | bool _has_peephole_opt; |
| 165 | bool _has_projection; |
| 166 | bool _has_cifg_opt; |
| 167 | }; |
| 168 | } |
| 169 | #endif /*__ARM_COMPUTE_LSTMPARAMS_H__ */ |