blob: bfb1a494b873f53f94ec96ce93ab72dbd4b06136 [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_NEGEMMLOWP_H__
25#define __ARM_COMPUTE_NEGEMMLOWP_H__
26
27#include "arm_compute/core/NEON/INEKernel.h"
28#include "arm_compute/runtime/IFunction.h"
29#include "arm_compute/runtime/Tensor.h"
30
31#include "arm_compute/core/NEON/kernels/NEFillBorderKernel.h"
32#include "arm_compute/core/NEON/kernels/NEGEMMInterleave4x4Kernel.h"
33#include "arm_compute/core/NEON/kernels/NEGEMMLowpMatrixMultiplyKernel.h"
34#include "arm_compute/core/NEON/kernels/NEGEMMTranspose1xWKernel.h"
35
36namespace arm_compute
37{
38class ITensor;
39
40/** Basic function to execute GEMMLowp on NEON. This function calls the following NEON kernels:
41*
42* -# @ref NEGEMMInterleave4x4Kernel
43* -# @ref NEGEMMTranspose1xWKernel
44* -# @ref NEGEMMLowpMatrixMultiplyKernel
45*
46*/
47class NEGEMMLowp : public IFunction
48{
49public:
50 /** Constructor */
51 NEGEMMLowp();
52 /** Initialise the kernel's inputs, output
53 *
54 * @note GEMM_LOWP: low precision GEMM kernel
55 * This kernel performs the following computation:
56 *
57 * -# Convert a values from uint8 to int32 and add a_offset to each of them.
58 * -# Convert b values from uint8 to int32 and add b_offset to each of them.
59 * -# Compute the int32 matrix product of the resulting a * b.
60 * -# Add output_offset to each entry of the result.
61 * -# Multiply each entry of the result and round to the nearest integer
62 * -# Clamp the resulting int32 values to the [0..255] range and cast to uint8.
63 *
64 * @param[in] a First input tensor (Matrix A). Data type supported: U8.
65 * @param[in] b Second input tensor (Matrix B). Data type supported: same as @p a
66 * @param[out] output Output tensor. Data type supported: same as @p a.
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 multiplied to each element of the output matrix
71 * @param[in] shift Number of bits to shift right the result.
72 */
73 void configure(const ITensor *a, const ITensor *b, 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:
75 void run() override;
76
77private:
78 NEGEMMInterleave4x4Kernel _interleave_kernel;
79 NEGEMMTranspose1xWKernel _transpose_kernel;
80 NEGEMMLowpMatrixMultiplyKernel _mm_kernel;
81 Tensor _tmp_a;
82 Tensor _tmp_b;
83};
84}
85#endif /*__ARM_COMPUTE_NEGEMMLOWP_H__ */