Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017 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_CLLOCALLYCONNECTEDLAYER_H__ |
| 25 | #define __ARM_COMPUTE_CLLOCALLYCONNECTEDLAYER_H__ |
| 26 | |
| 27 | #include "arm_compute/runtime/IFunction.h" |
| 28 | |
| 29 | #include "arm_compute/core/CL/kernels/CLCol2ImKernel.h" |
| 30 | #include "arm_compute/core/CL/kernels/CLIm2ColKernel.h" |
| 31 | #include "arm_compute/core/CL/kernels/CLLocallyConnectedMatrixMultiplyKernel.h" |
| 32 | #include "arm_compute/core/CL/kernels/CLWeightsReshapeKernel.h" |
| 33 | #include "arm_compute/core/Types.h" |
Georgios Pinitas | 8a94e7c | 2017-09-15 19:06:47 +0100 | [diff] [blame] | 34 | #include "arm_compute/runtime/CL/CLMemoryGroup.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 35 | #include "arm_compute/runtime/CL/CLTensor.h" |
Georgios Pinitas | 8a94e7c | 2017-09-15 19:06:47 +0100 | [diff] [blame] | 36 | #include "arm_compute/runtime/IMemoryManager.h" |
| 37 | |
| 38 | #include <memory> |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 39 | |
| 40 | namespace arm_compute |
| 41 | { |
| 42 | class ICLTensor; |
| 43 | |
| 44 | /** Basic function to compute the locally connected layer. This function calls the following OpenCL kernels: |
| 45 | * |
Gian Marco Iodice | 5cb4c42 | 2017-06-23 10:38:25 +0100 | [diff] [blame] | 46 | * -# @ref CLWeightsReshapeKernel (executed only once for each configuration) |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 47 | * -# @ref CLIm2ColKernel |
| 48 | * -# @ref CLLocallyConnectedMatrixMultiplyKernel |
| 49 | * -# @ref CLCol2ImKernel |
| 50 | */ |
| 51 | class CLLocallyConnectedLayer : public IFunction |
| 52 | { |
| 53 | public: |
| 54 | /** Default constructor */ |
Georgios Pinitas | 8a94e7c | 2017-09-15 19:06:47 +0100 | [diff] [blame] | 55 | CLLocallyConnectedLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 56 | /** Set the input and output tensors. |
| 57 | * |
| 58 | * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM], |
| 59 | * while every optional dimension from 4 and above represent a batch of inputs. |
| 60 | * Data types supported: F32. |
| 61 | * @param[in] weights Weights tensor. Weights are 5D tensor with dimensions [kernel_x, kernel_y, IFM, OFM, num_patches]. Data type supported:Same as @p input. |
| 62 | * @param[in] biases Biases tensor. Shared biases supported. Biases are 2D tensor with dimensions [OFM, num_patches]. Data type supported:Same as @p input. |
| 63 | * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs. |
| 64 | * Data types supported: Same as @p input. |
| 65 | * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. |
| 66 | */ |
| 67 | void configure(const ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info); |
| 68 | |
| 69 | // Inherited methods overridden: |
| 70 | void run() override; |
| 71 | |
| 72 | private: |
Georgios Pinitas | 8a94e7c | 2017-09-15 19:06:47 +0100 | [diff] [blame] | 73 | CLMemoryGroup _memory_group; |
Gian Marco Iodice | 5cb4c42 | 2017-06-23 10:38:25 +0100 | [diff] [blame] | 74 | CLIm2ColKernel _input_im2col_kernel; |
| 75 | CLWeightsReshapeKernel _weights_reshape_kernel; |
| 76 | CLLocallyConnectedMatrixMultiplyKernel _mm_kernel; |
| 77 | CLCol2ImKernel _output_col2im_kernel; |
| 78 | CLTensor _input_im2col_reshaped; |
| 79 | CLTensor _weights_reshaped; |
| 80 | CLTensor _gemm_output; |
| 81 | bool _is_first_run; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 82 | }; |
| 83 | } |
| 84 | #endif /* __ARM_COMPUTE_CLLOCALLYCONNECTEDLAYER_H__ */ |