blob: b6f1be199533aa0cff4f2e427d494a45ff60d236 [file] [log] [blame]
Michalis Spyrou04f089c2017-08-08 17:42:38 +01001/*
Manuel Bottini4b5c5882019-05-14 10:38:30 +01002 * Copyright (c) 2017-2019 ARM Limited.
Michalis Spyrou04f089c2017-08-08 17:42:38 +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_CLL2NORMALIZELAYERKERNEL_H
25#define ARM_COMPUTE_CLL2NORMALIZELAYERKERNEL_H
Michalis Spyrou04f089c2017-08-08 17:42:38 +010026
27#include "arm_compute/core/CL/ICLKernel.h"
28#include "arm_compute/core/Types.h"
29
30namespace arm_compute
31{
32class ICLTensor;
33
John Richardson62385bc2018-04-20 13:11:36 +010034/** Interface for performing a L2 normalize on a given axis given the square sum of it in this axis */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000035class CLL2NormalizeLayerKernel : public ICLKernel
Michalis Spyrou04f089c2017-08-08 17:42:38 +010036{
37public:
38 /** Default constructor */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000039 CLL2NormalizeLayerKernel();
Michalis Spyrou04f089c2017-08-08 17:42:38 +010040 /** Prevent instances of this class from being copied (As this class contains pointers) */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000041 CLL2NormalizeLayerKernel(const CLL2NormalizeLayerKernel &) = delete;
Michalis Spyrou04f089c2017-08-08 17:42:38 +010042 /** Prevent instances of this class from being copied (As this class contains pointers) */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000043 CLL2NormalizeLayerKernel &operator=(const CLL2NormalizeLayerKernel &) = delete;
Michalis Spyrou04f089c2017-08-08 17:42:38 +010044 /** Allow instances of this class to be moved */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000045 CLL2NormalizeLayerKernel(CLL2NormalizeLayerKernel &&) = default;
Michalis Spyrou04f089c2017-08-08 17:42:38 +010046 /** Allow instances of this class to be moved */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000047 CLL2NormalizeLayerKernel &operator=(CLL2NormalizeLayerKernel &&) = default;
Michalis Spyrou04f089c2017-08-08 17:42:38 +010048 /** Default destructor */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000049 ~CLL2NormalizeLayerKernel() = default;
Michalis Spyrou04f089c2017-08-08 17:42:38 +010050
51 /** Set the input and output tensors.
52 *
Michalis Spyrou5538d342018-11-14 08:10:13 +000053 * @param[in] input Source tensor. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC.
Michalis Spyrou04f089c2017-08-08 17:42:38 +010054 * @param[in] sum Sum values tensor. Data types supported: same as @p input.
John Richardson62385bc2018-04-20 13:11:36 +010055 * Sum will have the same number of dimensions as input.
56 * @param[out] output Destination tensor. Data types and data layouts supported: Same as @p input.
57 * Output will have the same number of dimensions as input.
Manuel Bottini4b5c5882019-05-14 10:38:30 +010058 * @param[in] axis Axis along which to reduce. Negative values wrap around. Maximum supported actual reduction axis : 2
Michalis Spyrou04f089c2017-08-08 17:42:38 +010059 * @param[in] epsilon Lower bound value for the normalization.
60 */
Manuel Bottini4b5c5882019-05-14 10:38:30 +010061 void configure(const ICLTensor *input, const ICLTensor *sum, ICLTensor *output, int axis, float epsilon);
Michalis Spyrou04f089c2017-08-08 17:42:38 +010062
John Richardson62385bc2018-04-20 13:11:36 +010063 /** Static function to check if given info will lead to a valid configuration of @ref CLL2NormalizeLayerKernel.
64 *
Michalis Spyrou5538d342018-11-14 08:10:13 +000065 * @param[in] input Source tensor info. Data types supported: F16/F32. Data layouts supported: NCHW/NHWC.
John Richardson62385bc2018-04-20 13:11:36 +010066 * @param[in] sum Sum values tensor info. Data types supported: same as @p input.
67 * Sum will have the same number of dimensions as input.
68 * @param[in] output Destination tensor info. Data types and data layouts supported: Same as @p input.
69 * Output will have the same number of dimensions as input.
Manuel Bottini4b5c5882019-05-14 10:38:30 +010070 * @param[in] axis Axis along which to reduce. Negative values wrap around. Maximum supported actual reduction axis : 2
John Richardson62385bc2018-04-20 13:11:36 +010071 * @param[in] epsilon Lower bound value for the normalization.
72 *
73 * @return a status
74 */
Manuel Bottini4b5c5882019-05-14 10:38:30 +010075 static Status validate(const ITensorInfo *input, const ITensorInfo *sum, const ITensorInfo *output, int axis, float epsilon);
John Richardson62385bc2018-04-20 13:11:36 +010076
Michalis Spyrou04f089c2017-08-08 17:42:38 +010077 // Inherited methods overridden:
78 void run(const Window &window, cl::CommandQueue &queue) override;
79
80private:
81 const ICLTensor *_input;
82 const ICLTensor *_sum;
83 ICLTensor *_output;
Manuel Bottini4b5c5882019-05-14 10:38:30 +010084 unsigned int _actual_axis;
Michalis Spyrou04f089c2017-08-08 17:42:38 +010085 float _epsilon;
86};
Gian Marco Iodicef670a0a2017-09-18 12:20:45 +010087} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +000088#endif /*ARM_COMPUTE_CLL2NORMALIZELAYERKERNEL_H */