blob: 4fe6484cf8f3795530b5b891ace6995e959c2ca2 [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Anthony Barbier7068f992017-10-26 15:23:08 +01003 *
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/core/GLES_COMPUTE/kernels/GCCol2ImKernel.h"
26
Stephen Lie855c232018-01-04 14:13:22 +080027#include "arm_compute/core/AccessWindowStatic.h"
Anthony Barbier7068f992017-10-26 15:23:08 +010028#include "arm_compute/core/Error.h"
29#include "arm_compute/core/GLES_COMPUTE/GCHelpers.h"
30#include "arm_compute/core/GLES_COMPUTE/GCKernelLibrary.h"
31#include "arm_compute/core/GLES_COMPUTE/IGCTensor.h"
32#include "arm_compute/core/GLES_COMPUTE/OpenGLES.h"
33#include "arm_compute/core/Helpers.h"
34#include "arm_compute/core/Types.h"
35#include "arm_compute/core/Validate.h"
Matthew Bentham758b5ba2020-03-05 23:37:48 +000036#include "support/StringSupport.h"
Anthony Barbier7068f992017-10-26 15:23:08 +010037
38using namespace arm_compute;
39
40GCCol2ImKernel::GCCol2ImKernel()
41 : _input(nullptr), _output(nullptr), _convolved_dims()
42{
43}
44
Matthew Bentham758b5ba2020-03-05 23:37:48 +000045void GCCol2ImKernel::configure(const IGCTensor *input, IGCTensor *output,
Anthony Barbier7068f992017-10-26 15:23:08 +010046 std::pair<unsigned int, unsigned int> convolved_dims)
47{
Stephen Lie855c232018-01-04 14:13:22 +080048 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
49 ARM_COMPUTE_ERROR_ON_NULLPTR(output);
50
51 TensorShape output_shape = input->info()->tensor_shape();
52 output_shape.set(0, convolved_dims.first);
53 output_shape.set(1, convolved_dims.second);
54 output_shape.set(2, input->info()->tensor_shape()[0]);
55
56 // Output auto inizialitation if not yet initialized
57 auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape));
58
59 ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape);
Anthony Barbier7068f992017-10-26 15:23:08 +010060 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
61
Anthony Barbier7068f992017-10-26 15:23:08 +010062 _input = input;
63 _output = output;
64 _convolved_dims = convolved_dims;
65
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010066 const DataType dt = input->info()->data_type();
67 const unsigned int local_size = 1;
Stephen Lie855c232018-01-04 14:13:22 +080068
Anthony Barbier7068f992017-10-26 15:23:08 +010069 // Create kernel
Stephen Lie855c232018-01-04 14:13:22 +080070 std::set<std::string> build_opts;
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010071 build_opts.emplace("#define COL2IM ");
Stephen Lie855c232018-01-04 14:13:22 +080072 build_opts.emplace("#define WIDTH_OUTPUT " + support::cpp11::to_string(_convolved_dims.first));
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010073 const std::string dt_name = (dt == DataType::F32) ? "DATA_TYPE_FP32" : "DATA_TYPE_FP16";
Stephen Lie855c232018-01-04 14:13:22 +080074 build_opts.emplace(("#define " + dt_name));
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010075 build_opts.emplace("#define LOCAL_SIZE_X " + support::cpp11::to_string(local_size));
76 build_opts.emplace("#define LOCAL_SIZE_Y " + support::cpp11::to_string(local_size));
77 build_opts.emplace("#define LOCAL_SIZE_Z " + support::cpp11::to_string(local_size));
Stephen Lie855c232018-01-04 14:13:22 +080078
Anthony Barbier7068f992017-10-26 15:23:08 +010079 _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel("col2im", build_opts));
80
Anthony Barbier7068f992017-10-26 15:23:08 +010081 // Configure window
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010082 const unsigned int num_elems_processed_per_iteration = (dt == DataType::F32) ? 1 : 2;
Anthony Barbier7068f992017-10-26 15:23:08 +010083
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010084 Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
85
86 AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
Stephen Lie855c232018-01-04 14:13:22 +080087 const int input_padding = ceil_to_multiple(input->info()->dimension(0), 2) - input->info()->dimension(0);
88
89 AccessWindowStatic input_access(input->info(), 0, 0, input->info()->dimension(0) + input_padding, input->info()->dimension(1) + 1);
90
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010091 update_window_and_padding(win, input_access, output_access);
Stephen Lie855c232018-01-04 14:13:22 +080092
93 output_access.set_valid_region(win, output->info()->valid_region());
Anthony Barbier7068f992017-10-26 15:23:08 +010094
Anthony Barbier7068f992017-10-26 15:23:08 +010095 IGCKernel::configure(win);
96}
97
98void GCCol2ImKernel::run(const Window &window)
99{
100 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
101 ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(IGCKernel::window(), window);
102
Anthony Barbier7068f992017-10-26 15:23:08 +0100103 _kernel.use();
104
Stephen Lie855c232018-01-04 14:13:22 +0800105 Window collapsed_window = window.collapse_if_possible(IGCKernel::window(), Window::DimZ);
106 Window slice = collapsed_window.first_slice_window_3D();
107
108 // Set static kernel arguments
109 unsigned int idx = 2 * num_arguments_per_3D_tensor();
110 //_kernel.set_argument(idx++, _output->info()->strides_in_bytes()[3]);
111 _kernel.set_argument(idx++, uint(_output->info()->dimension(2)));
112 _kernel.set_argument(idx++, _input->info()->strides_in_bytes()[2]);
113
Anthony Barbier7068f992017-10-26 15:23:08 +0100114 do
115 {
116 // Set inputs
Stephen Lie855c232018-01-04 14:13:22 +0800117 unsigned int idx = 0;
118 add_2D_tensor_argument(idx, _input, 1, slice);
119 add_3D_tensor_argument(idx, _output, 2, slice);
Anthony Barbier7068f992017-10-26 15:23:08 +0100120 _kernel.update_shader_params();
Stephen Lie855c232018-01-04 14:13:22 +0800121 enqueue(*this, slice);
Anthony Barbier7068f992017-10-26 15:23:08 +0100122 }
Stephen Lie855c232018-01-04 14:13:22 +0800123 while(collapsed_window.slide_window_slice_3D(slice));
Anthony Barbier7068f992017-10-26 15:23:08 +0100124}