Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 1 | /* |
SiCong Li | 4ceb453 | 2023-03-13 15:02:23 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2021, 2023 Arm Limited. |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +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 | */ |
| 24 | |
| 25 | #include "arm_compute/runtime/CL/functions/CLBatchToSpaceLayer.h" |
| 26 | |
| 27 | #include "arm_compute/core/Error.h" |
| 28 | #include "arm_compute/core/TensorInfo.h" |
| 29 | #include "arm_compute/core/Types.h" |
| 30 | #include "arm_compute/core/Validate.h" |
| 31 | #include "arm_compute/runtime/CL/CLScheduler.h" |
| 32 | |
ramelg01 | 6d89157 | 2021-09-29 10:05:09 +0100 | [diff] [blame] | 33 | #include "src/common/utils/Log.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 34 | #include "src/core/CL/kernels/CLBatchToSpaceLayerKernel.h" |
ramelg01 | 6d89157 | 2021-09-29 10:05:09 +0100 | [diff] [blame] | 35 | |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 36 | namespace arm_compute |
| 37 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 38 | CLBatchToSpaceLayer::CLBatchToSpaceLayer() : _batch_to_space_kernel(std::make_unique<CLBatchToSpaceLayerKernel>()) |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 39 | { |
| 40 | } |
| 41 | |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 42 | CLBatchToSpaceLayer::~CLBatchToSpaceLayer() = default; |
| 43 | |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 44 | void CLBatchToSpaceLayer::configure(const ICLTensor *input, const ICLTensor *block_shape, ICLTensor *output) |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 45 | { |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 46 | ARM_COMPUTE_LOG_PARAMS(input, block_shape, output); |
| 47 | _batch_to_space_kernel->configure(CLKernelLibrary::get().get_compile_context(), input, block_shape, output); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 48 | } |
| 49 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 50 | void CLBatchToSpaceLayer::configure(const CLCompileContext &compile_context, |
| 51 | const ICLTensor *input, |
| 52 | const ICLTensor *block_shape, |
| 53 | ICLTensor *output) |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 54 | { |
ramelg01 | 6d89157 | 2021-09-29 10:05:09 +0100 | [diff] [blame] | 55 | ARM_COMPUTE_LOG_PARAMS(input, block_shape, output); |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 56 | _batch_to_space_kernel->configure(compile_context, input, block_shape, output); |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 59 | void CLBatchToSpaceLayer::configure( |
| 60 | const ICLTensor *input, int32_t block_shape_x, int32_t block_shape_y, ICLTensor *output, const CropInfo &crop_info) |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 61 | { |
SiCong Li | 4ceb453 | 2023-03-13 15:02:23 +0000 | [diff] [blame] | 62 | configure(CLKernelLibrary::get().get_compile_context(), input, block_shape_x, block_shape_y, output, crop_info); |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 63 | } |
| 64 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 65 | void CLBatchToSpaceLayer::configure(const CLCompileContext &compile_context, |
| 66 | const ICLTensor *input, |
| 67 | int32_t block_shape_x, |
| 68 | int32_t block_shape_y, |
| 69 | ICLTensor *output, |
| 70 | const CropInfo &crop_info) |
Manuel Bottini | 2b84be5 | 2020-04-08 10:15:51 +0100 | [diff] [blame] | 71 | { |
ramelg01 | 6d89157 | 2021-09-29 10:05:09 +0100 | [diff] [blame] | 72 | ARM_COMPUTE_LOG_PARAMS(input, block_shape_x, block_shape_y, output); |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 73 | _batch_to_space_kernel->configure(compile_context, input, block_shape_x, block_shape_y, output, crop_info); |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 76 | Status |
| 77 | CLBatchToSpaceLayer::validate(const ITensorInfo *input, const ITensorInfo *block_shape, const ITensorInfo *output) |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 78 | { |
| 79 | return CLBatchToSpaceLayerKernel::validate(input, block_shape, output); |
| 80 | } |
| 81 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 82 | Status CLBatchToSpaceLayer::validate(const ITensorInfo *input, |
| 83 | int32_t block_shape_x, |
| 84 | int32_t block_shape_y, |
| 85 | const ITensorInfo *output, |
| 86 | const CropInfo &crop_info) |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 87 | { |
Omar Al Khatib | fff9a4c | 2023-03-28 11:14:29 +0100 | [diff] [blame] | 88 | return CLBatchToSpaceLayerKernel::validate(input, block_shape_x, block_shape_y, output, crop_info); |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | void CLBatchToSpaceLayer::run() |
| 92 | { |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 93 | CLScheduler::get().enqueue(*_batch_to_space_kernel, true); |
Michalis Spyrou | 6a8d3b6 | 2018-08-31 10:07:09 +0100 | [diff] [blame] | 94 | } |
Sang-Hoon Park | bef7fa2 | 2020-10-21 15:58:54 +0100 | [diff] [blame] | 95 | } // namespace arm_compute |