blob: c6f7f11079c2a7cffd52e44c6cea3210a4efcc4a [file] [log] [blame]
Michalis Spyrou16934a52018-08-21 18:03:58 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2018-2020 Arm Limited.
Michalis Spyrou16934a52018-08-21 18:03:58 +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_CLSPACETOBATCHLAYER_H
25#define ARM_COMPUTE_CLSPACETOBATCHLAYER_H
Michalis Spyrou16934a52018-08-21 18:03:58 +010026
27#include "arm_compute/runtime/IFunction.h"
28
Isabella Gottardicc6129c2018-12-14 11:40:40 +000029#include "arm_compute/core/CL/kernels/CLMemsetKernel.h"
Michalis Spyrou16934a52018-08-21 18:03:58 +010030#include "arm_compute/core/CL/kernels/CLSpaceToBatchLayerKernel.h"
31#include "arm_compute/core/Types.h"
32#include "arm_compute/runtime/CL/CLTensor.h"
33
34namespace arm_compute
35{
36class ICLTensor;
37
Isabella Gottardicc6129c2018-12-14 11:40:40 +000038/** Basic function to spatial divide a tensor. This function calls the following OpenCL kernels/functions:
39 *
40 * -# @ref CLMemsetKernel
41 * -# @ref CLSpaceToBatchLayerKernel
42 */
Michalis Spyrou16934a52018-08-21 18:03:58 +010043class CLSpaceToBatchLayer : public IFunction
44{
45public:
46 /** Default constructor */
47 CLSpaceToBatchLayer();
48 /** Prevent instances of this class from being copied (As this class contains pointers) */
49 CLSpaceToBatchLayer(const CLSpaceToBatchLayer &) = delete;
50 /** Prevent instances of this class from being copied (As this class contains pointers) */
51 CLSpaceToBatchLayer &operator=(const CLSpaceToBatchLayer &) = delete;
52 /** Allow instances of this class to be moved */
53 CLSpaceToBatchLayer(CLSpaceToBatchLayer &&) = default;
54 /** Allow instances of this class to be moved */
55 CLSpaceToBatchLayer &operator=(CLSpaceToBatchLayer &&) = default;
56 /** Default destructor */
57 virtual ~CLSpaceToBatchLayer() = default;
58 /** Set the input and output tensors.
59 *
Manuel Bottini8481d832019-12-10 15:28:40 +000060 * @param[in] input Tensor input. Supported tensor rank: 4. Data types supported: All.
Michalis Spyrou16934a52018-08-21 18:03:58 +010061 * @param[in] block_shape 1-D tensor with shape [M]. Data types supported: S32
62 * @param[in] paddings 2-D tensor with shape [2, M]. Data types supported: S32
63 * @param[out] output Tensor output. Data types supported: same as @p input
64 */
65 void configure(const ICLTensor *input, const ICLTensor *block_shape, const ICLTensor *paddings, ICLTensor *output);
Manuel Bottini2b84be52020-04-08 10:15:51 +010066 /** Set the input and output tensors.
67 *
68 * @param[in] compile_context The compile context to be used.
69 * @param[in] input Tensor input. Supported tensor rank: 4. Data types supported: All.
70 * @param[in] block_shape 1-D tensor with shape [M]. Data types supported: S32
71 * @param[in] paddings 2-D tensor with shape [2, M]. Data types supported: S32
72 * @param[out] output Tensor output. Data types supported: same as @p input
73 */
74 void configure(const CLCompileContext &compile_context, const ICLTensor *input, const ICLTensor *block_shape, const ICLTensor *paddings, ICLTensor *output);
Michalis Spyrou16934a52018-08-21 18:03:58 +010075 /** Set the input and output tensors. (Static block shape and paddings)
76 *
Manuel Bottini8481d832019-12-10 15:28:40 +000077 * @param[in] input Tensor input. Supported tensor rank: 4. Data types supported: All.
Michalis Spyrou16934a52018-08-21 18:03:58 +010078 * @param[in] block_shape_x Block shape x value.
79 * @param[in] block_shape_y Block shape y value.
80 * @param[in] padding_left The left padding of the output tensor.
81 * @param[in] padding_right The right padding of the output tensor.
82 * @param[out] output Tensor output. Data types supported: same as @p input
83 */
84 void configure(const ICLTensor *input, const int block_shape_x, const int block_shape_y, const Size2D &padding_left, const Size2D &padding_right, ICLTensor *output);
Manuel Bottini2b84be52020-04-08 10:15:51 +010085 /** Set the input and output tensors. (Static block shape and paddings)
86 *
87 * @param[in] compile_context The compile context to be used.
88 * @param[in] input Tensor input. Supported tensor rank: 4. Data types supported: All.
89 * @param[in] block_shape_x Block shape x value.
90 * @param[in] block_shape_y Block shape y value.
91 * @param[in] padding_left The left padding of the output tensor.
92 * @param[in] padding_right The right padding of the output tensor.
93 * @param[out] output Tensor output. Data types supported: same as @p input
94 */
95 void configure(const CLCompileContext &compile_context, const ICLTensor *input, const int block_shape_x, const int block_shape_y, const Size2D &padding_left, const Size2D &padding_right,
96 ICLTensor *output);
Michalis Spyrou16934a52018-08-21 18:03:58 +010097 /** Static function to check if given info will lead to a valid configuration of @ref CLSpaceToBatchLayer
98 *
Manuel Bottini8481d832019-12-10 15:28:40 +000099 * @param[in] input Tensor input info. Supported tensor rank: 4. Data types supported: All.
Michalis Spyrou16934a52018-08-21 18:03:58 +0100100 * @param[in] block_shape block shape tensor info with shape [M]. Data types supported: S32
101 * @param[in] paddings paddings tensor info with shape [2, M]. Data types supported: S32
102 * @param[out] output Tensor output info. Data types supported: same as @p input
103 *
104 * @return a status
105 */
106 static Status validate(const ITensorInfo *input, const ITensorInfo *block_shape, const ITensorInfo *paddings, const ITensorInfo *output);
107 /** Static function to check if given info will lead to a valid configuration of @ref CLSpaceToBatchLayer (Static block shape and paddings)
108 *
Manuel Bottini8481d832019-12-10 15:28:40 +0000109 * @param[in] input Tensor input info. Supported tensor rank: 4. Data types supported: All.
Michalis Spyrou16934a52018-08-21 18:03:58 +0100110 * @param[in] block_shape_x Block shape x value.
111 * @param[in] block_shape_y Block shape y value.
112 * @param[in] padding_left The left padding of the output tensor.
113 * @param[in] padding_right The right padding of the output tensor.
114 * @param[out] output Tensor output info. Data types supported: same as @p input
115 *
116 * @return a status
117 */
118 static Status validate(const ITensorInfo *input, const int block_shape_x, const int block_shape_y, const Size2D &padding_left, const Size2D &padding_right, const ITensorInfo *output);
119
120 // Inherited methods overridden:
121 void run() override;
122
123private:
124 CLSpaceToBatchLayerKernel _space_to_batch_kernel; /**< SpaceToBatch kernel to run */
Isabella Gottardicc6129c2018-12-14 11:40:40 +0000125 CLMemsetKernel _memset_kernel; /**< Memset kernel to run */
Michalis Spyrou16934a52018-08-21 18:03:58 +0100126 bool _has_padding; /**< Flag to check if the output has padding */
127};
128} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000129#endif /* ARM_COMPUTE_CLSPACETOBATCHLAYER_H */