blob: 59c919e161c32f62e3e394eb9ecfea44c3d76960 [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"
Gian Marco Iodiceab182122017-10-09 15:05:40 +010028#include "arm_compute/core/NEON/kernels/NEGEMMLowpFinalizeKernel.h"
29#include "arm_compute/core/NEON/kernels/NEGEMMLowpReductionKernel.h"
Anthony Barbier6ff3b192017-09-04 18:44:23 +010030#include "arm_compute/runtime/IFunction.h"
Georgios Pinitas658039b2017-09-15 16:30:50 +010031#include "arm_compute/runtime/IMemoryManager.h"
32#include "arm_compute/runtime/MemoryGroup.h"
Gian Marco Iodiceab182122017-10-09 15:05:40 +010033#include "arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCore.h"
34#include "arm_compute/runtime/Tensor.h"
Georgios Pinitas658039b2017-09-15 16:30:50 +010035
36#include <memory>
Anthony Barbier6ff3b192017-09-04 18:44:23 +010037
38namespace arm_compute
39{
40class ITensor;
41
Gian Marco Iodiceab182122017-10-09 15:05:40 +010042/** Basic function to execute GEMMLowp on NEON. This function calls the following NEON kernels/function:
43 *
44 * -# @ref NEGEMMLowpMatrixAReductionKernel
45 * -# @ref NEGEMMLowpMatrixBReductionKernel
46 * -# @ref NEGEMMLowpMatrixMultiplyCore
47 * -# @ref NEGEMMLowpFinalizeKernel
48 *
Anthony Barbier6ff3b192017-09-04 18:44:23 +010049*/
50class NEGEMMLowp : public IFunction
51{
52public:
53 /** Constructor */
Georgios Pinitas658039b2017-09-15 16:30:50 +010054 NEGEMMLowp(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
Anthony Barbier6ff3b192017-09-04 18:44:23 +010055 /** Initialise the kernel's inputs, output
56 *
57 * @note GEMM_LOWP: low precision GEMM kernel
Gian Marco Iodiceab182122017-10-09 15:05:40 +010058 * This kernel performs the following computations:
Anthony Barbier6ff3b192017-09-04 18:44:23 +010059 *
Pablo Tello6ff12a02017-11-02 16:09:35 +000060 * -# Convert a values from int8 to int32 and add a_offset to each of them.
61 * -# Convert b values from int8 to int32 and add b_offset to each of them.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010062 * -# Compute the int32 matrix product of the resulting a * b.
63 * -# Add output_offset to each entry of the result.
64 * -# Multiply each entry of the result and round to the nearest integer
Pablo Tello6ff12a02017-11-02 16:09:35 +000065 * -# Clamp the resulting int32 values to the [0..255] range and cast to int8.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010066 *
Pablo Tello6ff12a02017-11-02 16:09:35 +000067 * @param[in] a First input tensor (Matrix A). Data type supported: S8.
Anthony Barbier6ff3b192017-09-04 18:44:23 +010068 * @param[in] b Second input tensor (Matrix B). Data type supported: same as @p a
69 * @param[out] output Output tensor. Data type supported: same as @p a.
70 * @param[in] a_offset Offset to be added to each element of the matrix A.
71 * @param[in] b_offset Offset to be added to each element of the matrix B.
Gian Marco Iodiceab182122017-10-09 15:05:40 +010072 * @param[in] c_offset Offset to be added to each element of the output matrix
Anthony Barbier6ff3b192017-09-04 18:44:23 +010073 * @param[in] output_mult_int Value to be multiplied to each element of the output matrix
74 * @param[in] shift Number of bits to shift right the result.
75 */
Gian Marco Iodiceab182122017-10-09 15:05:40 +010076 void configure(const ITensor *a, const ITensor *b, ITensor *output, int32_t a_offset, int32_t b_offset, int32_t c_offset, int32_t output_mult_int, int32_t shift);
Pablo Tellobf2fb952017-09-29 16:43:25 +010077
Anthony Barbier6ff3b192017-09-04 18:44:23 +010078 // Inherited methods overridden:
79 void run() override;
80
81private:
Gian Marco Iodiceab182122017-10-09 15:05:40 +010082 MemoryGroup _memory_group;
83 NEGEMMLowpMatrixMultiplyCore _mm_func;
84 NEGEMMLowpMatrixAReductionKernel _mtx_a_reduction_kernel;
85 NEGEMMLowpMatrixBReductionKernel _mtx_b_reduction_kernel;
86 NEGEMMLowpFinalizeKernel _finalize_kernel;
87 Tensor _vector_sum_col;
88 Tensor _vector_sum_row;
89 Tensor _mm_output;
90 int32_t _a_offset;
91 int32_t _b_offset;
Anthony Barbier6ff3b192017-09-04 18:44:23 +010092};
93}
94#endif /*__ARM_COMPUTE_NEGEMMLOWP_H__ */