Debian Codegraph @

arm_compute/runtime/NEON/functions/NERNNLayer.h

raw
1 /*
2 * Copyright (c) 2018-2021, 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_NERNNLAYER_H
25 #define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NERNNLAYER_H
26
27 #include "arm_compute/core/Types.h"
28 #include "arm_compute/runtime/MemoryManagerOnDemand.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/NECopy.h"
32 #include "arm_compute/runtime/NEON/functions/NEFullyConnectedLayer.h"
33 #include "arm_compute/runtime/NEON/functions/NEGEMM.h"
34
35 namespace arm_compute
36 {
37 // Forward declarations
38 class ITensor;
39
40 /** Basic function to run @ref NERNNLayer */
41 class NERNNLayer : public IFunction
42 {
43 public:
44 /** Default constructor */
45 NERNNLayer(std::shared_ptr<IMemoryManager> memory_manager);
46 NERNNLayer() : NERNNLayer(MemoryManagerOnDemand::make_default())
47 {
48 }
49 /** Prevent instances of this class from being copied (As this class contains pointers) */
50 NERNNLayer(const NERNNLayer &) = delete;
51 /** Prevent instances of this class from being moved (As this class contains pointers) */
52 NERNNLayer(NERNNLayer &&) = delete;
53 /** Prevent instances of this class from being copied (As this class contains pointers) */
54 NERNNLayer &operator=(const NERNNLayer &) = delete;
55 /** Prevent instances of this class from being moved (As this class contains pointers) */
56 NERNNLayer &operator=(NERNNLayer &&) = delete;
57 /** Default destructor */
58 ~NERNNLayer();
59 /** Initialize the function
60 *
61 * Valid data layouts:
62 * - NHWC
63 * - NCHW
64 *
65 * Valid data type configurations:
66 * |src0 |src1 |src2 |src3 |dst0 |dst1 |
67 * |:------|:------|:------|:------|:------|:------|
68 * |F16 |F16 |F16 |F16 |F16 |F16 |
69 * |F32 |F32 |F32 |F32 |F32 |F32 |
70 *
71 * @param[in] input Input is a 2-D tensor of shape [input_size, batch_size]. Data types supported: F16/F32
72 * @param[in] weights Weights tensor of shape [input_size, num_units] that multiplies the input. Data types supported: Same as @p input
73 * @param[in] recurrent_weights Weights tensor of shape [num_units, num_units] that multiplies the current 'state'. Data types supported: Same as @p input
74 * @param[in] bias Bias vector of shape [num_units]. Data types supported: Same as @p input
75 * @param[out] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
76 * @param[in,out] hidden_state Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
77 * @param[in] info Activation layer parameter.
78 */
79 void configure(const ITensor *input,
80 const ITensor *weights,
81 const ITensor *recurrent_weights,
82 const ITensor *bias,
83 ITensor *hidden_state,
84 ITensor *output,
85 ActivationLayerInfo &info);
86 /** Initialize the function
87 *
88 * @param[in] input Input is a 2-D tensor of shape [input_size, batch_size]. Data types supported: F16/F32
89 * @param[in] weights Weights tensor of shape [input_size, num_units] that multiplies the input. Data types supported: Same as @p input
90 * @param[in] recurrent_weights Weights tensor of shape [num_units, num_units] that multiplies the current 'state'. Data types supported: Same as @p input
91 * @param[in] bias Bias vector of shape [num_units]. Data types supported: Same as @p input
92 * @param[in] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
93 * @param[in] hidden_state Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
94 * @param[in] info Activation layer parameter.
95 *
96 * @return a status
97 */
98 static Status validate(const ITensorInfo *input,
99 const ITensorInfo *weights,
100 const ITensorInfo *recurrent_weights,
101 const ITensorInfo *bias,
102 const ITensorInfo *hidden_state,
103 const ITensorInfo *output,
104 const ActivationLayerInfo &info);
105
106 // Inherited methods overridden:
107 void run() override;
108 void prepare() override;
109
110 private:
111 MemoryGroup _memory_group;
112 NEGEMM _gemm_state_f;
113 NEArithmeticAddition _add_f;
114 NEActivationLayer _activation;
115 NEFullyConnectedLayer _fully_connected;
116 NECopy _copy_f;
117 Tensor _fully_connected_out;
118 Tensor _gemm_output;
119 Tensor _add_output;
120 bool _is_prepared;
121 };
122 } // namespace arm_compute
123 #endif // ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NERNNLAYER_H