1 /* 2 * Copyright (c) 2016-2020 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_CLACCUMULATEKERNEL_H 25 #define ARM_COMPUTE_CLACCUMULATEKERNEL_H 26 27 #include "src/core/CL/ICLSimple2DKernel.h" 28 29 #include <cstdint> 30 31 namespace arm_compute 32 { 33 class ICLTensor; 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 CLAccumulateKernel : public ICLSimple2DKernel 41 { 42 public: 43 /** Set the input and accumulation tensors. 44 * 45 * @param[in] input Source tensor. Data types supported: U8. 46 * @param[out] accum Destination tensor. Data types supported: S16. 47 */ 48 void configure(const ICLTensor *input, ICLTensor *accum); 49 /** Set the input and accumulation tensors. 50 * 51 * @param[in] compile_context The compile context to be used. 52 * @param[in] input Source tensor. Data types supported: U8. 53 * @param[out] accum Destination tensor. Data types supported: S16. 54 */ 55 void configure(const CLCompileContext &compile_context, const ICLTensor *input, ICLTensor *accum); 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 CLAccumulateWeightedKernel : public ICLSimple2DKernel 68 { 69 public: 70 /** Set the input and accumulation images, and the scale value. 71 * 72 * @param[in] input Source tensor. Data types supported: U8. 73 * @param[in] alpha Scalar value in the range [0, 1.0]. Data types supported: F32. 74 * @param[in,out] accum Accumulated tensor. Data types supported: U8. 75 */ 76 void configure(const ICLTensor *input, float alpha, ICLTensor *accum); 77 /** Set the input and accumulation images, and the scale value. 78 * 79 * @param[in] compile_context The compile context to be used. 80 * @param[in] input Source tensor. Data types supported: U8. 81 * @param[in] alpha Scalar value in the range [0, 1.0]. Data types supported: F32. 82 * @param[in,out] accum Accumulated tensor. Data types supported: U8. 83 */ 84 void configure(const CLCompileContext &compile_context, const ICLTensor *input, float alpha, ICLTensor *accum); 85 }; 86 87 /** Interface for the accumulate squared kernel. 88 * 89 * The accumulation of squares is computed: 90 * @f[ accum(x,y) = saturate_{int16} ( (uint16) accum(x,y) + (((uint16)(input(x,y)^2)) >> (shift)) ) @f] 91 * 92 * Where @f$ 0 \le shift \le 15 @f$ 93 */ 94 class CLAccumulateSquaredKernel : public ICLSimple2DKernel 95 { 96 public: 97 /** Set the input and accumulation tensors and the shift value. 98 * 99 * @param[in] input Source tensor. Data types supported: U8. 100 * @param[in] shift Shift value in the range of [0, 15]. Data types supported: U32. 101 * @param[in,out] accum Accumulated tensor. Data types supported: S16. 102 */ 103 void configure(const ICLTensor *input, uint32_t shift, ICLTensor *accum); 104 /** Set the input and accumulation tensors and the shift value. 105 * 106 * @param[in] compile_context The compile context to be used. 107 * @param[in] input Source tensor. Data types supported: U8. 108 * @param[in] shift Shift value in the range of [0, 15]. Data types supported: U32. 109 * @param[in,out] accum Accumulated tensor. Data types supported: S16. 110 */ 111 void configure(const CLCompileContext &compile_context, const ICLTensor *input, uint32_t shift, ICLTensor *accum); 112 }; 113 } // namespace arm_compute 114 #endif /*ARM_COMPUTE_CLACCUMULATEKERNEL_H */ 115