blob: 0f3e3adacc6b2361b7412b185e0ffc33cbb32b7e [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 */
24#ifndef ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEMATMUL
25#define ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEMATMUL
26
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:
83 * |src0 |src1 |dst |
84 * |:--------------|:------------------|:--------------|
85 * |F32 |F32 |F32 |
86 * |F16 |F16 |F16 |
87 *
88 * @param[in] lhs Input source tensor.
89 * @param[in] rhs Input source tensor.
90 * @param[out] output Output tensor. Data type supported: same as @p lhs/rhs
91 * @param[in] info Class containing flags to transpose lhs/rhs
92 * @param[in] settings Class containing flags for function level settings i.e fast math
93 */
94 void configure(ITensor *lhs, ITensor *rhs, ITensor *output, const MatMulInfo &info, const CpuMatMulSettings &settings);
95 /** Static function to check if given info will lead to a valid configuration of @ref NEMatMul
96 *
97 * Parameters are similar to @ref NEMatMul::configure()
98 *
99 * @return Status
100 */
101 static Status validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *output, const MatMulInfo &info, const CpuMatMulSettings &settings);
102
103 // Inherited methods overridden
104 void run() override;
105
106private:
107 struct Impl;
108 std::unique_ptr<Impl> _impl;
109};
110}
111#endif /* ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEMATMUL */