blob: 90b658e354631d862c85e6d677f88c7c832873f4 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2016, 2017 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_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
30namespace arm_compute
31{
32class ITensor;
33
34/** Interface for the kernel to perform addition between two tensors */
35class NEPixelWiseMultiplicationKernel : public INEKernel
36{
37public:
38 /** Default constructor */
39 NEPixelWiseMultiplicationKernel();
40 /** Prevent instances of this class from being copied (As this class contains pointers) */
41 NEPixelWiseMultiplicationKernel(const NEPixelWiseMultiplicationKernel &) = delete;
42 /** Prevent instances of this class from being copied (As this class contains pointers) */
43 NEPixelWiseMultiplicationKernel &operator=(const NEPixelWiseMultiplicationKernel &) = delete;
44 /** Allow instances of this class to be moved */
45 NEPixelWiseMultiplicationKernel(NEPixelWiseMultiplicationKernel &&) = default;
46 /** Allow instances of this class to be moved */
47 NEPixelWiseMultiplicationKernel &operator=(NEPixelWiseMultiplicationKernel &&) = default;
48 /** Default destructor */
49 ~NEPixelWiseMultiplicationKernel() = default;
50 /** Initialise the kernel's input, output and border mode.
51 *
52 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
53 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
Michele Di Giorgio81f0d152017-07-11 15:00:52 +010054 * For QS8/QS16 scale = 1 is the only supported value.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010055 *
Michele Di Giorgio81f0d152017-07-11 15:00:52 +010056 * @param[in] input1 An input tensor. Data types supported: U8/QS8/QS16/S16/F16/F32
57 * @param[in] input2 An input tensor. Data types supported: U8, QS8 (only if @p input1 is QS8), QS16 (only if @p input1 is QS16), S16/F16 (only if @p input1 is F16), F32 (only if @p input1 is F32).
58 * @param[out] output The output tensor. Data types supported: U8 (Only if both inputs are U8), QS8 (only if both inputs are QS8), QS16 (only if both inputs are QS16), S16/F16 (only if @p input1 is F16), F32 (only if both inputs are F32).
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059 * @param[in] scale Scale to apply after multiplication.
60 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
61 * @param[in] overflow_policy Overflow policy.
62 * @param[in] rounding_policy Rounding policy.
63 */
64 void configure(const ITensor *input1, const ITensor *input2, ITensor *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy);
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000065 /** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplicationKernel
66 *
67 * @param[in] input1 An input tensor info. Data types supported: U8/QS8/QS16/S16/F16/F32
68 * @param[in] input2 An input tensor info. Data types supported: U8, QS8 (only if @p input1 is QS8), QS16 (only if @p input1 is QS16), S16/F16 (only if @p input1 is F16), F32 (only if @p input1 is F32).
69 * @param[in] output The output tensor info. Data types supported: U8 (Only if both inputs are U8), QS8 (only if both inputs are QS8), QS16 (only if both inputs are QS16), S16/F16 (only if @p input1 is F16), F32 (only if both inputs are F32).
70 * @param[in] scale Scale to apply after multiplication.
71 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
72 * @param[in] overflow_policy Overflow policy.
73 * @param[in] rounding_policy Rounding policy.
74 *
75 * @return an error status
76 */
77 static Error validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078
79 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010080 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010081
82private:
83 /** Common signature for all the specialised multiplication functions with integer scaling factor
84 *
85 * @param[in] input1_ptr Pointer to the first input tensor.
86 * @param[in] input2_ptr Pointer to the second input tensor.
87 * @param[out] output_ptr Pointer to the output tensor.
88 */
89 using MulFunctionInt = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, int scale);
90 /** Common signature for all the specialised multiplication functions with fixed-point values
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[in] scale Scaling factor.
95 * @param[in] fixed_point_position Fixed-point position that expresses the number of bits for the fractional part of the number.
96 * @param[out] output_ptr Pointer to the output tensor.
97 */
98 using MulFunctionQInt = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, int scale, int fixed_point_position);
99 /** Common signature for all the specialised multiplication functions with float scaling factor
100 *
101 * @param[in] input1_ptr Pointer to the first input tensor.
102 * @param[in] input2_ptr Pointer to the second input tensor.
103 * @param[out] output_ptr Pointer to the output tensor.
104 */
105 using MulFunctionFloat = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, float scale);
106
107 MulFunctionFloat *_func_float;
108 MulFunctionInt *_func_int;
109 MulFunctionQInt *_func_q_int;
110
111private:
112 const ITensor *_input1;
113 const ITensor *_input2;
114 ITensor *_output;
115 float _scale;
116 int _scale_exponent;
117};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100118} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100119#endif /*__ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H__ */