1 /* 2 * Copyright (c) 2021 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_CL_MUL_H 25 #define ARM_COMPUTE_CL_MUL_H 26 27 #include "src/gpu/cl/ClCompileContext.h" 28 #include "src/gpu/cl/IClOperator.h" 29 30 namespace arm_compute 31 { 32 namespace opencl 33 { 34 /** Basic function to run @ref opencl::kernels::ClMulKernel */ 35 class ClMul : public IClOperator 36 { 37 public: 38 /** Initialise the kernel's sources, dst and convertion policy. 39 * 40 * Valid configurations (src1,src2) -> Output : 41 * 42 * - (U8,U8) -> U8 43 * - (U8,U8) -> S16 44 * - (U8,S16) -> S16 45 * - (S16,U8) -> S16 46 * - (S16,S16) -> S16 47 * - (F16,F16) -> F16 48 * - (F32,F32) -> F32 49 * - (QASYMM8,QASYMM8) -> QASYMM8 50 * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED 51 * - (QSYMM16,QSYMM16) -> QSYMM16 52 * - (QSYMM16,QSYMM16) -> S32 53 * 54 * @param[in] compile_context The compile context to be used. 55 * @param[in, out] src1 An src tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32. 56 * The src tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. 57 * @param[in, out] src2 An src tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32. 58 * The src tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. 59 * @param[out] dst The dst tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32. 60 * @param[in] scale Scale to apply after multiplication. 61 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15. 62 * @param[in] overflow_policy Overflow policy. Supported overflow policies: Wrap, Saturate 63 * @param[in] rounding_policy Rounding policy. Supported rounding modes: to zero, to nearest even. 64 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. 65 */ 66 void configure(const CLCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, float scale, 67 ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info = ActivationLayerInfo()); 68 /** Static function to check if given info will lead to a valid configuration 69 * 70 * Similar to @ref ClMul::configure() 71 * 72 * @return a status 73 */ 74 static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, float scale, 75 ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info = ActivationLayerInfo()); 76 }; 77 78 /** Basic function to run @ref opencl::kernels::ClComplexMulKernel */ 79 class ClComplexMul : public IClOperator 80 { 81 public: 82 /** Initialise the kernel's sources, dst. 83 * 84 * @param[in] compile_context The compile context to be used. 85 * @param[in, out] src1 An src tensor info. Data types supported: F16/F32. Number of channels supported: 2. 86 * The src tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. 87 * @param[in, out] src2 An src tensor info. Data types supported: same as @p src1. Number of channels supported: same as @p src1. 88 * The src tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. 89 * @param[out] dst The dst tensor info, Data types supported: same as @p src1. Number of channels supported: same as @p src1. 90 * @param[in] act_info (Optional) Activation layer information in case of a fused activation. 91 */ 92 void configure(const CLCompileContext &compile_context, ITensorInfo *src1, ITensorInfo *src2, ITensorInfo *dst, const ActivationLayerInfo &act_info = ActivationLayerInfo()); 93 /** Static function to check if given info will lead to a valid configuration 94 * 95 * Similar to @ref ClComplexMul::configure() 96 * 97 * @return a status 98 */ 99 static Status validate(const ITensorInfo *src1, const ITensorInfo *src2, const ITensorInfo *dst, const ActivationLayerInfo &act_info = ActivationLayerInfo()); 100 }; 101 } // namespace opencl 102 } // namespace arm_compute 103 #endif /* ARM_COMPUTE_CL_MUL_H */