blob: 04166d417e830b396f46ac0f9a198cb7793b21cd [file] [log] [blame]
Gian Marco Iodice76335eb2022-11-17 11:03:39 +00001/*
Matthew Bentham314d3e22023-06-23 10:53:52 +00002 * Copyright (c) 2022-2023 Arm Limited.
Gian Marco Iodice76335eb2022-11-17 11:03:39 +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 */
24#ifndef ARM_COMPUTE_CL_DIRECT_CONV2D_KERNEL_H
25#define ARM_COMPUTE_CL_DIRECT_CONV2D_KERNEL_H
26
SiCong Li91295492023-07-21 18:16:13 +010027#include "arm_compute/function_info/ActivationLayerInfo.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Gian Marco Iodice76335eb2022-11-17 11:03:39 +000029#include "src/core/common/Macros.h"
30#include "src/gpu/cl/ClCompileContext.h"
31#include "src/gpu/cl/IClKernel.h"
32
33namespace arm_compute
34{
35// Forward declaration
36struct DirectConvComputeKernelInfo;
37
38namespace opencl
39{
40namespace kernels
41{
42/** Interface for the indirect convolution kernel. */
43class ClIndirectConv2dKernel : public IClKernel
44{
45public:
46 ClIndirectConv2dKernel();
47 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(ClIndirectConv2dKernel);
48 /** Set the src, offset, weights, biases and dst tensors info.
49 *
50 * @param[in] compile_context The compile context to be used.
51 * @param[in] src The src tensor info to convolve. 3 lower dimensions represent a single src [IFM, width, height],
52 * while every optional dimension from 4 and above represent a batch of inputs. Data types supported: F16/F32.
53 * @param[in] off The indirect buffer tensor info. Data types supported: S32.
54 * @param[in] weights Weights tensor info. Weights are 4D tensor with dimensions [IFM, kernel_x, kernel_y, OFM].
55 * Data type supported: Same as @p src.
56 * @param[in] biases Biases tensor info. Biases are 1D tensor with dimension [OFM].
57 * Data type supported: Same as @p src.
58 * @param[out] dst Output tensor info.
59 * The 3rd dimension must be equal to the 4th dimension of the @p weights tensor. Data types supported: Same as @p src.
60 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
61 * @param[in] act_info Contains activaton information described in @ref ActivationLayerInfo.
62 * @param[in] desc Direct convolution descriptor used to build the NHWC indirect convolution kernel.
63 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010064 void configure(const CLCompileContext &compile_context,
65 ITensorInfo *src,
66 ITensorInfo *off,
67 ITensorInfo *weights,
68 ITensorInfo *biases,
69 ITensorInfo *dst,
70 const PadStrideInfo &conv_info,
71 const ActivationLayerInfo &act_info,
72 const DirectConvComputeKernelInfo &desc);
Gian Marco Iodice76335eb2022-11-17 11:03:39 +000073 /** Static function to check if given info will lead to a valid configuration
74 *
75 * Similar to ClIndirectConv2dKernel::configure()
76 *
77 * @return a status
78 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010079 static Status validate(const ITensorInfo *src,
80 const ITensorInfo *off,
81 const ITensorInfo *weights,
82 const ITensorInfo *biases,
83 const ITensorInfo *dst,
84 const PadStrideInfo &conv_info,
85 const ActivationLayerInfo &act_info,
86 const DirectConvComputeKernelInfo &desc);
Gian Marco Iodice76335eb2022-11-17 11:03:39 +000087
88 // Inherited methods overridden:
89 void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override;
90
91public:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010092 bool _export_to_cl_image{false};
Gian Marco Iodice76335eb2022-11-17 11:03:39 +000093};
94} // namespace kernels
95} // namespace opencl
96} // namespace arm_compute
97#endif /* ARM_COMPUTE_CL_DIRECT_CONV2D_KERNEL_H */