Mohammed Suhail Munshi | a1b1e41 | 2023-03-23 22:21:31 +0000 | [diff] [blame] | 1 | /* |
| 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 Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 24 | #ifndef ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEMATMUL |
| 25 | #define ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEMATMUL |
Mohammed Suhail Munshi | a1b1e41 | 2023-03-23 22:21:31 +0000 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/runtime/IFunction.h" |
| 28 | #include <memory> |
| 29 | |
| 30 | namespace arm_compute |
| 31 | { |
| 32 | /** Settings for MatMul Cpu implementation*/ |
| 33 | class CpuMatMulSettings |
| 34 | { |
| 35 | public: |
| 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 | |
| 48 | private: |
| 49 | bool _fast_math{ false }; |
| 50 | }; |
| 51 | |
| 52 | // Forward declarations |
| 53 | class ITensor; |
| 54 | class ITensorInfo; |
| 55 | class MatMulInfo; |
| 56 | class Status; |
| 57 | |
| 58 | /** Basic function to run the following operators: |
| 59 | * |
| 60 | * -# @ref cpu::CpuMatMul |
| 61 | */ |
| 62 | class NEMatMul : public IFunction |
| 63 | { |
| 64 | public: |
| 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 Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 83 | * |lhs |rhs |dst | |
Mohammed Suhail Munshi | a1b1e41 | 2023-03-23 22:21:31 +0000 | [diff] [blame] | 84 | * |:--------------|:------------------|:--------------| |
| 85 | * |F32 |F32 |F32 | |
| 86 | * |F16 |F16 |F16 | |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 87 | * |QASYMM8_SIGNED |QASYMM8_SIGNED |QASYMM8_SIGNED | |
| 88 | * |QASYMM8 |QASYMM8 |QASYMM8 | |
Mohammed Suhail Munshi | a1b1e41 | 2023-03-23 22:21:31 +0000 | [diff] [blame] | 89 | * |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 90 | * @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 Munshi | a1b1e41 | 2023-03-23 22:21:31 +0000 | [diff] [blame] | 94 | * @param[in] settings Class containing flags for function level settings i.e fast math |
| 95 | */ |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 96 | void configure(ITensor *lhs, ITensor *rhs, ITensor *dst, const MatMulInfo &info, const CpuMatMulSettings &settings); |
Mohammed Suhail Munshi | a1b1e41 | 2023-03-23 22:21:31 +0000 | [diff] [blame] | 97 | /** 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 Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 103 | static Status validate(const ITensorInfo *lhs, const ITensorInfo *rhs, const ITensorInfo *dst, const MatMulInfo &info, const CpuMatMulSettings &settings); |
Mohammed Suhail Munshi | a1b1e41 | 2023-03-23 22:21:31 +0000 | [diff] [blame] | 104 | |
| 105 | // Inherited methods overridden |
| 106 | void run() override; |
| 107 | |
| 108 | private: |
| 109 | struct Impl; |
| 110 | std::unique_ptr<Impl> _impl; |
| 111 | }; |
| 112 | } |
Jakub Sujak | e9b3ee2 | 2023-04-17 12:08:48 +0100 | [diff] [blame] | 113 | #endif /* ACL_ARM_COMPUTE_RUNTIME_NEON_FUNCTIONS_NEMATMUL */ |