Xinghang Zhou | 33ff9ef | 2018-01-17 11:23:39 +0800 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2020 Arm Limited. |
Xinghang Zhou | 33ff9ef | 2018-01-17 11:23:39 +0800 | [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 | #include "arm_compute/core/GLES_COMPUTE/kernels/GCTensorShiftKernel.h" |
| 25 | |
Xinghang Zhou | 33ff9ef | 2018-01-17 11:23:39 +0800 | [diff] [blame] | 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/Helpers.h" |
| 31 | #include "arm_compute/core/IAccessWindow.h" |
| 32 | #include "arm_compute/core/ITensor.h" |
| 33 | #include "arm_compute/core/Types.h" |
| 34 | #include "arm_compute/core/Validate.h" |
Sang-Hoon Park | 68dd25f | 2020-10-19 16:00:11 +0100 | [diff] [blame] | 35 | #include "src/core/AccessWindowStatic.h" |
| 36 | #include "src/core/helpers/AutoConfiguration.h" |
| 37 | #include "src/core/helpers/WindowHelpers.h" |
Matthew Bentham | 758b5ba | 2020-03-05 23:37:48 +0000 | [diff] [blame] | 38 | #include "support/StringSupport.h" |
Xinghang Zhou | 33ff9ef | 2018-01-17 11:23:39 +0800 | [diff] [blame] | 39 | |
| 40 | using namespace arm_compute; |
Xinghang Zhou | 33ff9ef | 2018-01-17 11:23:39 +0800 | [diff] [blame] | 41 | |
| 42 | GCTensorShiftKernel::GCTensorShiftKernel() |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 43 | : _input(nullptr), _lws(gles::NDRange(1U, 1U, 1U)), _left_padding(0) |
Xinghang Zhou | 33ff9ef | 2018-01-17 11:23:39 +0800 | [diff] [blame] | 44 | { |
| 45 | } |
| 46 | |
| 47 | void GCTensorShiftKernel::configure(IGCTensor *input) |
| 48 | { |
| 49 | ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::F16, DataType::F32); |
| 50 | |
| 51 | _input = input; |
| 52 | |
| 53 | std::set<std::string> options; |
| 54 | options.emplace("#define LOCAL_SIZE_X " + support::cpp11::to_string(_lws[0])); |
| 55 | options.emplace("#define LOCAL_SIZE_Y " + support::cpp11::to_string(_lws[1])); |
| 56 | options.emplace("#define LOCAL_SIZE_Z " + support::cpp11::to_string(_lws[2])); |
| 57 | options.emplace("#define WIDTH " + support::cpp11::to_string(input->info()->dimension(0))); |
| 58 | |
| 59 | std::string dt_name = (input->info()->data_type() == DataType::F32) ? "DATA_TYPE_FP32" : "DATA_TYPE_FP16"; |
| 60 | options.emplace(("#define " + dt_name)); |
| 61 | |
| 62 | unsigned int num_elems_written_per_iteration_x = input->info()->dimension(0) + input->info()->padding().left + input->info()->padding().right; |
Xinghang Zhou | 33ff9ef | 2018-01-17 11:23:39 +0800 | [diff] [blame] | 63 | |
| 64 | std::stringstream kernel_name; |
| 65 | kernel_name << "tensorshift"; |
| 66 | |
| 67 | _kernel = static_cast<GCKernel>(GCKernelLibrary::get().create_kernel(kernel_name.str(), options)); |
| 68 | |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 69 | Window win; |
| 70 | win.set(Window::DimX, Window::Dimension(0, num_elems_written_per_iteration_x, num_elems_written_per_iteration_x)); |
| 71 | win.use_tensor_dimensions(input->info()->tensor_shape(), Window::DimY); |
| 72 | win.use_tensor_dimensions(input->info()->tensor_shape(), Window::DimZ); |
Xinghang Zhou | 33ff9ef | 2018-01-17 11:23:39 +0800 | [diff] [blame] | 73 | |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 74 | _left_padding = _input->info()->padding().left; |
Xinghang Zhou | 33ff9ef | 2018-01-17 11:23:39 +0800 | [diff] [blame] | 75 | |
| 76 | IGCKernel::configure(win); |
| 77 | } |
| 78 | |
| 79 | void GCTensorShiftKernel::run(const Window &window) |
| 80 | { |
| 81 | ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this); |
| 82 | ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IKernel::window(), window); |
| 83 | |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 84 | if(int(_left_padding) == 0 || !_input->needs_shifting()) |
| 85 | { |
| 86 | return; |
| 87 | } |
| 88 | |
Xinghang Zhou | 33ff9ef | 2018-01-17 11:23:39 +0800 | [diff] [blame] | 89 | _kernel.use(); |
| 90 | |
| 91 | // Get initial windows |
| 92 | Window slice = window.first_slice_window_3D(); |
| 93 | slice.shift(Window::DimX, -(_input->info()->padding()).left); |
| 94 | |
| 95 | do |
| 96 | { |
| 97 | unsigned int idx = 0; |
| 98 | |
| 99 | add_3D_tensor_argument(idx, _input, 1, slice); |
| 100 | |
Frank Lei | 4406fd6 | 2018-02-01 14:47:14 +0800 | [diff] [blame] | 101 | _kernel.set_argument(idx++, static_cast<unsigned int>(_left_padding)); |
Xinghang Zhou | 33ff9ef | 2018-01-17 11:23:39 +0800 | [diff] [blame] | 102 | |
| 103 | _kernel.update_shader_params(); |
| 104 | enqueue(*this, slice, _lws); |
| 105 | } |
| 106 | while(window.slide_window_slice_3D(slice)); |
| 107 | } |