blob: a331c55a98865c193fa93fceb27ae83c9b354799 [file] [log] [blame]
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +00001/*
2 * Copyright (c) 2023 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 */
Jakub Sujake9b3ee22023-04-17 12:08:48 +010024#ifndef ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEMATMUL
25#define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEMATMUL
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000026
27#include "arm_compute/runtime/IFunction.h"
28#include <memory>
29
30namespace arm_compute
31{
32/** Settings for MatMul Cpu implementation*/
33class CpuMatMulSettings
34{
35public:
36 // get fast math flag
37 bool fast_math() const
38 {
39 return _fast_math;
40 }
41 // Set fast math flag
42 CpuMatMulSettings &fast_math(bool fmath)
43 {
44 _fast_math = fmath;
45 return *this;
46 };
47
48private:
49 bool _fast_math{ false };
50};
51
52// Forward declarations
53class ITensor;
54class ITensorInfo;
55class MatMulInfo;
56class Status;
57
58/** Basic function to run the following operators:
59 *
60 * -# @ref cpu::CpuMatMul
61 */
62class NEMatMul : public IFunction
63{
64public:
65 /** Constructor */
66 NEMatMul();
67 /** Destructor */
68 ~NEMatMul();
69 /** Prevent instances of this class from being copied (As this class contains pointers) */
70 NEMatMul(const NEMatMul &) = delete;
71 /** Default move constructor */
72 NEMatMul(NEMatMul &&) = default;
73 /** Prevent instances of this class from being copied (As this class contains pointers) */
74 NEMatMul &operator=(const NEMatMul &) = delete;
75 /** Default move assignment operator */
76 NEMatMul &operator=(NEMatMul &&) = default;
77 /** Initialize
78 *
79 * Valid data layouts:
80 * - Any
81 *
82 * Valid data type configurations:
Jakub Sujake9b3ee22023-04-17 12:08:48 +010083 * |lhs |rhs |dst |
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000084 * |:--------------|:------------------|:--------------|
85 * |F32 |F32 |F32 |
86 * |F16 |F16 |F16 |
Jakub Sujake9b3ee22023-04-17 12:08:48 +010087 * |QASYMM8_SIGNED |QASYMM8_SIGNED |QASYMM8_SIGNED |
88 * |QASYMM8 |QASYMM8 |QASYMM8 |
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000089 *
Jakub Sujake9b3ee22023-04-17 12:08:48 +010090 * @param[in] lhs Left-hand side tensor info. Data types supported: F16/F32/QASYMM8_SIGNED/QASYMM8.
91 * @param[in] rhs Right-hand side tensor info. Data types supported: same as @p lhs.
92 * @param[out] dst Output tensor to store the result of the batched matrix multiplication. Data types supported: same as @p lhs / @p rhs.
93 * @param[in] info Contains MatMul operation information described in @ref MatMulInfo.
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000094 * @param[in] settings Class containing flags for function level settings i.e fast math
95 */
Jakub Sujake9b3ee22023-04-17 12:08:48 +010096 void configure(ITensor *lhs, ITensor *rhs, ITensor *dst, const MatMulInfo &info, const CpuMatMulSettings &settings);
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +000097 /** Static function to check if given info will lead to a valid configuration of @ref NEMatMul
98 *
99 * Parameters are similar to @ref NEMatMul::configure()
100 *
101 * @return Status
102 */
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100103 static Status validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *dst, const MatMulInfo &info, const CpuMatMulSettings &settings);
Mohammed Suhail Munshia1b1e412023-03-23 22:21:31 +0000104
105 // Inherited methods overridden
106 void run() override;
107
108private:
109 struct Impl;
110 std::unique_ptr<Impl> _impl;
111};
112}
Jakub Sujake9b3ee22023-04-17 12:08:48 +0100113#endif /* ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEMATMUL */