blob: 0c121182d4b940ea33e5f148cbb0f9060907aedc [file] [log] [blame]
Gian Marco Iodice76335eb2022-11-17 11:03:39 +00001/*
Matthew Benthamf1aeab92023-05-30 13:35:34 +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_INDIRECT_CONV2D_H
25#define ARM_COMPUTE_CL_INDIRECT_CONV2D_H
26
Matthew Benthamf1aeab92023-05-30 13:35:34 +000027#include "arm_compute/core/ActivationLayerInfo.h"
Gian Marco Iodice76335eb2022-11-17 11:03:39 +000028#include "arm_compute/core/TensorInfo.h"
29#include "arm_compute/runtime/CL/CLTensor.h"
30#include "arm_compute/runtime/CL/CLTypes.h"
31
32#include "src/gpu/cl/ClCompileContext.h"
33#include "src/gpu/cl/IClKernel.h"
34#include "src/gpu/cl/IClOperator.h"
35
36#include <memory>
37
38namespace arm_compute
39{
40// Forward declaration
41struct DirectConvComputeKernelInfo;
42
43namespace opencl
44{
45/** Basic function to execute indirect convolution on OpenCL. This function calls the following OpenCL kernels:
46 *
47 * -# @ref kernels::ClIndirectConv2dAddressPrecalculationKernel
48 * -# @ref kernels::ClIndirectConv2dKernel
49 */
50class ClIndirectConv2d : public IClOperator
51{
52public:
53 ClIndirectConv2d() = default;
54 /** Initialise the kernel's inputs and output
55 *
56 * Valid data layouts:
57 * - NHWC
58 *
59 * Valid data type configurations:
60 * |src0 |src1 |src2 |dst |
61 * |:------------|:-----------|:---------|:--------------|
62 * |F32 |F32 |F32 |F32 |
63 * |F16 |F16 |F16 |F16 |
64 *
65 * @note All tensors must have the same data type.
66 *
67 * @param[in] compile_context The compile context to be used.
68 * @param[in] src Source tensor. 3 lower dimensions represent a single src,
69 * while every optional dimension from 4 and above represent a batch of sources.
70 * Data types supported: F16/F32.
71 * @param[in] weights Weights tensor. Weights are 4D tensor with dimensions. Data type supported:Same as @p src.
72 * @param[in] biases Biases tensor. Shared biases supported. Biases are 1D tensor with dimensions [OFM].
73 * Data type supported: Should match @p src data type.
74 * @param[out] dst Destination tensor. 3 lower dimensions represent a single dst, while the rest represent batch of destinations.
75 * Data types supported: Same as @p src.
76 * @param[in] conv_info Contains padding and stride information described in @ref PadStrideInfo.
77 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
78 *
79 */
80 void configure(const CLCompileContext &compile_context, ITensorInfo *src, ITensorInfo *weights, ITensorInfo *biases, ITensorInfo *dst, const PadStrideInfo &conv_info,
81 const ActivationLayerInfo &act_info = ActivationLayerInfo());
82 /** Static function to check if given info will lead to a valid configuration
83 *
84 * Similar to ClIndirectConv2d::configure()
85 *
86 * @return a status
87 */
88 static Status validate(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *biases, const ITensorInfo *dst, const PadStrideInfo &conv_info,
89 const ActivationLayerInfo &act_info = ActivationLayerInfo());
90
91 // Inherited methods overridden:
92 void run(ITensorPack &tensors) override;
93 void prepare(ITensorPack &constants) override;
94 experimental::MemoryRequirements workspace() const override;
95
96private:
97 enum AuxTensorIdx
98 {
99 IndirectBuffer = 0,
100 Count
101 };
102
103 std::unique_ptr<IClKernel> _indirect_conv_kernel{ nullptr };
104 std::unique_ptr<IClKernel> _addr_precalculation_kernel{ nullptr };
105 TensorInfo _indirect_buffer{};
106 bool _is_prepared{ false };
107 experimental::MemoryRequirements _aux_mem{ Count };
108};
109} // namespace opencl
110} // namespace arm_compute
111#endif /* ARM_COMPUTE_CL_INDIRECT_CONV2D_H */