Compute Library
 21.05
NEGEMMAssemblyDispatch.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2021 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 SRC_NEGEMMASSEMBLYDISPATCH_H
25 #define SRC_NEGEMMASSEMBLYDISPATCH_H
26 
32 
33 namespace arm_compute
34 {
35 /* Convolution method supported by the assembly gemm interface */
36 enum class AsmConvMethod
37 {
38  Im2Col,
39  Indirect,
40  Conv
41 };
42 
44 {
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 
57 /** Assembly kernel glue */
59 {
60 public:
61  /** Constructor */
62  NEGEMMAssemblyDispatch(std::shared_ptr<IMemoryManager> memory_manager = nullptr, IWeightsManager *weights_manager = nullptr);
63  /** Prevent instances of this class from being copy constructed */
65  /** Prevent instances of this class from being copied */
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  };
79 
80 public:
81  /** If supported create a Compute Library function else fallback to the arm_gemm function.
82  *
83  * @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
88  */
89  void configure(const ITensor *a, const ITensor *b, const ITensor *c, ITensor *d, const AsmGemmInfo &info);
90 
91  /** Indicates whether or not this function can be used to process the given parameters.
92  *
93  * @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
98  *
99  * @return a status.
100  */
101  static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *d, const AsmGemmInfo &info);
102  /** 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);
109  /** Was the function successfully configured ?
110  *
111  * @return True if the function is configured and ready to run
112  */
113  bool is_configured() const;
114 
115  // Inherited methods overridden:
116  void prepare() override;
117  void run() override;
118 
119 private:
120  std::unique_ptr<IFallback> _arm_gemm; /**< Interface for the arm_gemm fallback */
121  MemoryGroup _memory_group; /**< Function memory group */
122  IWeightsManager *_weights_manager; /**< Pointer to the weights manager */
123 };
124 } // namespace arm_compute
125 #endif /* SRC_NEGEMMASSEMBLYDISPATCH_H */
Base class for all functions.
Definition: IFunction.h:30
NEGEMMAssemblyDispatch(std::shared_ptr< IMemoryManager > memory_manager=nullptr, IWeightsManager *weights_manager=nullptr)
Constructor.
ActivationLayerInfo activation_info
SimpleTensor< float > b
Definition: DFT.cpp:157
Store the tensor's metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
void run() override
Run the kernels contained in the function.
Activation Layer Information class.
Definition: Types.h:1478
Interface for CPU tensor.
Definition: ITensor.h:36
Copyright (c) 2017-2021 Arm Limited.
static bool is_activation_supported(const ActivationLayerInfo &activation)
Checks if activation is supported by the gemm assembly dispatcher.
void prepare() override
Prepare the function for executing.
NEGEMMAssemblyDispatch & operator=(const NEGEMMAssemblyDispatch &)=delete
Prevent instances of this class from being copied.
bool is_configured() const
Was the function successfully configured ?
GEMMLowp output stage info.
Definition: Types.h:1887
Padding and stride information class.
Definition: Types.h:650
static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *d, const AsmGemmInfo &info)
Indicates whether or not this function can be used to process the given parameters.
Weights manager interface to handle weights transformations.
GEMMLowpOutputStageInfo output_stage
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
void configure(const ITensor *a, const ITensor *b, const ITensor *c, ITensor *d, const AsmGemmInfo &info)
If supported create a Compute Library function else fallback to the arm_gemm function.