1 /* 2 * Copyright (c) 2016-2020 Arm Limited. 3 * 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_CLPIXELWISEMULTIPLICATIONKERNEL_H 25 #define ARM_COMPUTE_CLPIXELWISEMULTIPLICATIONKERNEL_H 26 27 #include "arm_compute/core/Types.h" 28 #include "src/core/CL/ICLKernel.h" 29 30 namespace arm_compute 31 { 32 // Forward declarations 33 class ICLTensor; 34 35 /** Interface for the pixelwise multiplication kernel. */ 36 class CLPixelWiseMultiplicationKernel : public ICLKernel 37 { 38 public: 39 /** Default constructor.*/ 40 CLPixelWiseMultiplicationKernel(); 41 /** Prevent instances of this class from being copied (As this class contains pointers) */ 42 CLPixelWiseMultiplicationKernel(const CLPixelWiseMultiplicationKernel &) = delete; 43 /** Prevent instances of this class from being copied (As this class contains pointers) */ 44 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 * 51 * 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 * 65 * @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. 68 * @param[in] scale Scale to apply after multiplication. 69 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15. 70 * @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. 72 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. 73 */ 74 void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, float scale, 75 ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info = ActivationLayerInfo()); 76 /** Initialise the kernel's input, output and border mode. 77 * 78 * 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 * 92 * @param[in] compile_context The compile context to be used. 93 * @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. 96 * @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 */ 102 void configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, float scale, 103 ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info = ActivationLayerInfo()); 104 /** Static function to check if given info will lead to a valid configuration of @ref CLPixelWiseMultiplicationKernel 105 * 106 * 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 * 120 * @param[in] input1 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32. 121 * @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. 123 * @param[in] scale Scale to apply after multiplication. 124 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15. 125 * @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. 127 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. 128 * 129 * @return a status 130 */ 131 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, 132 ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info = ActivationLayerInfo()); 133 134 // Inherited methods overridden: 135 void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override; 136 BorderSize border_size() const override; 137 138 private: 139 const ITensorInfo *_input1; 140 const ITensorInfo *_input2; 141 ITensorInfo *_output; 142 }; 143 144 /** Interface for the complex pixelwise multiplication kernel. */ 145 class CLComplexPixelWiseMultiplicationKernel : public ICLKernel 146 { 147 public: 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 * 160 * @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. 163 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. 164 */ 165 void configure(ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); 166 /** Initialise the kernel's input, output and border mode. 167 * 168 * @param[in] compile_context The compile context to be used. 169 * @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. 172 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. 173 */ 174 void configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); 175 /** Static function to check if given info will lead to a valid configuration of @ref CLComplexPixelWiseMultiplicationKernel 176 * 177 * @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. 181 * 182 * @return a status 183 */ 184 static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); 185 186 // Inherited methods overridden: 187 void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override; 188 BorderSize border_size() const override; 189 190 private: 191 const ITensorInfo *_input1; 192 const ITensorInfo *_input2; 193 ITensorInfo *_output; 194 }; 195 } // namespace arm_compute 196 #endif /*ARM_COMPUTE_CLPIXELWISEMULTIPLICATIONKERNEL_H */ 197