Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-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_NENORMALIZATIONLAYERKERNEL_H |
| 25 | #define ARM_COMPUTE_NENORMALIZATIONLAYERKERNEL_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/INEKernel.h" |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | class ITensor; |
| 32 | |
| 33 | /** Interface for the normalization layer kernel. |
| 34 | */ |
| 35 | class NENormalizationLayerKernel : public INEKernel |
| 36 | { |
| 37 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 38 | const char *name() const override |
| 39 | { |
| 40 | return "NENormalizationLayerKernel"; |
| 41 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 42 | /** Default constructor */ |
| 43 | NENormalizationLayerKernel(); |
| 44 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 45 | NENormalizationLayerKernel(const NENormalizationLayerKernel &) = delete; |
| 46 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 47 | NENormalizationLayerKernel &operator=(const NENormalizationLayerKernel &) = delete; |
| 48 | /** Default Move Constructor. */ |
| 49 | NENormalizationLayerKernel(NENormalizationLayerKernel &&) = default; |
Alex Gilday | c357c47 | 2018-03-21 13:54:09 +0000 | [diff] [blame] | 50 | /** Default move assignment operator */ |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 51 | NENormalizationLayerKernel &operator=(NENormalizationLayerKernel &&) = default; |
| 52 | /** Default destructor */ |
| 53 | ~NENormalizationLayerKernel() = default; |
| 54 | /** Set the input and output tensors. |
| 55 | * |
| 56 | * @param[in] input Source tensor. 3 lower dims represent a single input with dimensions [width, height, IFM], |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 57 | * and an optional 4th dimension for batch of inputs. Data types supported: FP16/F32. Data layouts supported: NCHW/NHWC. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 58 | * @param[in] input_squared Source with each element has been squared. 3 lower dims represent a single input with dimensions [width, height, IFM], |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 59 | * Data type and layout supported: same as @p input. |
| 60 | * @param[out] output Destination tensor. Output will have the same number of dimensions as input. Data type and layout supported: same as @p input. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 61 | * @param[in] norm_info Normalization layer information like the normalization type, normalization size and other parameters. |
| 62 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 63 | void |
| 64 | configure(const ITensor *input, const ITensor *input_squared, ITensor *output, NormalizationLayerInfo norm_info); |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 65 | /** Static function to check if given info will lead to a valid configuration of @ref NENormalizationLayerKernel |
| 66 | * |
| 67 | * @param[in] input Source tensor. 3 lower dims represent a single input with dimensions [width, height, IFM], |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 68 | * and an optional 4th dimension for batch of inputs. Data types supported: FP16/F32. Data layouts supported: NCHW/NHWC. |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 69 | * @param[in] input_squared Source with each element has been squared. 3 lower dims represent a single input with dimensions [width, height, IFM], |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 70 | * Data type and layout supported: same as @p input. |
| 71 | * @param[in] output Destination tensor. Output will have the same number of dimensions as input. Data type and layout supported: same as @p input. |
Michalis Spyrou | afa5d81 | 2017-11-30 14:25:57 +0000 | [diff] [blame] | 72 | * @param[in] norm_info Normalization layer information like the normalization type, normalization size and other parameters. |
| 73 | * |
| 74 | * @return a status |
| 75 | */ |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 76 | static Status validate(const ITensorInfo *input, |
| 77 | const ITensorInfo *input_squared, |
| 78 | const ITensorInfo *output, |
| 79 | NormalizationLayerInfo norm_info); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 80 | |
| 81 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 82 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 83 | |
| 84 | private: |
| 85 | /** Function to perform normalization depending on the given template |
| 86 | * dimension. The second template parameter specifies whether the |
| 87 | * normalization has to be 1D or 2D. |
| 88 | * |
| 89 | * @note Only supported normalizations are: |
| 90 | * - 1D over X or Z |
| 91 | * - 2D over X and Y |
| 92 | * |
| 93 | * @param[in] window Region on which to execute the kernel. |
| 94 | */ |
Michalis Spyrou | 0c71d0b | 2018-11-22 11:22:18 +0000 | [diff] [blame] | 95 | template <typename T, unsigned int S, unsigned int dim, bool do_2D_norm> |
Pablo Tello | df24618 | 2017-07-03 16:25:09 +0100 | [diff] [blame] | 96 | void normalize_float(const Window &window); |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 97 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 98 | /** Common signature for all the specialised normalization functions |
| 99 | * |
| 100 | * @param[in] window Region on which to execute the kernel. |
| 101 | */ |
| 102 | using NormalizationFunction = void (NENormalizationLayerKernel::*)(const Window &window); |
| 103 | |
| 104 | private: |
| 105 | NormalizationFunction _func; |
| 106 | const ITensor *_input; |
| 107 | const ITensor *_input_squared; |
| 108 | ITensor *_output; |
| 109 | NormalizationLayerInfo _norm_info; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 110 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 111 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 112 | #endif /*ARM_COMPUTE_NENORMALIZATIONLAYERKERNEL_H */ |