blob: ef9f1641121708e38df064283e54b80e0ae1e06f [file] [log] [blame]
Michalis Spyrou16934a52018-08-21 18:03:58 +01001/*
Manuel Bottini8481d832019-12-10 15:28:40 +00002 * 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);
66 /** Set the input and output tensors. (Static block shape and paddings)
67 *
Manuel Bottini8481d832019-12-10 15:28:40 +000068 * @param[in] input Tensor input. Supported tensor rank: 4. Data types supported: All.
Michalis Spyrou16934a52018-08-21 18:03:58 +010069 * @param[in] block_shape_x Block shape x value.
70 * @param[in] block_shape_y Block shape y value.
71 * @param[in] padding_left The left padding of the output tensor.
72 * @param[in] padding_right The right padding of the output tensor.
73 * @param[out] output Tensor output. Data types supported: same as @p input
74 */
75 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);
76 /** Static function to check if given info will lead to a valid configuration of @ref CLSpaceToBatchLayer
77 *
Manuel Bottini8481d832019-12-10 15:28:40 +000078 * @param[in] input Tensor input info. Supported tensor rank: 4. Data types supported: All.
Michalis Spyrou16934a52018-08-21 18:03:58 +010079 * @param[in] block_shape block shape tensor info with shape [M]. Data types supported: S32
80 * @param[in] paddings paddings tensor info with shape [2, M]. Data types supported: S32
81 * @param[out] output Tensor output info. Data types supported: same as @p input
82 *
83 * @return a status
84 */
85 static Status validate(const ITensorInfo *input, const ITensorInfo *block_shape, const ITensorInfo *paddings, const ITensorInfo *output);
86 /** Static function to check if given info will lead to a valid configuration of @ref CLSpaceToBatchLayer (Static block shape and paddings)
87 *
Manuel Bottini8481d832019-12-10 15:28:40 +000088 * @param[in] input Tensor input info. Supported tensor rank: 4. Data types supported: All.
Michalis Spyrou16934a52018-08-21 18:03:58 +010089 * @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 info. Data types supported: same as @p input
94 *
95 * @return a status
96 */
97 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);
98
99 // Inherited methods overridden:
100 void run() override;
101
102private:
103 CLSpaceToBatchLayerKernel _space_to_batch_kernel; /**< SpaceToBatch kernel to run */
Isabella Gottardicc6129c2018-12-14 11:40:40 +0000104 CLMemsetKernel _memset_kernel; /**< Memset kernel to run */
Michalis Spyrou16934a52018-08-21 18:03:58 +0100105 bool _has_padding; /**< Flag to check if the output has padding */
106};
107} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000108#endif /* ARM_COMPUTE_CLSPACETOBATCHLAYER_H */