blob: 1554a896722584696f67d5c7f7a58ceeb07ced80 [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Stephen Lie855c232018-01-04 14:13:22 +08002 * Copyright (c) 2017-2018 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"
36
37using namespace arm_compute;
38
39GCCol2ImKernel::GCCol2ImKernel()
40 : _input(nullptr), _output(nullptr), _convolved_dims()
41{
42}
43
44void GCCol2ImKernel::configure(const IGCTensor *input, IGCTensor *output,
45 std::pair<unsigned int, unsigned int> convolved_dims)
46{
Stephen Lie855c232018-01-04 14:13:22 +080047 ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32);
48 ARM_COMPUTE_ERROR_ON_NULLPTR(output);
49
50 TensorShape output_shape = input->info()->tensor_shape();
51 output_shape.set(0, convolved_dims.first);
52 output_shape.set(1, convolved_dims.second);
53 output_shape.set(2, input->info()->tensor_shape()[0]);
54
55 // Output auto inizialitation if not yet initialized
56 auto_init_if_empty(*output->info(), input->info()->clone()->set_tensor_shape(output_shape));
57
58 ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(output->info()->tensor_shape(), output_shape);
Anthony Barbier7068f992017-10-26 15:23:08 +010059 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
60
Anthony Barbier7068f992017-10-26 15:23:08 +010061 _input = input;
62 _output = output;
63 _convolved_dims = convolved_dims;
64
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010065 const DataType dt = input->info()->data_type();
66 const unsigned int local_size = 1;
Stephen Lie855c232018-01-04 14:13:22 +080067
Anthony Barbier7068f992017-10-26 15:23:08 +010068 // Create kernel
Stephen Lie855c232018-01-04 14:13:22 +080069 std::set<std::string> build_opts;
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010070 build_opts.emplace("#define COL2IM ");
Stephen Lie855c232018-01-04 14:13:22 +080071 build_opts.emplace("#define WIDTH_OUTPUT " + support::cpp11::to_string(_convolved_dims.first));
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010072 const std::string dt_name = (dt == DataType::F32) ? "DATA_TYPE_FP32" : "DATA_TYPE_FP16";
Stephen Lie855c232018-01-04 14:13:22 +080073 build_opts.emplace(("#define " + dt_name));
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010074 build_opts.emplace("#define LOCAL_SIZE_X " + support::cpp11::to_string(local_size));
75 build_opts.emplace("#define LOCAL_SIZE_Y " + support::cpp11::to_string(local_size));
76 build_opts.emplace("#define LOCAL_SIZE_Z " + support::cpp11::to_string(local_size));
Stephen Lie855c232018-01-04 14:13:22 +080077
Anthony Barbier7068f992017-10-26 15:23:08 +010078 _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel("col2im", build_opts));
79
Anthony Barbier7068f992017-10-26 15:23:08 +010080 // Configure window
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010081 const unsigned int num_elems_processed_per_iteration = (dt == DataType::F32) ? 1 : 2;
Anthony Barbier7068f992017-10-26 15:23:08 +010082
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010083 Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration));
84
85 AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
Stephen Lie855c232018-01-04 14:13:22 +080086 const int input_padding = ceil_to_multiple(input->info()->dimension(0), 2) - input->info()->dimension(0);
87
88 AccessWindowStatic input_access(input->info(), 0, 0, input->info()->dimension(0) + input_padding, input->info()->dimension(1) + 1);
89
Michele Di Giorgiofc1d1e22018-04-10 14:24:35 +010090 update_window_and_padding(win, input_access, output_access);
Stephen Lie855c232018-01-04 14:13:22 +080091
92 output_access.set_valid_region(win, output->info()->valid_region());
Anthony Barbier7068f992017-10-26 15:23:08 +010093
Anthony Barbier7068f992017-10-26 15:23:08 +010094 IGCKernel::configure(win);
95}
96
97void GCCol2ImKernel::run(const Window &window)
98{
99 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
100 ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(IGCKernel::window(), window);
101
Anthony Barbier7068f992017-10-26 15:23:08 +0100102 _kernel.use();
103
Stephen Lie855c232018-01-04 14:13:22 +0800104 Window collapsed_window = window.collapse_if_possible(IGCKernel::window(), Window::DimZ);
105 Window slice = collapsed_window.first_slice_window_3D();
106
107 // Set static kernel arguments
108 unsigned int idx = 2 * num_arguments_per_3D_tensor();
109 //_kernel.set_argument(idx++, _output->info()->strides_in_bytes()[3]);
110 _kernel.set_argument(idx++, uint(_output->info()->dimension(2)));
111 _kernel.set_argument(idx++, _input->info()->strides_in_bytes()[2]);
112
Anthony Barbier7068f992017-10-26 15:23:08 +0100113 do
114 {
115 // Set inputs
Stephen Lie855c232018-01-04 14:13:22 +0800116 unsigned int idx = 0;
117 add_2D_tensor_argument(idx, _input, 1, slice);
118 add_3D_tensor_argument(idx, _output, 2, slice);
Anthony Barbier7068f992017-10-26 15:23:08 +0100119 _kernel.update_shader_params();
Stephen Lie855c232018-01-04 14:13:22 +0800120 enqueue(*this, slice);
Anthony Barbier7068f992017-10-26 15:23:08 +0100121 }
Stephen Lie855c232018-01-04 14:13:22 +0800122 while(collapsed_window.slide_window_slice_3D(slice));
Anthony Barbier7068f992017-10-26 15:23:08 +0100123}