1 /* 2 * Copyright (c) 2017-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_CLL2NORMALIZELAYERKERNEL_H 25 #define ARM_COMPUTE_CLL2NORMALIZELAYERKERNEL_H 26 27 #include "arm_compute/core/Types.h" 28 #include "src/core/CL/ICLKernel.h" 29 30 namespace arm_compute 31 { 32 class ICLTensor; 33 34 /** Interface for performing a L2 normalize on a given axis given the square sum of it in this axis */ 35 class CLL2NormalizeLayerKernel : public ICLKernel 36 { 37 public: 38 /** Default constructor */ 39 CLL2NormalizeLayerKernel(); 40 /** Prevent instances of this class from being copied (As this class contains pointers) */ 41 CLL2NormalizeLayerKernel(const CLL2NormalizeLayerKernel &) = delete; 42 /** Prevent instances of this class from being copied (As this class contains pointers) */ 43 CLL2NormalizeLayerKernel &operator=(const CLL2NormalizeLayerKernel &) = delete; 44 /** Allow instances of this class to be moved */ 45 CLL2NormalizeLayerKernel(CLL2NormalizeLayerKernel &&) = default; 46 /** Allow instances of this class to be moved */ 47 CLL2NormalizeLayerKernel &operator=(CLL2NormalizeLayerKernel &&) = default; 48 /** Default destructor */ 49 ~CLL2NormalizeLayerKernel() = default; 50 51 /** Set the input and output tensors. 52 * 53 * @param[in] input Source tensor. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC. 54 * @param[in] sum Sum values tensor. Data types supported: same as @p input. 55 * Sum will have the same number of dimensions as input. 56 * @param[out] output Destination tensor. Data types and data layouts supported: Same as @p input. 57 * Output will have the same number of dimensions as input. 58 * @param[in] axis Axis along which to reduce. Negative values wrap around. Maximum supported actual reduction axis : 2 59 * @param[in] epsilon Lower bound value for the normalization. 60 */ 61 void configure(const ICLTensor *input, const ICLTensor *sum, ICLTensor *output, int axis, float epsilon); 62 /** Set the input and output tensors. 63 * 64 * @param[in] compile_context The compile context to be used. 65 * @param[in] input Source tensor. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC. 66 * @param[in] sum Sum values tensor. Data types supported: same as @p input. 67 * Sum will have the same number of dimensions as input. 68 * @param[out] output Destination tensor. Data types and data layouts supported: Same as @p input. 69 * Output will have the same number of dimensions as input. 70 * @param[in] axis Axis along which to reduce. Negative values wrap around. Maximum supported actual reduction axis : 2 71 * @param[in] epsilon Lower bound value for the normalization. 72 */ 73 void configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *sum, ICLTensor *output, int axis, float epsilon); 74 75 /** Static function to check if given info will lead to a valid configuration of @ref CLL2NormalizeLayerKernel. 76 * 77 * @param[in] input Source tensor info. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC. 78 * @param[in] sum Sum values tensor info. Data types supported: same as @p input. 79 * Sum will have the same number of dimensions as input. 80 * @param[in] output Destination tensor info. Data types and data layouts supported: Same as @p input. 81 * Output will have the same number of dimensions as input. 82 * @param[in] axis Axis along which to reduce. Negative values wrap around. Maximum supported actual reduction axis : 2 83 * @param[in] epsilon Lower bound value for the normalization. 84 * 85 * @return a status 86 */ 87 static Status validate(const ITensorInfo *input, const ITensorInfo *sum, const ITensorInfo *output, int axis, float epsilon); 88 89 // Inherited methods overridden: 90 void run(const Window &window, cl::CommandQueue &queue) override; 91 92 private: 93 const ICLTensor *_input; 94 const ICLTensor *_sum; 95 ICLTensor *_output; 96 unsigned int _actual_axis; 97 float _epsilon; 98 }; 99 } // namespace arm_compute 100 #endif /*ARM_COMPUTE_CLL2NORMALIZELAYERKERNEL_H */ 101