blob: a52a1f58ea7e4841ccaa2a19eca2718b8a4a9e34 [file] [log] [blame]
Manuel Bottini24b89202021-07-01 18:13:33 +01001/*
2 * Copyright (c) 2017-2021 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 */
Georgios Pinitas7891a732021-08-20 21:39:25 +010024#include "src/cpu/kernels/CpuCol2ImKernel.h"
Manuel Bottini24b89202021-07-01 18:13:33 +010025
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/Size2D.h"
30#include "arm_compute/core/TensorInfo.h"
31#include "arm_compute/core/Types.h"
Manuel Bottini24b89202021-07-01 18:13:33 +010032#include "arm_compute/core/utils/misc/ShapeCalculator.h"
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010033#include "arm_compute/core/Validate.h"
34
Manuel Bottini24b89202021-07-01 18:13:33 +010035#include "src/core/helpers/AutoConfiguration.h"
36#include "src/core/helpers/WindowHelpers.h"
37
38namespace arm_compute
39{
40using namespace misc::shape_calculator;
41namespace cpu
42{
43namespace kernels
44{
45namespace
46{
47Status validate_arguments(const ITensorInfo *src, const ITensorInfo *dst, const Size2D &convolved_dims)
48{
49 //Note: ARM_COMPUTE_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(input) is not needed here as this kernel doesn't use CPU FP16 instructions.
50 ARM_COMPUTE_RETURN_ERROR_ON(src->data_type() == DataType::UNKNOWN);
51
52 // Validate configured output
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010053 if (dst->total_size() != 0)
Manuel Bottini24b89202021-07-01 18:13:33 +010054 {
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010055 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DIMENSIONS(dst->tensor_shape(),
56 compute_col2im_shape(*src, convolved_dims, false));
Manuel Bottini24b89202021-07-01 18:13:33 +010057 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(src, dst);
58 ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(src, dst);
59 }
60
61 return Status{};
62}
63} // namespace
64
65void CpuCol2ImKernel::configure(const ITensorInfo *src, ITensorInfo *dst, const Size2D &convolved_dims)
66{
67 ARM_COMPUTE_ERROR_ON_NULLPTR(src, dst);
68 ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(src, dst, convolved_dims));
69
70 _convolved_dims = convolved_dims;
71
72 // Configure kernel window
73 // Output auto inizialitation if not yet initialized
74 auto_init_if_empty(*dst, src->clone()->set_tensor_shape(compute_col2im_shape(*src, convolved_dims, false)));
75
76 // Configure kernel window
77 Window win = calculate_max_window(*src, Steps());
78
79 ICpuKernel::configure(win);
80}
81
82Status CpuCol2ImKernel::validate(const ITensorInfo *src, const ITensorInfo *output, const Size2D &convolved_dims)
83{
84 ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(src, output, convolved_dims));
85 return Status{};
86}
87
88void CpuCol2ImKernel::run_op(ITensorPack &tensors, const Window &window, const ThreadInfo &info)
89{
90 ARM_COMPUTE_UNUSED(info);
91 ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(this);
92 ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(ICpuKernel::window(), window);
93
94 auto src = tensors.get_const_tensor(TensorType::ACL_SRC);
95 auto dst = tensors.get_tensor(TensorType::ACL_DST);
96
97 const uint8_t el_size = src->info()->element_size();
98 const int output_stride_x = dst->info()->strides_in_bytes().x();
99 const int output_stride_y = dst->info()->strides_in_bytes().y();
100 const int output_stride_z = dst->info()->strides_in_bytes().z();
101
102 Window window_out(window);
103 window_out.set(Window::DimX, Window::Dimension(0, 0, 0));
104 window_out.set(Window::DimY, Window::Dimension(0, 0, 0));
105 window_out.set(Window::DimZ, Window::Dimension(0, 0, 0));
106
107 // Create iterators
108 Iterator in(src, window);
109 Iterator out(dst, window_out);
110
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100111 execute_window_loop(
112 window,
113 [&](const Coordinates &id)
114 {
115 const int hidx = id.y();
116 const int idx = id.x() * output_stride_z + (hidx / _convolved_dims.width) * output_stride_y +
117 (hidx % _convolved_dims.width) * output_stride_x;
118 std::memcpy(out.ptr() + idx, in.ptr(), el_size);
119 },
120 in, out);
Manuel Bottini24b89202021-07-01 18:13:33 +0100121}
122
123const char *CpuCol2ImKernel::name() const
124{
125 return "CpuCol2ImKernel";
126}
127} // namespace kernels
128} // namespace cpu
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100129} // namespace arm_compute