blob: 577ce5b69e3478809730628a53ccc1fe018281e3 [file] [log] [blame]
giuros01be1c0172018-12-04 11:36:08 +00001/*
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +01002 * Copyright (c) 2018-2020 Arm Limited.
giuros01be1c0172018-12-04 11:36:08 +00003 *
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 */
Michalis Spyrouebcebf12020-10-21 00:04:14 +010024#include "src/core/NEON/kernels/NETileKernel.h"
giuros01be1c0172018-12-04 11:36:08 +000025
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"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010030#include "arm_compute/core/utils/misc/ShapeCalculator.h"
giuros01be1c0172018-12-04 11:36:08 +000031#include "arm_compute/core/Validate.h"
32#include "arm_compute/core/Window.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010033
Sang-Hoon Park68dd25f2020-10-19 16:00:11 +010034#include "src/core/helpers/AutoConfiguration.h"
35#include "src/core/helpers/WindowHelpers.h"
giuros01be1c0172018-12-04 11:36:08 +000036
37namespace arm_compute
38{
39namespace
40{
41Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, const Multiples &multiples)
42{
43 ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output);
Georgios Pinitas33843562019-12-10 13:33:18 +000044 ARM_COMPUTE_RETURN_ERROR_ON(input->data_type() == DataType::UNKNOWN);
giuros01be1c0172018-12-04 11:36:08 +000045 ARM_COMPUTE_RETURN_ERROR_ON(multiples.size() > 4);
46 ARM_COMPUTE_RETURN_ERROR_ON(multiples.empty());
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010047 ARM_COMPUTE_RETURN_ERROR_ON(std::any_of(multiples.begin(), multiples.end(), [](uint32_t e) { return e == 0; }));
giuros01be1c0172018-12-04 11:36:08 +000048
49 // Validate output if initialized
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010050 if (output->total_size() != 0)
giuros01be1c0172018-12-04 11:36:08 +000051 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010052 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(
53 misc::shape_calculator::compute_tiled_shape(input->tensor_shape(), multiples), output->tensor_shape());
giuros01be1c0172018-12-04 11:36:08 +000054 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output);
55 }
56
57 return Status{};
58}
59} // namespace
60
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010061NETileKernel::NETileKernel() : _input(nullptr), _output(nullptr)
giuros01be1c0172018-12-04 11:36:08 +000062{
63}
64
65void NETileKernel::configure(const ITensor *input, ITensor *output, const Multiples &multiples)
66{
67 ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
68
69 // Auto initialize output
70 TensorShape tiled_shape = misc::shape_calculator::compute_tiled_shape(input->info()->tensor_shape(), multiples);
71 auto_init_if_empty(*output->info(), tiled_shape, 1, input->info()->data_type());
72
73 // Validate
74 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info(), multiples));
75
76 _input = input;
77 _output = output;
78
79 // Configure window without padding
80 Window win = calculate_max_window(*output->info());
81 INEKernel::configure(win);
82}
83
84Status NETileKernel::validate(const ITensorInfo *input, const ITensorInfo *output, const Multiples &multiples)
85{
86 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output, multiples));
87 return Status{};
88}
89
90void NETileKernel::run(const Window &window, const ThreadInfo &info)
91{
92 ARM_COMPUTE_UNUSED(info);
93 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
94 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(INEKernel::window(), window);
95
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010096 Window output_window{window};
97 output_window.set(Window::DimX, Window::Dimension(output_window.x().start(), output_window.x().end(),
98 _input->info()->dimension(0)));
giuros01be1c0172018-12-04 11:36:08 +000099 Window out_slice = output_window.first_slice_window_1D();
100
101 const auto src_shape = _input->info()->tensor_shape();
102 do
103 {
104 Iterator output_it(_output, out_slice);
105
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100106 execute_window_loop(
107 out_slice,
108 [&](const Coordinates &id)
109 {
110 const size_t x = id.x();
111 const size_t y = id.y();
112 const size_t z = id.z();
113 const size_t w = id[3];
114 Coordinates input_coords{x % src_shape[0], y % src_shape[1], z % src_shape[2], w % src_shape[3]};
115 memcpy(output_it.ptr(), _input->ptr_to_element(input_coords),
116 _input->info()->dimension(0) * _input->info()->element_size());
117 },
118 output_it);
119 } while (output_window.slide_window_slice_1D(out_slice));
giuros01be1c0172018-12-04 11:36:08 +0000120}
121} // namespace arm_compute