blob: 03bfc51a460b7540213b529fcac13f6a1e6ed554 [file] [log] [blame]
Michalis Spyrou96f977e2021-07-01 12:20:56 +01001/*
Gunes Bayirc2a51bd2023-09-28 10:30:18 +01002 * Copyright (c) 2021-2023 Arm Limited.
Michalis Spyrou96f977e2021-07-01 12:20:56 +01003 *
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 */
Gunes Bayirc2a51bd2023-09-28 10:30:18 +010024#ifndef ACL_SRC_CPU_OPERATORS_CPUWINOGRADCONV2D_H
25#define ACL_SRC_CPU_OPERATORS_CPUWINOGRADCONV2D_H
Michalis Spyrou96f977e2021-07-01 12:20:56 +010026
27#include "arm_compute/core/TensorInfo.h"
28#include "arm_compute/runtime/FunctionDescriptors.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010029
Michalis Spyrou96f977e2021-07-01 12:20:56 +010030#include "src/core/common/Macros.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010031#include "src/cpu/ICpuOperator.h"
Gunes Bayirc2a51bd2023-09-28 10:30:18 +010032#include "src/cpu/kernels/assembly/gemm_common.hpp"
SiCong Lic5ab4df2023-10-17 17:38:57 +010033#include "src/cpu/kernels/CpuWinogradConv2dKernel.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010034#include "src/cpu/operators/CpuActivation.h"
35#include "src/cpu/operators/CpuGemm.h"
36#include "src/cpu/operators/CpuPermute.h"
37#include "src/cpu/operators/internal/CpuGemmAssemblyDispatch.h"
Michalis Spyrou96f977e2021-07-01 12:20:56 +010038
39namespace arm_compute
40{
41namespace cpu
42{
43class CpuWinogradConv2d : public ICpuOperator
44{
45public:
46 /** Constructor */
47 CpuWinogradConv2d();
48 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuWinogradConv2d);
49 /** Destructor */
50 ~CpuWinogradConv2d();
51
52 /** Set the input and output tensors.
53 *
54 * Valid data layouts:
55 * - NHWC
56 * - NCHW
57 *
58 * Valid data type configurations:
59 * |src0 |src1 |src2 |dst |
60 * |:--------------|:--------------|:------|:--------------|
61 * |F16 |F16 |F16 |F16 |
62 * |F32 |F32 |F32 |F32 |
63 *
ramelg01a1f78512022-06-29 16:28:10 +010064 * @param[in] src Source tensor Info. 3 lower dimensions represent a single input [width, height, IFM],
Michalis Spyrou96f977e2021-07-01 12:20:56 +010065 * while every optional dimension from 4 and above represent a batch of inputs.
66 * Data types supported: F16/F32.
ramelg01a1f78512022-06-29 16:28:10 +010067 * @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.
Gunes Bayirc2a51bd2023-09-28 10:30:18 +010068 * For supported kernel sizes, see @ref arm_compute::NEWinogradConvolutionLayer
ramelg01a1f78512022-06-29 16:28:10 +010069 * @param[in] biases Biases tensor Info. Shared biases supported. Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p weights.
70 * @param[out] dst Destination tensor Info. 3 lower dimensions represent a single output [width, height, OFM], while the rest represent batch of outputs.
Michalis Spyrou96f977e2021-07-01 12:20:56 +010071 * Data types supported: Same as @p input.
72 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo. Currently only unit strides are supported.
73 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
74 * @param[in] enable_fast_math (Optional) Enable fast math computation. In case this flag were set, the function could dispatch the fastest implementation
75 * available which may introduce a drop of accuracy as well. Default is false
76 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010077 void configure(const ITensorInfo *src,
78 const ITensorInfo *weights,
79 const ITensorInfo *biases,
80 ITensorInfo *dst,
81 const PadStrideInfo &conv_info,
Michalis Spyrou96f977e2021-07-01 12:20:56 +010082 const ActivationLayerInfo &act_info = ActivationLayerInfo(),
83 bool enable_fast_math = false);
84 /** Static function to check if given info will lead to a valid configuration of @ref CpuWinogradConv2d
85 *
86 * Similar to CpuWinogradConv2d::configure()
87 *
88 * @return a status
89 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010090 static Status validate(const ITensorInfo *src,
91 const ITensorInfo *weights,
92 const ITensorInfo *biases,
93 const ITensorInfo *dst,
94 const PadStrideInfo &conv_info,
Michalis Spyrou96f977e2021-07-01 12:20:56 +010095 const ActivationLayerInfo &act_info = ActivationLayerInfo(),
96 bool enable_fast_math = false);
97
98 // Inherited methods overridden:
SiCong Lic5ab4df2023-10-17 17:38:57 +010099 void run(ITensorPack &tensors) override;
100 void prepare(ITensorPack &constants) override;
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100101 experimental::MemoryRequirements workspace() const override;
102
103private:
104 enum AuxTensorIdx
105 {
SiCong Lic5ab4df2023-10-17 17:38:57 +0100106 /** Slot 0 - 6 reserved for CpuGemm */
107 TransformedInput = 7,
108 TransformedOutput,
109 WorkspaceIO,
110 TransformedWeights,
111 PermutedWeights,
112 Count,
113 PermutedInput = TransformedOutput,
114 PermutedOutput = TransformedInput
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100115 };
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100116 std::unique_ptr<CpuGemm> _gemm_function;
117 std::unique_ptr<CpuActivation> _activation_func;
118 std::unique_ptr<ICPPKernel> _transform_input_kernel;
119 std::unique_ptr<ICPPKernel> _transform_output_kernel;
120 std::unique_ptr<CpuPermute> _permute_input;
121 std::unique_ptr<CpuPermute> _permute_output;
122 std::unique_ptr<CpuPermute> _permute_weights;
SiCong Lic5ab4df2023-10-17 17:38:57 +0100123 experimental::MemoryRequirements _aux_mem{Count};
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100124 std::unique_ptr<arm_conv::ConvolutionArgs>
SiCong Lic5ab4df2023-10-17 17:38:57 +0100125 _conv_args; // Make it unique ptr because this type does not have a default constructor
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100126 arm_conv::winograd::WinogradImpl _winograd_impl;
127 DataLayout _data_layout;
128 TensorInfo _winograd_transformed_input;
129 TensorInfo _winograd_transformed_output;
130 TensorInfo _winograd_transformed_weights;
131 TensorInfo _input_workspace;
132 TensorInfo _output_workspace;
133 TensorInfo _weights_hwio;
134 TensorInfo _input_nhwc;
135 TensorInfo _output_nhwc;
136 bool _is_prepared;
137 bool _run_activation;
Michalis Spyrou96f977e2021-07-01 12:20:56 +0100138};
139} // namespace cpu
140} // namespace arm_compute
141
Gunes Bayirc2a51bd2023-09-28 10:30:18 +0100142#endif // ACL_SRC_CPU_OPERATORS_CPUWINOGRADCONV2D_H