Compute Library
 22.05
NENormalizationLayerKernel.h
Go to the documentation of this file.
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_NENORMALIZATIONLAYERKERNEL_H
25 #define ARM_COMPUTE_NENORMALIZATIONLAYERKERNEL_H
26 
28 
29 namespace arm_compute
30 {
31 class ITensor;
32 
33 /** Interface for the normalization layer kernel.
34  */
36 {
37 public:
38  const char *name() const override
39  {
40  return "NENormalizationLayerKernel";
41  }
42  /** Default constructor */
44  /** Prevent instances of this class from being copied (As this class contains pointers) */
46  /** Prevent instances of this class from being copied (As this class contains pointers) */
48  /** Default Move Constructor. */
50  /** Default move assignment operator */
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],
57  * and an optional 4th dimension for batch of inputs. Data types supported: FP16/F32. Data layouts supported: NCHW/NHWC.
58  * @param[in] input_squared Source with each element has been squared. 3 lower dims represent a single input with dimensions [width, height, IFM],
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.
61  * @param[in] norm_info Normalization layer information like the normalization type, normalization size and other parameters.
62  */
63  void configure(const ITensor *input, const ITensor *input_squared, ITensor *output, NormalizationLayerInfo norm_info);
64  /** Static function to check if given info will lead to a valid configuration of @ref NENormalizationLayerKernel
65  *
66  * @param[in] input Source tensor. 3 lower dims represent a single input with dimensions [width, height, IFM],
67  * and an optional 4th dimension for batch of inputs. Data types supported: FP16/F32. Data layouts supported: NCHW/NHWC.
68  * @param[in] input_squared Source with each element has been squared. 3 lower dims represent a single input with dimensions [width, height, IFM],
69  * Data type and layout supported: same as @p input.
70  * @param[in] output Destination tensor. Output will have the same number of dimensions as input. Data type and layout supported: same as @p input.
71  * @param[in] norm_info Normalization layer information like the normalization type, normalization size and other parameters.
72  *
73  * @return a status
74  */
75  static Status validate(const ITensorInfo *input, const ITensorInfo *input_squared, const ITensorInfo *output, NormalizationLayerInfo norm_info);
76 
77  // Inherited methods overridden:
78  void run(const Window &window, const ThreadInfo &info) override;
79 
80 private:
81  /** Function to perform normalization depending on the given template
82  * dimension. The second template parameter specifies whether the
83  * normalization has to be 1D or 2D.
84  *
85  * @note Only supported normalizations are:
86  * - 1D over X or Z
87  * - 2D over X and Y
88  *
89  * @param[in] window Region on which to execute the kernel.
90  */
91  template <typename T, unsigned int S, unsigned int dim, bool do_2D_norm>
92  void normalize_float(const Window &window);
93 
94  /** Common signature for all the specialised normalization functions
95  *
96  * @param[in] window Region on which to execute the kernel.
97  */
98  using NormalizationFunction = void (NENormalizationLayerKernel::*)(const Window &window);
99 
100 private:
101  NormalizationFunction _func;
102  const ITensor *_input;
103  const ITensor *_input_squared;
104  ITensor *_output;
105  NormalizationLayerInfo _norm_info;
106 };
107 } // namespace arm_compute
108 #endif /*ARM_COMPUTE_NENORMALIZATIONLAYERKERNEL_H */
static Status validate(const ITensorInfo *input, const ITensorInfo *input_squared, const ITensorInfo *output, NormalizationLayerInfo norm_info)
Static function to check if given info will lead to a valid configuration of NENormalizationLayerKern...
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
~NENormalizationLayerKernel()=default
Default destructor.
Common interface for all kernels implemented in C++.
Definition: ICPPKernel.h:38
Normalization Layer Information class.
Definition: Types.h:1726
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
Interface for CPU tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2022 Arm Limited.
const char * name() const override
Name of the kernel.
Interface for the normalization layer kernel.
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
Information about executing thread and CPU.
Definition: CPPTypes.h:169
NENormalizationLayerKernel & operator=(const NENormalizationLayerKernel &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
void configure(const ITensor *input, const ITensor *input_squared, ITensor *output, NormalizationLayerInfo norm_info)
Set the input and output tensors.
Describe a multidimensional execution window.
Definition: Window.h:39