blob: 20496adb76eca8ebbdc7c2580deabe98e1c73aca [file] [log] [blame]
Michalis Spyrou1d382592018-08-13 17:28:04 +01001/*
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/NEON/kernels/NECopyKernel.h"
25
26#include "arm_compute/core/Error.h"
27#include "arm_compute/core/Helpers.h"
28#include "arm_compute/core/ITensor.h"
29#include "arm_compute/core/TensorInfo.h"
30#include "arm_compute/core/Validate.h"
31#include "arm_compute/core/Window.h"
32
33using namespace arm_compute;
34
35NECopyKernel::NECopyKernel()
36 : _input(nullptr), _output(nullptr)
37{
38}
39
40void NECopyKernel::configure(const ITensor *input, ITensor *output)
41{
42 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
43
44 _input = input;
45 _output = output;
46
47 INEKernel::configure(calculate_max_window(*output->info()));
48}
49
50Status NECopyKernel::validate(const arm_compute::ITensorInfo *input, const arm_compute::ITensorInfo *output)
51{
52 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(input, output);
53 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_LAYOUT(input, output);
54 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
55 return Status{};
56}
57
58void NECopyKernel::run(const Window &window, const ThreadInfo &info)
59{
60 ARM_COMPUTE_UNUSED(info);
61 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
62 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
63
64 Window output_window{ window };
65 output_window.set(Window::DimX, Window::Dimension(output_window.x().start(), output_window.x().end(), _input->info()->dimension(0)));
66
67 Window out_slice = output_window.first_slice_window_1D();
68
69 do
70 {
71 Iterator input_it(_input, out_slice);
72 Iterator output_it(_output, out_slice);
73
74 execute_window_loop(out_slice, [&](const Coordinates & id)
75 {
76 memcpy(output_it.ptr(), input_it.ptr(), _output->info()->dimension(0) * _output->info()->element_size());
77 },
78 input_it, output_it);
79
80 }
81 while(output_window.slide_window_slice_1D(out_slice));
82}