blob: fedb9e971e325766f8337cc20453721465c1c759 [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"
Georgios Pinitas7891a732021-08-20 21:39:25 +010028#include "src/gpu/cl/ClCompileContext.h"
29#include "src/gpu/cl/IClKernel.h"
30#include "src/gpu/cl/IClOperator.h"
Sheri Zhang1efed922021-03-10 22:43:38 +000031
32#include <memory>
33
34namespace arm_compute
35{
36namespace opencl
37{
38/** Basic function to simulate a directly convolution layer. This function calls the following OpenCL kernels:
39 *
40 * -# @ref CLFillBorderKernel (executed if padding size is different from zero)
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010041 * -# @ref opencl::ClDirectConv2d
Sheri Zhang1efed922021-03-10 22:43:38 +000042 */
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010043class ClDirectConv2d : public IClOperator
Sheri Zhang1efed922021-03-10 22:43:38 +000044{
45public:
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010046 ClDirectConv2d() = default;
Sheri Zhang1efed922021-03-10 22:43:38 +000047 /** Set the src and dst tensors.
48 *
49 * @param[in] compile_context The compile context to be used.
50 * @param[in] src Source tensor. 3 lower dimensions represent a single src [width, height, IFM],
51 * while every optional dimension from 4 and above represent a batch of srcs.
52 * Data types supported: QASYMM8_SIGNED/QASYMM8/F16/F32.
53 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions [kernel_x, kernel_y, IFM, OFM]. Data type supported:Same as @p src.
54 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
55 * 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.
56 * @param[out] dst Destination tensor. 3 lower dimensions represent a single dst [width, height, OFM], while the rest represent batch of dsts.
57 * Data types supported: Same as @p src.
58 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
59 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
60 *
61 */
62 void configure(const CLCompileContext &compile_context, ITensorInfo *src, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *dst, const PadStrideInfo &conv_info,
63 const ActivationLayerInfo &act_info = ActivationLayerInfo());
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010064 /** Static function to check if given info will lead to a valid configuration
Sheri Zhang1efed922021-03-10 22:43:38 +000065 *
Manuel Bottinib4bb6a02021-05-24 16:01:32 +010066 * Similar to ClDirectConv2d::configure()
Sheri Zhang1efed922021-03-10 22:43:38 +000067 *
68 * @return a status
69 */
70 static Status validate(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const PadStrideInfo &conv_info,
71 const ActivationLayerInfo &act_info = ActivationLayerInfo());
72
73 // Inherited method overridden
74 void run(ITensorPack &tensors) override;
75
76private:
77 std::unique_ptr<IClKernel> _direct_conv_kernel{ nullptr };
78 std::unique_ptr<IClKernel> _src_border_handler{ nullptr };
79 std::unique_ptr<IClKernel> _activation_kernel{ nullptr };
80};
81} // namespace opencl
82} // namespace arm_compute
Matthew Benthamf1aeab92023-05-30 13:35:34 +000083#endif /* ARM_COMPUTE_CL_DIRECT_CONV2D_H */