Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 1 | /* |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame^] | 2 | * Copyright (c) 2017-2019 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 | */ |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 24 | #include "arm_compute/core/GLES_COMPUTE/kernels/GCDepthConcatenateLayerKernel.h" |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 25 | |
| 26 | #include "arm_compute/core/Error.h" |
| 27 | #include "arm_compute/core/GLES_COMPUTE/GCHelpers.h" |
| 28 | #include "arm_compute/core/GLES_COMPUTE/GCKernelLibrary.h" |
| 29 | #include "arm_compute/core/GLES_COMPUTE/IGCTensor.h" |
| 30 | #include "arm_compute/core/GLES_COMPUTE/OpenGLES.h" |
| 31 | #include "arm_compute/core/Helpers.h" |
| 32 | #include "arm_compute/core/Utils.h" |
| 33 | #include "arm_compute/core/Validate.h" |
| 34 | #include "arm_compute/core/Window.h" |
| 35 | |
| 36 | #include "support/ToolchainSupport.h" |
| 37 | |
| 38 | using namespace arm_compute; |
| 39 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 40 | GCDepthConcatenateLayerKernel::GCDepthConcatenateLayerKernel() |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame^] | 41 | : _input(nullptr), _output(nullptr), _depth_offset(0) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 42 | { |
| 43 | } |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 44 | void GCDepthConcatenateLayerKernel::configure(const IGCTensor *input, unsigned int depth_offset, IGCTensor *output) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 45 | { |
| 46 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32); |
| 47 | ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 48 | |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame^] | 49 | ARM_COMPUTE_ERROR_ON(input->info()->dimension(Window::DimX) != output->info()->dimension(Window::DimX)); |
| 50 | ARM_COMPUTE_ERROR_ON(input->info()->dimension(Window::DimY) != output->info()->dimension(Window::DimY)); |
| 51 | ARM_COMPUTE_ERROR_ON(input->info()->dimension(2) + depth_offset > output->info()->dimension(2)); |
| 52 | ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(3, input, output); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 53 | |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 54 | _input = input; |
| 55 | _output = output; |
| 56 | _depth_offset = depth_offset; |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 57 | |
| 58 | // Add build options |
| 59 | std::set<std::string> build_opts; |
| 60 | std::string dt_name = (input->info()->data_type() == DataType::F32) ? "DATA_TYPE_FP32" : "DATA_TYPE_FP16"; |
| 61 | build_opts.emplace(("#define " + dt_name)); |
| 62 | build_opts.emplace("#define LOCAL_SIZE_X " + support::cpp11::to_string(1)); |
| 63 | build_opts.emplace("#define LOCAL_SIZE_Y " + support::cpp11::to_string(1)); |
| 64 | build_opts.emplace("#define LOCAL_SIZE_Z " + support::cpp11::to_string(1)); |
| 65 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 66 | // Create kernel |
| 67 | _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel("concatenate_depth", build_opts)); |
| 68 | |
| 69 | unsigned int num_elems_processed_per_iteration = 1; |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame^] | 70 | if(input->info()->data_type() == DataType::F16) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 71 | { |
| 72 | num_elems_processed_per_iteration = 4; |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 73 | } |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 74 | |
| 75 | // The window needs to be based on input as we copy all the depths of input |
| 76 | Window win = calculate_max_window(*output->info(), Steps(num_elems_processed_per_iteration)); |
| 77 | win.set(Window::DimZ, Window::Dimension(0, input->info()->tensor_shape().z(), 1)); |
| 78 | |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame^] | 79 | AccessWindowHorizontal input_access(input->info(), 0, num_elems_processed_per_iteration); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 80 | AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration); |
| 81 | update_window_and_padding(win, input_access, output_access); |
Diego Lopez Recas | bcbc970 | 2017-12-18 11:28:27 +0000 | [diff] [blame] | 82 | output_access.set_valid_region(win, ValidRegion(Coordinates(), output->info()->tensor_shape())); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 83 | |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 84 | IGCKernel::configure(win); |
| 85 | } |
| 86 | |
Giorgio Arena | 04a8f8c | 2017-11-23 11:45:24 +0000 | [diff] [blame] | 87 | void GCDepthConcatenateLayerKernel::run(const Window &window) |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 88 | { |
| 89 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 90 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IGCKernel::window(), window); |
| 91 | |
| 92 | _kernel.use(); |
| 93 | |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 94 | _output->set_needs_shifting(true); |
| 95 | |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 96 | Window slice_in = window.first_slice_window_3D(); |
| 97 | Window slice_out = window.first_slice_window_3D(); |
| 98 | |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 99 | slice_out.set(Window::DimZ, Window::Dimension(_depth_offset)); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 100 | |
| 101 | do |
| 102 | { |
Joel Liang | abd03cf | 2018-01-08 15:20:48 +0800 | [diff] [blame] | 103 | unsigned int idx = 0; |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 104 | add_3D_tensor_argument(idx, _input, 1, slice_in); |
| 105 | add_3D_tensor_argument(idx, _output, 2, slice_out); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 106 | |
| 107 | _kernel.update_shader_params(); |
| 108 | |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame^] | 109 | enqueue(*this, slice_in); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 110 | } |
Michalis Spyrou | a9c4472 | 2019-04-05 17:18:36 +0100 | [diff] [blame^] | 111 | while(window.slide_window_slice_3D(slice_in)); |
Anthony Barbier | 7068f99 | 2017-10-26 15:23:08 +0100 | [diff] [blame] | 112 | } |