From 1009e87127e08a58561373c3f83f22b5f0922641 Mon Sep 17 00:00:00 2001 From: Michalis Spyrou Date: Mon, 27 Jul 2020 12:48:34 +0100 Subject: COMPMID-3385: Async support to CLArithmetic* kernels/functions Pt.2 Signed-off-by: Michalis Spyrou Change-Id: Idc5ac2dd2ba5295c00c88b44a783645327a27e15 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3617 Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas Comments-Addressed: Arm Jenkins --- .../CL/functions/CLPixelWiseMultiplication.h | 157 ++++++++++++++++++++- 1 file changed, 153 insertions(+), 4 deletions(-) (limited to 'arm_compute/runtime/CL/functions/CLPixelWiseMultiplication.h') diff --git a/arm_compute/runtime/CL/functions/CLPixelWiseMultiplication.h b/arm_compute/runtime/CL/functions/CLPixelWiseMultiplication.h index b87daba1f8..ca8d77e6b7 100644 --- a/arm_compute/runtime/CL/functions/CLPixelWiseMultiplication.h +++ b/arm_compute/runtime/CL/functions/CLPixelWiseMultiplication.h @@ -24,18 +24,141 @@ #ifndef ARM_COMPUTE_CLPIXELWISEMULTIPLICATION_H #define ARM_COMPUTE_CLPIXELWISEMULTIPLICATION_H -#include "arm_compute/core/Types.h" -#include "arm_compute/runtime/CL/ICLSimpleFunction.h" +#include "arm_compute/core/CL/kernels/CLFillBorderKernel.h" +#include "arm_compute/runtime/CL/ICLOperator.h" +#include "arm_compute/runtime/IFunction.h" namespace arm_compute { // Forward declaration class ICLTensor; +namespace experimental +{ +/** Basic function to run @ref CLPixelWiseMultiplicationKernel. */ +class CLPixelWiseMultiplication : public ICLOperator +{ +public: + /** Default Constructor */ + CLPixelWiseMultiplication(); + /** Initialise the kernel's inputs, output and convertion policy. + * + * Valid configurations (Input1,Input2) -> Output : + * + * - (U8,U8) -> U8 + * - (U8,U8) -> S16 + * - (U8,S16) -> S16 + * - (S16,U8) -> S16 + * - (S16,S16) -> S16 + * - (F16,F16) -> F16 + * - (F32,F32) -> F32 + * - (QASYMM8,QASYMM8) -> QASYMM8 + * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED + * - (QSYMM16,QSYMM16) -> QSYMM16 + * - (QSYMM16,QSYMM16) -> S32 + * + * @param[in] compile_context The compile context to be used. + * @param[in, out] input1 An input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32. + * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. + * @param[in, out] input2 An input tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32. + * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. + * @param[out] output The output tensor. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32. + * @param[in] scale Scale to apply after multiplication. + * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15. + * @param[in] overflow_policy Overflow policy. Supported overflow policies: Wrap, Saturate + * @param[in] rounding_policy Rounding policy. Supported rounding modes: to zero, to nearest even. + * @param[in] act_info (Optional) Activation layer information in case of a fused activation. + */ + void configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, float scale, + ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info = ActivationLayerInfo()); + /** Static function to check if given info will lead to a valid configuration of @ref CLPixelWiseMultiplication + * + * Valid configurations (Input1,Input2) -> Output : + * + * - (U8,U8) -> U8 + * - (U8,U8) -> S16 + * - (U8,S16) -> S16 + * - (S16,U8) -> S16 + * - (S16,S16) -> S16 + * - (F16,F16) -> F16 + * - (F32,F32) -> F32 + * - (QASYMM8,QASYMM8) -> QASYMM8 + * - (QASYMM8_SIGNED,QASYMM8_SIGNED) -> QASYMM8_SIGNED + * - (QSYMM16,QSYMM16) -> QSYMM16 + * - (QSYMM16,QSYMM16) -> S32 + * + * + * @param[in] input1 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32. + * @param[in] input2 An input tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32. + * @param[in] output The output tensor info. Data types supported: U8/QASYMM8/QASYMM8_SIGNED/S16/QSYMM16/F16/F32. + * @param[in] scale Scale to apply after multiplication. + * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15. + * @param[in] overflow_policy Overflow policy. Supported overflow policies: Wrap, Saturate + * @param[in] rounding_policy Rounding policy. Supported rounding modes: to zero, to nearest even. + * @param[in] act_info (Optional) Activation layer information in case of a fused activation. + * + * @return a status + */ + static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, + ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info = ActivationLayerInfo()); + + // Inherited methods overridden: + void run(InputTensorMap inputs, OutputTensorMap outputs, OperatorTensorMap workspace) override; + +private: + CLFillBorderKernel _border_handler; +}; + +/** Basic function to run @ref CLComplexPixelWiseMultiplicationKernel. */ +class CLComplexPixelWiseMultiplication : public ICLOperator +{ +public: + /** Default Constructor */ + CLComplexPixelWiseMultiplication(); + /** Initialise the kernel's inputs, output. + * + * @param[in] compile_context The compile context to be used. + * @param[in, out] input1 An input tensor. Data types supported: F32. Number of channels supported: 2. + * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. + * @param[in, out] input2 An input tensor. Data types supported: same as @p input1. Number of channels supported: same as @p input1. + * The input tensor is [in, out] because its TensorInfo might be modified inside the kernel in case of broadcasting of dimension 0. + * @param[out] output The output tensor, Data types supported: same as @p input1. Number of channels supported: same as @p input1. + * @param[in] act_info (Optional) Activation layer information in case of a fused activation. + */ + void configure(const CLCompileContext &compile_context, ITensorInfo *input1, ITensorInfo *input2, ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); + /** Static function to check if given info will lead to a valid configuration of @ref CLComplexPixelWiseMultiplication + * + * @param[in] input1 An input tensor info. Data types supported: F32. Number of channels supported: 2. + * @param[in] input2 An input tensor info. Data types supported: same as @p input1. Number of channels supported: same as @p input1. + * @param[in] output The output tensor info, Data types supported: same as @p input1. Number of channels supported: same as @p input1. + * @param[in] act_info (Optional) Activation layer information in case of a fused activation. + */ + static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); + + // Inherited methods overridden: + void run(InputTensorMap inputs, OutputTensorMap outputs, OperatorTensorMap workspace) override; + +private: + CLFillBorderKernel _border_handler; +}; +} // namespace experimental + /** Basic function to run @ref CLPixelWiseMultiplicationKernel. */ -class CLPixelWiseMultiplication : public ICLSimpleFunction +class CLPixelWiseMultiplication : public IFunction { public: + /** Default Constructor */ + CLPixelWiseMultiplication(); + /** Default Destructor */ + ~CLPixelWiseMultiplication(); + /** Prevent instances of this class from being copied (As this class contains pointers) */ + CLPixelWiseMultiplication(const CLPixelWiseMultiplication &) = delete; + /** Default move constructor */ + CLPixelWiseMultiplication(CLPixelWiseMultiplication &&); + /** Prevent instances of this class from being copied (As this class contains pointers) */ + CLPixelWiseMultiplication &operator=(const CLPixelWiseMultiplication &) = delete; + /** Default move assignment operator */ + CLPixelWiseMultiplication &operator=(CLPixelWiseMultiplication &&); /** Initialise the kernel's inputs, output and convertion policy. * * Valid configurations (Input1,Input2) -> Output : @@ -125,12 +248,31 @@ public: */ static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy, const ActivationLayerInfo &act_info = ActivationLayerInfo()); + + // Inherited methods overridden: + void run() override; + +private: + struct Impl; + std::unique_ptr _impl; }; /** Basic function to run @ref CLComplexPixelWiseMultiplicationKernel. */ -class CLComplexPixelWiseMultiplication : public ICLSimpleFunction +class CLComplexPixelWiseMultiplication : public IFunction { public: + /** Default Constructor */ + CLComplexPixelWiseMultiplication(); + /** Default Destructor */ + ~CLComplexPixelWiseMultiplication(); + /** Prevent instances of this class from being copied (As this class contains pointers) */ + CLComplexPixelWiseMultiplication(const CLComplexPixelWiseMultiplication &) = delete; + /** Default move constructor */ + CLComplexPixelWiseMultiplication(CLComplexPixelWiseMultiplication &&); + /** Prevent instances of this class from being copied (As this class contains pointers) */ + CLComplexPixelWiseMultiplication &operator=(const CLComplexPixelWiseMultiplication &) = delete; + /** Default move assignment operator */ + CLComplexPixelWiseMultiplication &operator=(CLComplexPixelWiseMultiplication &&); /** Initialise the kernel's inputs, output. * * @param[in, out] input1 An input tensor. Data types supported: F32. Number of channels supported: 2. @@ -160,6 +302,13 @@ public: * @param[in] act_info (Optional) Activation layer information in case of a fused activation. */ static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, const ActivationLayerInfo &act_info = ActivationLayerInfo()); + + // Inherited methods overridden: + void run() override; + +private: + struct Impl; + std::unique_ptr _impl; }; } // namespace arm_compute #endif /*ARM_COMPUTE_CLPIXELWISEMULTIPLICATION_H */ -- cgit v1.2.1