blob: f6bc2152da892505342d6d2d71073ceb838ca9e5 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 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#ifndef __ARM_COMPUTE_NECOL2IMKERNEL_H__
25#define __ARM_COMPUTE_NECOL2IMKERNEL_H__
26
27#include "arm_compute/core/NEON/INEKernel.h"
28
29namespace arm_compute
30{
31class ITensor;
32
33/** NEON kernel to perform col2im reshaping.
34 *
35 * Rearranges each matrix column into image blocks. It's the inverse operation of @ref NEIm2ColKernel.
36 *
37 * For example, a vector of 9 elements can be reshaped to a block(image) of 3x3:
38 *
39 * @f[
40 * \left( \begin{array}{ccccccccc}
41 * a0 & a1 & a2 & a3 & a4 & a5 & a6 & a7 & a8 \\
42 * \end{array} \right)
43 * \rightarrow
44 * \left( \begin{array}{ccc}
45 * a0 & a1 & a2 \\
46 * a3 & a4 & a5 \\
47 * a6 & a7 & a8 \\
48 * \end{array} \right)
49 * @f]
50 */
51class NECol2ImKernel : public INEKernel
52{
53public:
54 /** Default constructor */
55 NECol2ImKernel();
56 /** Prevent instances of this class from being copied (As this class contains pointers) */
57 NECol2ImKernel(const NECol2ImKernel &) = delete;
58 /** Prevent instances of this class from being copied (As this class contains pointers) */
59 NECol2ImKernel &operator=(const NECol2ImKernel &) = delete;
60 /** Allow instances of this class to be moved */
61 NECol2ImKernel(NECol2ImKernel &&) = default;
62 /** Allow instances of this class to be moved */
63 NECol2ImKernel &operator=(NECol2ImKernel &&) = default;
64 /** Default destructor */
65 ~NECol2ImKernel() = default;
66
67 /** Set the input and output of the kernel.
68 *
69 * @param[in] input The input tensor to convert. Data types supported: U8/S8/QS8/U16/S16/QS16/F16/U32/S32/F32
70 * @param[out] output The output tensor. 3 lower dimensions represent a single output [width, height, OFM],
71 * while the rest represent batch of outputs. Data types supported: Same as @p input
72 * @param[in] convolved_dims Output convolved dimensions.
73 */
74 void configure(const ITensor *input, ITensor *output, std::pair<unsigned int, unsigned int> convolved_dims);
75
76 // Inherited methods overridden:
77 void run(const Window &window) override;
78
79private:
80 /** Template function to run the col2im
81 *
82 * @param[in] window Region on which to execute the kernel. (Must be a valid region of the window returned by window()).
83 */
84 template <typename T>
85 void run_col2im(const Window &window);
86
87 /** Common signature for all the specialised col2im functions
88 *
89 * @param[in] window Region on which to execute the kernel.
90 */
91 using Col2ImFunctionPtr = void (NECol2ImKernel::*)(const Window &window);
92
93 Col2ImFunctionPtr _func;
94 const ITensor *_input;
95 ITensor *_output;
96 std::pair<unsigned int, unsigned int> _convolved_dims;
97};
98}
99
100#endif /*__ARM_COMPUTE_NECOL2IMKERNEL_H__ */