blob: 405daf1068eb023940fbff9bdceb46f200669b9d [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 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
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:
38 /** Default constructor */
39 NENormalizationLayerKernel();
40 /** Prevent instances of this class from being copied (As this class contains pointers) */
41 NENormalizationLayerKernel(const NENormalizationLayerKernel &) = delete;
42 /** Prevent instances of this class from being copied (As this class contains pointers) */
43 NENormalizationLayerKernel &operator=(const NENormalizationLayerKernel &) = delete;
44 /** Default Move Constructor. */
45 NENormalizationLayerKernel(NENormalizationLayerKernel &&) = default;
46 /** Default move assignment operator. */
47 NENormalizationLayerKernel &operator=(NENormalizationLayerKernel &&) = default;
48 /** Default destructor */
49 ~NENormalizationLayerKernel() = default;
50 /** Set the input and output tensors.
51 *
52 * @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 +010053 * and an optional 4th dimension for batch of inputs. Data types supported: QS8/QS16/FP16/F32.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010054 * @param[in] input_squared Source with each element has been squared. 3 lower dims represent a single input with dimensions [width, height, IFM],
55 * Data type supported: same as @p input
56 * @param[out] output Destination tensor. Output will have the same number of dimensions as input. Data type supported: same as @p input
57 * @param[in] norm_info Normalization layer information like the normalization type, normalization size and other parameters.
58 */
59 void configure(const ITensor *input, const ITensor *input_squared, ITensor *output, NormalizationLayerInfo norm_info);
Michalis Spyrouafa5d812017-11-30 14:25:57 +000060 /** Static function to check if given info will lead to a valid configuration of @ref NENormalizationLayerKernel
61 *
62 * @param[in] input Source tensor. 3 lower dims represent a single input with dimensions [width, height, IFM],
63 * and an optional 4th dimension for batch of inputs. Data types supported: QS8/QS16/FP16/F32.
64 * @param[in] input_squared Source with each element has been squared. 3 lower dims represent a single input with dimensions [width, height, IFM],
65 * Data type supported: same as @p input
66 * @param[in] output Destination tensor. Output will have the same number of dimensions as input. Data type supported: same as @p input
67 * @param[in] norm_info Normalization layer information like the normalization type, normalization size and other parameters.
68 *
69 * @return a status
70 */
71 static Status validate(const ITensorInfo *input, const ITensorInfo *input_squared, const ITensorInfo *output, NormalizationLayerInfo norm_info);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010072
73 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010074 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010075 BorderSize border_size() const override;
76
77private:
78 /** Function to perform normalization depending on the given template
79 * dimension. The second template parameter specifies whether the
80 * normalization has to be 1D or 2D.
81 *
82 * @note Only supported normalizations are:
83 * - 1D over X or Z
84 * - 2D over X and Y
85 *
86 * @param[in] window Region on which to execute the kernel.
87 */
Pablo Tellodf246182017-07-03 16:25:09 +010088 template <DataType dt, unsigned int dim, bool do_2D_norm>
89 void normalize_float(const Window &window);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010090
91 /** Function to perform normalization for fixed-point values depending on
92 * the given template dimension. The second template parameter specifies
93 * whether the normalization has to be 1D or 2D.
94 *
95 * @note Only supported normalizations are:
96 * - 1D over X or Z
97 * - 2D over X and Y
98 *
99 * @param[in] window Region on which to execute the kernel.
100 */
Michele Di Giorgiod5e65c72017-07-26 17:09:17 +0100101 template <DataType dt, unsigned int dim, bool do_2D_norm>
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100102 void normalize_fixed_point(const Window &window);
103 /** Common signature for all the specialised normalization functions
104 *
105 * @param[in] window Region on which to execute the kernel.
106 */
107 using NormalizationFunction = void (NENormalizationLayerKernel::*)(const Window &window);
108
109private:
110 NormalizationFunction _func;
111 const ITensor *_input;
112 const ITensor *_input_squared;
113 ITensor *_output;
114 NormalizationLayerInfo _norm_info;
115 BorderSize _border_size;
116};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100117} // namespace arm_compute
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100118#endif /*__ARM_COMPUTE_NENORMALIZATIONLAYERKERNEL_H__ */