blob: 9d1cb1a724e4c22d48f0a902ea2fb0c7a4c5cf32 [file] [log] [blame]
Michalis Spyrou36a559e2018-03-20 10:30:58 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 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/core/CL/kernels/CLCopyKernel.h"
28#include "arm_compute/runtime/CL/ICLSimpleFunction.h"
Georgios Pinitasab23dd02020-07-06 14:57:36 +010029#include "arm_compute/runtime/CL/functions/CLActivationLayer.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
34namespace arm_compute
35{
36class ICLTensor;
37
38/** Basic function to run @ref CLRNNLayer */
39class CLRNNLayer : public IFunction
40{
41public:
42 /** Default constructor */
43 CLRNNLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
44 /** Initialize the function
45 *
46 * @param[in] input Input is a 2-D tensor of shape [input_size, batch_size]. Data types supported: F16/F32
47 * @param[in] weights Weights tensor of shape [input_size, num_units] that multiplies the input. Data types supported: Same as @p input
48 * @param[in] recurrent_weights Weights tensor of shape [num_units, num_units] that multiplies the current 'state'. Data types supported: Same as @p input
49 * @param[in] bias Bias vector of shape [num_units]. Data types supported: Same as @p input
50 * @param[out] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
51 * @param[in,out] hidden_state Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
52 * @param[in] info Activation layer parameter.
53 */
54 void configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *recurrent_weights, const ICLTensor *bias, ICLTensor *hidden_state, ICLTensor *output, ActivationLayerInfo &info);
55 /** Initialize the function
56 *
Manuel Bottini2b84be52020-04-08 10:15:51 +010057 * @param[in] compile_context The compile context to be used.
58 * @param[in] input Input is a 2-D tensor of shape [input_size, batch_size]. Data types supported: F16/F32
59 * @param[in] weights Weights tensor of shape [input_size, num_units] that multiplies the input. Data types supported: Same as @p input
60 * @param[in] recurrent_weights Weights tensor of shape [num_units, num_units] that multiplies the current 'state'. Data types supported: Same as @p input
61 * @param[in] bias Bias vector of shape [num_units]. Data types supported: Same as @p input
62 * @param[out] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
63 * @param[in,out] hidden_state Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
64 * @param[in] info Activation layer parameter.
65 */
66 void configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *weights, const ICLTensor *recurrent_weights, const ICLTensor *bias, ICLTensor *hidden_state,
67 ICLTensor *output, ActivationLayerInfo &info);
68 /** Initialize the function
69 *
Michalis Spyrou36a559e2018-03-20 10:30:58 +000070 * @param[in] input Input is a 2-D tensor of shape [input_size, batch_size]. Data types supported: F16/F32
71 * @param[in] weights Weights tensor of shape [input_size, num_units] that multiplies the input. Data types supported: Same as @p input
72 * @param[in] recurrent_weights Weights tensor of shape [num_units, num_units] that multiplies the current 'state'. Data types supported: Same as @p input
73 * @param[in] bias Bias vector of shape [num_units]. Data types supported: Same as @p input
74 * @param[in] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
75 * @param[in] hidden_state Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
76 * @param[in] info Activation layer parameter.
77 *
78 * @return a status
79 */
80 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *recurrent_weights, const ITensorInfo *bias, const ITensorInfo *hidden_state, const ITensorInfo *output,
81 const ActivationLayerInfo &info);
82
83 // Inherited methods overridden:
84 void run() override;
Georgios Pinitas72219332018-06-05 14:56:06 +010085 void prepare() override;
Michalis Spyrou36a559e2018-03-20 10:30:58 +000086
87private:
Michalis Spyrouad7515d2020-07-24 00:02:23 +010088 MemoryGroup _memory_group;
89 CLGEMM _gemm_state_f;
90 CLArithmeticAddition _add_kernel;
91 CLActivationLayer _activation;
92 CLFullyConnectedLayer _fully_connected_kernel;
93 CLCopyKernel _copy_kernel;
94 CLTensor _fully_connected_out;
95 CLTensor _gemm_output;
96 CLTensor _add_output;
97 bool _is_prepared;
Michalis Spyrou36a559e2018-03-20 10:30:58 +000098};
99}
Michalis Spyrouf4643372019-11-29 16:17:13 +0000100#endif /* ARM_COMPUTE_CLRNN_LAYER_H */