Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2018 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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_NEPIXELWISEMULTIPLICATIONKERNEL_H__ |
| 25 | #define __ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H__ |
| 26 | |
| 27 | #include "arm_compute/core/NEON/INEKernel.h" |
| 28 | #include "arm_compute/core/Types.h" |
| 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | class ITensor; |
| 33 | |
| 34 | /** Interface for the kernel to perform addition between two tensors */ |
| 35 | class NEPixelWiseMultiplicationKernel : public INEKernel |
| 36 | { |
| 37 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 38 | const char *name() const override |
| 39 | { |
| 40 | return "NEPixelWiseMultiplicationKernel"; |
| 41 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 42 | /** Default constructor */ |
| 43 | NEPixelWiseMultiplicationKernel(); |
| 44 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 45 | NEPixelWiseMultiplicationKernel(const NEPixelWiseMultiplicationKernel &) = delete; |
| 46 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 47 | NEPixelWiseMultiplicationKernel &operator=(const NEPixelWiseMultiplicationKernel &) = delete; |
| 48 | /** Allow instances of this class to be moved */ |
| 49 | NEPixelWiseMultiplicationKernel(NEPixelWiseMultiplicationKernel &&) = default; |
| 50 | /** Allow instances of this class to be moved */ |
| 51 | NEPixelWiseMultiplicationKernel &operator=(NEPixelWiseMultiplicationKernel &&) = default; |
| 52 | /** Default destructor */ |
| 53 | ~NEPixelWiseMultiplicationKernel() = default; |
| 54 | /** Initialise the kernel's input, output and border mode. |
| 55 | * |
| 56 | * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported. |
| 57 | * For all other scale values only round to zero (implemented as round towards minus infinity) is supported. |
| 58 | * |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 59 | * @param[in] input1 An input tensor. Data types supported: U8/S16/F16/F32 |
| 60 | * @param[in] input2 An input tensor. Data types supported: U8, S16/F16 (only if @p input1 is F16), F32 (only if @p input1 is F32). |
| 61 | * @param[out] output The output tensor. Data types supported: U8 (Only if both inputs are U8), S16/F16 (only if @p input1 is F16), F32 (only if both inputs are F32). |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 62 | * @param[in] scale Scale to apply after multiplication. |
| 63 | * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15. |
| 64 | * @param[in] overflow_policy Overflow policy. |
| 65 | * @param[in] rounding_policy Rounding policy. |
| 66 | */ |
| 67 | void configure(const ITensor *input1, const ITensor *input2, ITensor *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy); |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 68 | /** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplicationKernel |
| 69 | * |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 70 | * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported. |
| 71 | * For all other scale values only round to zero (implemented as round towards minus infinity) is supported. |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 72 | * |
Vidhya Sudhan Loganathan | 7485d5a | 2018-07-04 09:34:00 +0100 | [diff] [blame] | 73 | * @param[in] input1 An input tensor. Data types supported: U8/S16/F16/F32 |
| 74 | * @param[in] input2 An input tensor. Data types supported: U8, S16/F16 (only if @p input1 is F16), F32 (only if @p input1 is F32). |
| 75 | * @param[in] output The output tensor. Data types supported: U8 (Only if both inputs are U8), S16/F16 (only if @p input1 is F16), F32 (only if both inputs are F32). |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 76 | * @param[in] scale Scale to apply after multiplication. |
| 77 | * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15. |
| 78 | * @param[in] overflow_policy Overflow policy. |
| 79 | * @param[in] rounding_policy Rounding policy. |
| 80 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 81 | * @return a status |
Ioan-Cristian Szabo | 754e952 | 2017-11-28 18:29:43 +0000 | [diff] [blame] | 82 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 83 | static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 84 | |
| 85 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 86 | void run(const Window &window, const ThreadInfo &info) override; |
Michalis Spyrou | 861f0db | 2018-02-26 16:47:58 +0000 | [diff] [blame] | 87 | BorderSize border_size() const override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 88 | |
| 89 | private: |
| 90 | /** Common signature for all the specialised multiplication functions with integer scaling factor |
| 91 | * |
| 92 | * @param[in] input1_ptr Pointer to the first input tensor. |
| 93 | * @param[in] input2_ptr Pointer to the second input tensor. |
| 94 | * @param[out] output_ptr Pointer to the output tensor. |
| 95 | */ |
| 96 | using MulFunctionInt = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, int scale); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 97 | /** Common signature for all the specialised multiplication functions with float scaling factor |
| 98 | * |
| 99 | * @param[in] input1_ptr Pointer to the first input tensor. |
| 100 | * @param[in] input2_ptr Pointer to the second input tensor. |
| 101 | * @param[out] output_ptr Pointer to the output tensor. |
| 102 | */ |
| 103 | using MulFunctionFloat = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, float scale); |
| 104 | |
| 105 | MulFunctionFloat *_func_float; |
| 106 | MulFunctionInt *_func_int; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 107 | |
| 108 | private: |
| 109 | const ITensor *_input1; |
| 110 | const ITensor *_input2; |
| 111 | ITensor *_output; |
| 112 | float _scale; |
| 113 | int _scale_exponent; |
| 114 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 115 | } // namespace arm_compute |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 116 | #endif /*__ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H__ */ |