blob: 8c245569a59683bf381a101e42e73118f665a531 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Anthony Barbiere8a49832018-01-18 10:04:05 +00002 * Copyright (c) 2016-2018 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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:
Anthony Barbiere8a49832018-01-18 10:04:05 +000038 const char *name() const override
39 {
40 return "NEPixelWiseMultiplicationKernel";
41 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010042 /** 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.
Michele Di Giorgio81f0d152017-07-11 15:00:52 +010058 * For QS8/QS16 scale = 1 is the only supported value.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059 *
Michele Di Giorgio81f0d152017-07-11 15:00:52 +010060 * @param[in] input1 An input tensor. Data types supported: U8/QS8/QS16/S16/F16/F32
61 * @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).
62 * @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 +010063 * @param[in] scale Scale to apply after multiplication.
64 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
65 * @param[in] overflow_policy Overflow policy.
66 * @param[in] rounding_policy Rounding policy.
67 */
68 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 +000069 /** Static function to check if given info will lead to a valid configuration of @ref NEPixelWiseMultiplicationKernel
70 *
Michalis Spyrouafa5d812017-11-30 14:25:57 +000071 * @note For @p scale equal to 1/255 only round to nearest even (implemented as round half up) is supported.
72 * For all other scale values only round to zero (implemented as round towards minus infinity) is supported.
73 * For QS8/QS16 scale = 1 is the only supported value.
74 *
75 * @param[in] input1 An input tensor. Data types supported: U8/QS8/QS16/S16/F16/F32
76 * @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).
77 * @param[in] 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).
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000078 * @param[in] scale Scale to apply after multiplication.
79 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
80 * @param[in] overflow_policy Overflow policy.
81 * @param[in] rounding_policy Rounding policy.
82 *
Georgios Pinitas631c41a2017-12-06 11:53:03 +000083 * @return a status
Ioan-Cristian Szabo754e9522017-11-28 18:29:43 +000084 */
Georgios Pinitas631c41a2017-12-06 11:53:03 +000085 static Status 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 +010086
87 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010088 void run(const Window &window, const ThreadInfo &info) override;
Michalis Spyrou861f0db2018-02-26 16:47:58 +000089 BorderSize border_size() const override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010090
91private:
92 /** Common signature for all the specialised multiplication functions with integer scaling factor
93 *
94 * @param[in] input1_ptr Pointer to the first input tensor.
95 * @param[in] input2_ptr Pointer to the second input tensor.
96 * @param[out] output_ptr Pointer to the output tensor.
97 */
98 using MulFunctionInt = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, int scale);
99 /** Common signature for all the specialised multiplication functions with fixed-point values
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[in] scale Scaling factor.
104 * @param[in] fixed_point_position Fixed-point position that expresses the number of bits for the fractional part of the number.
105 * @param[out] output_ptr Pointer to the output tensor.
106 */
107 using MulFunctionQInt = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, int scale, int fixed_point_position);
108 /** Common signature for all the specialised multiplication functions with float scaling factor
109 *
110 * @param[in] input1_ptr Pointer to the first input tensor.
111 * @param[in] input2_ptr Pointer to the second input tensor.
112 * @param[out] output_ptr Pointer to the output tensor.
113 */
114 using MulFunctionFloat = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, float scale);
115
116 MulFunctionFloat *_func_float;
117 MulFunctionInt *_func_int;
118 MulFunctionQInt *_func_q_int;
119
120private:
121 const ITensor *_input1;
122 const ITensor *_input2;
123 ITensor *_output;
124 float _scale;
125 int _scale_exponent;
126};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100127} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100128#endif /*__ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H__ */