blob: 367385dd7abbcd38d211b945ab2984da7f5de7dd [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michalis Spyrouf4643372019-11-29 16:17:13 +00002 * Copyright (c) 2016-2019 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
27#include "arm_compute/core/NEON/INESimpleKernel.h"
28
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 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010047 /** Set the input and accumulation tensors
48 *
49 * @param[in] input Source tensor. Data type supported: U8.
50 * @param[out] accum Destination tensor. Data type supported: S16.
51 */
52 void configure(const ITensor *input, ITensor *accum);
53
54 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010055 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010056};
57
58/** Interface for the accumulate weighted kernel
59 *
60 * Weighted accumulation is computed:
61 * @f[ accum(x,y) = (1 - \alpha)*accum(x,y) + \alpha*input(x,y) @f]
62 *
63 * Where @f$ 0 \le \alpha \le 1 @f$
64 * Conceptually, the rounding for this is defined as:
65 * @f[ output(x,y)= uint8( (1 - \alpha) * float32( int32( output(x,y) ) ) + \alpha * float32( int32( input(x,y) ) ) ) @f]
66*/
67class NEAccumulateWeightedKernel : public INESimpleKernel
68{
69public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000070 const char *name() const override
71 {
72 return "NEAccumulateWeightedKernel";
73 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010074 /** Default constructor */
75 NEAccumulateWeightedKernel();
76 /** Set the input and accumulation tensors, and the scale value
77 *
78 * @param[in] input Source tensor. Data type supported: U8.
79 * @param[in] alpha Scalar value in the range [0.0f, 1.0f]
80 * @param[in,out] accum Accumulated tensor. Data type supported: U8.
81 */
82 void configure(const ITensor *input, float alpha, ITensor *accum);
83
84 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010085 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010086
87protected:
88 float _alpha;
89};
90
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +000091#ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
Anthony Barbier6ff3b192017-09-04 18:44:23 +010092/** Interface for the accumulate weighted kernel using F16 */
93class NEAccumulateWeightedFP16Kernel : public NEAccumulateWeightedKernel
94{
95public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000096 const char *name() const override
97 {
98 return "NEAccumulateWeightedFP16Kernel";
99 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100101 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100102};
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000103#else /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Alex Gildayc357c472018-03-21 13:54:09 +0000104/** Interface for the accumulate weighted kernel using F16 */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100105using NEAccumulateWeightedFP16Kernel = NEAccumulateWeightedKernel;
Ioan-Cristian Szabo5edbd1c2017-11-13 13:34:08 +0000106#endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100107
108/** Interface for the accumulate squared kernel
109 *
110 * The accumulation of squares is computed:
111 * @f[ accum(x,y) = saturate_{int16} ( (uint16) accum(x,y) + (((uint16)(input(x,y)^2)) >> (shift)) ) @f]
112 *
113 * Where @f$ 0 \le shift \le 15 @f$
114*/
115class NEAccumulateSquaredKernel : public INESimpleKernel
116{
117public:
Anthony Barbiere8a49832018-01-18 10:04:05 +0000118 const char *name() const override
119 {
120 return "NEAccumulateSquaredKernel";
121 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100122 /** Default constructor */
123 NEAccumulateSquaredKernel();
124 /** Set the input and accumulation tensors and the shift value.
125 *
126 * @param[in] input Source tensor. Data type supported: U8.
127 * @param[in] shift Shift value in the range of [0, 15]
128 * @param[in,out] accum Accumulated tensor. Data type supported: S16.
129 */
130 void configure(const ITensor *input, uint32_t shift, ITensor *accum);
131
132 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +0100133 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100134
135private:
136 uint32_t _shift;
137};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100138} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000139#endif /*ARM_COMPUTE_NEACCUMULATEKERNEL_H */