blob: b835ca7c5343ff49e61a79ce13271d2855552151 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Anthony Barbiere8a49832018-01-18 10:04:05 +00002 * Copyright (c) 2017-2018 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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
27#include "arm_compute/core/NEON/INEKernel.h"
28
29namespace arm_compute
30{
31class ITensor;
32
33/** Interface for the normalization layer kernel.
34 */
35class NENormalizationLayerKernel : public INEKernel
36{
37public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000038 const char *name() const override
39 {
40 return "NENormalizationLayerKernel";
41 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010042 /** 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;
50 /** Default move assignment operator. */
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],
Michele Di Giorgiod5e65c72017-07-26 17:09:17 +010057 * and an optional 4th dimension for batch of inputs. Data types supported: QS8/QS16/FP16/F32.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010058 * @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 supported: same as @p input
60 * @param[out] output Destination tensor. Output will have the same number of dimensions as input. Data type 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);
Michalis Spyrouafa5d812017-11-30 14:25:57 +000064 /** 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: QS8/QS16/FP16/F32.
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 supported: same as @p input
70 * @param[in] output Destination tensor. Output will have the same number of dimensions as input. Data type 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);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010076
77 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010078 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010079 BorderSize border_size() const override;
80
81private:
82 /** Function to perform normalization depending on the given template
83 * dimension. The second template parameter specifies whether the
84 * normalization has to be 1D or 2D.
85 *
86 * @note Only supported normalizations are:
87 * - 1D over X or Z
88 * - 2D over X and Y
89 *
90 * @param[in] window Region on which to execute the kernel.
91 */
Pablo Tellodf246182017-07-03 16:25:09 +010092 template <DataType dt, unsigned int dim, bool do_2D_norm>
93 void normalize_float(const Window &window);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010094
95 /** Function to perform normalization for fixed-point values depending on
96 * the given template dimension. The second template parameter specifies
97 * whether the normalization has to be 1D or 2D.
98 *
99 * @note Only supported normalizations are:
100 * - 1D over X or Z
101 * - 2D over X and Y
102 *
103 * @param[in] window Region on which to execute the kernel.
104 */
Michele Di Giorgiod5e65c72017-07-26 17:09:17 +0100105 template <DataType dt, unsigned int dim, bool do_2D_norm>
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106 void normalize_fixed_point(const Window &window);
107 /** Common signature for all the specialised normalization functions
108 *
109 * @param[in] window Region on which to execute the kernel.
110 */
111 using NormalizationFunction = void (NENormalizationLayerKernel::*)(const Window &window);
112
113private:
114 NormalizationFunction _func;
115 const ITensor *_input;
116 const ITensor *_input_squared;
117 ITensor *_output;
118 NormalizationLayerInfo _norm_info;
119 BorderSize _border_size;
120};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100121} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100122#endif /*__ARM_COMPUTE_NENORMALIZATIONLAYERKERNEL_H__ */