blob: 8e6f5646791702f289de0e5e5c41914cb98fa34c [file] [log] [blame]
Sheri Zhang6d9c9822021-09-24 16:02:57 +01001/*
Giorgio Arena5ae8d802021-11-18 18:02:13 +00002 * Copyright (c) 2021-2022 Arm Limited.
Sheri Zhang6d9c9822021-09-24 16:02:57 +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 */
24#ifndef ARM_COMPUTE_CPU_DIRECT_CONV3D_KERNEL_H
25#define ARM_COMPUTE_CPU_DIRECT_CONV3D_KERNEL_H
26
27#include "arm_compute/runtime/FunctionDescriptors.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Sheri Zhang6d9c9822021-09-24 16:02:57 +010029#include "src/core/common/Macros.h"
30#include "src/cpu/ICpuKernel.h"
Giorgio Arena5ae8d802021-11-18 18:02:13 +000031
Sheri Zhang6d9c9822021-09-24 16:02:57 +010032namespace arm_compute
33{
34namespace cpu
35{
36namespace kernels
37{
38/** Interface for the kernel to perform 3D Direct Convolution Layer. */
Yair Schwarzbaum46d44d22022-01-12 16:38:58 +020039class CpuDirectConv3dKernel : public ICpuKernel<CpuDirectConv3dKernel>
Sheri Zhang6d9c9822021-09-24 16:02:57 +010040{
Giorgio Arena5ae8d802021-11-18 18:02:13 +000041private:
42 /* Template function for convolution 3d NDHWC */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010043 using DirectConv3dKernelPtr = std::add_pointer<void(
44 const ITensor *, const ITensor *, const ITensor *, ITensor *, const Conv3dInfo &, const Window &)>::type;
Giorgio Arena5ae8d802021-11-18 18:02:13 +000045
Sheri Zhang6d9c9822021-09-24 16:02:57 +010046public:
47 CpuDirectConv3dKernel() = default;
48 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuDirectConv3dKernel);
Sheri Zhang5dda2172021-10-15 19:54:17 +010049 /** Set the src, weights, biases and dst tensor info.
Sheri Zhang6d9c9822021-09-24 16:02:57 +010050 *
51 * Valid data type configurations:
52 * |src0 |src1 |src2 |dst |
53 * |:--------------|:------------------|:------|:--------------|
54 * |F16 |F16 |F16 |F16 |
55 * |F32 |F32 |F32 |F32 |
Freddie Liardetf727ef42021-10-18 13:28:57 +010056 * |QASYMM8 |QASYMM8 |S32 |QASYMM8 |
57 * |QASYMM8_SIGNED |QASYMM8_SIGNED |S32 |QASYMM8_SIGNED |
Sheri Zhang6d9c9822021-09-24 16:02:57 +010058 *
Sheri Zhang5dda2172021-10-15 19:54:17 +010059 * @param[in, out] src0 Input tensor info.
60 * @param[in] src1 Set of kernels to convolve the input volume.
Sheri Zhang6d9c9822021-09-24 16:02:57 +010061 * The 2nd dimension must be the same as the input's volume 1st dimension.
Sheri Zhang5dda2172021-10-15 19:54:17 +010062 * @param[in] src2 Set of biases. Can be nullptr.
Sheri Zhang6d9c9822021-09-24 16:02:57 +010063 * @param[out] dst Output tensor info.
64 * The 1st dimensions must be equal to the 1st dimension of the @p kernels tensor.
65 * @param[in] conv_info Contains padding, stride, acitvation information.
66 *
67 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010068 void configure(const ITensorInfo *src0,
69 const ITensorInfo *src1,
70 const ITensorInfo *src2,
71 ITensorInfo *dst,
72 const Conv3dInfo &conv_info);
Sheri Zhang6d9c9822021-09-24 16:02:57 +010073 /** Static function to check if given info will lead to a valid configuration
74 *
75 * Similar to CpuDirectConv3dKernel::configure()
76 *
77 * @return a status
78 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010079 static Status validate(const ITensorInfo *src0,
80 const ITensorInfo *src1,
81 const ITensorInfo *src2,
82 const ITensorInfo *dst,
83 const Conv3dInfo &conv_info);
Sheri Zhang6d9c9822021-09-24 16:02:57 +010084
85 // Inherited methods overridden:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010086 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
Sheri Zhang6d9c9822021-09-24 16:02:57 +010087 const char *name() const override;
88
Giorgio Arena5ae8d802021-11-18 18:02:13 +000089 struct DirectConv3dKernel
90 {
91 const char *name;
92 const DataTypeISASelectorPtr is_selected;
93 DirectConv3dKernelPtr ukernel;
94 };
Sheri Zhang6d9c9822021-09-24 16:02:57 +010095
Giorgio Arena5ae8d802021-11-18 18:02:13 +000096 static const std::vector<DirectConv3dKernel> &get_available_kernels();
97
98private:
Sheri Zhang5dda2172021-10-15 19:54:17 +010099 Conv3dInfo _conv_info{};
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100100 DirectConv3dKernelPtr _run_method{nullptr};
Sheri Zhang5dda2172021-10-15 19:54:17 +0100101 std::string _name{};
Sheri Zhang6d9c9822021-09-24 16:02:57 +0100102};
Giorgio Arena5ae8d802021-11-18 18:02:13 +0000103
Sheri Zhang6d9c9822021-09-24 16:02:57 +0100104} // namespace kernels
105} // namespace cpu
106} // namespace arm_compute
107#endif /*ARM_COMPUTE_CPU_DIRECTCONV3D_KERNEL_H */