giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 1 | /* |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 2 | * Copyright (c) 2019-2021 Arm Limited. |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [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/NEON/functions/NESpaceToBatchLayer.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" |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 31 | #include "arm_compute/runtime/NEON/functions/NEFill.h" |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 32 | #include "arm_compute/runtime/NEON/NEScheduler.h" |
| 33 | |
ramelg01 | cbbb038 | 2021-09-17 17:36:57 +0100 | [diff] [blame] | 34 | #include "src/common/utils/Log.h" |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 35 | #include "src/core/NEON/kernels/NESpaceToBatchLayerKernel.h" |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 36 | |
| 37 | namespace arm_compute |
| 38 | { |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 39 | NESpaceToBatchLayer::~NESpaceToBatchLayer() = default; |
| 40 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 41 | NESpaceToBatchLayer::NESpaceToBatchLayer() : _space_to_batch_kernel(), _fill_f(), _has_padding(false) |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 42 | { |
| 43 | } |
| 44 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 45 | void NESpaceToBatchLayer::configure(const ITensor *input, |
| 46 | const ITensor *block_shape, |
| 47 | const ITensor *paddings, |
| 48 | ITensor *output) |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 49 | { |
| 50 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, block_shape, paddings, output); |
ramelg01 | cbbb038 | 2021-09-17 17:36:57 +0100 | [diff] [blame] | 51 | ARM_COMPUTE_LOG_PARAMS(input, block_shape, paddings, output); |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 52 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 53 | if (input->info()->tensor_shape().total_size() != output->info()->tensor_shape().total_size()) |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 54 | { |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 55 | _has_padding = true; |
| 56 | _fill_f = std::make_unique<NEFill>(); |
| 57 | _fill_f->configure(output, PixelValue(0, input->info()->data_type(), input->info()->quantization_info())); |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 58 | } |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 59 | _space_to_batch_kernel = std::make_unique<NESpaceToBatchLayerKernel>(); |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 60 | _space_to_batch_kernel->configure(input, block_shape, paddings, output); |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 63 | void NESpaceToBatchLayer::configure(const ITensor *input, |
| 64 | const int block_shape_x, |
| 65 | const int block_shape_y, |
| 66 | const Size2D &padding_left, |
| 67 | const Size2D &padding_right, |
| 68 | ITensor *output) |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 69 | { |
| 70 | ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); |
| 71 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 72 | if (input->info()->tensor_shape().total_size() != output->info()->tensor_shape().total_size()) |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 73 | { |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 74 | _has_padding = true; |
| 75 | _fill_f = std::make_unique<NEFill>(); |
| 76 | _fill_f->configure(output, PixelValue(0, input->info()->data_type(), input->info()->quantization_info())); |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 77 | } |
Georgios Pinitas | 40f51a6 | 2020-11-21 03:04:18 +0000 | [diff] [blame] | 78 | _space_to_batch_kernel = std::make_unique<NESpaceToBatchLayerKernel>(); |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 79 | _space_to_batch_kernel->configure(input, block_shape_x, block_shape_y, padding_left, padding_right, output); |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 80 | } |
| 81 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 82 | Status NESpaceToBatchLayer::validate(const ITensorInfo *input, |
| 83 | const ITensorInfo *block_shape, |
| 84 | const ITensorInfo *paddings, |
| 85 | const ITensorInfo *output) |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 86 | { |
| 87 | ARM_COMPUTE_RETURN_ON_ERROR(NESpaceToBatchLayerKernel::validate(input, block_shape, paddings, output)); |
| 88 | |
| 89 | return Status{}; |
| 90 | } |
| 91 | |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 92 | Status NESpaceToBatchLayer::validate(const ITensorInfo *input, |
| 93 | const int block_shape_x, |
| 94 | const int block_shape_y, |
| 95 | const Size2D &padding_left, |
| 96 | const Size2D &padding_right, |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 97 | const ITensorInfo *output) |
| 98 | { |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 99 | ARM_COMPUTE_RETURN_ON_ERROR( |
| 100 | NESpaceToBatchLayerKernel::validate(input, block_shape_x, block_shape_y, padding_left, padding_right, output)); |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 101 | |
| 102 | return Status{}; |
| 103 | } |
| 104 | |
| 105 | void NESpaceToBatchLayer::run() |
| 106 | { |
| 107 | // Zero out output only if we have paddings |
Felix Thomasmathibalan | afd38f0 | 2023-09-27 17:46:17 +0100 | [diff] [blame] | 108 | if (_has_padding) |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 109 | { |
Georgios Pinitas | 0f7ef8a | 2021-01-10 04:23:52 +0000 | [diff] [blame] | 110 | _fill_f->run(); |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 111 | } |
Michalis Spyrou | ebcebf1 | 2020-10-21 00:04:14 +0100 | [diff] [blame] | 112 | NEScheduler::get().schedule(_space_to_batch_kernel.get(), Window::DimY); |
giuros01 | ba36825 | 2019-02-19 13:53:10 +0000 | [diff] [blame] | 113 | } |
| 114 | } // namespace arm_compute |