blob: 78b008484e4b5643e52c2e65ce8a72f4768f8f46 [file] [log] [blame]
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +08001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +08003 *
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 Zhou33ff9ef2018-01-17 11:23:39 +080026#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 Park68dd25f2020-10-19 16:00:11 +010035#include "src/core/AccessWindowStatic.h"
36#include "src/core/helpers/AutoConfiguration.h"
37#include "src/core/helpers/WindowHelpers.h"
Matthew Bentham758b5ba2020-03-05 23:37:48 +000038#include "support/StringSupport.h"
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +080039
40using namespace arm_compute;
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +080041
42GCTensorShiftKernel::GCTensorShiftKernel()
Frank Lei4406fd62018-02-01 14:47:14 +080043 : _input(nullptr), _lws(gles::NDRange(1U, 1U, 1U)), _left_padding(0)
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +080044{
45}
46
47void 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 Zhou33ff9ef2018-01-17 11:23:39 +080063
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 Lei4406fd62018-02-01 14:47:14 +080069 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 Zhou33ff9ef2018-01-17 11:23:39 +080073
Frank Lei4406fd62018-02-01 14:47:14 +080074 _left_padding = _input->info()->padding().left;
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +080075
76 IGCKernel::configure(win);
77}
78
79void 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 Lei4406fd62018-02-01 14:47:14 +080084 if(int(_left_padding) == 0 || !_input->needs_shifting())
85 {
86 return;
87 }
88
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +080089 _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 Lei4406fd62018-02-01 14:47:14 +0800101 _kernel.set_argument(idx++, static_cast<unsigned int>(_left_padding));
Xinghang Zhou33ff9ef2018-01-17 11:23:39 +0800102
103 _kernel.update_shader_params();
104 enqueue(*this, slice, _lws);
105 }
106 while(window.slide_window_slice_3D(slice));
107}