blob: af1298f53f382a56b0b8e304e6800694fdf0d76f [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michalis Spyrouebcebf12020-10-21 00:04:14 +01002 * Copyright (c) 2016-2020 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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEACCUMULATEKERNEL_H
25#define ARM_COMPUTE_NEACCUMULATEKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
Michalis Spyrouebcebf12020-10-21 00:04:14 +010027#include "src/core/NEON/INESimpleKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028
29#include <cstdint>
30
31namespace arm_compute
32{
33class ITensor;
34
35/** Interface for the accumulate kernel
36 *
37 * Accumulation is computed by:
38 * @f[ accum(x,y) = accum(x,y) + input(x,y) @f]
39 */
40class NEAccumulateKernel : public INESimpleKernel
41{
42public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000043 const char *name() const override
44 {
45 return "NEAccumulateKernel";
46 }
Michalis Spyrouebcebf12020-10-21 00:04:14 +010047 /** Default constructor */
48 NEAccumulateKernel() = default;
49 /** Prevent instances of this class from being copied (As this class contains pointers) */
50 NEAccumulateKernel(const NEAccumulateKernel &) = delete;
51 /** Prevent instances of this class from being copied (As this class contains pointers) */
52 NEAccumulateKernel &operator=(const NEAccumulateKernel &) = delete;
53 /** Allow instances of this class to be moved */
54 NEAccumulateKernel(NEAccumulateKernel &&) = default;
55 /** Allow instances of this class to be moved */
56 NEAccumulateKernel &operator=(NEAccumulateKernel &&) = default;
57 /** Default destructor */
58 ~NEAccumulateKernel() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059 /** Set the input and accumulation tensors
60 *
61 * @param[in] input Source tensor. Data type supported: U8.
62 * @param[out] accum Destination tensor. Data type supported: S16.
63 */
64 void configure(const ITensor *input, ITensor *accum);
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};
69
70/** Interface for the accumulate weighted kernel
71 *
72 * Weighted accumulation is computed:
73 * @f[ accum(x,y) = (1 - \alpha)*accum(x,y) + \alpha*input(x,y) @f]
74 *
75 * Where @f$ 0 \le \alpha \le 1 @f$
76 * Conceptually, the rounding for this is defined as:
77 * @f[ output(x,y)= uint8( (1 - \alpha) * float32( int32( output(x,y) ) ) + \alpha * float32( int32( input(x,y) ) ) ) @f]
78*/
79class NEAccumulateWeightedKernel : public INESimpleKernel
80{
81public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000082 const char *name() const override
83 {
84 return "NEAccumulateWeightedKernel";
85 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010086 /** Default constructor */
87 NEAccumulateWeightedKernel();
Michalis Spyrouebcebf12020-10-21 00:04:14 +010088 /** Prevent instances of this class from being copied (As this class contains pointers) */
89 NEAccumulateWeightedKernel(const NEAccumulateWeightedKernel &) = delete;
90 /** Prevent instances of this class from being copied (As this class contains pointers) */
91 NEAccumulateWeightedKernel &operator=(const NEAccumulateWeightedKernel &) = delete;
92 /** Allow instances of this class to be moved */
93 NEAccumulateWeightedKernel(NEAccumulateWeightedKernel &&) = default;
94 /** Allow instances of this class to be moved */
95 NEAccumulateWeightedKernel &operator=(NEAccumulateWeightedKernel &&) = default;
96 /** Default destructor */
97 ~NEAccumulateWeightedKernel() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010098 /** Set the input and accumulation tensors, and the scale value
99 *
100 * @param[in] input Source tensor. Data type supported: U8.
101 * @param[in] alpha Scalar value in the range [0.0f, 1.0f]
102 * @param[in,out] accum Accumulated tensor. Data type supported: U8.
103 */
104 void configure(const ITensor *input, float alpha, ITensor *accum);
105
106 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100107 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100108
109protected:
110 float _alpha;
111};
112
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000113#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100114/** Interface for the accumulate weighted kernel using F16 */
115class NEAccumulateWeightedFP16Kernel : public NEAccumulateWeightedKernel
116{
117public:
Anthony Barbiere8a49832018-01-18 10:04:05 +0000118 const char *name() const override
119 {
120 return "NEAccumulateWeightedFP16Kernel";
121 }
Michalis Spyrouebcebf12020-10-21 00:04:14 +0100122 /** Default constructor */
123 NEAccumulateWeightedFP16Kernel() = default;
124 /** Prevent instances of this class from being copied (As this class contains pointers) */
125 NEAccumulateWeightedFP16Kernel(const NEAccumulateWeightedFP16Kernel &) = delete;
126 /** Prevent instances of this class from being copied (As this class contains pointers) */
127 NEAccumulateWeightedFP16Kernel &operator=(const NEAccumulateWeightedFP16Kernel &) = delete;
128 /** Allow instances of this class to be moved */
129 NEAccumulateWeightedFP16Kernel(NEAccumulateWeightedFP16Kernel &&) = default;
130 /** Allow instances of this class to be moved */
131 NEAccumulateWeightedFP16Kernel &operator=(NEAccumulateWeightedFP16Kernel &&) = default;
132 /** Default destructor */
133 ~NEAccumulateWeightedFP16Kernel() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100134 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100135 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100136};
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000137#else /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Alex Gildayc357c472018-03-21 13:54:09 +0000138/** Interface for the accumulate weighted kernel using F16 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100139using NEAccumulateWeightedFP16Kernel = NEAccumulateWeightedKernel;
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000140#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100141
142/** Interface for the accumulate squared kernel
143 *
144 * The accumulation of squares is computed:
145 * @f[ accum(x,y) = saturate_{int16} ( (uint16) accum(x,y) + (((uint16)(input(x,y)^2)) >> (shift)) ) @f]
146 *
147 * Where @f$ 0 \le shift \le 15 @f$
148*/
149class NEAccumulateSquaredKernel : public INESimpleKernel
150{
151public:
Anthony Barbiere8a49832018-01-18 10:04:05 +0000152 const char *name() const override
153 {
154 return "NEAccumulateSquaredKernel";
155 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100156 /** Default constructor */
157 NEAccumulateSquaredKernel();
Michalis Spyrouebcebf12020-10-21 00:04:14 +0100158 /** Prevent instances of this class from being copied (As this class contains pointers) */
159 NEAccumulateSquaredKernel(const NEAccumulateSquaredKernel &) = delete;
160 /** Prevent instances of this class from being copied (As this class contains pointers) */
161 NEAccumulateSquaredKernel &operator=(const NEAccumulateSquaredKernel &) = delete;
162 /** Allow instances of this class to be moved */
163 NEAccumulateSquaredKernel(NEAccumulateSquaredKernel &&) = default;
164 /** Allow instances of this class to be moved */
165 NEAccumulateSquaredKernel &operator=(NEAccumulateSquaredKernel &&) = default;
166 /** Default destructor */
167 ~NEAccumulateSquaredKernel() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100168 /** Set the input and accumulation tensors and the shift value.
169 *
170 * @param[in] input Source tensor. Data type supported: U8.
171 * @param[in] shift Shift value in the range of [0, 15]
172 * @param[in,out] accum Accumulated tensor. Data type supported: S16.
173 */
174 void configure(const ITensor *input, uint32_t shift, ITensor *accum);
175
176 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100177 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100178
179private:
180 uint32_t _shift;
181};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100182} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000183#endif /*ARM_COMPUTE_NEACCUMULATEKERNEL_H */