Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 1 | /* |
Michele Di Giorgio | d9eaf61 | 2020-07-08 11:12:57 +0100 | [diff] [blame] | 2 | * Copyright (c) 2018-2020 Arm Limited. |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEGEMMASSEMBLYDISPATCH_H |
| 25 | #define ARM_COMPUTE_NEGEMMASSEMBLYDISPATCH_H |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 26 | |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 27 | #include "arm_compute/runtime/IFunction.h" |
| 28 | #include "arm_compute/runtime/IMemoryManager.h" |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 29 | #include "arm_compute/runtime/IWeightsManager.h" |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 30 | #include "arm_compute/runtime/MemoryGroup.h" |
| 31 | #include "arm_compute/runtime/Tensor.h" |
| 32 | |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 33 | namespace arm_compute |
| 34 | { |
| 35 | /** Assembly kernel glue */ |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 36 | class NEGEMMAssemblyDispatch : public IFunction |
| 37 | { |
| 38 | public: |
Michalis Spyrou | 1a569a3 | 2019-09-10 17:20:34 +0100 | [diff] [blame] | 39 | /** Constructor */ |
| 40 | NEGEMMAssemblyDispatch(std::shared_ptr<IMemoryManager> memory_manager = nullptr, IWeightsManager *weights_manager = nullptr); |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 41 | /** Prevent instances of this class from being copy constructed */ |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 42 | NEGEMMAssemblyDispatch(const NEGEMMAssemblyDispatch &) = delete; |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 43 | /** Prevent instances of this class from being copied */ |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 44 | NEGEMMAssemblyDispatch &operator=(const NEGEMMAssemblyDispatch &) = delete; |
| 45 | NEGEMMAssemblyDispatch(NEGEMMAssemblyDispatch &&) = default; |
| 46 | NEGEMMAssemblyDispatch &operator=(NEGEMMAssemblyDispatch &&) = default; |
| 47 | ~NEGEMMAssemblyDispatch() = default; |
| 48 | |
| 49 | class IFallback |
| 50 | { |
| 51 | public: |
| 52 | virtual void run() = 0; |
| 53 | virtual void prepare() = 0; |
| 54 | virtual bool is_configured() const = 0; |
| 55 | virtual ~IFallback() = default; |
| 56 | }; |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 57 | |
| 58 | private: |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 59 | /** Interface for the arm_gemm fallback */ |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 60 | std::unique_ptr<IFallback> _arm_gemm; |
| 61 | MemoryGroup _memory_group; /**< Function memory group */ |
| 62 | IWeightsManager *_weights_manager; /**< Pointer to the weights manager */ |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 63 | public: |
Anthony Barbier | c8e84b5 | 2018-07-17 16:48:42 +0100 | [diff] [blame] | 64 | /** If supported create an ACL function else fallback to the arm_gemm function. |
| 65 | * |
Georgios Pinitas | 37d080f | 2019-06-21 18:43:12 +0100 | [diff] [blame] | 66 | * @param[in] a Input tensor (Matrix A) |
| 67 | * @param[in] b Input tensor (Matrix B) |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 68 | * @param[in] c Input tensor (Matrix C) used to pass the bias for quantized calculations |
Georgios Pinitas | 37d080f | 2019-06-21 18:43:12 +0100 | [diff] [blame] | 69 | * @param[out] d Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0. |
Georgios Pinitas | 37d080f | 2019-06-21 18:43:12 +0100 | [diff] [blame] | 70 | * @param[in] gemm_info GEMM meta-data |
Anthony Barbier | c8e84b5 | 2018-07-17 16:48:42 +0100 | [diff] [blame] | 71 | */ |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 72 | void configure(const ITensor *a, const ITensor *b, const ITensor *c, ITensor *d, const GEMMInfo &gemm_info); |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 73 | |
| 74 | /** Indicates whether or not this function can be used to process the given parameters. |
| 75 | * |
Georgios Pinitas | cfa2bba | 2019-06-27 17:00:52 +0100 | [diff] [blame] | 76 | * @param[in] a Input tensor info (Matrix A) |
| 77 | * @param[in] b Input tensor info (Matrix B) |
| 78 | * @param[in] c Input tensor info (Matrix C) used to pass the bias for quantized calculations |
Georgios Pinitas | 37d080f | 2019-06-21 18:43:12 +0100 | [diff] [blame] | 79 | * @param[in] d Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0. |
Georgios Pinitas | 37d080f | 2019-06-21 18:43:12 +0100 | [diff] [blame] | 80 | * @param[in] gemm_info GEMM meta-data |
Anthony Barbier | eaefd00 | 2018-07-20 17:49:35 +0100 | [diff] [blame] | 81 | * |
| 82 | * @return a status. |
| 83 | */ |
Georgios Pinitas | 48b3ef8 | 2019-10-14 19:03:09 +0100 | [diff] [blame] | 84 | static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *d, const GEMMInfo &gemm_info); |
| 85 | /** Checks if activation is supported by the gemm assembly dispatcher |
| 86 | * |
| 87 | * @param[in] activation Activation to check |
| 88 | * |
| 89 | * @return True if activation is supported else false |
| 90 | */ |
| 91 | static bool is_activation_supported(const ActivationLayerInfo &activation); |
Anthony Barbier | c8e84b5 | 2018-07-17 16:48:42 +0100 | [diff] [blame] | 92 | /** Was the function successfully configured ? |
| 93 | * |
| 94 | * @return True if the function is configured and ready to run |
| 95 | */ |
Anthony Barbier | 71d9b57 | 2018-07-06 17:05:59 +0100 | [diff] [blame] | 96 | bool is_configured() const; |
| 97 | // Inherited methods overridden: |
| 98 | /** Runs a preparation step, usually for pre-transposing matrix b */ |
| 99 | void prepare() override; |
| 100 | void run() override; |
| 101 | }; |
Anthony Barbier | c8e84b5 | 2018-07-17 16:48:42 +0100 | [diff] [blame] | 102 | } // namespace arm_compute |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 103 | #endif /* ARM_COMPUTE_NEGEMMASSEMBLYDISPATCH_H */ |