blob: 2b3b35e37d9de22b9963b8f35f9a5fb32e47ecab [file] [log] [blame]
Michalis Spyrou36a559e2018-03-20 10:30:58 +00001/*
Sheri Zhang7e20e292021-02-02 11:49:34 +00002 * Copyright (c) 2018-2021 Arm Limited.
Michalis Spyrou36a559e2018-03-20 10:30:58 +00003 *
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_CLRNN_LAYER_H
25#define ARM_COMPUTE_CLRNN_LAYER_H
Michalis Spyrou36a559e2018-03-20 10:30:58 +000026
Michalis Spyrou36a559e2018-03-20 10:30:58 +000027#include "arm_compute/runtime/CL/ICLSimpleFunction.h"
Georgios Pinitasab23dd02020-07-06 14:57:36 +010028#include "arm_compute/runtime/CL/functions/CLActivationLayer.h"
Sheri Zhang7e20e292021-02-02 11:49:34 +000029#include "arm_compute/runtime/CL/functions/CLCopy.h"
Michalis Spyrouad7515d2020-07-24 00:02:23 +010030#include "arm_compute/runtime/CL/functions/CLElementwiseOperations.h"
Michalis Spyrou36a559e2018-03-20 10:30:58 +000031#include "arm_compute/runtime/CL/functions/CLFullyConnectedLayer.h"
32#include "arm_compute/runtime/CL/functions/CLGEMM.h"
33
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010034#include <memory>
35
Michalis Spyrou36a559e2018-03-20 10:30:58 +000036namespace arm_compute
37{
38class ICLTensor;
39
40/** Basic function to run @ref CLRNNLayer */
41class CLRNNLayer : public IFunction
42{
43public:
44 /** Default constructor */
45 CLRNNLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Sang-Hoon Parkbef7fa22020-10-21 15:58:54 +010046 /** Prevent instances of this class from being copied */
47 CLRNNLayer(const CLRNNLayer &) = delete;
48 /** Prevent instances of this class from being copied */
49 CLRNNLayer &operator=(const CLRNNLayer &) = delete;
50 /** Default destructor */
51 ~CLRNNLayer();
Michalis Spyrou36a559e2018-03-20 10:30:58 +000052 /** Initialize the function
53 *
Teresa Charlin62687422021-04-28 10:58:49 +010054 * Valid data layouts:
55 * - NHWC
56 * - NCHW
57 *
58 * Valid data type configurations:
59 * |src0 |src1 |src2 |src3 |dst0 |dst1 |
60 * |:------|:------|:------|:------|:------|:------|
61 * |F16 |F16 |F16 |F16 |F16 |F16 |
62 * |F32 |F32 |F32 |F32 |F32 |F32 |
63 *
Michalis Spyrou36a559e2018-03-20 10:30:58 +000064 * @param[in] input Input is a 2-D tensor of shape [input_size, batch_size]. Data types supported: F16/F32
65 * @param[in] weights Weights tensor of shape [input_size, num_units] that multiplies the input. Data types supported: Same as @p input
66 * @param[in] recurrent_weights Weights tensor of shape [num_units, num_units] that multiplies the current 'state'. Data types supported: Same as @p input
67 * @param[in] bias Bias vector of shape [num_units]. Data types supported: Same as @p input
68 * @param[out] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
69 * @param[in,out] hidden_state Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
70 * @param[in] info Activation layer parameter.
71 */
72 void configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *recurrent_weights, const ICLTensor *bias, ICLTensor *hidden_state, ICLTensor *output, ActivationLayerInfo &info);
73 /** Initialize the function
74 *
Manuel Bottini2b84be52020-04-08 10:15:51 +010075 * @param[in] compile_context The compile context to be used.
76 * @param[in] input Input is a 2-D tensor of shape [input_size, batch_size]. Data types supported: F16/F32
77 * @param[in] weights Weights tensor of shape [input_size, num_units] that multiplies the input. Data types supported: Same as @p input
78 * @param[in] recurrent_weights Weights tensor of shape [num_units, num_units] that multiplies the current 'state'. Data types supported: Same as @p input
79 * @param[in] bias Bias vector of shape [num_units]. Data types supported: Same as @p input
80 * @param[out] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
81 * @param[in,out] hidden_state Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
82 * @param[in] info Activation layer parameter.
83 */
84 void configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *weights, const ICLTensor *recurrent_weights, const ICLTensor *bias, ICLTensor *hidden_state,
85 ICLTensor *output, ActivationLayerInfo &info);
86 /** Initialize the function
87 *
Michalis Spyrou36a559e2018-03-20 10:30:58 +000088 * @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, const ITensorInfo *weights, const ITensorInfo *recurrent_weights, const ITensorInfo *bias, const ITensorInfo *hidden_state, const ITensorInfo *output,
99 const ActivationLayerInfo &info);
100
101 // Inherited methods overridden:
102 void run() override;
Georgios Pinitas72219332018-06-05 14:56:06 +0100103 void prepare() override;
Michalis Spyrou36a559e2018-03-20 10:30:58 +0000104
105private:
Sheri Zhang7e20e292021-02-02 11:49:34 +0000106 MemoryGroup _memory_group;
107 CLGEMM _gemm_state_f;
108 CLArithmeticAddition _add_kernel;
109 CLActivationLayer _activation;
110 CLFullyConnectedLayer _fully_connected_kernel;
111 CLCopy _copy;
112 CLTensor _fully_connected_out;
113 CLTensor _gemm_output;
114 CLTensor _add_output;
115 bool _is_prepared;
Michalis Spyrou36a559e2018-03-20 10:30:58 +0000116};
117}
Michalis Spyrouf4643372019-11-29 16:17:13 +0000118#endif /* ARM_COMPUTE_CLRNN_LAYER_H */