blob: 381fa4de311a6880655c5467ca16c06b941dcd89 [file] [log] [blame]
Anthony Barbier71d9b572018-07-06 17:05:59 +01001/*
Georgios Pinitas2ee98012021-02-15 20:42:39 +00002 * Copyright (c) 2018-2021 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 */
Georgios Pinitasec2256b2020-12-03 18:51:58 +000024#ifndef SRC_NEGEMMASSEMBLYDISPATCH_H
25#define SRC_NEGEMMASSEMBLYDISPATCH_H
Anthony Barbier71d9b572018-07-06 17:05:59 +010026
Anthony Barbier71d9b572018-07-06 17:05:59 +010027#include "arm_compute/runtime/IFunction.h"
28#include "arm_compute/runtime/IMemoryManager.h"
Michalis Spyrou1a569a32019-09-10 17:20:34 +010029#include "arm_compute/runtime/IWeightsManager.h"
Anthony Barbier71d9b572018-07-06 17:05:59 +010030#include "arm_compute/runtime/MemoryGroup.h"
31#include "arm_compute/runtime/Tensor.h"
32
Anthony Barbier71d9b572018-07-06 17:05:59 +010033namespace arm_compute
34{
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000035/* Convolution method supported by the assembly gemm interface */
36enum class AsmConvMethod
37{
38 Im2Col,
39 Indirect,
40 Conv
41};
42
43struct AsmGemmInfo
44{
45 AsmConvMethod method{ AsmConvMethod::Im2Col };
46 PadStrideInfo ps_info{};
47 ActivationLayerInfo activation_info{};
48 GEMMLowpOutputStageInfo output_stage{};
49 bool negated_offsets{ true };
50 bool reinterpret_input_as_3d{ false };
51 bool depth_output_gemm3d{ false };
52 int64_t padding_top{ 0 };
53 int64_t padding_left{ 0 };
54 float padding_value{ 0.f };
55};
56
Anthony Barbier71d9b572018-07-06 17:05:59 +010057/** Assembly kernel glue */
Anthony Barbier71d9b572018-07-06 17:05:59 +010058class NEGEMMAssemblyDispatch : public IFunction
59{
60public:
Michalis Spyrou1a569a32019-09-10 17:20:34 +010061 /** Constructor */
62 NEGEMMAssemblyDispatch(std::shared_ptr<IMemoryManager> memory_manager = nullptr, IWeightsManager *weights_manager = nullptr);
Anthony Barbier71d9b572018-07-06 17:05:59 +010063 /** Prevent instances of this class from being copy constructed */
Anthony Barbiereaefd002018-07-20 17:49:35 +010064 NEGEMMAssemblyDispatch(const NEGEMMAssemblyDispatch &) = delete;
Anthony Barbier71d9b572018-07-06 17:05:59 +010065 /** Prevent instances of this class from being copied */
Anthony Barbiereaefd002018-07-20 17:49:35 +010066 NEGEMMAssemblyDispatch &operator=(const NEGEMMAssemblyDispatch &) = delete;
67 NEGEMMAssemblyDispatch(NEGEMMAssemblyDispatch &&) = default;
68 NEGEMMAssemblyDispatch &operator=(NEGEMMAssemblyDispatch &&) = default;
69 ~NEGEMMAssemblyDispatch() = default;
70
71 class IFallback
72 {
73 public:
74 virtual void run() = 0;
75 virtual void prepare() = 0;
76 virtual bool is_configured() const = 0;
77 virtual ~IFallback() = default;
78 };
Anthony Barbier71d9b572018-07-06 17:05:59 +010079
Anthony Barbier71d9b572018-07-06 17:05:59 +010080public:
Michele Di Giorgio57f30a92020-09-08 14:03:51 +010081 /** If supported create a Compute Library function else fallback to the arm_gemm function.
Anthony Barbierc8e84b52018-07-17 16:48:42 +010082 *
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000083 * @param[in] a Input tensor (Matrix A)
84 * @param[in] b Input tensor (Matrix B)
85 * @param[in] c Input tensor (Matrix C) used to pass the bias for quantized calculations
86 * @param[out] d Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0.
87 * @param[in] info GEMM meta-data
Anthony Barbierc8e84b52018-07-17 16:48:42 +010088 */
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000089 void configure(const ITensor *a, const ITensor *b, const ITensor *c, ITensor *d, const AsmGemmInfo &info);
Anthony Barbiereaefd002018-07-20 17:49:35 +010090
91 /** Indicates whether or not this function can be used to process the given parameters.
92 *
Georgios Pinitasc0b6f762020-11-02 01:37:17 +000093 * @param[in] a Input tensor info (Matrix A)
94 * @param[in] b Input tensor info (Matrix B)
95 * @param[in] c Input tensor info (Matrix C) used to pass the bias for quantized calculations
96 * @param[in] d Output tensor to store the result of matrix multiplication. Data type supported: same as @p input0.
97 * @param[in] info GEMM meta-data
Anthony Barbiereaefd002018-07-20 17:49:35 +010098 *
99 * @return a status.
100 */
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000101 static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *d, const AsmGemmInfo &info);
Georgios Pinitas48b3ef82019-10-14 19:03:09 +0100102 /** Checks if activation is supported by the gemm assembly dispatcher
103 *
104 * @param[in] activation Activation to check
105 *
106 * @return True if activation is supported else false
107 */
108 static bool is_activation_supported(const ActivationLayerInfo &activation);
Anthony Barbierc8e84b52018-07-17 16:48:42 +0100109 /** Was the function successfully configured ?
110 *
111 * @return True if the function is configured and ready to run
112 */
Anthony Barbier71d9b572018-07-06 17:05:59 +0100113 bool is_configured() const;
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000114
Anthony Barbier71d9b572018-07-06 17:05:59 +0100115 // Inherited methods overridden:
Anthony Barbier71d9b572018-07-06 17:05:59 +0100116 void prepare() override;
117 void run() override;
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000118
119private:
Georgios Pinitas2ee98012021-02-15 20:42:39 +0000120 std::unique_ptr<IFallback> _arm_gemm; /**< Interface for the arm_gemm fallback */
Georgios Pinitasc0b6f762020-11-02 01:37:17 +0000121 MemoryGroup _memory_group; /**< Function memory group */
122 IWeightsManager *_weights_manager; /**< Pointer to the weights manager */
Anthony Barbier71d9b572018-07-06 17:05:59 +0100123};
Anthony Barbierc8e84b52018-07-17 16:48:42 +0100124} // namespace arm_compute
Georgios Pinitasec2256b2020-12-03 18:51:58 +0000125#endif /* SRC_NEGEMMASSEMBLYDISPATCH_H */