blob: af1e34ef59123d35d046ccf2d5de515422d39b3f [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
Stephen Lie855c232018-01-04 14:13:22 +080065 unsigned int num_elems_processed_per_iteration = 1;
66
Anthony Barbier7068f992017-10-26 15:23:08 +010067 // Create kernel
Stephen Lie855c232018-01-04 14:13:22 +080068 std::set<std::string> build_opts;
69 build_opts.emplace("#define WIDTH_OUTPUT " + support::cpp11::to_string(_convolved_dims.first));
70 std::string dt_name = (input->info()->data_type() == DataType::F32) ? "DATA_TYPE_FP32" : "DATA_TYPE_FP16";
71 build_opts.emplace(("#define " + dt_name));
Anthony Barbier7068f992017-10-26 15:23:08 +010072 build_opts.emplace("#define LOCAL_SIZE_X " + support::cpp11::to_string(num_elems_processed_per_iteration));
73 build_opts.emplace("#define LOCAL_SIZE_Y " + support::cpp11::to_string(num_elems_processed_per_iteration));
Stephen Lie855c232018-01-04 14:13:22 +080074 build_opts.emplace("#define LOCAL_SIZE_Z " + support::cpp11::to_string(num_elems_processed_per_iteration));
75
Anthony Barbier7068f992017-10-26 15:23:08 +010076 _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel("col2im", build_opts));
77
Anthony Barbier7068f992017-10-26 15:23:08 +010078 // Configure window
Stephen Lie855c232018-01-04 14:13:22 +080079 unsigned int nums = 2;
80 Window win = calculate_max_window(*output->info(), Steps(nums));
Anthony Barbier7068f992017-10-26 15:23:08 +010081
Stephen Lie855c232018-01-04 14:13:22 +080082 AccessWindowHorizontal output_access(output->info(), 0, 2);
83 const int input_padding = ceil_to_multiple(input->info()->dimension(0), 2) - input->info()->dimension(0);
84
85 AccessWindowStatic input_access(input->info(), 0, 0, input->info()->dimension(0) + input_padding, input->info()->dimension(1) + 1);
86
87 update_window_and_padding(win, input_access,
88 output_access);
89
90 output_access.set_valid_region(win, output->info()->valid_region());
Anthony Barbier7068f992017-10-26 15:23:08 +010091
Anthony Barbier7068f992017-10-26 15:23:08 +010092 IGCKernel::configure(win);
93}
94
95void GCCol2ImKernel::run(const Window &window)
96{
97 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
98 ARM_COMPUTE_ERROR_ON_MISMATCHING_WINDOWS(IGCKernel::window(), window);
99
Anthony Barbier7068f992017-10-26 15:23:08 +0100100 _kernel.use();
101
Stephen Lie855c232018-01-04 14:13:22 +0800102 Window collapsed_window = window.collapse_if_possible(IGCKernel::window(), Window::DimZ);
103 Window slice = collapsed_window.first_slice_window_3D();
104
105 // Set static kernel arguments
106 unsigned int idx = 2 * num_arguments_per_3D_tensor();
107 //_kernel.set_argument(idx++, _output->info()->strides_in_bytes()[3]);
108 _kernel.set_argument(idx++, uint(_output->info()->dimension(2)));
109 _kernel.set_argument(idx++, _input->info()->strides_in_bytes()[2]);
110
Anthony Barbier7068f992017-10-26 15:23:08 +0100111 do
112 {
113 // Set inputs
Stephen Lie855c232018-01-04 14:13:22 +0800114 unsigned int idx = 0;
115 add_2D_tensor_argument(idx, _input, 1, slice);
116 add_3D_tensor_argument(idx, _output, 2, slice);
Anthony Barbier7068f992017-10-26 15:23:08 +0100117 _kernel.update_shader_params();
Stephen Lie855c232018-01-04 14:13:22 +0800118 enqueue(*this, slice);
Anthony Barbier7068f992017-10-26 15:23:08 +0100119 }
Stephen Lie855c232018-01-04 14:13:22 +0800120 while(collapsed_window.slide_window_slice_3D(slice));
Anthony Barbier7068f992017-10-26 15:23:08 +0100121}