Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 1 | /* |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 2 | * Copyright (c) 2017-2018 ARM Limited. |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 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_NEGEMMLOWPMATRIXMULTIPLYKERNEL_H__ |
| 25 | #define __ARM_COMPUTE_NEGEMMLOWPMATRIXMULTIPLYKERNEL_H__ |
| 26 | |
| 27 | #include "arm_compute/core/NEON/INEKernel.h" |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | class 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 Tello | 6ff12a0 | 2017-11-02 16:09:35 +0000 | [diff] [blame] | 38 | * -# Convert a values from int8 to int32 |
| 39 | * -# Convert b values from int8 to int32 |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 40 | * -# Compute the int32 matrix product of the resulting a * b and store the result as int32 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 41 | * |
| 42 | */ |
| 43 | class NEGEMMLowpMatrixMultiplyKernel : public INEKernel |
| 44 | { |
| 45 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 46 | const char *name() const override |
| 47 | { |
| 48 | return "NEGEMMLowpMatrixMultiplyKernel"; |
| 49 | } |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 50 | /** 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 Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 65 | * @param[in] input0 Input tensor containing the interleaved Matrix A. Data type supported: QASYMM8 |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 66 | * @param[in] input1 Input tensor containing the transposed1xW Matrix B. Data type supported: same as @p input0 |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 67 | * @param[out] output Output tensor to store the result of matrix multiplication. Data type supported: S32 |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 68 | */ |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 69 | void configure(const ITensor *input0, const ITensor *input1, ITensor *output); |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 70 | /** 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 Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 76 | * @return a status |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 77 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 78 | static Status validate(const ITensorInfo *input0, const ITensorInfo *input1, const ITensorInfo *output); |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 79 | |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 80 | // Inherited methods overridden: |
Moritz Pflanzer | c186b57 | 2017-09-07 09:48:04 +0100 | [diff] [blame] | 81 | void run(const Window &window, const ThreadInfo &info) override; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 82 | |
| 83 | private: |
| 84 | const ITensor *_input0; |
| 85 | const ITensor *_input1; |
| 86 | ITensor *_output; |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 87 | bool _slide_matrix_b; |
Anthony Barbier | 6ff3b19 | 2017-09-04 18:44:23 +0100 | [diff] [blame] | 88 | }; |
Gian Marco Iodice | 356f643 | 2017-09-22 11:32:21 +0100 | [diff] [blame] | 89 | } // namespace arm_compute |
Pablo Tello | 6ff12a0 | 2017-11-02 16:09:35 +0000 | [diff] [blame] | 90 | #endif /*__ARM_COMPUTE_NEGEMMLOWPMATRIXMULTIPLYKERNEL_H__*/ |