Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 1 | /* |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 3 | * |
| 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 Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 27 | #include "arm_compute/core/AccessWindowStatic.h" |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 28 | #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 | |
| 37 | using namespace arm_compute; |
| 38 | |
| 39 | GCCol2ImKernel::GCCol2ImKernel() |
| 40 | : _input(nullptr), _output(nullptr), _convolved_dims() |
| 41 | { |
| 42 | } |
| 43 | |
| 44 | void GCCol2ImKernel::configure(const IGCTensor *input, IGCTensor *output, |
| 45 | std::pair<unsigned int, unsigned int> convolved_dims) |
| 46 | { |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 47 | 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 Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 59 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
| 60 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 61 | _input = input; |
| 62 | _output = output; |
| 63 | _convolved_dims = convolved_dims; |
| 64 | |
Michele Di Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame^] | 65 | const DataType dt = input->info()->data_type(); |
| 66 | const unsigned int local_size = 1; |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 67 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 68 | // Create kernel |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 69 | std::set<std::string> build_opts; |
Michele Di Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame^] | 70 | build_opts.emplace("#define COL2IM "); |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 71 | build_opts.emplace("#define WIDTH_OUTPUT " + support::cpp11::to_string(_convolved_dims.first)); |
Michele Di Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame^] | 72 | const std::string dt_name = (dt == DataType::F32) ? "DATA_TYPE_FP32" : "DATA_TYPE_FP16"; |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 73 | build_opts.emplace(("#define " + dt_name)); |
Michele Di Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame^] | 74 | 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 Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 77 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 78 | _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel("col2im", build_opts)); |
| 79 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 80 | // Configure window |
Michele Di Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame^] | 81 | const unsigned int num_elems_processed_per_iteration = (dt == DataType::F32) ? 1 : 2; |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 82 | |
Michele Di Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame^] | 83 | 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 Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 86 | 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 Giorgio | fc1d1e2 | 2018-04-10 14:24:35 +0100 | [diff] [blame^] | 90 | update_window_and_padding(win, input_access, output_access); |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 91 | |
| 92 | output_access.set_valid_region(win, output->info()->valid_region()); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 93 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 94 | IGCKernel::configure(win); |
| 95 | } |
| 96 | |
| 97 | void 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 Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 102 | _kernel.use(); |
| 103 | |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 104 | 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 Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 113 | do |
| 114 | { |
| 115 | // Set inputs |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 116 | unsigned int idx = 0; |
| 117 | add_2D_tensor_argument(idx, _input, 1, slice); |
| 118 | add_3D_tensor_argument(idx, _output, 2, slice); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 119 | _kernel.update_shader_params(); |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 120 | enqueue(*this, slice); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 121 | } |
Stephen Li | e855c23 | 2018-01-04 14:13:22 +0800 | [diff] [blame] | 122 | while(collapsed_window.slide_window_slice_3D(slice)); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 123 | } |