blob: bdba42d6ba86a508867a9b933bf5d2ab6e8c852a [file] [log] [blame]
Michalis Spyrou542e92d2018-06-05 11:45:48 +01001/*
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_NERNNLAYER_H__
25#define __ARM_COMPUTE_NERNNLAYER_H__
26
27#include "arm_compute/core/NEON/kernels/NEActivationLayerKernel.h"
28#include "arm_compute/core/NEON/kernels/NEArithmeticAdditionKernel.h"
Georgios Pinitas3ada2b72018-08-23 15:54:36 +010029#include "arm_compute/core/NEON/kernels/NECopyKernel.h"
Michalis Spyrou542e92d2018-06-05 11:45:48 +010030#include "arm_compute/runtime/NEON/INESimpleFunction.h"
31
32#include "arm_compute/core/Types.h"
33#include "arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h"
34#include "arm_compute/runtime/NEON/functions/NEGEMM.h"
35
36namespace arm_compute
37{
38// Forward declarations
39class ITensor;
40
41/** Basic function to run @ref NERNNLayer */
42class NERNNLayer : public IFunction
43{
44public:
45 /** Default constructor */
46 NERNNLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
47 /** Prevent instances of this class from being copied (As this class contains pointers) */
48 NERNNLayer(const NERNNLayer &) = delete;
49 /** Default move constructor */
50 NERNNLayer(NERNNLayer &&) = default;
51 /** Prevent instances of this class from being copied (As this class contains pointers) */
52 NERNNLayer &operator=(const NERNNLayer &) = delete;
53 /** Default move assignment operator */
54 NERNNLayer &operator=(NERNNLayer &&) = default;
55 /** Initialize the function
56 *
57 * @param[in] input Input is a 2-D tensor of shape [input_size, batch_size]. Data types supported: F16/F32
58 * @param[in] weights Weights tensor of shape [input_size, num_units] that multiplies the input. Data types supported: Same as @p input
59 * @param[in] recurrent_weights Weights tensor of shape [num_units, num_units] that multiplies the current 'state'. Data types supported: Same as @p input
60 * @param[in] bias Bias vector of shape [num_units]. Data types supported: Same as @p input
61 * @param[out] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
62 * @param[in,out] hidden_state Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
63 * @param[in] info Activation layer parameter.
64 */
65 void configure(const ITensor *input, const ITensor *weights, const ITensor *recurrent_weights, const ITensor *bias, ITensor *hidden_state, ITensor *output, ActivationLayerInfo &info);
66 /** Initialize the function
67 *
68 * @param[in] input Input is a 2-D tensor of shape [input_size, batch_size]. Data types supported: F16/F32
69 * @param[in] weights Weights tensor of shape [input_size, num_units] that multiplies the input. Data types supported: Same as @p input
70 * @param[in] recurrent_weights Weights tensor of shape [num_units, num_units] that multiplies the current 'state'. Data types supported: Same as @p input
71 * @param[in] bias Bias vector of shape [num_units]. Data types supported: Same as @p input
72 * @param[in] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
73 * @param[in] hidden_state Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
74 * @param[in] info Activation layer parameter.
75 *
76 * @return a status
77 */
78 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *recurrent_weights, const ITensorInfo *bias, const ITensorInfo *hidden_state, const ITensorInfo *output,
79 const ActivationLayerInfo &info);
80
81 // Inherited methods overridden:
82 void run() override;
Georgios Pinitas3ada2b72018-08-23 15:54:36 +010083 void prepare() override;
Michalis Spyrou542e92d2018-06-05 11:45:48 +010084
85private:
86 MemoryGroup _memory_group;
87 NEGEMM _gemm_state_f;
88 NEArithmeticAdditionKernel _add_kernel;
89 NEActivationLayerKernel _activation_kernel;
90 NEFullyConnectedLayer _fully_connected_kernel;
Georgios Pinitas3ada2b72018-08-23 15:54:36 +010091 NECopyKernel _copy_kernel;
Michalis Spyrou542e92d2018-06-05 11:45:48 +010092 Tensor _fully_connected_out;
93 Tensor _gemm_output;
94 Tensor _add_output;
Georgios Pinitas3ada2b72018-08-23 15:54:36 +010095 bool _is_prepared;
Michalis Spyrou542e92d2018-06-05 11:45:48 +010096};
97} // namespace arm_compute
98#endif /* __ARM_COMPUTE_NERNNLAYER_H__ */