blob: 0f18490814a72d639fd6f13b040b74e2f7b4b895 [file] [log] [blame]
Sheri Zhang1efed922021-03-10 22:43:38 +00001/*
Matthew Benthamf1aeab92023-05-30 13:35:34 +00002 * Copyright (c) 2021, 2023 Arm Limited.
Sheri Zhang1efed922021-03-10 22:43:38 +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 */
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010024#ifndef ARM_COMPUTE_CL_DIRECT_CONV2D_H
25#define ARM_COMPUTE_CL_DIRECT_CONV2D_H
Sheri Zhang1efed922021-03-10 22:43:38 +000026
SiCong Li91295492023-07-21 18:16:13 +010027#include "arm_compute/function_info/ActivationLayerInfo.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Georgios Pinitas7891a732021-08-20 21:39:25 +010029#include "src/gpu/cl/ClCompileContext.h"
30#include "src/gpu/cl/IClKernel.h"
31#include "src/gpu/cl/IClOperator.h"
Sheri Zhang1efed922021-03-10 22:43:38 +000032
33#include <memory>
34
35namespace arm_compute
36{
37namespace opencl
38{
39/** Basic function to simulate a directly convolution layer. This function calls the following OpenCL kernels:
40 *
41 * -# @ref CLFillBorderKernel (executed if padding size is different from zero)
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010042 * -# @ref opencl::ClDirectConv2d
Sheri Zhang1efed922021-03-10 22:43:38 +000043 */
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010044class ClDirectConv2d : public IClOperator
Sheri Zhang1efed922021-03-10 22:43:38 +000045{
46public:
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010047 ClDirectConv2d() = default;
Sheri Zhang1efed922021-03-10 22:43:38 +000048 /** Set the src and dst tensors.
49 *
50 * @param[in] compile_context The compile context to be used.
51 * @param[in] src Source tensor. 3 lower dimensions represent a single src [width, height, IFM],
52 * while every optional dimension from 4 and above represent a batch of srcs.
53 * Data types supported: QASYMM8_SIGNED/QASYMM8/F16/F32.
54 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p src.
55 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
56 * Data type supported: Should match @p src data type, except for src of QASYMM8 and QASYMM8_SIGNED type where biases should be of S32 type.
57 * @param[out] dst Destination tensor. 3 lower dimensions represent a single dst [width, height, OFM], while the rest represent batch of dsts.
58 * Data types supported: Same as @p src.
59 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
60 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
61 *
62 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010063 void configure(const CLCompileContext &compile_context,
64 ITensorInfo *src,
65 ITensorInfo *weights,
66 ITensorInfo *biases,
67 ITensorInfo *dst,
68 const PadStrideInfo &conv_info,
Sheri Zhang1efed922021-03-10 22:43:38 +000069 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010070 /** Static function to check if given info will lead to a valid configuration
Sheri Zhang1efed922021-03-10 22:43:38 +000071 *
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010072 * Similar to ClDirectConv2d::configure()
Sheri Zhang1efed922021-03-10 22:43:38 +000073 *
74 * @return a status
75 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010076 static Status validate(const ITensorInfo *src,
77 const ITensorInfo *weights,
78 const ITensorInfo *biases,
79 const ITensorInfo *dst,
80 const PadStrideInfo &conv_info,
Sheri Zhang1efed922021-03-10 22:43:38 +000081 const ActivationLayerInfo &act_info = ActivationLayerInfo());
82
83 // Inherited method overridden
84 void run(ITensorPack &tensors) override;
85
86private:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010087 std::unique_ptr<IClKernel> _direct_conv_kernel{nullptr};
88 std::unique_ptr<IClKernel> _src_border_handler{nullptr};
89 std::unique_ptr<IClKernel> _activation_kernel{nullptr};
Sheri Zhang1efed922021-03-10 22:43:38 +000090};
91} // namespace opencl
92} // namespace arm_compute
Matthew Benthamf1aeab92023-05-30 13:35:34 +000093#endif /* ARM_COMPUTE_CL_DIRECT_CONV2D_H */