blob: fc86992bdf8dedc5c1cfb4f1c41134be18e81825 [file] [log] [blame]
Michalis Spyrou36a559e2018-03-20 10:30:58 +00001/*
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_CLRNN_LAYER_H__
25#define __ARM_COMPUTE_CLRNN_LAYER_H__
26
27#include "arm_compute/core/CL/kernels/CLActivationLayerKernel.h"
Michalis Spyrou36a559e2018-03-20 10:30:58 +000028#include "arm_compute/core/CL/kernels/CLCopyKernel.h"
giuros01164a2722018-11-20 18:34:46 +000029#include "arm_compute/core/CL/kernels/CLElementwiseOperationKernel.h"
Michalis Spyrou36a559e2018-03-20 10:30:58 +000030#include "arm_compute/runtime/CL/ICLSimpleFunction.h"
31#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 *
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[in] output Output tensor of shape [num_units, batch_size]. Data types supported: Same as @p input
62 * @param[in] 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 * @return a status
66 */
67 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *recurrent_weights, const ITensorInfo *bias, const ITensorInfo *hidden_state, const ITensorInfo *output,
68 const ActivationLayerInfo &info);
69
70 // Inherited methods overridden:
71 void run() override;
Georgios Pinitas72219332018-06-05 14:56:06 +010072 void prepare() override;
Michalis Spyrou36a559e2018-03-20 10:30:58 +000073
74private:
giuros01164a2722018-11-20 18:34:46 +000075 CLMemoryGroup _memory_group;
76 CLGEMM _gemm_state_f;
77 CLSaturatedArithmeticOperationKernel _add_kernel;
78 CLActivationLayerKernel _activation_kernel;
79 CLFullyConnectedLayer _fully_connected_kernel;
80 CLCopyKernel _copy_kernel;
81 CLTensor _fully_connected_out;
82 CLTensor _gemm_output;
83 CLTensor _add_output;
84 bool _is_prepared;
Michalis Spyrou36a559e2018-03-20 10:30:58 +000085};
86}
87#endif /* __ARM_COMPUTE_CLRNN_LAYER_H__ */