Michalis Spyrou | 36a559e | 2018-03-20 10:30:58 +0000 | [diff] [blame] | 1 | /* |
| 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 Spyrou | 36a559e | 2018-03-20 10:30:58 +0000 | [diff] [blame] | 28 | #include "arm_compute/core/CL/kernels/CLCopyKernel.h" |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/CL/kernels/CLElementwiseOperationKernel.h" |
Michalis Spyrou | 36a559e | 2018-03-20 10:30:58 +0000 | [diff] [blame] | 30 | #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 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | class ICLTensor; |
| 37 | |
| 38 | /** Basic function to run @ref CLRNNLayer */ |
| 39 | class CLRNNLayer : public IFunction |
| 40 | { |
| 41 | public: |
| 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 Pinitas | 7221933 | 2018-06-05 14:56:06 +0100 | [diff] [blame] | 72 | void prepare() override; |
Michalis Spyrou | 36a559e | 2018-03-20 10:30:58 +0000 | [diff] [blame] | 73 | |
| 74 | private: |
giuros01 | 164a272 | 2018-11-20 18:34:46 +0000 | [diff] [blame] | 75 | 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 Spyrou | 36a559e | 2018-03-20 10:30:58 +0000 | [diff] [blame] | 85 | }; |
| 86 | } |
| 87 | #endif /* __ARM_COMPUTE_CLRNN_LAYER_H__ */ |