blob: 556ebdd800db5e3050b092c648d9db1b32d5c2fb [file] [log] [blame]
giuros01ba368252019-02-19 13:53:10 +00001/*
Georgios Pinitas0f7ef8a2021-01-10 04:23:52 +00002 * Copyright (c) 2019-2021 Arm Limited.
giuros01ba368252019-02-19 13:53:10 +00003 *
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 Pinitas0f7ef8a2021-01-10 04:23:52 +000031#include "arm_compute/runtime/NEON/functions/NEFill.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010032#include "arm_compute/runtime/NEON/NEScheduler.h"
33
ramelg01cbbb0382021-09-17 17:36:57 +010034#include "src/common/utils/Log.h"
Michalis Spyrouebcebf12020-10-21 00:04:14 +010035#include "src/core/NEON/kernels/NESpaceToBatchLayerKernel.h"
giuros01ba368252019-02-19 13:53:10 +000036
37namespace arm_compute
38{
Michalis Spyrouebcebf12020-10-21 00:04:14 +010039NESpaceToBatchLayer::~NESpaceToBatchLayer() = default;
40
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010041NESpaceToBatchLayer::NESpaceToBatchLayer() : _space_to_batch_kernel(), _fill_f(), _has_padding(false)
giuros01ba368252019-02-19 13:53:10 +000042{
43}
44
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010045void NESpaceToBatchLayer::configure(const ITensor *input,
46 const ITensor *block_shape,
47 const ITensor *paddings,
48 ITensor *output)
giuros01ba368252019-02-19 13:53:10 +000049{
50 ARM_COMPUTE_ERROR_ON_NULLPTR(input, block_shape, paddings, output);
ramelg01cbbb0382021-09-17 17:36:57 +010051 ARM_COMPUTE_LOG_PARAMS(input, block_shape, paddings, output);
giuros01ba368252019-02-19 13:53:10 +000052
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010053 if (input->info()->tensor_shape().total_size() != output->info()->tensor_shape().total_size())
giuros01ba368252019-02-19 13:53:10 +000054 {
Georgios Pinitas0f7ef8a2021-01-10 04:23:52 +000055 _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()));
giuros01ba368252019-02-19 13:53:10 +000058 }
Georgios Pinitas40f51a62020-11-21 03:04:18 +000059 _space_to_batch_kernel = std::make_unique<NESpaceToBatchLayerKernel>();
Michalis Spyrouebcebf12020-10-21 00:04:14 +010060 _space_to_batch_kernel->configure(input, block_shape, paddings, output);
giuros01ba368252019-02-19 13:53:10 +000061}
62
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010063void 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)
giuros01ba368252019-02-19 13:53:10 +000069{
70 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
71
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010072 if (input->info()->tensor_shape().total_size() != output->info()->tensor_shape().total_size())
giuros01ba368252019-02-19 13:53:10 +000073 {
Georgios Pinitas0f7ef8a2021-01-10 04:23:52 +000074 _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()));
giuros01ba368252019-02-19 13:53:10 +000077 }
Georgios Pinitas40f51a62020-11-21 03:04:18 +000078 _space_to_batch_kernel = std::make_unique<NESpaceToBatchLayerKernel>();
Michalis Spyrouebcebf12020-10-21 00:04:14 +010079 _space_to_batch_kernel->configure(input, block_shape_x, block_shape_y, padding_left, padding_right, output);
giuros01ba368252019-02-19 13:53:10 +000080}
81
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010082Status NESpaceToBatchLayer::validate(const ITensorInfo *input,
83 const ITensorInfo *block_shape,
84 const ITensorInfo *paddings,
85 const ITensorInfo *output)
giuros01ba368252019-02-19 13:53:10 +000086{
87 ARM_COMPUTE_RETURN_ON_ERROR(NESpaceToBatchLayerKernel::validate(input, block_shape, paddings, output));
88
89 return Status{};
90}
91
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010092Status 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,
giuros01ba368252019-02-19 13:53:10 +000097 const ITensorInfo *output)
98{
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010099 ARM_COMPUTE_RETURN_ON_ERROR(
100 NESpaceToBatchLayerKernel::validate(input, block_shape_x, block_shape_y, padding_left, padding_right, output));
giuros01ba368252019-02-19 13:53:10 +0000101
102 return Status{};
103}
104
105void NESpaceToBatchLayer::run()
106{
107 // Zero out output only if we have paddings
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100108 if (_has_padding)
giuros01ba368252019-02-19 13:53:10 +0000109 {
Georgios Pinitas0f7ef8a2021-01-10 04:23:52 +0000110 _fill_f->run();
giuros01ba368252019-02-19 13:53:10 +0000111 }
Michalis Spyrouebcebf12020-10-21 00:04:14 +0100112 NEScheduler::get().schedule(_space_to_batch_kernel.get(), Window::DimY);
giuros01ba368252019-02-19 13:53:10 +0000113}
114} // namespace arm_compute