blob: baa4112ca99cbd98d99dc52e07b3d6510b9e8328 [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);
65
66 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010067 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010068
69private:
70 /** Common signature for all the specialised multiplication functions with integer scaling factor
71 *
72 * @param[in] input1_ptr Pointer to the first input tensor.
73 * @param[in] input2_ptr Pointer to the second input tensor.
74 * @param[out] output_ptr Pointer to the output tensor.
75 */
76 using MulFunctionInt = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, int scale);
77 /** Common signature for all the specialised multiplication functions with fixed-point values
78 *
79 * @param[in] input1_ptr Pointer to the first input tensor.
80 * @param[in] input2_ptr Pointer to the second input tensor.
81 * @param[in] scale Scaling factor.
82 * @param[in] fixed_point_position Fixed-point position that expresses the number of bits for the fractional part of the number.
83 * @param[out] output_ptr Pointer to the output tensor.
84 */
85 using MulFunctionQInt = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, int scale, int fixed_point_position);
86 /** Common signature for all the specialised multiplication functions with float scaling factor
87 *
88 * @param[in] input1_ptr Pointer to the first input tensor.
89 * @param[in] input2_ptr Pointer to the second input tensor.
90 * @param[out] output_ptr Pointer to the output tensor.
91 */
92 using MulFunctionFloat = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, float scale);
93
94 MulFunctionFloat *_func_float;
95 MulFunctionInt *_func_int;
96 MulFunctionQInt *_func_q_int;
97
98private:
99 const ITensor *_input1;
100 const ITensor *_input2;
101 ITensor *_output;
102 float _scale;
103 int _scale_exponent;
104};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100105} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106#endif /*__ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H__ */