Debian Codegraph @

arm_compute/runtime/NEON/functions/NEMatMul.h

raw
1 /*
2 * Copyright (c) 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_NEMATMUL_H
25 #define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEMATMUL_H
26
27 #include "arm_compute/core/Types.h"
28 #include "arm_compute/function_info/ActivationLayerInfo.h"
29 #include "arm_compute/runtime/IFunction.h"
30 #include "arm_compute/runtime/MemoryManagerOnDemand.h"
31
32 #include <memory>
33
34 namespace arm_compute
35 {
36 /** Settings for MatMul Cpu implementation*/
37 class CpuMatMulSettings
38 {
39 public:
40 // get fast math flag
41 bool fast_math() const
42 {
43 return _fast_math;
44 }
45 // get fixed format flag
46 bool fixed_format() const
47 {
48 return _fixed_format;
49 }
50 // Set fast math flag
51 CpuMatMulSettings &fast_math(bool fmath)
52 {
53 _fast_math = fmath;
54 return *this;
55 }
56 // Set fixed format flag
57 CpuMatMulSettings &fixed_format(bool fixed_format)
58 {
59 _fixed_format = fixed_format;
60 return *this;
61 }
62
63 private:
64 bool _fast_math{false};
65 bool _fixed_format{false};
66 };
67
68 // Forward declarations
69 class ITensor;
70 class ITensorInfo;
71 class MatMulInfo;
72 class Status;
73
74 /** Basic function to run the following operators:
75 *
76 * -# cpu::CpuMatMul
77 */
78 class NEMatMul : public IFunction
79 {
80 public:
81 /** Constructor */
82 NEMatMul(std::shared_ptr<IMemoryManager> memory_manager);
83 NEMatMul() : NEMatMul(MemoryManagerOnDemand::make_default())
84 {
85 }
86 /** Destructor */
87 ~NEMatMul();
88 /** Prevent instances of this class from being copied (As this class contains pointers) */
89 NEMatMul(const NEMatMul &) = delete;
90 /** Default move constructor */
91 NEMatMul(NEMatMul &&) = default;
92 /** Prevent instances of this class from being copied (As this class contains pointers) */
93 NEMatMul &operator=(const NEMatMul &) = delete;
94 /** Default move assignment operator */
95 NEMatMul &operator=(NEMatMul &&) = default;
96 /** Initialize
97 *
98 * Valid data layouts:
99 * - Any
100 *
101 * Valid data type configurations:
102 * |lhs |rhs |dst |
103 * |:--------------|:------------------|:--------------|
104 * |F32 |F32 |F32 |
105 * |F16 |F16 |F16 |
106 * |BFLOAT16 |BFLOAT16 |BFLOAT16 |
107 * |QASYMM8_SIGNED |QASYMM8_SIGNED |QASYMM8_SIGNED |
108 * |QASYMM8 |QASYMM8 |QASYMM8 |
109 *
110 * @param[in] lhs Left-hand side tensor info. Data types supported: F16/F32/QASYMM8_SIGNED/QASYMM8.
111 * @param[in] rhs Right-hand side tensor info. Data types supported: same as @p lhs.
112 * @param[out] dst Output tensor to store the result of the batched matrix multiplication. Data types supported: same as @p lhs / @p rhs.
113 * @param[in] info Contains MatMul operation information described in @ref MatMulInfo.
114 * @param[in] settings Contains flags for function level settings i.e fast math
115 * @param[in] act_info (Optional) Contains activation function and lower and upper bound values for bounded activation functions.
116 */
117 void configure(ITensor *lhs,
118 ITensor *rhs,
119 ITensor *dst,
120 const MatMulInfo &info,
121 const CpuMatMulSettings &settings,
122 const ActivationLayerInfo &act_info = ActivationLayerInfo());
123 /** Static function to check if given info will lead to a valid configuration of @ref NEMatMul
124 *
125 * @param[in] lhs Left-hand side tensor info. Data types supported: F16/F32/QASYMM8_SIGNED/QASYMM8.
126 * @param[in] rhs Right-hand side tensor info. Data types supported: same as @p lhs.
127 * @param[out] dst Output tensor info to store the result of the batched matrix multiplication. Data types supported: same as @p lhs / @p rhs.
128 * @param[in] info Contains MatMul operation information described in @ref MatMulInfo.
129 * @param[in] settings Contains flags for function level settings i.e fast math
130 * @param[in] act_info (Optional) Contains activation function and lower and upper bound values for bounded activation functions.
131 *
132 * @return Status
133 */
134 static Status validate(const ITensorInfo *lhs,
135 const ITensorInfo *rhs,
136 const ITensorInfo *dst,
137 const MatMulInfo &info,
138 const CpuMatMulSettings &settings,
139 const ActivationLayerInfo &act_info = ActivationLayerInfo());
140
141 // Inherited methods overridden
142 void run() override;
143
144 private:
145 struct Impl;
146 std::unique_ptr<Impl> _impl;
147 };
148 } // namespace arm_compute
149 #endif // ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEMATMUL_H