blob: 7e402cd220f8772f4877b7d3c8d31cc6a4391b57 [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.
54 *
55 * @param[in] input1 An input tensor. Data types supported: U8/QS8/S16/F32.
56 * @param[in] input2 An input tensor. Data types supported: U8/QS8/S16/F32.
57 * @param[out] output The output tensor. Data types supported: U8 (Only if both inputs are U8) /S16/F32.
58 * @param[in] scale Scale to apply after multiplication.
59 * Scale must be positive and its value must be either 1/255 or 1/2^n where n is between 0 and 15.
60 * @param[in] overflow_policy Overflow policy.
61 * @param[in] rounding_policy Rounding policy.
62 */
63 void configure(const ITensor *input1, const ITensor *input2, ITensor *output, float scale, ConvertPolicy overflow_policy, RoundingPolicy rounding_policy);
64
65 // Inherited methods overridden:
66 void run(const Window &window) override;
67
68private:
69 /** Common signature for all the specialised multiplication functions with integer scaling factor
70 *
71 * @param[in] input1_ptr Pointer to the first input tensor.
72 * @param[in] input2_ptr Pointer to the second input tensor.
73 * @param[out] output_ptr Pointer to the output tensor.
74 */
75 using MulFunctionInt = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, int scale);
76 /** Common signature for all the specialised multiplication functions with fixed-point values
77 *
78 * @param[in] input1_ptr Pointer to the first input tensor.
79 * @param[in] input2_ptr Pointer to the second input tensor.
80 * @param[in] scale Scaling factor.
81 * @param[in] fixed_point_position Fixed-point position that expresses the number of bits for the fractional part of the number.
82 * @param[out] output_ptr Pointer to the output tensor.
83 */
84 using MulFunctionQInt = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, int scale, int fixed_point_position);
85 /** Common signature for all the specialised multiplication functions with float scaling factor
86 *
87 * @param[in] input1_ptr Pointer to the first input tensor.
88 * @param[in] input2_ptr Pointer to the second input tensor.
89 * @param[out] output_ptr Pointer to the output tensor.
90 */
91 using MulFunctionFloat = void(const void *__restrict input1_ptr, const void *__restrict input2_ptr, void *__restrict output_ptr, float scale);
92
93 MulFunctionFloat *_func_float;
94 MulFunctionInt *_func_int;
95 MulFunctionQInt *_func_q_int;
96
97private:
98 const ITensor *_input1;
99 const ITensor *_input2;
100 ITensor *_output;
101 float _scale;
102 int _scale_exponent;
103};
104}
105#endif /*__ARM_COMPUTE_NEPIXELWISEMULTIPLICATIONKERNEL_H__ */