blob: 8822a97d4d3fb356c23615bdb9812c5e4e8c7a81 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
2 * Copyright (c) 2017 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_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 *
38 * -# Convert a values from uint8 to int32 and add a_offset to each of them.
39 * -# Convert b values from uint8 to int32 and add b_offset to each of them.
40 * -# Compute the int32 matrix product of the resulting a * b.
41 * -# Add output_offset to each entry of the result.
42 * -# Multiply each entry of the result and round to the nearest integer
43 * -# Clamp the resulting int32 values to the [0..255] range and cast to uint8.
44 *
45 */
46class NEGEMMLowpMatrixMultiplyKernel : public INEKernel
47{
48public:
49 /** Constructor */
50 NEGEMMLowpMatrixMultiplyKernel();
51 /** Prevent instances of this class from being copied (As this class contains pointers)*/
52 NEGEMMLowpMatrixMultiplyKernel(const NEGEMMLowpMatrixMultiplyKernel &) = delete;
53 /** Prevent instances of this class from being copied (As this class contains pointers)*/
54 NEGEMMLowpMatrixMultiplyKernel &operator=(const NEGEMMLowpMatrixMultiplyKernel &) = delete;
55 /** Allow instances of this class to be moved */
56 NEGEMMLowpMatrixMultiplyKernel(NEGEMMLowpMatrixMultiplyKernel &&) = default;
57 /** Allow instances of this class to be moved */
58 NEGEMMLowpMatrixMultiplyKernel &operator=(NEGEMMLowpMatrixMultiplyKernel &&) = default;
59 /** Initialise the kernel's input and output.
60 *
61 * The input matrices @p input0 and @p input1 must be the output of the kernels: @ref NEGEMMInterleave4x4Kernel and @ref NEGEMMTranspose1xWKernel. These two
62 * kernels change the layout of the original matrices to be more cache-friendly.
63 *
64 * @param[in] input0 Input tensor containing the interleaved Matrix A. Data type supported: U8
65 * @param[in] input1 Input tensor containing the transposed Matrix B. Data type supported: same as @p input0
66 * @param[out] output Output tensor to store the result of matrix multiplication, Data type supported: same as @p input0
67 * @param[in] a_offset Offset to be added to each element of the matrix A.
68 * @param[in] b_offset Offset to be added to each element of the matrix B.
69 * @param[in] output_offset Offset to be added to each element of the output matrix
70 * @param[in] output_mult_int Value to be multipied to each entry of the result.
71 * @param[in] shift Number of bits to shift right the result.
72 */
73 void configure(const ITensor *input0, const ITensor *input1, ITensor *output, int32_t a_offset, int32_t b_offset, int32_t output_offset, int32_t output_mult_int, int32_t shift);
74 // Inherited methods overridden:
Moritz Pflanzerc186b572017-09-07 09:48:04 +010075 void run(const Window &window, const ThreadInfo &info) override;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010076
77private:
78 const ITensor *_input0;
79 const ITensor *_input1;
80 ITensor *_output;
81 int32_t _a_offset;
82 int32_t _b_offset;
83 int32_t _output_offset;
84 int32_t _output_mult_int;
85 int32_t _shift;
86};
87}
88#endif /*__ARM_COMPUTE_NEGEMMLOWPMATRIXMULTIPLYKERNEL_H__*/