blob: 1b2b2ee3cf4b057b3b81fdc2fa6139cfd66ab779 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
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_NELOCALLYCONNECTEDLAYER_H__
25#define __ARM_COMPUTE_NELOCALLYCONNECTEDLAYER_H__
26
27#include "arm_compute/runtime/IFunction.h"
28
29#include "arm_compute/core/NEON/kernels/NECol2ImKernel.h"
30#include "arm_compute/core/NEON/kernels/NEIm2ColKernel.h"
31#include "arm_compute/core/NEON/kernels/NELocallyConnectedMatrixMultiplyKernel.h"
32#include "arm_compute/core/NEON/kernels/NEWeightsReshapeKernel.h"
33#include "arm_compute/core/Types.h"
34#include "arm_compute/runtime/Tensor.h"
35
36namespace arm_compute
37{
38class INETensor;
39
40/** Basic function to compute the locally connected layer. This function calls the following NEON kernels:
41 *
42 * -# @ref NEWeightsReshapeKernel (executed only once for each configuration)
43 * -# @ref NEIm2ColKernel
44 * -# @ref NELocallyConnectedMatrixMultiplyKernel
45 * -# @ref NECol2ImKernel
46 */
47class NELocallyConnectedLayer : public IFunction
48{
49public:
50 /** Default constructor */
51 NELocallyConnectedLayer();
52 /** Set the input and output tensors.
53 *
54 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
55 * while every optional dimension from 4 and above represent a batch of inputs.
56 * Data types supported: F32.
57 * @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.
58 * @param[in] biases Biases tensor. Shared biases supported. Biases are 2D tensor with dimensions [OFM, num_patches]. Data type supported:Same as @p input.
59 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
60 * Data types supported: Same as @p input.
61 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
62 */
63 void configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info);
64
65 // Inherited methods overridden:
66 void run() override;
67
68private:
69 NEIm2ColKernel _input_im2col_kernel;
70 NEWeightsReshapeKernel _weights_reshape_kernel;
71 NELocallyConnectedMatrixMultiplyKernel _mm_kernel;
72 NECol2ImKernel _output_col2im_kernel;
73 Tensor _input_im2col_reshaped;
74 Tensor _weights_reshaped;
75 Tensor _gemm_output;
76 bool _is_first_run;
77};
78}
79#endif /* __ARM_COMPUTE_NELOCALLYCONNECTEDLAYER_H__ */