blob: 6292c07136fba377629e641f06e8a55104139299 [file] [log] [blame]
giuros01ba368252019-02-19 13:53:10 +00001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2019-2020 Arm Limited.
giuros01ba368252019-02-19 13:53:10 +00003 *
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_NESPACETOBATCHLAYERKERNEL_H
25#define ARM_COMPUTE_NESPACETOBATCHLAYERKERNEL_H
giuros01ba368252019-02-19 13:53:10 +000026
giuros01ba368252019-02-19 13:53:10 +000027#include "arm_compute/core/Types.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028
Michalis Spyrouebcebf12020-10-21 00:04:14 +010029#include "src/core/NEON/INEKernel.h"
giuros01ba368252019-02-19 13:53:10 +000030
31namespace arm_compute
32{
Georgios Pinitas33843562019-12-10 13:33:18 +000033// Forward declaration
giuros01ba368252019-02-19 13:53:10 +000034class ITensor;
35
36/** Interface for the space to batch kernel */
37class NESpaceToBatchLayerKernel : public INEKernel
38{
39public:
40 const char *name() const override
41 {
42 return "NESpaceToBatchLayerKernel";
43 }
44 /** Default constructor */
45 NESpaceToBatchLayerKernel();
46 /** Prevent instances of this class from being copied (As this class contains pointers) */
47 NESpaceToBatchLayerKernel(const NESpaceToBatchLayerKernel &) = delete;
48 /** Prevent instances of this class from being copied (As this class contains pointers) */
49 NESpaceToBatchLayerKernel &operator=(const NESpaceToBatchLayerKernel &) = delete;
50 /** Allow instances of this class to be moved */
51 NESpaceToBatchLayerKernel(NESpaceToBatchLayerKernel &&) = default;
52 /** Allow instances of this class to be moved */
53 NESpaceToBatchLayerKernel &operator=(NESpaceToBatchLayerKernel &&) = default;
54 /** Default destructor */
55 ~NESpaceToBatchLayerKernel() = default;
56 /** Initialise the kernel's inputs and output.
57 *
Georgios Pinitas33843562019-12-10 13:33:18 +000058 * @param[in] input Tensor input. Supported tensor rank: 4. Data types supported: All.
SiCong Li18bdfae2020-11-08 21:58:01 +000059 * @param[in] block_shape 1-D tensor with shape [M]. Supported M: 2. Data types supported: S32
60 * @param[in] paddings 2-D tensor with shape [2, M] (First dimension is the fastest-changing dimension). Supported M: 2. Data types supported: S32
giuros01ba368252019-02-19 13:53:10 +000061 * @param[out] output Tensor output. Data types supported: same as @p input
62 */
63 void configure(const ITensor *input, const ITensor *block_shape, const ITensor *paddings, ITensor *output);
64 /** Initialise the kernel's input and output. (Static block shape and paddings)
65 *
Georgios Pinitas33843562019-12-10 13:33:18 +000066 * @param[in] input Tensor input. Supported tensor rank: 4. Data types supported: All.
giuros01ba368252019-02-19 13:53:10 +000067 * @param[in] block_shape_x Block shape x value.
68 * @param[in] block_shape_y Block shape y value.
SiCong Li18bdfae2020-11-08 21:58:01 +000069 * @param[in] padding_left The padding at the beginning of every dimension of the output tensor.
70 * @param[in] padding_right The padding at the end of every dimension of the output tensor.
giuros01ba368252019-02-19 13:53:10 +000071 * @param[out] output Tensor output. Data types supported: same as @p input
72 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010073 void configure(const ITensor *input,
74 const int block_shape_x,
75 const int block_shape_y,
76 const Size2D &padding_left,
77 const Size2D &padding_right,
78 ITensor *output);
giuros01ba368252019-02-19 13:53:10 +000079 /** Static function to check if given info will lead to a valid configuration of @ref NESpaceToBatchLayerKernel
80 *
Georgios Pinitas33843562019-12-10 13:33:18 +000081 * @param[in] input Tensor input. Supported tensor rank: 4. Data types supported: All.
SiCong Li18bdfae2020-11-08 21:58:01 +000082 * @param[in] block_shape 1-D tensor with shape [M]. Supported M: 2. Data types supported: S32
83 * @param[in] paddings 2-D tensor with shape [2, M] (First dimension is the fastest-changing dimension). Supported M: 2. Data types supported: S32
giuros01ba368252019-02-19 13:53:10 +000084 * @param[in] output Tensor output. Data types supported: same as @p input
85 *
86 * @return a status
87 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010088 static Status validate(const ITensorInfo *input,
89 const ITensorInfo *block_shape,
90 const ITensorInfo *paddings,
91 const ITensorInfo *output);
giuros01ba368252019-02-19 13:53:10 +000092 /** Static function to check if given info will lead to a valid configuration of @ref NESpaceToBatchLayerKernel (Static block shape and paddings)
93 *
Georgios Pinitas33843562019-12-10 13:33:18 +000094 * @param[in] input Tensor input. Supported tensor rank: 4. Data types supported: All.
giuros01ba368252019-02-19 13:53:10 +000095 * @param[in] block_shape_x Block shape x value.
96 * @param[in] block_shape_y Block shape y value.
SiCong Li18bdfae2020-11-08 21:58:01 +000097 * @param[in] padding_left The padding at the beginning of every dimension of the output tensor.
98 * @param[in] padding_right The padding at the end of every dimension of the output tensor.
giuros01ba368252019-02-19 13:53:10 +000099 * @param[in] output Tensor output. Data types supported: same as @p input
100 *
101 * @return a status
102 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100103 static Status validate(const ITensorInfo *input,
104 const int block_shape_x,
105 const int block_shape_y,
106 const Size2D &padding_left,
107 const Size2D &padding_right,
108 const ITensorInfo *output);
giuros01ba368252019-02-19 13:53:10 +0000109
110 // Inherited methods overridden:
111 void run(const Window &window, const ThreadInfo &info) override;
112
113private:
114 const ITensor *_input; /**< Source tensor */
SiCong Li18bdfae2020-11-08 21:58:01 +0000115 const ITensor *_block_shape; /**< Block shape tensor for dynamic evaluation */
116 const ITensor *_paddings; /**< Paddings tensor for dynamic evaluation */
giuros01ba368252019-02-19 13:53:10 +0000117 ITensor *_output; /**< Destination tensor */
Sadik Armagan29658042020-05-11 10:35:08 +0100118 DataLayout _data_layout; /**< Data layout to be used at run-time */
giuros01ba368252019-02-19 13:53:10 +0000119
120 Size2D _padding_left;
121 int _block_shape_x;
122 int _block_shape_y;
123};
124} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000125#endif /* ARM_COMPUTE_NESPACETOBATCHLAYERKERNEL_H */