blob: 53a06b9ed9907d76a7edcc8435413fd659dc88c4 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NENORMALIZATIONLAYERKERNEL_H
25#define ARM_COMPUTE_NENORMALIZATIONLAYERKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
Michalis Spyrouebcebf12020-10-21 00:04:14 +010027#include "src/core/NEON/INEKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028
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;
Alex Gildayc357c472018-03-21 13:54:09 +000050 /** Default move assignment operator */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010051 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 Spyrou0c71d0b2018-11-22 11:22:18 +000057 * and an optional 4th dimension for batch of inputs. Data types supported: FP16/F32. Data layouts supported: NCHW/NHWC.
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],
Michalis Spyrou0c71d0b2018-11-22 11:22:18 +000059 * 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 Barbier6ff3b192017-09-04 18:44:23 +010061 * @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],
Michalis Spyrou0c71d0b2018-11-22 11:22:18 +000067 * and an optional 4th dimension for batch of inputs. Data types supported: FP16/F32. Data layouts supported: NCHW/NHWC.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000068 * @param[in] input_squared Source with each element has been squared. 3 lower dims represent a single input with dimensions [width, height, IFM],
Michalis Spyrou0c71d0b2018-11-22 11:22:18 +000069 * 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.
Michalis Spyrouafa5d812017-11-30 14:25:57 +000071 * @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
80private:
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 */
Michalis Spyrou0c71d0b2018-11-22 11:22:18 +000091 template <typename T, unsigned int S, unsigned int dim, bool do_2D_norm>
Pablo Tellodf246182017-07-03 16:25:09 +010092 void normalize_float(const Window &window);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010093
Anthony Barbier6ff3b192017-09-04 18:44:23 +010094 /** 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
100private:
101 NormalizationFunction _func;
102 const ITensor *_input;
103 const ITensor *_input_squared;
104 ITensor *_output;
105 NormalizationLayerInfo _norm_info;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100106};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100107} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000108#endif /*ARM_COMPUTE_NENORMALIZATIONLAYERKERNEL_H */