blob: 12e3ef9c571f58e9f2d13d9ad6e7de98a68ac8fe [file] [log] [blame]
Michalis Spyrou542e92d2018-06-05 11:45:48 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Michalis Spyrou542e92d2018-06-05 11:45:48 +01003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NERNNLAYER_H
25#define ARM_COMPUTE_NERNNLAYER_H
Michalis Spyrou542e92d2018-06-05 11:45:48 +010026
Georgios Pinitas3ada2b72018-08-23 15:54:36 +010027#include "arm_compute/core/NEON/kernels/NECopyKernel.h"
Michalis Spyrou542e92d2018-06-05 11:45:48 +010028
29#include "arm_compute/core/Types.h"
Georgios Pinitas1fd2c802020-06-16 17:44:46 +010030#include "arm_compute/runtime/NEON/functions/NEActivationLayer.h"
Michalis Spyrou173ba9b2020-06-23 17:25:43 +010031#include "arm_compute/runtime/NEON/functions/NEArithmeticAddition.h"
Michalis Spyrou542e92d2018-06-05 11:45:48 +010032#include "arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h"
33#include "arm_compute/runtime/NEON/functions/NEGEMM.h"
34
35namespace arm_compute
36{
37// Forward declarations
38class ITensor;
39
40/** Basic function to run @ref NERNNLayer */
41class NERNNLayer : public IFunction
42{
43public:
44 /** Default constructor */
45 NERNNLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
46 /** Prevent instances of this class from being copied (As this class contains pointers) */
47 NERNNLayer(const NERNNLayer &) = delete;
48 /** Default move constructor */
49 NERNNLayer(NERNNLayer &&) = default;
50 /** Prevent instances of this class from being copied (As this class contains pointers) */
51 NERNNLayer &operator=(const NERNNLayer &) = delete;
52 /** Default move assignment operator */
53 NERNNLayer &operator=(NERNNLayer &&) = default;
54 /** Initialize the function
55 *
56 * @param[in] input Input is a 2-D tensor of shape [input_size, batch_size]. Data types supported: F16/F32
57 * @param[in] weights Weights tensor of shape [input_size, num_units] that multiplies the input. Data types supported: Same as @p input
58 * @param[in] recurrent_weights Weights tensor of shape [num_units, num_units] that multiplies the current 'state'. Data types supported: Same as @p input
59 * @param[in] bias Bias vector of shape [num_units]. Data types supported: Same as @p input
60 * @param[out] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
61 * @param[in,out] hidden_state Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
62 * @param[in] info Activation layer parameter.
63 */
64 void configure(const ITensor *input, const ITensor *weights, const ITensor *recurrent_weights, const ITensor *bias, ITensor *hidden_state, ITensor *output, ActivationLayerInfo &info);
65 /** Initialize the function
66 *
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[in] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
72 * @param[in] 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 * @return a status
76 */
77 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *recurrent_weights, const ITensorInfo *bias, const ITensorInfo *hidden_state, const ITensorInfo *output,
78 const ActivationLayerInfo &info);
79
80 // Inherited methods overridden:
81 void run() override;
Georgios Pinitas3ada2b72018-08-23 15:54:36 +010082 void prepare() override;
Michalis Spyrou542e92d2018-06-05 11:45:48 +010083
84private:
Michalis Spyrou173ba9b2020-06-23 17:25:43 +010085 MemoryGroup _memory_group;
86 NEGEMM _gemm_state_f;
87 NEArithmeticAddition _add_f;
88 NEActivationLayer _activation;
89 NEFullyConnectedLayer _fully_connected;
90 NECopyKernel _copy_kernel;
91 Tensor _fully_connected_out;
92 Tensor _gemm_output;
93 Tensor _add_output;
94 bool _is_prepared;
Michalis Spyrou542e92d2018-06-05 11:45:48 +010095};
96} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +000097#endif /* ARM_COMPUTE_NERNNLAYER_H */