Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2020 Arm Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEACCUMULATEKERNEL_H |
| 25 | #define ARM_COMPUTE_NEACCUMULATEKERNEL_H |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 26 | |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 27 | #include "src/core/NEON/INESimpleKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | |
| 29 | #include <cstdint> |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | class 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 | */ |
| 40 | class NEAccumulateKernel : public INESimpleKernel |
| 41 | { |
| 42 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 43 | const char *name() const override |
| 44 | { |
| 45 | return "NEAccumulateKernel"; |
| 46 | } |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 47 | /** 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 59 | /** 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 Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 67 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 68 | }; |
| 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 | */ |
| 79 | class NEAccumulateWeightedKernel : public INESimpleKernel |
| 80 | { |
| 81 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 82 | const char *name() const override |
| 83 | { |
| 84 | return "NEAccumulateWeightedKernel"; |
| 85 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 86 | /** Default constructor */ |
| 87 | NEAccumulateWeightedKernel(); |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 88 | /** 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 98 | /** 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 Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 107 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 108 | |
| 109 | protected: |
| 110 | float _alpha; |
| 111 | }; |
| 112 | |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 113 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 114 | /** Interface for the accumulate weighted kernel using F16 */ |
| 115 | class NEAccumulateWeightedFP16Kernel : public NEAccumulateWeightedKernel |
| 116 | { |
| 117 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 118 | const char *name() const override |
| 119 | { |
| 120 | return "NEAccumulateWeightedFP16Kernel"; |
| 121 | } |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 122 | /** 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 134 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 135 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 136 | }; |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 137 | #else /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 138 | /** Interface for the accumulate weighted kernel using F16 */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 139 | using NEAccumulateWeightedFP16Kernel = NEAccumulateWeightedKernel; |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 140 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 141 | |
| 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 | */ |
| 149 | class NEAccumulateSquaredKernel : public INESimpleKernel |
| 150 | { |
| 151 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 152 | const char *name() const override |
| 153 | { |
| 154 | return "NEAccumulateSquaredKernel"; |
| 155 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 156 | /** Default constructor */ |
| 157 | NEAccumulateSquaredKernel(); |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 158 | /** 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 Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 168 | /** 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 Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 177 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 178 | |
| 179 | private: |
| 180 | uint32_t _shift; |
| 181 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 182 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 183 | #endif /*ARM_COMPUTE_NEACCUMULATEKERNEL_H */ |