blob: ae0ae440d827536eaac302386b45068241c2dab9 [file] [log] [blame]
Anthony Barbier71d9b572018-07-06 17:05:59 +01001/*
Georgios Pinitas37d080f2019-06-21 18:43:12 +01002 * Copyright (c) 2018-2019 ARM Limited.
Anthony Barbier71d9b572018-07-06 17:05:59 +01003 *
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 Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_NEGEMMASSEMBLYDISPATCH_H
25#define ARM_COMPUTE_NEGEMMASSEMBLYDISPATCH_H
Anthony Barbier71d9b572018-07-06 17:05:59 +010026
27#include "arm_compute/core/NEON/kernels/assembly/NEGEMMAssemblyWrapperKernel.h"
28#include "arm_compute/runtime/IFunction.h"
29#include "arm_compute/runtime/IMemoryManager.h"
Michalis Spyrou1a569a32019-09-10 17:20:34 +010030#include "arm_compute/runtime/IWeightsManager.h"
Anthony Barbier71d9b572018-07-06 17:05:59 +010031#include "arm_compute/runtime/MemoryGroup.h"
32#include "arm_compute/runtime/Tensor.h"
33
34#include "arm_compute/core/NEON/kernels/assembly/arm_gemm.hpp"
35
36namespace arm_compute
37{
38/** Assembly kernel glue */
Anthony Barbier71d9b572018-07-06 17:05:59 +010039class NEGEMMAssemblyDispatch : public IFunction
40{
41public:
Michalis Spyrou1a569a32019-09-10 17:20:34 +010042 /** Constructor */
43 NEGEMMAssemblyDispatch(std::shared_ptr<IMemoryManager> memory_manager = nullptr, IWeightsManager *weights_manager = nullptr);
Anthony Barbier71d9b572018-07-06 17:05:59 +010044 /** Prevent instances of this class from being copy constructed */
Anthony Barbiereaefd002018-07-20 17:49:35 +010045 NEGEMMAssemblyDispatch(const NEGEMMAssemblyDispatch &) = delete;
Anthony Barbier71d9b572018-07-06 17:05:59 +010046 /** Prevent instances of this class from being copied */
Anthony Barbiereaefd002018-07-20 17:49:35 +010047 NEGEMMAssemblyDispatch &operator=(const NEGEMMAssemblyDispatch &) = delete;
48 NEGEMMAssemblyDispatch(NEGEMMAssemblyDispatch &&) = default;
49 NEGEMMAssemblyDispatch &operator=(NEGEMMAssemblyDispatch &&) = default;
50 ~NEGEMMAssemblyDispatch() = default;
51
52 class IFallback
53 {
54 public:
55 virtual void run() = 0;
56 virtual void prepare() = 0;
57 virtual bool is_configured() const = 0;
58 virtual ~IFallback() = default;
59 };
Anthony Barbier71d9b572018-07-06 17:05:59 +010060
61private:
Anthony Barbiereaefd002018-07-20 17:49:35 +010062 /** Interface for the arm_gemm fallback */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010063 std::unique_ptr<IFallback> _arm_gemm;
64 MemoryGroup _memory_group; /**< Function memory group */
65 IWeightsManager *_weights_manager; /**< Pointer to the weights manager */
Anthony Barbier71d9b572018-07-06 17:05:59 +010066public:
Anthony Barbierc8e84b52018-07-17 16:48:42 +010067 /** If supported create an ACL function else fallback to the arm_gemm function.
68 *
Georgios Pinitas37d080f2019-06-21 18:43:12 +010069 * @param[in] a Input tensor (Matrix A)
70 * @param[in] b Input tensor (Matrix B)
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010071 * @param[in] c Input tensor (Matrix C) used to pass the bias for quantized calculations
Georgios Pinitas37d080f2019-06-21 18:43:12 +010072 * @param[out] d Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0.
Georgios Pinitas37d080f2019-06-21 18:43:12 +010073 * @param[in] gemm_info GEMM meta-data
Anthony Barbierc8e84b52018-07-17 16:48:42 +010074 */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010075 void configure(const ITensor *a, const ITensor *b, const ITensor *c, ITensor *d, const GEMMInfo &gemm_info);
Anthony Barbiereaefd002018-07-20 17:49:35 +010076
77 /** Indicates whether or not this function can be used to process the given parameters.
78 *
Georgios Pinitascfa2bba2019-06-27 17:00:52 +010079 * @param[in] a Input tensor info (Matrix A)
80 * @param[in] b Input tensor info (Matrix B)
81 * @param[in] c Input tensor info (Matrix C) used to pass the bias for quantized calculations
Georgios Pinitas37d080f2019-06-21 18:43:12 +010082 * @param[in] d Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0.
Georgios Pinitas37d080f2019-06-21 18:43:12 +010083 * @param[in] gemm_info GEMM meta-data
Anthony Barbiereaefd002018-07-20 17:49:35 +010084 *
85 * @return a status.
86 */
Georgios Pinitas48b3ef82019-10-14 19:03:09 +010087 static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *d, const GEMMInfo &gemm_info);
88 /** Checks if activation is supported by the gemm assembly dispatcher
89 *
90 * @param[in] activation Activation to check
91 *
92 * @return True if activation is supported else false
93 */
94 static bool is_activation_supported(const ActivationLayerInfo &activation);
Anthony Barbierc8e84b52018-07-17 16:48:42 +010095 /** Was the function successfully configured ?
96 *
97 * @return True if the function is configured and ready to run
98 */
Anthony Barbier71d9b572018-07-06 17:05:59 +010099 bool is_configured() const;
100 // Inherited methods overridden:
101 /** Runs a preparation step, usually for pre-transposing matrix b */
102 void prepare() override;
103 void run() override;
104};
Anthony Barbierc8e84b52018-07-17 16:48:42 +0100105} // namespace arm_compute
Michalis Spyrouf4643372019-11-29 16:17:13 +0000106#endif /* ARM_COMPUTE_NEGEMMASSEMBLYDISPATCH_H */