blob: 68bbdcb3cbc3d768ff6b4b6e68e26131f08817b2 [file] [log] [blame]
Georgios Pinitas284cfe22018-02-13 12:15:13 +00001/*
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#ifndef __ARM_COMPUTE_NEPERMUTEKERNEL_H__
25#define __ARM_COMPUTE_NEPERMUTEKERNEL_H__
26
27#include "arm_compute/core/NEON/INEKernel.h"
28
29namespace arm_compute
30{
31class ITensor;
32
33/** NEON kernel to perform tensor permutation.
34 *
35 * Permutes given a permutation vector
36 */
37class NEPermuteKernel : public INEKernel
38{
39public:
40 const char *name() const override
41 {
42 return "NEPermuteKernel";
43 }
44 /** Default constructor */
45 NEPermuteKernel();
46 /** Prevent instances of this class from being copied (As this class contains pointers) */
47 NEPermuteKernel(const NEPermuteKernel &) = delete;
48 /** Prevent instances of this class from being copied (As this class contains pointers) */
49 NEPermuteKernel &operator=(const NEPermuteKernel &) = delete;
50 /** Allow instances of this class to be moved */
51 NEPermuteKernel(NEPermuteKernel &&) = default;
52 /** Allow instances of this class to be moved */
53 NEPermuteKernel &operator=(NEPermuteKernel &&) = default;
54 /** Default destructor */
55 ~NEPermuteKernel() = default;
56
57 /** Set the input and output of the kernel.
58 *
59 * @note Supported permutation vectors : [2, 0, 1], [1, 2, 0]
60 *
61 * @param[in] input The input tensor to permute. Data types supported: U8/S8/QS8/QASYMM8/U16/S16/QS16/F16/U32/S32/F32
62 * @param[out] output The output tensor. Data types supported: Same as @p input
63 * @param[in] perm Permutation vector
64 */
65 void configure(const ITensor *input, ITensor *output, const PermutationVector &perm);
66 /** Static function to check if given info will lead to a valid configuration of @ref CPPPermuteKernel
67 *
68 * @note Supported permutation vectors : [2, 0, 1], [1, 2, 0]
69 *
70 * @param[in] input The input tensor to permute. Data types supported: U8/S8/QS8/QASYMM8/U16/S16/QS16/F16/U32/S32/F32
71 * @param[in] output The output tensor. Data types supported: Same as @p input
72 * @param[in] perm Permutation vector
73 *
74 * @return a status
75 */
76 static Status validate(const ITensorInfo *input, const ITensorInfo *output, const PermutationVector &perm);
77
78 // Inherited methods overridden:
79 void run(const Window &window, const ThreadInfo &info) override;
80
81private:
82 /** Template function to run the permute
83 *
84 * @param[in] window Region on which to execute the kernel. (Must be a valid region of the window returned by window()).
85 */
86 template <typename T>
87 void run_permute(const Window &window);
88
89 /** Common signature for all the specialised permute functions
90 *
91 * @param[in] window Region on which to execute the kernel.
92 */
93 using PermuteFunctionPtr = void (NEPermuteKernel::*)(const Window &window);
94
95 PermuteFunctionPtr _func;
96 const ITensor *_input;
97 ITensor *_output;
98 PermutationVector _perm;
99};
100} // namespace arm_compute
101#endif /*__ARM_COMPUTE_NEPERMUTEKERNEL_H__ */