Michalis Spyrou | 16934a5 | 2018-08-21 18:03:58 +0100 | [diff] [blame] | 1 | /* |
Manuel Bottini | 8481d83 | 2019-12-10 15:28:40 +0000 | [diff] [blame^] | 2 | * Copyright (c) 2018-2020 ARM Limited. |
Michalis Spyrou | 16934a5 | 2018-08-21 18:03:58 +0100 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_CLSPACETOBATCHLAYER_H |
| 25 | #define ARM_COMPUTE_CLSPACETOBATCHLAYER_H |
Michalis Spyrou | 16934a5 | 2018-08-21 18:03:58 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/runtime/IFunction.h" |
| 28 | |
Isabella Gottardi | cc6129c | 2018-12-14 11:40:40 +0000 | [diff] [blame] | 29 | #include "arm_compute/core/CL/kernels/CLMemsetKernel.h" |
Michalis Spyrou | 16934a5 | 2018-08-21 18:03:58 +0100 | [diff] [blame] | 30 | #include "arm_compute/core/CL/kernels/CLSpaceToBatchLayerKernel.h" |
| 31 | #include "arm_compute/core/Types.h" |
| 32 | #include "arm_compute/runtime/CL/CLTensor.h" |
| 33 | |
| 34 | namespace arm_compute |
| 35 | { |
| 36 | class ICLTensor; |
| 37 | |
Isabella Gottardi | cc6129c | 2018-12-14 11:40:40 +0000 | [diff] [blame] | 38 | /** Basic function to spatial divide a tensor. This function calls the following OpenCL kernels/functions: |
| 39 | * |
| 40 | * -# @ref CLMemsetKernel |
| 41 | * -# @ref CLSpaceToBatchLayerKernel |
| 42 | */ |
Michalis Spyrou | 16934a5 | 2018-08-21 18:03:58 +0100 | [diff] [blame] | 43 | class CLSpaceToBatchLayer : public IFunction |
| 44 | { |
| 45 | public: |
| 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 Bottini | 8481d83 | 2019-12-10 15:28:40 +0000 | [diff] [blame^] | 60 | * @param[in] input Tensor input. Supported tensor rank: 4. Data types supported: All. |
Michalis Spyrou | 16934a5 | 2018-08-21 18:03:58 +0100 | [diff] [blame] | 61 | * @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 Bottini | 8481d83 | 2019-12-10 15:28:40 +0000 | [diff] [blame^] | 68 | * @param[in] input Tensor input. Supported tensor rank: 4. Data types supported: All. |
Michalis Spyrou | 16934a5 | 2018-08-21 18:03:58 +0100 | [diff] [blame] | 69 | * @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 Bottini | 8481d83 | 2019-12-10 15:28:40 +0000 | [diff] [blame^] | 78 | * @param[in] input Tensor input info. Supported tensor rank: 4. Data types supported: All. |
Michalis Spyrou | 16934a5 | 2018-08-21 18:03:58 +0100 | [diff] [blame] | 79 | * @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 Bottini | 8481d83 | 2019-12-10 15:28:40 +0000 | [diff] [blame^] | 88 | * @param[in] input Tensor input info. Supported tensor rank: 4. Data types supported: All. |
Michalis Spyrou | 16934a5 | 2018-08-21 18:03:58 +0100 | [diff] [blame] | 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 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 | |
| 102 | private: |
| 103 | CLSpaceToBatchLayerKernel _space_to_batch_kernel; /**< SpaceToBatch kernel to run */ |
Isabella Gottardi | cc6129c | 2018-12-14 11:40:40 +0000 | [diff] [blame] | 104 | CLMemsetKernel _memset_kernel; /**< Memset kernel to run */ |
Michalis Spyrou | 16934a5 | 2018-08-21 18:03:58 +0100 | [diff] [blame] | 105 | bool _has_padding; /**< Flag to check if the output has padding */ |
| 106 | }; |
| 107 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 108 | #endif /* ARM_COMPUTE_CLSPACETOBATCHLAYER_H */ |