blob: 00750ebe979ca9892b61833884594aa8ac5d7bf7 [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);
60
61 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010062 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010063 BorderSize border_size() const override;
64
65private:
66 /** Function to perform normalization depending on the given template
67 * dimension. The second template parameter specifies whether the
68 * normalization has to be 1D or 2D.
69 *
70 * @note Only supported normalizations are:
71 * - 1D over X or Z
72 * - 2D over X and Y
73 *
74 * @param[in] window Region on which to execute the kernel.
75 */
Pablo Tellodf246182017-07-03 16:25:09 +010076 template <DataType dt, unsigned int dim, bool do_2D_norm>
77 void normalize_float(const Window &window);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078
79 /** Function to perform normalization for fixed-point values depending on
80 * the given template dimension. The second template parameter specifies
81 * whether the normalization has to be 1D or 2D.
82 *
83 * @note Only supported normalizations are:
84 * - 1D over X or Z
85 * - 2D over X and Y
86 *
87 * @param[in] window Region on which to execute the kernel.
88 */
Michele Di Giorgiod5e65c72017-07-26 17:09:17 +010089 template <DataType dt, unsigned int dim, bool do_2D_norm>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010090 void normalize_fixed_point(const Window &window);
91 /** Common signature for all the specialised normalization functions
92 *
93 * @param[in] window Region on which to execute the kernel.
94 */
95 using NormalizationFunction = void (NENormalizationLayerKernel::*)(const Window &window);
96
97private:
98 NormalizationFunction _func;
99 const ITensor *_input;
100 const ITensor *_input_squared;
101 ITensor *_output;
102 NormalizationLayerInfo _norm_info;
103 BorderSize _border_size;
104};
105}
106#endif /*__ARM_COMPUTE_NENORMALIZATIONLAYERKERNEL_H__ */