blob: a939f828548c6bca831775baa162a41dcb6ce3ae [file] [log] [blame]
Pablo Tello89519332017-11-17 11:52:36 +00001/*
Pablo Tello9ceebbe2018-01-10 16:44:13 +00002 * Copyright (c) 2017-2018 ARM Limited.
Pablo Tello89519332017-11-17 11:52:36 +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 */
24#ifndef __ARM_COMPUTE_NEWINOGRADLAYER_H__
25#define __ARM_COMPUTE_NEWINOGRADLAYER_H__
26
27#include "arm_compute/runtime/IFunction.h"
28
Pablo Tellof6c572c2018-02-14 12:47:30 +000029#include "arm_compute/core/NEON/INEKernel.h"
Pablo Tello89519332017-11-17 11:52:36 +000030#include "arm_compute/core/Types.h"
Pablo Tello02541fb2017-12-15 09:48:59 +000031#include "arm_compute/runtime/CPP/functions/CPPPermute.h"
Pablo Tello89519332017-11-17 11:52:36 +000032#include "arm_compute/runtime/MemoryGroup.h"
33#include "arm_compute/runtime/Tensor.h"
34
35#include <memory>
36
37namespace arm_compute
38{
39class ITensor;
40/** Basic function to simulate a convolution layer. This function calls the following NEON kernels:
Pablo Tellof6c572c2018-02-14 12:47:30 +000041 * -# @ref NEWinogradLayerTransformWeightsKernel (executed only once in the first call to the run() method )
42 * -# @ref NEWinogradLayerTransformInputKernel
43 * -# @ref NEWinogradLayerTransformOutputKernel
44 * -# @ref NEWinogradLayerBatchedGEMMKernel
45 * -# @ref CPPPermute (three times: weights, input and output)
Pablo Tello89519332017-11-17 11:52:36 +000046 */
47class NEWinogradLayer : public IFunction
48{
49public:
50 /** Constructor */
51 NEWinogradLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
52
53 /** Set the input and output tensors.
54 *
55 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
56 * while every optional dimension from 4 and above represent a batch of inputs.
57 * Data types supported: F32.
58 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as @p input.
59 * Currently only 3x3 kernels are supported.
Pablo Tellod6ca4782018-01-23 09:36:04 +000060 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p weights.
Pablo Tello89519332017-11-17 11:52:36 +000061 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
62 * Data types supported: Same as @p input.
63 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. Currently only unit strides are supported.
64 */
65 void configure(const ITensor *input, const ITensor *weights, const ITensor *biases, ITensor *output, const PadStrideInfo &conv_info);
66
67 // Inherited methods overridden:
68 void run() override;
69
Isabella Gottardi6acc6ad2018-02-02 17:19:18 +000070 /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMConvolutionLayer
71 *
72 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
73 * while every optional dimension from 4 and above represent a batch of inputs.
74 * Data types supported: F32.
75 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input.
76 * Currently only 3x3 kernels are supported.
77 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p weights.
78 * @param[in] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
79 * Data types supported: Same as @p input.
80 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. Currently only unit strides are supported.
81 *
82 * @return a status
83 */
84 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info);
85
Pablo Tello89519332017-11-17 11:52:36 +000086 /** Prevent instances of this class from being copied (As this class contains pointers) */
87 NEWinogradLayer(const NEWinogradLayer &) = delete;
88 /** Prevent instances of this class from being copied (As this class contains pointers) */
89 NEWinogradLayer &operator=(const NEWinogradLayer &) = delete;
90
91private:
Pablo Tellof6c572c2018-02-14 12:47:30 +000092 MemoryGroup _memory_group;
93 std::unique_ptr<INEKernel> _batched_gemm_kernel;
94 std::unique_ptr<INEKernel> _transform_input_kernel;
95 std::unique_ptr<INEKernel> _transform_output_kernel;
96 std::unique_ptr<INEKernel> _transform_weights_kernel;
97
Pablo Tello52140b42018-01-30 14:48:11 +000098 CPPPermute _permute_input;
99 CPPPermute _permute_weights;
100 CPPPermute _permute_output;
101 Tensor _input_workspace;
102 Tensor _output_workspace;
103 Tensor _kernel_storage;
104 Tensor _input_nhwc;
105 Tensor _output_nhwc;
106 Tensor _weights_hwio;
107 const ITensor *_input;
108 const ITensor *_weights;
109 ITensor *_output;
110 bool _reshaped_kernel;
Pablo Tello89519332017-11-17 11:52:36 +0000111};
112}
113#endif /* __ARM_COMPUTE_NEWINOGRADLAYER_H__ */