blob: 92fbd12a54cbd3a29a41a5f7c8628c3166ce5f76 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Sheri Zhangcece42c2021-02-10 15:32:38 +00002 * Copyright (c) 2016-2021 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_NEGEMMINTERLEAVE4x4KERNEL_H
25#define ARM_COMPUTE_NEGEMMINTERLEAVE4x4KERNEL_H
Anthony Barbier6ff3b192017-09-04 18:44:23 +010026
Michalis Spyrouebcebf12020-10-21 00:04:14 +010027#include "src/core/NEON/INESimpleKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010028
29namespace arm_compute
30{
31class ITensor;
32
Sheri Zhangcece42c2021-02-10 15:32:38 +000033/** Neon kernel to interleave the elements of a matrix
Anthony Barbier6ff3b192017-09-04 18:44:23 +010034 *
35 * This function puts the values in a 4x4 block of Matrix A on the same row (Interleaved values)
36 *
37 * @f[
38 * \left( \begin{array}{cccc}
39 * a00 & a01 & a02 & a03 \\
40 * a10 & a11 & a12 & a13 \\
41 * a20 & a21 & a22 & a23 \\
42 * a30 & a31 & a32 & a33 \\
43 * \end{array} \right)
44 * \rightarrow
45 * \left( \begin{array}{ccccccccccccccccc}
46 * a00 & a10 & a20 & a30 & a01 & a11 & a21 & a31 & a02 & a12 & a22 & a32 & a03 & a13 & a23 & a33 \\
47 * \end{array} \right)
48 * @f]
49 *
50 * After this operation, the output matrix will have the following shape: [ height * 4, ceil(width / 4.0f) ]
51 */
52class NEGEMMInterleave4x4Kernel : public INESimpleKernel
53{
54public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000055 const char *name() const override
56 {
57 return "NEGEMMInterleave4x4Kernel";
58 }
Michalis Spyrouebcebf12020-10-21 00:04:14 +010059 /** Constructor */
Anthony Barbier6ff3b192017-09-04 18:44:23 +010060 NEGEMMInterleave4x4Kernel();
Michalis Spyrouebcebf12020-10-21 00:04:14 +010061 /** Prevent instances of this class from being copied (As this class contains pointers) */
62 NEGEMMInterleave4x4Kernel(const NEGEMMInterleave4x4Kernel &) = delete;
63 /** Prevent instances of this class from being copied (As this class contains pointers) */
64 NEGEMMInterleave4x4Kernel &operator=(const NEGEMMInterleave4x4Kernel &) = delete;
65 /** Allow instances of this class to be moved */
66 NEGEMMInterleave4x4Kernel(NEGEMMInterleave4x4Kernel &&) = default;
67 /** Allow instances of this class to be moved */
68 NEGEMMInterleave4x4Kernel &operator=(NEGEMMInterleave4x4Kernel &&) = default;
69 /** Default destructor */
70 ~NEGEMMInterleave4x4Kernel() = default;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010071 /** Initialise the kernel's input and output.
72 *
Georgios Pinitasdbdea0d2019-10-16 19:21:40 +010073 * @param[in] input Input tensor. Data types supported: All
Anthony Barbier6ff3b192017-09-04 18:44:23 +010074 * @param[out] output Output tensor which stores the interleaved matrix. Data type supported: same as @p input.
75 */
76 void configure(const ITensor *input, ITensor *output);
Georgios Pinitasa3b1b462017-11-16 19:24:39 +000077 /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMInterleave4x4Kernel
78 *
Georgios Pinitasdbdea0d2019-10-16 19:21:40 +010079 * @param[in] input Input tensor info. Data types supported: All
Georgios Pinitasa3b1b462017-11-16 19:24:39 +000080 * @param[in] output Output tensor info which stores the interleaved matrix. Data type supported: same as @p input.
81 *
Georgios Pinitas631c41a2017-12-06 11:53:03 +000082 * @return a status
Georgios Pinitasa3b1b462017-11-16 19:24:39 +000083 */
Georgios Pinitas631c41a2017-12-06 11:53:03 +000084 static Status validate(const ITensorInfo *input, const ITensorInfo *output);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010085
86 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010087 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010088
89private:
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010090 /** Template function to run gemm interleave 4x4
Anthony Barbier6ff3b192017-09-04 18:44:23 +010091 *
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010092 * @tparam ScalarType Scalar datatype
93 *
94 * @param[in] input Input tensor. Data types supported: uint32_t, uint16_t and uint8_t
95 * @param[out] output Output tensor. Data types supported: uint32_t, uint16_t and uint8_t
96 * @param[in] window Region on which to execute the kernel. (Must be a valid region of the window returned by window()).
Anthony Barbier6ff3b192017-09-04 18:44:23 +010097 */
Gian Marco Iodicefeaea102020-09-03 13:20:34 +010098 template <typename ScalarType>
99 void gemm_interleave4x4(const ITensor *input, ITensor *output, const Window &window);
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100100
Gian Marco Iodicefeaea102020-09-03 13:20:34 +0100101 /** Common signature for all the specialised gemm interleave 4x4 functions
102 *
103 * @param[in] input Input tensor. Data types supported: uint32_t, uint16_t and uint8_t
104 * @param[out] output Output tensor. Data types supported: uint32_t, uint16_t and uint8_t
105 * @param[in] window Region on which to execute the kernel. (Must be a valid region of the window returned by window()).
106 */
107 using GEMMInterleaveFunctionFuncPtr = void (NEGEMMInterleave4x4Kernel::*)(const ITensor *input, ITensor *output, const Window &window);
108
109 GEMMInterleaveFunctionFuncPtr _func;
Anthony Barbier6ff3b192017-09-04 18:44:23 +0100110};
Gian Marco Iodice356f6432017-09-22 11:32:21 +0100111} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000112#endif /*ARM_COMPUTE_NEGEMMINTERLEAVE4x4KERNEL_H*/