blob: 6f70efe5c7edf4cb2402cc675aa947a1c92a4b74 [file] [log] [blame]
Anthony Barbier7068f992017-10-26 15:23:08 +01001/*
Michalis Spyroua9c44722019-04-05 17:18:36 +01002 * Copyright (c) 2017-2019 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 */
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000024#include "arm_compute/core/GLES_COMPUTE/kernels/GCDepthConcatenateLayerKernel.h"
Anthony Barbier7068f992017-10-26 15:23:08 +010025
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
38using namespace arm_compute;
39
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000040GCDepthConcatenateLayerKernel::GCDepthConcatenateLayerKernel()
Michalis Spyroua9c44722019-04-05 17:18:36 +010041 : _input(nullptr), _output(nullptr), _depth_offset(0)
Anthony Barbier7068f992017-10-26 15:23:08 +010042{
43}
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000044void GCDepthConcatenateLayerKernel::configure(const IGCTensor *input, unsigned int depth_offset, IGCTensor *output)
Anthony Barbier7068f992017-10-26 15:23:08 +010045{
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 Barbier7068f992017-10-26 15:23:08 +010048
Michalis Spyroua9c44722019-04-05 17:18:36 +010049 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 Barbier7068f992017-10-26 15:23:08 +010053
Frank Lei4406fd62018-02-01 14:47:14 +080054 _input = input;
55 _output = output;
56 _depth_offset = depth_offset;
Anthony Barbier7068f992017-10-26 15:23:08 +010057
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 Barbier7068f992017-10-26 15:23:08 +010066 // 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 Spyroua9c44722019-04-05 17:18:36 +010070 if(input->info()->data_type() == DataType::F16)
Anthony Barbier7068f992017-10-26 15:23:08 +010071 {
72 num_elems_processed_per_iteration = 4;
Anthony Barbier7068f992017-10-26 15:23:08 +010073 }
Anthony Barbier7068f992017-10-26 15:23:08 +010074
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 Spyroua9c44722019-04-05 17:18:36 +010079 AccessWindowHorizontal input_access(input->info(), 0, num_elems_processed_per_iteration);
Anthony Barbier7068f992017-10-26 15:23:08 +010080 AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
81 update_window_and_padding(win, input_access, output_access);
Diego Lopez Recasbcbc9702017-12-18 11:28:27 +000082 output_access.set_valid_region(win, ValidRegion(Coordinates(), output->info()->tensor_shape()));
Anthony Barbier7068f992017-10-26 15:23:08 +010083
Anthony Barbier7068f992017-10-26 15:23:08 +010084 IGCKernel::configure(win);
85}
86
Giorgio Arena04a8f8c2017-11-23 11:45:24 +000087void GCDepthConcatenateLayerKernel::run(const Window &window)
Anthony Barbier7068f992017-10-26 15:23:08 +010088{
89 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
90 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(IGCKernel::window(), window);
91
92 _kernel.use();
93
Frank Lei4406fd62018-02-01 14:47:14 +080094 _output->set_needs_shifting(true);
95
Frank Lei4406fd62018-02-01 14:47:14 +080096 Window slice_in = window.first_slice_window_3D();
97 Window slice_out = window.first_slice_window_3D();
98
Frank Lei4406fd62018-02-01 14:47:14 +080099 slice_out.set(Window::DimZ, Window::Dimension(_depth_offset));
Anthony Barbier7068f992017-10-26 15:23:08 +0100100
101 do
102 {
Joel Liangabd03cf2018-01-08 15:20:48 +0800103 unsigned int idx = 0;
Frank Lei4406fd62018-02-01 14:47:14 +0800104 add_3D_tensor_argument(idx, _input, 1, slice_in);
105 add_3D_tensor_argument(idx, _output, 2, slice_out);
Anthony Barbier7068f992017-10-26 15:23:08 +0100106
107 _kernel.update_shader_params();
108
Michalis Spyroua9c44722019-04-05 17:18:36 +0100109 enqueue(*this, slice_in);
Anthony Barbier7068f992017-10-26 15:23:08 +0100110 }
Michalis Spyroua9c44722019-04-05 17:18:36 +0100111 while(window.slide_window_slice_3D(slice_in));
Anthony Barbier7068f992017-10-26 15:23:08 +0100112}