blob: 0d6f58611710802762892de5e5aa564957cc56ab [file] [log] [blame]
Sheri Zhang1e3ab422021-03-16 17:35:08 +00001/*
Giorgio Arena5ae8d802021-11-18 18:02:13 +00002 * Copyright (c) 2016-2022 Arm Limited.
Sheri Zhang1e3ab422021-03-16 17:35:08 +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 */
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010024#ifndef ARM_COMPUTE_CPU_MUL_KERNEL_H
25#define ARM_COMPUTE_CPU_MUL_KERNEL_H
Sheri Zhang1e3ab422021-03-16 17:35:08 +000026
27#include "src/core/common/Macros.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010028#include "src/cpu/ICpuKernel.h"
Sheri Zhang1e3ab422021-03-16 17:35:08 +000029
30namespace arm_compute
31{
32namespace cpu
33{
34namespace kernels
35{
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010036/** Interface for the kernel to perform multiplication between two tensors */
Yair Schwarzbaum46d44d22022-01-12 16:38:58 +020037class CpuMulKernel : public ICpuKernel<CpuMulKernel>
Sheri Zhang1e3ab422021-03-16 17:35:08 +000038{
39public:
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010040 CpuMulKernel() = default;
41 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuMulKernel);
Sheri Zhang1e3ab422021-03-16 17:35:08 +000042 /** Initialise the kernel's input, dst and border mode.
43 *
44 * Valid configurations (Src1,Src2) -> Dst :
45 *
46 * Support: Broadcast? Scale=1/255?
47 * - (U8,U8) -> U8, S16 N Y
48 * - (U8,S16) -> S16 N Y
49 * - (S16,U8) -> S16 N Y
50 * - (S16,S16) -> S16 N Y
51 * - (S32,S32) -> S32 Y N
52 * - (F16,F16) -> F16 N Y
53 * - (F32,F32) -> F32 Y Y
54 * - (QASYMM8,QASYMM8) -> QASYMM8 Y Y
55 * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED Y Y
56 * - (QSYMM16,QSYMM16) -> QSYMM16, S32 N Y
57 *
58 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
59 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
60 *
61 * @param[in] src1 First input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
62 * @param[in] src2 Second input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
63 * @param[out] dst Dst tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/S32/QSYMM16/F16/F32
64 * @param[in] scale Scale to apply after multiplication.
65 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
66 * If both @p src1, @p src2 and @p dst are of datatype S32, scale cannot be 1/255
67 * @param[in] overflow_policy Overflow policy. ConvertPolicy cannot be WRAP if any of the inputs is of quantized datatype
68 * @param[in] rounding_policy Rounding policy.
69 */
70 void configure(ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy);
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010071 /** Static function to check if given info will lead to a valid configuration
Sheri Zhang1e3ab422021-03-16 17:35:08 +000072 *
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +010073 * Similar to @ref CpuMulKernel::configure()
Sheri Zhang1e3ab422021-03-16 17:35:08 +000074 *
75 * @return a status
76 */
77 static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy);
78
79 // Inherited methods overridden
80 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
81 const char *name() const override;
82
Fadi Arafeh73bb6b72022-10-06 16:20:14 +000083 /** Return minimum workload size of the relevant kernel
84 *
85 * @param[in] platform The CPU platform used to create the context.
86 * @param[in] thread_count Number of threads in the execution.
87 *
88 * @return[out] mws Minimum workload size for requested configuration.
89 */
90 size_t get_mws(const CPUInfo &platform, size_t thread_count) const override;
91
Viet-Hoa Do0d05b662022-09-09 15:39:05 +010092 /** Get the preferred dimension in which the scheduler splits the work into multiple jobs.
93 *
94 * @return The split dimension hint.
95 */
96 size_t get_split_dimension_hint() const
97 {
98 return _split_dimension;
99 }
100
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000101private:
102 /** Common signature for all the specialised multiplication functions with integer scaling factor
103 *
104 * @param[in] src1 Src1 tensor object.
105 * @param[in] src2 Src2 tensor object.
106 * @param[out] dst Dst tensor object.
107 * @param[in] window Region on which to execute the kernel
108 * @param[in] scale Integer scale factor.
109 */
110 using MulFunctionInt = void(const ITensor *src1, const ITensor *src2, ITensor *dst, const Window &window, int scale);
111 /** Common signature for all the specialised multiplication functions with float scaling factor
112 *
113 * @param[in] src1 Src1 tensor object.
114 * @param[in] src2 Src2 tensor object.
115 * @param[out] dst Dst tensor object.
116 * @param[in] window Region on which to execute the kernel
117 * @param[in] scale Float scale factor.
118 */
119 using MulFunctionFloat = void(const ITensor *src1, const ITensor *src2, ITensor *dst, const Window &window, float scale);
120 /** Common signature for all the specialised QASYMM8 multiplication functions with float scaling factor
121 *
122 * @param[in] src1 Src1 tensor object.
123 * @param[in] src2 Src2 tensor object.
124 * @param[out] dst Dst tensor object.
125 * @param[in] window Region on which to execute the kernel
126 * @param[in] scale Float scale factor.
127 *
128 */
129 using MulFunctionQuantized = void(const ITensor *src1, const ITensor *src2, ITensor *dst, const Window &window, float scale);
130
131 MulFunctionFloat *_func_float{ nullptr };
132 MulFunctionInt *_func_int{ nullptr };
133 MulFunctionQuantized *_func_quantized{ nullptr };
134 float _scale{ 0 };
135 int _scale_exponent{ 0 };
Viet-Hoa Do0d05b662022-09-09 15:39:05 +0100136 size_t _split_dimension{ Window::DimY };
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000137};
138
139/** Interface for the complex pixelwise multiplication kernel. */
Yair Schwarzbaum46d44d22022-01-12 16:38:58 +0200140class CpuComplexMulKernel : public ICpuKernel<CpuComplexMulKernel>
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000141{
142public:
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +0100143 CpuComplexMulKernel() = default;
144 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(CpuComplexMulKernel);
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000145 /** Initialise the kernel's src, dst and border mode.
146 *
147 * @param[in] src1 An src tensor. Data types supported: F32. Number of channels supported: 2 (complex tensor).
148 * @param[in] src2 An src tensor. Data types supported: same as @p src1. Number of channels supported: same as @p src1.
149 * @param[out] dst The dst tensor, Data types supported: same as @p src1. Number of channels supported: same as @p src1.
150 */
151 void configure(ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst);
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +0100152 /** Static function to check if given info will lead to a valid configuration
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000153 *
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +0100154 * Similar to @ref CpuComplexMulKernel::configure()
Sheri Zhang1e3ab422021-03-16 17:35:08 +0000155 *
156 * @return a status
157 */
158 static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst);
159
160 // Inherited methods overridden:
161 void run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info) override;
162 const char *name() const override;
163};
164} // namespace kernels
165} // namespace cpu
166} // namespace arm_compute
Georgios Pinitas0dc0d8e2021-04-30 03:18:37 +0100167#endif /* ARM_COMPUTE_CPU_MUL_KERNEL_H */