Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 Arm Limited. |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +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_CLL2NORMALIZELAYERKERNEL_H |
| 25 | #define ARM_COMPUTE_CLL2NORMALIZELAYERKERNEL_H |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 26 | |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 27 | #include "arm_compute/core/Types.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 28 | |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 29 | #include "src/core/CL/ICLKernel.h" |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | class ICLTensor; |
| 34 | |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 35 | /** Interface for performing a L2 normalize on a given axis given the square sum of it in this axis */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 36 | class CLL2NormalizeLayerKernel : public ICLKernel |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 37 | { |
| 38 | public: |
| 39 | /** Default constructor */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 40 | CLL2NormalizeLayerKernel(); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 41 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 42 | CLL2NormalizeLayerKernel(const CLL2NormalizeLayerKernel &) = delete; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 43 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 44 | CLL2NormalizeLayerKernel &operator=(const CLL2NormalizeLayerKernel &) = delete; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 45 | /** Allow instances of this class to be moved */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 46 | CLL2NormalizeLayerKernel(CLL2NormalizeLayerKernel &&) = default; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 47 | /** Allow instances of this class to be moved */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 48 | CLL2NormalizeLayerKernel &operator=(CLL2NormalizeLayerKernel &&) = default; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 49 | /** Default destructor */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 50 | ~CLL2NormalizeLayerKernel() = default; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 51 | |
| 52 | /** Set the input and output tensors. |
| 53 | * |
Michalis Spyrou | 5538d34 | 2018-11-14 08:10:13 +0000 | [diff] [blame] | 54 | * @param[in] input Source tensor. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC. |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 55 | * @param[in] sum Sum values tensor. Data types supported: same as @p input. |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 56 | * Sum will have the same number of dimensions as input. |
| 57 | * @param[out] output Destination tensor. Data types and data layouts supported: Same as @p input. |
| 58 | * Output will have the same number of dimensions as input. |
Manuel Bottini | 4b5c588 | 2019-05-14 10:38:30 +0100 | [diff] [blame] | 59 | * @param[in] axis Axis along which to reduce. Negative values wrap around. Maximum supported actual reduction axis : 2 |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 60 | * @param[in] epsilon Lower bound value for the normalization. |
| 61 | */ |
Manuel Bottini | 4b5c588 | 2019-05-14 10:38:30 +0100 | [diff] [blame] | 62 | void configure(const ICLTensor *input, const ICLTensor *sum, ICLTensor *output, int axis, float epsilon); |
Manuel Bottini | 4c6bd51 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 63 | /** Set the input and output tensors. |
| 64 | * |
| 65 | * @param[in] compile_context The compile context to be used. |
| 66 | * @param[in] input Source tensor. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC. |
| 67 | * @param[in] sum Sum values tensor. Data types supported: same as @p input. |
| 68 | * Sum will have the same number of dimensions as input. |
| 69 | * @param[out] output Destination tensor. Data types and data layouts supported: Same as @p input. |
| 70 | * Output will have the same number of dimensions as input. |
| 71 | * @param[in] axis Axis along which to reduce. Negative values wrap around. Maximum supported actual reduction axis : 2 |
| 72 | * @param[in] epsilon Lower bound value for the normalization. |
| 73 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 74 | void configure(const CLCompileContext &compile_context, |
| 75 | const ICLTensor *input, |
| 76 | const ICLTensor *sum, |
| 77 | ICLTensor *output, |
| 78 | int axis, |
| 79 | float epsilon); |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 80 | |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 81 | /** Static function to check if given info will lead to a valid configuration of @ref CLL2NormalizeLayerKernel. |
| 82 | * |
Michalis Spyrou | 5538d34 | 2018-11-14 08:10:13 +0000 | [diff] [blame] | 83 | * @param[in] input Source tensor info. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC. |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 84 | * @param[in] sum Sum values tensor info. Data types supported: same as @p input. |
| 85 | * Sum will have the same number of dimensions as input. |
| 86 | * @param[in] output Destination tensor info. Data types and data layouts supported: Same as @p input. |
| 87 | * Output will have the same number of dimensions as input. |
Manuel Bottini | 4b5c588 | 2019-05-14 10:38:30 +0100 | [diff] [blame] | 88 | * @param[in] axis Axis along which to reduce. Negative values wrap around. Maximum supported actual reduction axis : 2 |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 89 | * @param[in] epsilon Lower bound value for the normalization. |
| 90 | * |
| 91 | * @return a status |
| 92 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 93 | static Status |
| 94 | validate(const ITensorInfo *input, const ITensorInfo *sum, const ITensorInfo *output, int axis, float epsilon); |
John Richardson | 62385bc | 2018-04-20 13:11:36 +0100 | [diff] [blame] | 95 | |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 96 | // Inherited methods overridden: |
| 97 | void run(const Window &window, cl::CommandQueue &queue) override; |
| 98 | |
| 99 | private: |
| 100 | const ICLTensor *_input; |
| 101 | const ICLTensor *_sum; |
| 102 | ICLTensor *_output; |
Manuel Bottini | 4b5c588 | 2019-05-14 10:38:30 +0100 | [diff] [blame] | 103 | unsigned int _actual_axis; |
Michalis Spyrou | 04f089c | 2017-08-08 17:42:38 +0100 | [diff] [blame] | 104 | float _epsilon; |
| 105 | }; |
Gian Marco Iodice | f670a0a | 2017-09-18 12:20:45 +0100 | [diff] [blame] | 106 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 107 | #endif /*ARM_COMPUTE_CLL2NORMALIZELAYERKERNEL_H */ |