blob: 6478774701a2db24d83d4f116f116b19ceb2b617 [file] [log] [blame]
Michalis Spyrou16934a52018-08-21 18:03:58 +01001/*
2 * Copyright (c) 2018 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_CLSPACETOBATCHLAYER_H__
25#define __ARM_COMPUTE_CLSPACETOBATCHLAYER_H__
26
27#include "arm_compute/runtime/IFunction.h"
28
29#include "arm_compute/core/CL/kernels/CLSpaceToBatchLayerKernel.h"
30#include "arm_compute/core/Types.h"
31#include "arm_compute/runtime/CL/CLTensor.h"
32
33namespace arm_compute
34{
35class ICLTensor;
36
37/** Basic function to run @ref CLSpaceToBatchLayerKernel. */
38class CLSpaceToBatchLayer : public IFunction
39{
40public:
41 /** Default constructor */
42 CLSpaceToBatchLayer();
43 /** Prevent instances of this class from being copied (As this class contains pointers) */
44 CLSpaceToBatchLayer(const CLSpaceToBatchLayer &) = delete;
45 /** Prevent instances of this class from being copied (As this class contains pointers) */
46 CLSpaceToBatchLayer &operator=(const CLSpaceToBatchLayer &) = delete;
47 /** Allow instances of this class to be moved */
48 CLSpaceToBatchLayer(CLSpaceToBatchLayer &&) = default;
49 /** Allow instances of this class to be moved */
50 CLSpaceToBatchLayer &operator=(CLSpaceToBatchLayer &&) = default;
51 /** Default destructor */
52 virtual ~CLSpaceToBatchLayer() = default;
53 /** Set the input and output tensors.
54 *
55 * @param[in] input Tensor input. Supported tensor rank: 4. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
56 * @param[in] block_shape 1-D tensor with shape [M]. Data types supported: S32
57 * @param[in] paddings 2-D tensor with shape [2, M]. Data types supported: S32
58 * @param[out] output Tensor output. Data types supported: same as @p input
59 */
60 void configure(const ICLTensor *input, const ICLTensor *block_shape, const ICLTensor *paddings, ICLTensor *output);
61 /** Set the input and output tensors. (Static block shape and paddings)
62 *
63 * @param[in] input Tensor input. Supported tensor rank: 4. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
64 * @param[in] block_shape_x Block shape x value.
65 * @param[in] block_shape_y Block shape y value.
66 * @param[in] padding_left The left padding of the output tensor.
67 * @param[in] padding_right The right padding of the output tensor.
68 * @param[out] output Tensor output. Data types supported: same as @p input
69 */
70 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);
71 /** Static function to check if given info will lead to a valid configuration of @ref CLSpaceToBatchLayer
72 *
73 * @param[in] input Tensor input info. Supported tensor rank: 4. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
74 * @param[in] block_shape block shape tensor info with shape [M]. Data types supported: S32
75 * @param[in] paddings paddings tensor info with shape [2, M]. Data types supported: S32
76 * @param[out] output Tensor output info. Data types supported: same as @p input
77 *
78 * @return a status
79 */
80 static Status validate(const ITensorInfo *input, const ITensorInfo *block_shape, const ITensorInfo *paddings, const ITensorInfo *output);
81 /** Static function to check if given info will lead to a valid configuration of @ref CLSpaceToBatchLayer (Static block shape and paddings)
82 *
83 * @param[in] input Tensor input info. Supported tensor rank: 4. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32.
84 * @param[in] block_shape_x Block shape x value.
85 * @param[in] block_shape_y Block shape y value.
86 * @param[in] padding_left The left padding of the output tensor.
87 * @param[in] padding_right The right padding of the output tensor.
88 * @param[out] output Tensor output info. Data types supported: same as @p input
89 *
90 * @return a status
91 */
92 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);
93
94 // Inherited methods overridden:
95 void run() override;
96
97private:
98 CLSpaceToBatchLayerKernel _space_to_batch_kernel; /**< SpaceToBatch kernel to run */
99 ICLTensor *_output; /**< Output tensor */
100 bool _has_padding; /**< Flag to check if the output has padding */
101};
102} // namespace arm_compute
103#endif /* __ARM_COMPUTE_CLSPACETOBATCHLAYER_H__ */