blob: 9aa10626225cec52af9a87bf2ad57fc0647dc387 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Georgios Pinitas6e1791b2019-12-02 19:01:25 +00002 * Copyright (c) 2017-2019 ARM Limited.
Anthony Barbier6ff3b192017-09-04 18:44:23 +01003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NECOL2IMKERNEL_H
25#define ARM_COMPUTE_NECOL2IMKERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
27#include "arm_compute/core/NEON/INEKernel.h"
28
Georgios Pinitasd912fd82017-11-27 21:00:13 +000029#include "arm_compute/core/Size2D.h"
30
Anthony Barbier6ff3b192017-09-04 18:44:23 +010031namespace arm_compute
32{
33class ITensor;
34
35/** NEON kernel to perform col2im reshaping.
36 *
37 * Rearranges each matrix column into image blocks. It's the inverse operation of @ref NEIm2ColKernel.
38 *
39 * For example, a vector of 9 elements can be reshaped to a block(image) of 3x3:
40 *
41 * @f[
42 * \left( \begin{array}{ccccccccc}
43 * a0 & a1 & a2 & a3 & a4 & a5 & a6 & a7 & a8 \\
44 * \end{array} \right)
45 * \rightarrow
46 * \left( \begin{array}{ccc}
47 * a0 & a1 & a2 \\
48 * a3 & a4 & a5 \\
49 * a6 & a7 & a8 \\
50 * \end{array} \right)
51 * @f]
52 */
53class NECol2ImKernel : public INEKernel
54{
55public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000056 const char *name() const override
57 {
58 return "NECol2ImKernel";
59 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010060 /** Default constructor */
61 NECol2ImKernel();
62 /** Prevent instances of this class from being copied (As this class contains pointers) */
63 NECol2ImKernel(const NECol2ImKernel &) = delete;
64 /** Prevent instances of this class from being copied (As this class contains pointers) */
65 NECol2ImKernel &operator=(const NECol2ImKernel &) = delete;
66 /** Allow instances of this class to be moved */
67 NECol2ImKernel(NECol2ImKernel &&) = default;
68 /** Allow instances of this class to be moved */
69 NECol2ImKernel &operator=(NECol2ImKernel &&) = default;
70 /** Default destructor */
71 ~NECol2ImKernel() = default;
72
73 /** Set the input and output of the kernel.
74 *
Georgios Pinitas33843562019-12-10 13:33:18 +000075 * @param[in] input The input tensor to convert. Data types supported: All
Anthony Barbier6ff3b192017-09-04 18:44:23 +010076 * @param[out] output The output tensor. 3 lower dimensions represent a single output [width, height, OFM],
77 * while the rest represent batch of outputs. Data types supported: Same as @p input
78 * @param[in] convolved_dims Output convolved dimensions.
79 */
Georgios Pinitasd912fd82017-11-27 21:00:13 +000080 void configure(const ITensor *input, ITensor *output, const Size2D &convolved_dims);
81 /** Static function to check if given info will lead to a valid configuration of @ref NECol2ImKernel
82 *
Georgios Pinitas33843562019-12-10 13:33:18 +000083 * @param[in] input The input tensor to convert. Data types supported: All
Georgios Pinitasd912fd82017-11-27 21:00:13 +000084 * @param[in] output The output tensor. 3 lower dimensions represent a single output [width, height, OFM],
85 * while the rest represent batch of outputs. Data types supported: Same as @p input
86 * @param[in] convolved_dims Output convolved dimensions.
87 *
Georgios Pinitas631c41a2017-12-06 11:53:03 +000088 * @return a status
Georgios Pinitasd912fd82017-11-27 21:00:13 +000089 */
Georgios Pinitas631c41a2017-12-06 11:53:03 +000090 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const Size2D &convolved_dims);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010091
92 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010093 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010094
95private:
96 /** Template function to run the col2im
97 *
98 * @param[in] window Region on which to execute the kernel. (Must be a valid region of the window returned by window()).
99 */
100 template <typename T>
101 void run_col2im(const Window &window);
102
103 /** Common signature for all the specialised col2im functions
104 *
105 * @param[in] window Region on which to execute the kernel.
106 */
107 using Col2ImFunctionPtr = void (NECol2ImKernel::*)(const Window &window);
108
109 Col2ImFunctionPtr _func;
110 const ITensor *_input;
111 ITensor *_output;
Georgios Pinitasd912fd82017-11-27 21:00:13 +0000112 Size2D _convolved_dims;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100113};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100114} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000115#endif /*ARM_COMPUTE_NECOL2IMKERNEL_H */