blob: ae705ac86b8df6b6505a2791a59f75a1f7628a51 [file] [log] [blame]
Michalis Spyrou96f977e2021-07-01 12:20:56 +01001/*
2 * Copyright (c) 2021 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_CPU_WINOGRAD_CONV2D_KERNEL_H
25#define ARM_COMPUTE_CPU_WINOGRAD_CONV2D_KERNEL_H
26
27#include "arm_compute/core/TensorInfo.h"
28#include "arm_compute/runtime/FunctionDescriptors.h"
29#include "src/core/common/Macros.h"
30#include "src/core/cpu/kernels/CpuWinogradConv2dKernel.h"
31#include "src/runtime/cpu/ICpuOperator.h"
32#include "src/runtime/cpu/operators/CpuActivation.h"
33#include "src/runtime/cpu/operators/CpuGemm.h"
34#include "src/runtime/cpu/operators/CpuPermute.h"
35#include "src/runtime/cpu/operators/internal/CpuGemmAssemblyDispatch.h"
36
37namespace arm_compute
38{
39namespace cpu
40{
41class CpuWinogradConv2d : public ICpuOperator
42{
43public:
44 /** Constructor */
45 CpuWinogradConv2d();
46 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuWinogradConv2d);
47 /** Destructor */
48 ~CpuWinogradConv2d();
49
50 /** Set the input and output tensors.
51 *
52 * Valid data layouts:
53 * - NHWC
54 * - NCHW
55 *
56 * Valid data type configurations:
57 * |src0 |src1 |src2 |dst |
58 * |:--------------|:--------------|:------|:--------------|
59 * |F16 |F16 |F16 |F16 |
60 * |F32 |F32 |F32 |F32 |
61 *
62 * @param[in] src Source tensor info. 3 lower dimensions represent a single input [width, height, IFM],
63 * while every optional dimension from 4 and above represent a batch of inputs.
64 * Data types supported: F16/F32.
65 * @param[in] weights Weights tensor info. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported: Same as @p input.
66 * Currently only 3x3 and 5x5 kernels are supported.
67 * @param[in] biases Biases tensor info. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p weights.
68 * @param[out] dst Destination tensor info. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
69 * Data types supported: Same as @p input.
70 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. Currently only unit strides are supported.
71 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
72 * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation
73 * available which may introduce a drop of accuracy as well. Default is false
74 */
75 void configure(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, ITensorInfo *dst, const PadStrideInfo &conv_info,
76 const ActivationLayerInfo &act_info = ActivationLayerInfo(),
77 bool enable_fast_math = false);
78 /** Static function to check if given info will lead to a valid configuration of @ref CpuWinogradConv2d
79 *
80 * Similar to CpuWinogradConv2d::configure()
81 *
82 * @return a status
83 */
Michele Di Giorgiod9cdf142021-07-02 15:17:08 +010084 static Status validate(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const PadStrideInfo &conv_info,
Michalis Spyrou96f977e2021-07-01 12:20:56 +010085 const ActivationLayerInfo &act_info = ActivationLayerInfo(),
86 bool enable_fast_math = false);
87
88 // Inherited methods overridden:
89 void run(ITensorPack &tensors) override;
90 void prepare(ITensorPack &constants) override;
91 experimental::MemoryRequirements workspace() const override;
92
93private:
94 enum AuxTensorIdx
95 {
96 GemmWorkspace = 0,
97 Pretranspose,
98 InterleavedLHS,
99 TransposedRHS,
100 TempResult,
101 PermutedInput,
102 InputTransformed,
103 InputWorkspace,
104 PermutedOutput,
105 PermutedWeights,
106 WeightsTransformed,
107 OutputTransformed,
108 OutputWorkspace,
109 Count
110 };
111
112 std::unique_ptr<CpuGemm> _gemm_function;
113 std::unique_ptr<CpuActivation> _activation_func;
114 std::unique_ptr<CpuPermute> _permute_input;
115 std::unique_ptr<CpuPermute> _permute_output;
116 std::unique_ptr<CpuPermute> _permute_weights;
117 std::unique_ptr<ICPPKernel> _transform_input_kernel;
118 std::unique_ptr<ICPPKernel> _transform_weights_kernel;
119 std::unique_ptr<ICPPKernel> _transform_output_kernel;
120
121 DataLayout _data_layout;
122 experimental::MemoryRequirements _aux_mem{ Count };
123 TensorInfo _input_nhwc;
124 TensorInfo _output_nhwc;
125 TensorInfo _input_workspace;
126 TensorInfo _kernel_storage;
127 TensorInfo _output_workspace;
128 TensorInfo _input_transformed;
129 TensorInfo _output_transformed;
130 TensorInfo _weights_hwio;
131 bool _run_activation;
132 bool _is_prepared;
133};
134} // namespace cpu
135} // namespace arm_compute
136
137#endif /* ARM_COMPUTE_CPU_WINOGRAD_CONV2D_KERNEL_H */