blob: 5781c564eaf8adbce41bb9de4ee2596301cb15e2 [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
27#include "arm_compute/core/Error.h"
28#include "arm_compute/core/GLES_COMPUTE/GCHelpers.h"
29#include "arm_compute/core/GLES_COMPUTE/GCKernelLibrary.h"
30#include "arm_compute/core/GLES_COMPUTE/IGCTensor.h"
31#include "arm_compute/core/GLES_COMPUTE/OpenGLES.h"
32#include "arm_compute/core/Helpers.h"
33#include "arm_compute/core/Types.h"
34#include "arm_compute/core/Validate.h"
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010035#include "src/core/AccessWindowStatic.h"
36#include "src/core/helpers/AutoConfiguration.h"
37#include "src/core/helpers/WindowHelpers.h"
Matthew Bentham758b5ba2020-03-05 23:37:48 +000038#include "support/StringSupport.h"
Anthony Barbier7068f992017-10-26 15:23:08 +010039
40using namespace arm_compute;
41
42GCCol2ImKernel::GCCol2ImKernel()
43 : _input(nullptr), _output(nullptr), _convolved_dims()
44{
45}
46
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010047void GCCol2ImKernel::configure(const IGCTensor *input, IGCTensor *output,
Anthony Barbier7068f992017-10-26 15:23:08 +010048 std::pair<unsigned int, unsigned int> convolved_dims)
49{
Stephen Lie855c232018-01-04 14:13:22 +080050 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
51 ARM_COMPUTE_ERROR_ON_NULLPTR(output);
52
53 TensorShape output_shape = input->info()->tensor_shape();
54 output_shape.set(0, convolved_dims.first);
55 output_shape.set(1, convolved_dims.second);
56 output_shape.set(2, input->info()->tensor_shape()[0]);
57
58 // Output auto inizialitation if not yet initialized
59 auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape));
60
61 ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape);
Anthony Barbier7068f992017-10-26 15:23:08 +010062 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
63
Anthony Barbier7068f992017-10-26 15:23:08 +010064 _input = input;
65 _output = output;
66 _convolved_dims = convolved_dims;
67
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010068 const DataType dt = input->info()->data_type();
69 const unsigned int local_size = 1;
Stephen Lie855c232018-01-04 14:13:22 +080070
Anthony Barbier7068f992017-10-26 15:23:08 +010071 // Create kernel
Stephen Lie855c232018-01-04 14:13:22 +080072 std::set<std::string> build_opts;
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010073 build_opts.emplace("#define COL2IM ");
Stephen Lie855c232018-01-04 14:13:22 +080074 build_opts.emplace("#define WIDTH_OUTPUT " + support::cpp11::to_string(_convolved_dims.first));
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010075 const std::string dt_name = (dt == DataType::F32) ? "DATA_TYPE_FP32" : "DATA_TYPE_FP16";
Stephen Lie855c232018-01-04 14:13:22 +080076 build_opts.emplace(("#define " + dt_name));
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010077 build_opts.emplace("#define LOCAL_SIZE_X " + support::cpp11::to_string(local_size));
78 build_opts.emplace("#define LOCAL_SIZE_Y " + support::cpp11::to_string(local_size));
79 build_opts.emplace("#define LOCAL_SIZE_Z " + support::cpp11::to_string(local_size));
Stephen Lie855c232018-01-04 14:13:22 +080080
Anthony Barbier7068f992017-10-26 15:23:08 +010081 _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel("col2im", build_opts));
82
Anthony Barbier7068f992017-10-26 15:23:08 +010083 // Configure window
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010084 const unsigned int num_elems_processed_per_iteration = (dt == DataType::F32) ? 1 : 2;
Anthony Barbier7068f992017-10-26 15:23:08 +010085
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010086 Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
87
88 AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
Stephen Lie855c232018-01-04 14:13:22 +080089 const int input_padding = ceil_to_multiple(input->info()->dimension(0), 2) - input->info()->dimension(0);
90
91 AccessWindowStatic input_access(input->info(), 0, 0, input->info()->dimension(0) + input_padding, input->info()->dimension(1) + 1);
92
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010093 update_window_and_padding(win, input_access, output_access);
Stephen Lie855c232018-01-04 14:13:22 +080094
95 output_access.set_valid_region(win, output->info()->valid_region());
Anthony Barbier7068f992017-10-26 15:23:08 +010096
Anthony Barbier7068f992017-10-26 15:23:08 +010097 IGCKernel::configure(win);
98}
99
100void GCCol2ImKernel::run(const Window &window)
101{
102 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
103 ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(IGCKernel::window(), window);
104
Anthony Barbier7068f992017-10-26 15:23:08 +0100105 _kernel.use();
106
Stephen Lie855c232018-01-04 14:13:22 +0800107 Window collapsed_window = window.collapse_if_possible(IGCKernel::window(), Window::DimZ);
108 Window slice = collapsed_window.first_slice_window_3D();
109
110 // Set static kernel arguments
111 unsigned int idx = 2 * num_arguments_per_3D_tensor();
112 //_kernel.set_argument(idx++, _output->info()->strides_in_bytes()[3]);
113 _kernel.set_argument(idx++, uint(_output->info()->dimension(2)));
114 _kernel.set_argument(idx++, _input->info()->strides_in_bytes()[2]);
115
Anthony Barbier7068f992017-10-26 15:23:08 +0100116 do
117 {
118 // Set inputs
Stephen Lie855c232018-01-04 14:13:22 +0800119 unsigned int idx = 0;
120 add_2D_tensor_argument(idx, _input, 1, slice);
121 add_3D_tensor_argument(idx, _output, 2, slice);
Anthony Barbier7068f992017-10-26 15:23:08 +0100122 _kernel.update_shader_params();
Stephen Lie855c232018-01-04 14:13:22 +0800123 enqueue(*this, slice);
Anthony Barbier7068f992017-10-26 15:23:08 +0100124 }
Stephen Lie855c232018-01-04 14:13:22 +0800125 while(collapsed_window.slide_window_slice_3D(slice));
Anthony Barbier7068f992017-10-26 15:23:08 +0100126}