Michalis Spyrou | 542e92d | 2018-06-05 11:45:48 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021 Arm Limited. |
Michalis Spyrou | 542e92d | 2018-06-05 11:45:48 +0100 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NERNNLAYER_H |
| 25 | #define ARM_COMPUTE_NERNNLAYER_H |
Michalis Spyrou | 542e92d | 2018-06-05 11:45:48 +0100 | [diff] [blame] | 26 | |
Michalis Spyrou | 542e92d | 2018-06-05 11:45:48 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/Types.h" |
Georgios Pinitas | 1fd2c80 | 2020-06-16 17:44:46 +0100 | [diff] [blame] | 28 | #include "arm_compute/runtime/NEON/functions/NEActivationLayer.h" |
Michalis Spyrou | 173ba9b | 2020-06-23 17:25:43 +0100 | [diff] [blame] | 29 | #include "arm_compute/runtime/NEON/functions/NEArithmeticAddition.h" |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 30 | #include "arm_compute/runtime/NEON/functions/NECopy.h" |
Michalis Spyrou | 542e92d | 2018-06-05 11:45:48 +0100 | [diff] [blame] | 31 | #include "arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h" |
| 32 | #include "arm_compute/runtime/NEON/functions/NEGEMM.h" |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | // Forward declarations |
| 37 | class ITensor; |
| 38 | |
| 39 | /** Basic function to run @ref NERNNLayer */ |
| 40 | class NERNNLayer : public IFunction |
| 41 | { |
| 42 | public: |
| 43 | /** Default constructor */ |
| 44 | NERNNLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
| 45 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 46 | NERNNLayer(const NERNNLayer &) = delete; |
Michalis Spyrou | 770dfeb | 2020-11-04 18:55:34 +0000 | [diff] [blame] | 47 | /** Prevent instances of this class from being moved (As this class contains pointers) */ |
| 48 | NERNNLayer(NERNNLayer &&) = delete; |
Michalis Spyrou | 542e92d | 2018-06-05 11:45:48 +0100 | [diff] [blame] | 49 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 50 | NERNNLayer &operator=(const NERNNLayer &) = delete; |
Michalis Spyrou | 770dfeb | 2020-11-04 18:55:34 +0000 | [diff] [blame] | 51 | /** Prevent instances of this class from being moved (As this class contains pointers) */ |
| 52 | NERNNLayer &operator=(NERNNLayer &&) = delete; |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 53 | /** Default destructor */ |
| 54 | ~NERNNLayer(); |
Michalis Spyrou | 542e92d | 2018-06-05 11:45:48 +0100 | [diff] [blame] | 55 | /** Initialize the function |
| 56 | * |
Teresa Charlin | 6268742 | 2021-04-28 10:58:49 +0100 | [diff] [blame] | 57 | * Valid data layouts: |
| 58 | * - NHWC |
| 59 | * - NCHW |
| 60 | * |
| 61 | * Valid data type configurations: |
| 62 | * |src0 |src1 |src2 |src3 |dst0 |dst1 | |
| 63 | * |:------|:------|:------|:------|:------|:------| |
| 64 | * |F16 |F16 |F16 |F16 |F16 |F16 | |
| 65 | * |F32 |F32 |F32 |F32 |F32 |F32 | |
| 66 | * |
Michalis Spyrou | 542e92d | 2018-06-05 11:45:48 +0100 | [diff] [blame] | 67 | * @param[in] input Input is a 2-D tensor of shape [input_size, batch_size]. Data types supported: F16/F32 |
| 68 | * @param[in] weights Weights tensor of shape [input_size, num_units] that multiplies the input. Data types supported: Same as @p input |
| 69 | * @param[in] recurrent_weights Weights tensor of shape [num_units, num_units] that multiplies the current 'state'. Data types supported: Same as @p input |
| 70 | * @param[in] bias Bias vector of shape [num_units]. Data types supported: Same as @p input |
| 71 | * @param[out] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input |
| 72 | * @param[in,out] hidden_state Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input |
| 73 | * @param[in] info Activation layer parameter. |
| 74 | */ |
| 75 | void configure(const ITensor *input, const ITensor *weights, const ITensor *recurrent_weights, const ITensor *bias, ITensor *hidden_state, ITensor *output, ActivationLayerInfo &info); |
| 76 | /** Initialize the function |
| 77 | * |
| 78 | * @param[in] input Input is a 2-D tensor of shape [input_size, batch_size]. Data types supported: F16/F32 |
| 79 | * @param[in] weights Weights tensor of shape [input_size, num_units] that multiplies the input. Data types supported: Same as @p input |
| 80 | * @param[in] recurrent_weights Weights tensor of shape [num_units, num_units] that multiplies the current 'state'. Data types supported: Same as @p input |
| 81 | * @param[in] bias Bias vector of shape [num_units]. Data types supported: Same as @p input |
| 82 | * @param[in] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input |
| 83 | * @param[in] hidden_state Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input |
| 84 | * @param[in] info Activation layer parameter. |
| 85 | * |
| 86 | * @return a status |
| 87 | */ |
| 88 | static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *recurrent_weights, const ITensorInfo *bias, const ITensorInfo *hidden_state, const ITensorInfo *output, |
| 89 | const ActivationLayerInfo &info); |
| 90 | |
| 91 | // Inherited methods overridden: |
| 92 | void run() override; |
Georgios Pinitas | 3ada2b7 | 2018-08-23 15:54:36 +0100 | [diff] [blame] | 93 | void prepare() override; |
Michalis Spyrou | 542e92d | 2018-06-05 11:45:48 +0100 | [diff] [blame] | 94 | |
| 95 | private: |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 96 | MemoryGroup _memory_group; |
| 97 | NEGEMM _gemm_state_f; |
| 98 | NEArithmeticAddition _add_f; |
| 99 | NEActivationLayer _activation; |
| 100 | NEFullyConnectedLayer _fully_connected; |
| 101 | NECopy _copy_f; |
| 102 | Tensor _fully_connected_out; |
| 103 | Tensor _gemm_output; |
| 104 | Tensor _add_output; |
| 105 | bool _is_prepared; |
Michalis Spyrou | 542e92d | 2018-06-05 11:45:48 +0100 | [diff] [blame] | 106 | }; |
| 107 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 108 | #endif /* ARM_COMPUTE_NERNNLAYER_H */ |