blob: 354ae21e29965994f5e1ed0dc1b7d88e87c45457 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
Anthony Barbiere8a49832018-01-18 10:04:05 +00002 * Copyright (c) 2017-2018 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 */
24#ifndef __ARM_COMPUTE_NEGEMMLOWPMATRIXMULTIPLYKERNEL_H__
25#define __ARM_COMPUTE_NEGEMMLOWPMATRIXMULTIPLYKERNEL_H__
26
27#include "arm_compute/core/NEON/INEKernel.h"
28
29namespace arm_compute
30{
31class ITensor;
32
33/** NEON kernel to multiply matrices
34 *
35 * @note @ref NEGEMMLowpMatrixMultiplyKernel low precision matrix product kernel
36 * This kernel performs the following computation:
37 *
Pablo Tello6ff12a02017-11-02 16:09:35 +000038 * -# Convert a values from int8 to int32
39 * -# Convert b values from int8 to int32
Gian Marco Iodiceab182122017-10-09 15:05:40 +010040 * -# Compute the int32 matrix product of the resulting a * b and store the result as int32
Anthony Barbier6ff3b192017-09-04 18:44:23 +010041 *
42 */
43class NEGEMMLowpMatrixMultiplyKernel : public INEKernel
44{
45public:
Anthony Barbiere8a49832018-01-18 10:04:05 +000046 const char *name() const override
47 {
48 return "NEGEMMLowpMatrixMultiplyKernel";
49 }
Anthony Barbier6ff3b192017-09-04 18:44:23 +010050 /** Constructor */
51 NEGEMMLowpMatrixMultiplyKernel();
52 /** Prevent instances of this class from being copied (As this class contains pointers)*/
53 NEGEMMLowpMatrixMultiplyKernel(const NEGEMMLowpMatrixMultiplyKernel &) = delete;
54 /** Prevent instances of this class from being copied (As this class contains pointers)*/
55 NEGEMMLowpMatrixMultiplyKernel &operator=(const NEGEMMLowpMatrixMultiplyKernel &) = delete;
56 /** Allow instances of this class to be moved */
57 NEGEMMLowpMatrixMultiplyKernel(NEGEMMLowpMatrixMultiplyKernel &&) = default;
58 /** Allow instances of this class to be moved */
59 NEGEMMLowpMatrixMultiplyKernel &operator=(NEGEMMLowpMatrixMultiplyKernel &&) = default;
60 /** Initialise the kernel's input and output.
61 *
62 * The input matrices @p input0 and @p input1 must be the output of the kernels: @ref NEGEMMInterleave4x4Kernel and @ref NEGEMMTranspose1xWKernel. These two
63 * kernels change the layout of the original matrices to be more cache-friendly.
64 *
Georgios Pinitasa3b1b462017-11-16 19:24:39 +000065 * @param[in] input0 Input tensor containing the interleaved Matrix A. Data type supported: QASYMM8
Gian Marcoe75a02b2017-11-08 12:24:09 +000066 * @param[in] input1 Input tensor containing the transposed1xW Matrix B. Data type supported: same as @p input0
Gian Marco Iodiceab182122017-10-09 15:05:40 +010067 * @param[out] output Output tensor to store the result of matrix multiplication. Data type supported: S32
Anthony Barbier6ff3b192017-09-04 18:44:23 +010068 */
Gian Marco Iodiceab182122017-10-09 15:05:40 +010069 void configure(const ITensor *input0, const ITensor *input1, ITensor *output);
Georgios Pinitasa3b1b462017-11-16 19:24:39 +000070 /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMLowpMatrixMultiplyKernel
71 *
72 * @param[in] input0 Input tensor info containing the interleaved Matrix A. Data type supported: QASYMM8
73 * @param[in] input1 Input tensor info containing the transposed Matrix B. Data type supported: same as @p input0
74 * @param[in] output Output tensor info to store the result of matrix multiplication. Data type supported: S32
75 *
Georgios Pinitas631c41a2017-12-06 11:53:03 +000076 * @return a status
Georgios Pinitasa3b1b462017-11-16 19:24:39 +000077 */
Georgios Pinitas631c41a2017-12-06 11:53:03 +000078 static Status validate(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output);
Gian Marco Iodiceab182122017-10-09 15:05:40 +010079
Anthony Barbier6ff3b192017-09-04 18:44:23 +010080 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010081 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010082
83private:
84 const ITensor *_input0;
85 const ITensor *_input1;
86 ITensor *_output;
Gian Marco Iodiceab182122017-10-09 15:05:40 +010087 bool _slide_matrix_b;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010088};
Gian Marco Iodice356f6432017-09-22 11:32:21 +010089} // namespace arm_compute
Pablo Tello6ff12a02017-11-02 16:09:35 +000090#endif /*__ARM_COMPUTE_NEGEMMLOWPMATRIXMULTIPLYKERNEL_H__*/