Debian Codegraph @

arm_compute/runtime/NEON/functions/NEGEMMLowpMatrixMultiplyCore.h

raw
1 /*
2 * Copyright (c) 2017-2021, 2023-2024 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 ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEGEMMLOWPMATRIXMULTIPLYCORE_H
25 #define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEGEMMLOWPMATRIXMULTIPLYCORE_H
26
27 #include "arm_compute/core/Types.h"
28 #include "arm_compute/function_info/GEMMInfo.h"
29 #include "arm_compute/runtime/IFunction.h"
30 #include "arm_compute/runtime/IMemoryManager.h"
31 #include "arm_compute/runtime/IWeightsManager.h"
32 #include "arm_compute/runtime/MemoryManagerOnDemand.h"
33
34 #include <memory>
35
36 namespace arm_compute
37 {
38 class ITensor;
39 class ITensorInfo;
40
41 /** Function to run Gemm on quantized types.
42 *
43 * This function calls the following:
44 *
45 * -# cpu::CpuGemmLowpMatrixMultiplyCore
46 */
47 class NEGEMMLowpMatrixMultiplyCore : public IFunction
48 {
49 public:
50 /** Constructor */
51 NEGEMMLowpMatrixMultiplyCore(std::shared_ptr<IMemoryManager> memory_manager,
52 IWeightsManager *weights_manager = nullptr);
53 NEGEMMLowpMatrixMultiplyCore() : NEGEMMLowpMatrixMultiplyCore(MemoryManagerOnDemand::make_default())
54 {
55 }
56 /** Prevent instances of this class from being copied (As this class contains pointers) */
57 NEGEMMLowpMatrixMultiplyCore(const NEGEMMLowpMatrixMultiplyCore &) = delete;
58 /** Default move constructor */
59 NEGEMMLowpMatrixMultiplyCore(NEGEMMLowpMatrixMultiplyCore &&) = default;
60 /** Prevent instances of this class from being copied (As this class contains pointers) */
61 NEGEMMLowpMatrixMultiplyCore &operator=(const NEGEMMLowpMatrixMultiplyCore &) = delete;
62 /** Default move assignment operator */
63 NEGEMMLowpMatrixMultiplyCore &operator=(NEGEMMLowpMatrixMultiplyCore &&) = default;
64 /** Default destructor */
65 ~NEGEMMLowpMatrixMultiplyCore();
66 /** Initialise the kernel's inputs, output
67 *
68 * Valid data layouts:
69 * - NHWC
70 * - NCHW
71 *
72 * Valid data type configurations:
73 * |src0 |src1 |src2 |dst |
74 * |:--------------|:------------------|:--------|:--------------|
75 * |QASYMM8 |QASYMM8 |S32 |QASYMM8 |
76 * |QASYMM8 |QASYMM8_SIGNED |S32 |QASYMM8 |
77 * |QASYMM8 |QSYMM8_PER_CHANNEL |S32 |QASYMM8 |
78 * |QASYMM8 |QSYMM8 |S32 |QASYMM8 |
79 * |QASYMM8 |QASYMM8 |S32 |S32 |
80 * |QASYMM8 |QSYMM8_PER_CHANNEL |S32 |S32 |
81 * |QASYMM8 |QSYMM8 |S32 |S32 |
82 * |QASYMM8 |QASYMM8_SIGNED |F32 |F32 |
83 * |QASYMM8_SIGNED |QASYMM8_SIGNED |S32 |QASYMM8_SIGNED |
84 * |QASYMM8_SIGNED |QSYMM8_PER_CHANNEL |S32 |QASYMM8_SIGNED |
85 * |QASYMM8_SIGNED |QSYMM8 |S32 |QASYMM8_SIGNED |
86 * |QASYMM8_SIGNED |QASYMM8_SIGNED |S32 |S32 |
87 * |QASYMM8_SIGNED |QSYMM8_PER_CHANNEL |S32 |S32 |
88 * |QASYMM8_SIGNED |QSYMM8 |S32 |S32 |
89 * |QASYMM8_SIGNED |QASYMM8_SIGNED |F32 |F32 |
90 *
91 * @note GEMM_LOWP: low precision GEMM kernel
92 * This kernel performs the following computations:
93 *
94 * -# Convert a values from QASYMM8 to int32 and add a_offset to each of them.
95 * -# Convert b values from QASYMM8 to int32 add b_offset to each of them.
96 * -# Compute the matrix product of the resulting a * b in int32.
97 *
98 * @note The @p output type is S32 if @p gemm_info.type == GEMMLowpOutputStageType::NONE. It is QASYMM8/QASYMM8_SIGNED/F32 otherwise
99 *
100 * @param[in] a First input tensor (Matrix A). Data type supported: QASYMM8/QASYMM8_SIGNED.
101 * @param[in] b Second input tensor (Matrix B). Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8/QSYMM8_PER_CHANNEL.
102 * @param[in] c Third input tensor (Matrix C). It can be a nullptr. Data type supported: S32/F32
103 * @param[out] output Output tensor. Data type supported: Data type supported: S32/QASYMM8/QASYMM8_SIGNED/F32
104 * @param[in] gemm_info (Optional) Specifies if the matrix A and/or matrix B have been reshaped and
105 * if the reshape of matrix B should be executed only for the first run
106 */
107 void configure(
108 const ITensor *a, const ITensor *b, const ITensor *c, ITensor *output, const GEMMInfo &gemm_info = GEMMInfo());
109 /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMLowpMatrixMultiplyCore
110 *
111 * Similar to @ref NEGEMMLowpMatrixMultiplyCore::configure()
112 *
113 * @return a status
114 */
115 static Status validate(const ITensorInfo *a,
116 const ITensorInfo *b,
117 const ITensorInfo *c,
118 const ITensorInfo *output,
119 const GEMMInfo &gemm_info = GEMMInfo());
120
121 // Update of quantization information at the run stage so that the quantization multipliers can be properly calculated.
122 // Please have a look at NEGEMMConvolutionLayer.h for a more in-depth explanation and example.
123 void update_quantization_parameters();
124
125 // Inherited methods overridden
126 void run() override;
127 void prepare() override;
128
129 private:
130 struct Impl;
131 std::unique_ptr<Impl> _impl;
132 };
133 } // namespace arm_compute
134 #endif // ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEGEMMLOWPMATRIXMULTIPLYCORE_H