Compute Library
 21.08
CLGEMM.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2016-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 ARM_COMPUTE_CLGEMM_H
25 #define ARM_COMPUTE_CLGEMM_H
26 
33 
34 #include <memory>
35 
36 namespace arm_compute
37 {
38 // Forward declarations
39 class CLCompileContext;
40 class ICLTensor;
41 class ITensorInfo;
42 
43 /** Basic function to execute GEMM on OpenCL */
44 class CLGEMM : public IFunction
45 {
46 public:
47  /** Default constructor.
48  *
49  * @param[in] memory_manager (Optional) Memory manager.
50  * @param[in] weights_manager (Optional) Weights manager.
51  */
52  CLGEMM(std::shared_ptr<IMemoryManager> memory_manager = nullptr, IWeightsManager *weights_manager = nullptr);
53  /** Default destructor */
54  ~CLGEMM();
55  /** Prevent instances of this class from being copied (As this class contains pointers) */
56  CLGEMM(const CLGEMM &) = delete;
57  /** Default move constructor */
58  CLGEMM(CLGEMM &&);
59  /** Prevent instances of this class from being copied (As this class contains pointers) */
60  CLGEMM &operator=(const CLGEMM &) = delete;
61  /** Default move assignment operator */
62  CLGEMM &operator=(CLGEMM &&);
63  /** Initialise the kernel's inputs and output
64  *
65  * Valid data layouts:
66  * - All
67  *
68  * Valid data type configurations:
69  * |src0 |src1 |src2 |dst |
70  * |:------------|:-----------|:---------|:--------------|
71  * |F32 |F32 |F32 |F32 |
72  * |F16 |F16 |F16 |F16 |
73  *
74  * @note GEMM: General Matrix Multiply - [alpha * A * B + beta * C].
75  *
76  * @note All tensors must have the same data type.
77  *
78  * @note Whilst the first input tensor can be a vector, the second input tensor must be at least a matrix
79  *
80  * @param[in] compile_context The compile context to be used.
81  * @param[in] a First input tensor (Matrix or Vector A). Data types supported: F16/F32
82  * @param[in] b Second input tensor (Matrix B). Data type supported: same as @p a.
83  * @param[in] c Third input tensor (Matrix C). It can be a nullptr if just the multiplication between @p a and @p b is needed. Data type supported: same as @p a.
84  * @param[out] output Output tensor. Data type supported: same as @p a
85  * @param[in] alpha Weight of the matrix product
86  * @param[in] beta Weight of matrix C
87  * @param[in] gemm_info (Optional) Specifies if the matrix A and/or matrix B have been reshaped and
88  * if the reshape of matrix B should happen only for the first run. GEMMInfo also contains information about the reshaping
89  * in case matrix A and matrix B have been already transformed.
90  */
91  void configure(const CLCompileContext &compile_context, const ICLTensor *a, const ICLTensor *b, const ICLTensor *c, ICLTensor *output, float alpha, float beta, const GEMMInfo &gemm_info = GEMMInfo());
92 
93  /** Initialise the kernel's inputs and output
94  *
95  * Similar to @ref CLGEMM::configure()
96  */
97  void configure(const ICLTensor *a, const ICLTensor *b, const ICLTensor *c, ICLTensor *output, float alpha, float beta, const GEMMInfo &gemm_info = GEMMInfo());
98 
99  /** Static function to check if given info will lead to a valid configuration of @ref CLGEMM.
100  *
101  * Similar to @ref CLGEMM::configure()
102  *
103  * @return a status
104  */
105  static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *output, float alpha, float beta, const GEMMInfo &gemm_info = GEMMInfo());
106 
107  // Inherited methods overridden:
108  void run() override;
109  void prepare() override;
110 
111 private:
112  struct Impl;
113  std::unique_ptr<Impl> _impl;
114 };
115 } // namespace arm_compute
116 
117 #endif /* ARM_COMPUTE_CLGEMM_H */
void prepare() override
Prepare the function for executing.
Definition: CLGEMM.cpp:109
Base class for all functions.
Definition: IFunction.h:30
~CLGEMM()
Default destructor.
void run() override
Run the kernels contained in the function.
Definition: CLGEMM.cpp:100
SimpleTensor< float > b
Definition: DFT.cpp:157
CLGEMM(std::shared_ptr< IMemoryManager > memory_manager=nullptr, IWeightsManager *weights_manager=nullptr)
Default constructor.
Definition: CLGEMM.cpp:55
Store the tensor&#39;s metadata.
Definition: ITensorInfo.h:40
Status class.
Definition: Error.h:52
CLGEMM & operator=(const CLGEMM &)=delete
Prevent instances of this class from being copied (As this class contains pointers) ...
Copyright (c) 2017-2021 Arm Limited.
void configure(const CLCompileContext &compile_context, const ICLTensor *a, const ICLTensor *b, const ICLTensor *c, ICLTensor *output, float alpha, float beta, const GEMMInfo &gemm_info=GEMMInfo())
Initialise the kernel&#39;s inputs and output.
Definition: CLGEMM.cpp:69
Basic function to execute GEMM on OpenCL.
Definition: CLGEMM.h:44
Weights manager interface to handle weights transformations.
CLCompileContext class.
Interface for OpenCL tensor.
Definition: ICLTensor.h:42
static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *output, float alpha, float beta, const GEMMInfo &gemm_info=GEMMInfo())
Static function to check if given info will lead to a valid configuration of CLGEMM.
Definition: CLGEMM.cpp:95
GEMM information class.
Definition: Types.h:1939