Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 2 | * Copyright (c) 2016-2019 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 | |
| 27 | #include "arm_compute/core/NEON/INESimpleKernel.h" |
| 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 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 47 | /** 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 Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 55 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 56 | }; |
| 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 | */ |
| 67 | class NEAccumulateWeightedKernel : public INESimpleKernel |
| 68 | { |
| 69 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 70 | const char *name() const override |
| 71 | { |
| 72 | return "NEAccumulateWeightedKernel"; |
| 73 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 74 | /** 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 Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 85 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 86 | |
| 87 | protected: |
| 88 | float _alpha; |
| 89 | }; |
| 90 | |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 91 | #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 92 | /** Interface for the accumulate weighted kernel using F16 */ |
| 93 | class NEAccumulateWeightedFP16Kernel : public NEAccumulateWeightedKernel |
| 94 | { |
| 95 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 96 | const char *name() const override |
| 97 | { |
| 98 | return "NEAccumulateWeightedFP16Kernel"; |
| 99 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 100 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 101 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 102 | }; |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 103 | #else /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 104 | /** Interface for the accumulate weighted kernel using F16 */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 105 | using NEAccumulateWeightedFP16Kernel = NEAccumulateWeightedKernel; |
Ioan-Cristian Szabo | 5edbd1c | 2017-11-13 13:34:08 +0000 | [diff] [blame] | 106 | #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 107 | |
| 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 | */ |
| 115 | class NEAccumulateSquaredKernel : public INESimpleKernel |
| 116 | { |
| 117 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 118 | const char *name() const override |
| 119 | { |
| 120 | return "NEAccumulateSquaredKernel"; |
| 121 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 122 | /** 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 Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 133 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 134 | |
| 135 | private: |
| 136 | uint32_t _shift; |
| 137 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 138 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 139 | #endif /*ARM_COMPUTE_NEACCUMULATEKERNEL_H */ |