blob: 14de169236a3dd71f8d881427a06f7785ea01fca [file] [log] [blame]
Gian Marco Iodiced2fab732018-03-02 11:18:12 +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_CLWINOGRADCONVOLUTIONLAYER_H__
25#define __ARM_COMPUTE_CLWINOGRADCONVOLUTIONLAYER_H__
26
27#include "arm_compute/core/CL/kernels/CLWinogradFilterTransformKernel.h"
28#include "arm_compute/core/CL/kernels/CLWinogradOutputTransformKernel.h"
29#include "arm_compute/core/Types.h"
30#include "arm_compute/runtime/CL/functions/CLGEMM.h"
31#include "arm_compute/runtime/CL/functions/CLWinogradInputTransform.h"
32#include "arm_compute/runtime/IFunction.h"
33
34namespace arm_compute
35{
36class ICLTensor;
37
38/** Basic function to execute Winograd-based convolution on OpenCL. This function calls the following OpenCL functions/kernels:
39 *
40 * -# @ref CLWinogradInputTransform
41 * -# @ref CLWinogradFilterTransformKernel (only once)
42 * -# @ref CLGEMM
43 * -# @ref CLWinogradOutputTransformKernel
44 *
45 */
46class CLWinogradConvolutionLayer : public IFunction
47{
48public:
49 /** Default constructor */
50 CLWinogradConvolutionLayer(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
51 /** Set the input and output tensors.
52 *
53 * @note: This function only works with 3x3 kernels and unit strides
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 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].Data type supported: Same as @p input
60 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
61 * Data types supported: Same as @p input.
62 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
63 */
64 void configure(ICLTensor *input, const ICLTensor *weights, const ICLTensor *biases, ICLTensor *output, const PadStrideInfo &conv_info);
65 /** Static function to check if given info will lead to a valid configuration of @ref CLWinogradConvolutionLayer
66 *
67 * @note: This function only works with 3x3 kernels and unit strides
68 *
69 * @param[in] input Source tensor. 3 lower dimensions represent a single input [width, height, IFM],
70 * while every optional dimension from 4 and above represent a batch of inputs.
71 * Data types supported: F32.
72 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p input.
73 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].Data type supported: Same as @p input
74 * @param[out] output Destination tensor. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
75 * Data types supported: Same as @p input.
76 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
77 *
78 * @return a status
79 */
80 static Status validate(const ITensorInfo *input, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *output, const PadStrideInfo &conv_info);
81
82 // Inherited methods overridden:
83 void run() override;
84
85private:
86 CLMemoryGroup _memory_group;
87 CLGEMM _batched_mm;
88 CLWinogradInputTransform _input_transform;
89 CLWinogradFilterTransformKernel _filter_transform;
90 CLWinogradOutputTransformKernel _output_transform;
91 CLTensor _input0;
92 CLTensor _input1;
93 CLTensor _batched_mm_output;
94 bool _is_first_run;
95};
96}
97#endif /* __ARM_COMPUTE_CLWINOGRADCONVOLUTIONLAYER_H__ */