summaryrefslogtreecommitdiff
path: root/libs/ARMComputeEx/arm_compute/core/NEON/kernels/NENormalizationLayerExKernel.h
blob: f7bf729853a2c929c8d2803770b9474aaa75d23a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved
 * Copyright (c) 2016-2018 ARM Limited.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef __ARM_COMPUTE_NENORMALIZATIONLAYEREXKERNEL_H__
#define __ARM_COMPUTE_NENORMALIZATIONLAYEREXKERNEL_H__

#include "arm_compute/core/NEON/INEKernel.h"

namespace arm_compute
{
class ITensor;

/** Interface for the normalization layer kernel.
 */
class NENormalizationLayerExKernel : public INEKernel
{
public:
  const char *name() const override { return "NENormalizationLayerKernel"; }
  /** Default constructor */
  NENormalizationLayerExKernel();
  /** Prevent instances of this class from being copied (As this class contains pointers) */
  NENormalizationLayerExKernel(const NENormalizationLayerExKernel &) = delete;
  /** Prevent instances of this class from being copied (As this class contains pointers) */
  NENormalizationLayerExKernel &operator=(const NENormalizationLayerExKernel &) = delete;
  /** Default Move Constructor. */
  NENormalizationLayerExKernel(NENormalizationLayerExKernel &&) = default;
  /** Default move assignment operator */
  NENormalizationLayerExKernel &operator=(NENormalizationLayerExKernel &&) = default;
  /** Default destructor */
  ~NENormalizationLayerExKernel() = default;
  /** Set the input and output tensors.
   *
   * @param[in]  input         Source tensor. 3 lower dims represent a single input with dimensions
   * [width, height, IFM],
   *                           and an optional 4th dimension for batch of inputs. Data types
   * supported: FP16/F32.
   * @param[in]  input_squared Source with each element has been squared. 3 lower dims represent a
   * single input with dimensions [width, height, IFM],
   *                           Data type supported: same as @p input
   * @param[out] output        Destination tensor. Output will have the same number of dimensions as
   * input. Data type supported: same as @p input
   * @param[in]  norm_info     Normalization layer information like the normalization type,
   * normalization size and other parameters.
   */
  void configure(const ITensor *input, const ITensor *input_squared, ITensor *output,
                 NormalizationLayerInfo norm_info);
  /** Static function to check if given info will lead to a valid configuration of @ref
   * NENormalizationLayerKernel
   *
   * @param[in] input         Source tensor. 3 lower dims represent a single input with dimensions
   * [width, height, IFM],
   *                          and an optional 4th dimension for batch of inputs. Data types
   * supported: FP16/F32.
   * @param[in] input_squared Source with each element has been squared. 3 lower dims represent a
   * single input with dimensions [width, height, IFM],
   *                          Data type supported: same as @p input
   * @param[in] output        Destination tensor. Output will have the same number of dimensions as
   * input. Data type supported: same as @p input
   * @param[in] norm_info     Normalization layer information like the normalization type,
   * normalization size and other parameters.
   *
   * @return a status
   */
  static Status validate(const ITensorInfo *input, const ITensorInfo *input_squared,
                         const ITensorInfo *output, NormalizationLayerInfo norm_info);

  // Inherited methods overridden:
  void run(const Window &window, const ThreadInfo &info) override;
  BorderSize border_size() const override;

private:
  /** Function to perform normalization depending on the given template
   *  dimension. The second template parameter specifies whether the
   *  normalization has to be 1D or 2D.
   *
   * @note Only supported normalizations are:
   *  - 1D over X or Z
   *  - 2D over X and Y
   *
   * @param[in] window Region on which to execute the kernel.
   */
  template <DataType dt, unsigned int dim, bool do_2D_norm>
  void normalize_float(const Window &window);

  /** Common signature for all the specialised normalization functions
   *
   * @param[in] window Region on which to execute the kernel.
   */
  using NormalizationFunctionEx = void (NENormalizationLayerExKernel::*)(const Window &window);

private:
  NormalizationFunctionEx _func;
  const ITensor *_input;
  const ITensor *_input_squared;
  ITensor *_output;
  NormalizationLayerInfo _norm_info;
  BorderSize _border_size;
};
} // namespace arm_compute
#endif /*__ARM_COMPUTE_NENORMALIZATIONLAYEREXKERNEL_H__ */