blob: 86159fc9157a5e73be81f3543cfcda8f3310e647 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2016-2020 Arm Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CLPIXELWISEMULTIPLICATIONKERNEL_H
25#define ARM_COMPUTE_CLPIXELWISEMULTIPLICATIONKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/CL/ICLKernel.h"
28#include "arm_compute/core/Types.h"
29
30namespace arm_compute
31{
Georgios Pinitas8be91482019-03-26 17:23:28 +000032// Forward declarations
Anthony Barbier6ff3b192017-09-04 18:44:23 +010033class ICLTensor;
34
Georgios Pinitas8be91482019-03-26 17:23:28 +000035/** Interface for the pixelwise multiplication kernel. */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010036class CLPixelWiseMultiplicationKernel : public ICLKernel
37{
38public:
39 /** Default constructor.*/
40 CLPixelWiseMultiplicationKernel();
Alex Gildayc357c472018-03-21 13:54:09 +000041 /** Prevent instances of this class from being copied (As this class contains pointers) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010042 CLPixelWiseMultiplicationKernel(const CLPixelWiseMultiplicationKernel &) = delete;
Alex Gildayc357c472018-03-21 13:54:09 +000043 /** Prevent instances of this class from being copied (As this class contains pointers) */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010044 CLPixelWiseMultiplicationKernel &operator=(const CLPixelWiseMultiplicationKernel &) = delete;
45 /** Allow instances of this class to be moved */
46 CLPixelWiseMultiplicationKernel(CLPixelWiseMultiplicationKernel &&) = default;
47 /** Allow instances of this class to be moved */
48 CLPixelWiseMultiplicationKernel &operator=(CLPixelWiseMultiplicationKernel &&) = default;
49 /** Initialise the kernel's input, output and border mode.
50 *
Michele Di Giorgiof6f78762020-07-06 11:27:21 +010051 * Valid configurations (Input1,Input2) -> Output :
52 *
53 * - (U8,U8) -> U8
54 * - (U8,U8) -> S16
55 * - (U8,S16) -> S16
56 * - (S16,U8) -> S16
57 * - (S16,S16) -> S16
58 * - (F16,F16) -> F16
59 * - (F32,F32) -> F32
60 * - (QASYMM8,QASYMM8) -> QASYMM8
61 * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED
62 * - (QSYMM16,QSYMM16) -> QSYMM16
63 * - (QSYMM16,QSYMM16) -> S32
64 *
Michalis Spyrou1009e872020-07-27 12:48:34 +010065 * @param[in] input1 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32.
66 * @param[in] input2 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32.
67 * @param[out] output The output tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010068 * @param[in] scale Scale to apply after multiplication.
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +010069 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010070 * @param[in] overflow_policy Overflow policy. Supported overflow policies: Wrap, Saturate
71 * @param[in] rounding_policy Rounding policy. Supported rounding modes: to zero, to nearest even.
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000072 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010073 */
Michalis Spyrou1009e872020-07-27 12:48:34 +010074 void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, float scale,
Giorgio Arena8b2a7d32020-02-11 17:21:31 +000075 ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info = ActivationLayerInfo());
Manuel Bottini4c6bd512020-04-08 10:15:51 +010076 /** Initialise the kernel's input, output and border mode.
77 *
Michele Di Giorgiof6f78762020-07-06 11:27:21 +010078 * Valid configurations (Input1,Input2) -> Output :
79 *
80 * - (U8,U8) -> U8
81 * - (U8,U8) -> S16
82 * - (U8,S16) -> S16
83 * - (S16,U8) -> S16
84 * - (S16,S16) -> S16
85 * - (F16,F16) -> F16
86 * - (F32,F32) -> F32
87 * - (QASYMM8,QASYMM8) -> QASYMM8
88 * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED
89 * - (QSYMM16,QSYMM16) -> QSYMM16
90 * - (QSYMM16,QSYMM16) -> S32
91 *
Manuel Bottini4c6bd512020-04-08 10:15:51 +010092 * @param[in] compile_context The compile context to be used.
Michalis Spyrou1009e872020-07-27 12:48:34 +010093 * @param[in] input1 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32.
94 * @param[in] input2 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32.
95 * @param[out] output The output tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32.
Manuel Bottini4c6bd512020-04-08 10:15:51 +010096 * @param[in] scale Scale to apply after multiplication.
97 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
98 * @param[in] overflow_policy Overflow policy. Supported overflow policies: Wrap, Saturate
99 * @param[in] rounding_policy Rounding policy. Supported rounding modes: to zero, to nearest even.
100 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
101 */
Michalis Spyrou1009e872020-07-27 12:48:34 +0100102 void configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, float scale,
Manuel Bottini4c6bd512020-04-08 10:15:51 +0100103 ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info = ActivationLayerInfo());
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000104 /** Static function to check if given info will lead to a valid configuration of @ref CLPixelWiseMultiplicationKernel
105 *
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100106 * Valid configurations (Input1,Input2) -> Output :
107 *
108 * - (U8,U8) -> U8
109 * - (U8,U8) -> S16
110 * - (U8,S16) -> S16
111 * - (S16,U8) -> S16
112 * - (S16,S16) -> S16
113 * - (F16,F16) -> F16
114 * - (F32,F32) -> F32
115 * - (QASYMM8,QASYMM8) -> QASYMM8
116 * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED
117 * - (QSYMM16,QSYMM16) -> QSYMM16
118 * - (QSYMM16,QSYMM16) -> S32
119 *
Michele Di Giorgiocbbed282019-12-20 13:26:08 +0000120 * @param[in] input1 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32.
Michele Di Giorgiof6f78762020-07-06 11:27:21 +0100121 * @param[in] input2 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32.
122 * @param[in] output The output tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32.
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000123 * @param[in] scale Scale to apply after multiplication.
Vidhya Sudhan Loganathan7485d5a2018-07-04 09:34:00 +0100124 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000125 * @param[in] overflow_policy Overflow policy. Supported overflow policies: Wrap, Saturate
126 * @param[in] rounding_policy Rounding policy. Supported rounding modes: to zero, to nearest even.
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000127 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000128 *
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000129 * @return a status
Georgios Pinitasf9d3a0a2017-11-03 19:01:44 +0000130 */
Georgios Pinitas631c41a2017-12-06 11:53:03 +0000131 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale,
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000132 ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info = ActivationLayerInfo());
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100133
134 // Inherited methods overridden:
Michalis Spyrou1009e872020-07-27 12:48:34 +0100135 void run_op(const InputTensorMap &inputs, const OutputTensorMap &outputs, const Window &window, cl::CommandQueue &queue) override;
Michele Di Giorgio6259e5f2018-01-17 17:29:33 +0000136 BorderSize border_size() const override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100137
138private:
Michalis Spyrou1009e872020-07-27 12:48:34 +0100139 const ITensorInfo *_input1;
140 const ITensorInfo *_input2;
141 ITensorInfo *_output;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100142};
Georgios Pinitas8be91482019-03-26 17:23:28 +0000143
144/** Interface for the complex pixelwise multiplication kernel. */
145class CLComplexPixelWiseMultiplicationKernel : public ICLKernel
146{
147public:
148 /** Default constructor.*/
149 CLComplexPixelWiseMultiplicationKernel();
150 /** Prevent instances of this class from being copied (As this class contains pointers) */
151 CLComplexPixelWiseMultiplicationKernel(const CLComplexPixelWiseMultiplicationKernel &) = delete;
152 /** Prevent instances of this class from being copied (As this class contains pointers) */
153 CLComplexPixelWiseMultiplicationKernel &operator=(const CLComplexPixelWiseMultiplicationKernel &) = delete;
154 /** Allow instances of this class to be moved */
155 CLComplexPixelWiseMultiplicationKernel(CLComplexPixelWiseMultiplicationKernel &&) = default;
156 /** Allow instances of this class to be moved */
157 CLComplexPixelWiseMultiplicationKernel &operator=(CLComplexPixelWiseMultiplicationKernel &&) = default;
158 /** Initialise the kernel's input, output and border mode.
159 *
Michalis Spyrou1009e872020-07-27 12:48:34 +0100160 * @param[in] input1 An input tensor info. Data types supported: F32. Number of channels supported: 2.
161 * @param[in] input2 An input tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
162 * @param[out] output The output tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000163 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
Georgios Pinitas8be91482019-03-26 17:23:28 +0000164 */
Michalis Spyrou1009e872020-07-27 12:48:34 +0100165 void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
Manuel Bottini4c6bd512020-04-08 10:15:51 +0100166 /** Initialise the kernel's input, output and border mode.
167 *
168 * @param[in] compile_context The compile context to be used.
Michalis Spyrou1009e872020-07-27 12:48:34 +0100169 * @param[in] input1 An input tensor info. Data types supported: F32. Number of channels supported: 2.
170 * @param[in] input2 An input tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
171 * @param[out] output The output tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
Manuel Bottini4c6bd512020-04-08 10:15:51 +0100172 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
173 */
Michalis Spyrou1009e872020-07-27 12:48:34 +0100174 void configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
Georgios Pinitas8be91482019-03-26 17:23:28 +0000175 /** Static function to check if given info will lead to a valid configuration of @ref CLComplexPixelWiseMultiplicationKernel
176 *
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000177 * @param[in] input1 An input tensor info. Data types supported: F32. Number of channels supported: 2.
178 * @param[in] input2 An input tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
179 * @param[in] output The output tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1.
180 * @param[in] act_info (Optional) Activation layer information in case of a fused activation.
Georgios Pinitas8be91482019-03-26 17:23:28 +0000181 *
182 * @return a status
183 */
Giorgio Arena8b2a7d32020-02-11 17:21:31 +0000184 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo());
Georgios Pinitas8be91482019-03-26 17:23:28 +0000185
186 // Inherited methods overridden:
Michalis Spyrou1009e872020-07-27 12:48:34 +0100187 void run_op(const InputTensorMap &inputs, const OutputTensorMap &outputs, const Window &window, cl::CommandQueue &queue) override;
Georgios Pinitas8be91482019-03-26 17:23:28 +0000188 BorderSize border_size() const override;
189
190private:
Michalis Spyrou1009e872020-07-27 12:48:34 +0100191 const ITensorInfo *_input1;
192 const ITensorInfo *_input2;
193 ITensorInfo *_output;
Georgios Pinitas8be91482019-03-26 17:23:28 +0000194};
Gian Marco Iodicef670a0a2017-09-18 12:20:45 +0100195} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000196#endif /*ARM_COMPUTE_CLPIXELWISEMULTIPLICATIONKERNEL_H */