blob: 4f00ef9eef96badd97374d8c68e02cb34cabe9e7 [file] [log] [blame]
Michalis Spyrou5c8e05c2018-03-22 11:56:01 +00001/*
2 * Copyright (c) 2018 ARM Limited.
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/CL/kernels/CLCopyKernel.h"
25
26#include "arm_compute/core/AccessWindowStatic.h"
27#include "arm_compute/core/CL/CLHelpers.h"
28#include "arm_compute/core/CL/CLKernelLibrary.h"
29#include "arm_compute/core/CL/ICLTensor.h"
30#include "arm_compute/core/Error.h"
31#include "arm_compute/core/Helpers.h"
32#include "arm_compute/core/TensorInfo.h"
33#include "arm_compute/core/Validate.h"
34#include "arm_compute/core/Window.h"
35
36#include <algorithm>
37
38using namespace arm_compute;
39
40CLCopyKernel::CLCopyKernel()
41 : _input(nullptr), _output(nullptr)
42{
43}
44
45void CLCopyKernel::configure(const ICLTensor *input, ICLTensor *output)
46{
47 ARM_COMPUTE_ERROR_ON_MISMATCHING_DIMENSIONS(input->info()->tensor_shape(), output->info()->tensor_shape());
48 ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
49
50 _input = input;
51 _output = output;
52
53 // Create kernel
54 CLBuildOptions build_opts;
55 build_opts.add_option("-DDATA_TYPE=" + get_cl_type_from_data_type(input->info()->data_type()));
56 _kernel = static_cast<cl::Kernel>(CLKernelLibrary::get().create_kernel("copy_tensor", build_opts.options()));
57
58 // Configure window
59 constexpr unsigned int num_elems_processed_per_iteration = 16;
60
61 Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration));
62
63 AccessWindowHorizontal input_access(input->info(), 0, num_elems_processed_per_iteration);
64 AccessWindowHorizontal output_access(output->info(), 0, num_elems_processed_per_iteration);
65
66 update_window_and_padding(win, input_access, output_access);
67
68 ICLKernel::configure(win);
69}
70
71void CLCopyKernel::run(const Window &window, cl::CommandQueue &queue)
72{
73 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
74 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICLKernel::window(), window);
75
76 Window collapsed = window.collapse_if_possible(ICLKernel::window(), Window::DimX);
77 Window slice = collapsed.first_slice_window_1D();
78
79 do
80 {
81 unsigned int idx = 0;
82 add_1D_tensor_argument(idx, _input, slice);
83 add_1D_tensor_argument(idx, _output, slice);
84 enqueue(queue, *this, slice);
85 }
86 while(collapsed.slide_window_slice_1D(slice));
87}