Compute Library
 23.11
CLGEMMLowpMatrixMultiplyCore.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017-2021, 2023 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_CLGEMMLOWPMATRIXMULTIPLYCORE_H
25 #define ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYCORE_H
26 
31 
32 #include <memory>
33 
34 namespace arm_compute
35 {
36 class CLCompileContext;
37 class IMemoryManager;
38 class ICLTensor;
39 class ITensorInfo;
40 
41 /** Basic function to execute GEMMLowpMatrixMultiplyCore on OpenCL. */
43 {
44 public:
45  /** Constructor */
46  CLGEMMLowpMatrixMultiplyCore(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
47  /** Prevent instances of this class from being copied (As this class contains pointers) */
49  /** Default move constructor */
51  /** Prevent instances of this class from being copied (As this class contains pointers) */
53  /** Default move assignment operator */
55  /** Default destructor */
57  /** Initialise the kernel's inputs, output
58  *
59  * Valid data layouts:
60  * - NHWC
61  * - NCHW
62  *
63  * Valid data type configurations:
64  * |src0 |src1 |src2 |dst |
65  * |:--------------|:------------------|:--------|:--------------|
66  * |QASYMM8 |QASYMM8 |S32 |QASYMM8 |
67  * |QASYMM8 |QSYMM8_PER_CHANNEL |S32 |QASYMM8 |
68  * |QASYMM8 |QSYMM8 |S32 |QASYMM8 |
69  * |QASYMM8 |QASYMM8 |S32 |S32 |
70  * |QASYMM8 |QSYMM8_PER_CHANNEL |S32 |S32 |
71  * |QASYMM8 |QSYMM8 |S32 |S32 |
72  * |QASYMM8_SIGNED |QASYMM8_SIGNED |S32 |QASYMM8_SIGNED |
73  * |QASYMM8_SIGNED |QSYMM8_PER_CHANNEL |S32 |QASYMM8_SIGNED |
74  * |QASYMM8_SIGNED |QSYMM8 |S32 |QASYMM8_SIGNED |
75  * |QASYMM8_SIGNED |QASYMM8_SIGNED |S32 |S32 |
76  * |QASYMM8_SIGNED |QSYMM8_PER_CHANNEL |S32 |S32 |
77  * |QASYMM8_SIGNED |QSYMM8 |S32 |S32 |
78  *
79  * @note GEMMLowp: low precision GEMM kernel. [A * B + C]
80  * This kernel performs the following computations:
81  *
82  * -# Convert a values from 8-bit quantized to int32 and add a_offset to each of them.
83  * -# Convert b values from 8-bit quantized to int32 and add b_offset to each of them.
84  * -# Compute the matrix product of the resulting a * b in int32.
85  * -# Quantize to uint8 if gemm_info.gemmlowp_output_stage != NONE
86  *
87  * @param[in] a First input tensor (Matrix A). Data type supported: QASYMM8/QASYMM8_SIGNED.
88  * @param[in] b Second input tensor (Matrix B). Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8/QSYMM8_PER_CHANNEL
89  * @param[in] c Third input tensor (Matrix C). It can be a nullptr. Data type supported: S32
90  * @param[out] output Output tensor. Data type supported: S32 or QASYMM8/QASYMM8_SIGNED if gemm_info.gemmlowp_output_stage != NONE
91  * @param[in] gemm_info (Optional) Specifies if the matrix A and/or matrix B have been reshaped and
92  * if the reshape of matrix B should be executed only for the first run
93  */
94  void configure(const ICLTensor *a,
95  const ICLTensor *b,
96  const ICLTensor *c,
97  ICLTensor *output,
98  const GEMMInfo &gemm_info = GEMMInfo());
99  /** Initialise the kernel's inputs, output
100  *
101  * @note GEMMLowp: low precision GEMM kernel. [A * B + C]
102  * This kernel performs the following computations:
103  *
104  * -# Convert a values from 8-bit quantized to int32 and add a_offset to each of them.
105  * -# Convert b values from 8-bit quantized to int32 and add b_offset to each of them.
106  * -# Compute the matrix product of the resulting a * b in int32.
107  * -# Quantize to uint8 if gemm_info.gemmlowp_output_stage != NONE
108  *
109  * @param[in] compile_context The compile context to be used.
110  * @param[in] a First input tensor (Matrix A). Data type supported: QASYMM8/QASYMM8_SIGNED.
111  * @param[in] b Second input tensor (Matrix B). Data type supported: same as @p a
112  * @param[in] c Third input tensor (Matrix C). It can be a nullptr. Data type supported: S32
113  * @param[out] output Output tensor. Data type supported: S32 or QASYMM8/QASYMM8_SIGNED if gemm_info.gemmlowp_output_stage != NONE
114  * @param[in] gemm_info (Optional) Specifies if the matrix A and/or matrix B have been reshaped and
115  * if the reshape of matrix B should be executed only for the first run
116  */
117  void configure(const CLCompileContext &compile_context,
118  const ICLTensor *a,
119  const ICLTensor *b,
120  const ICLTensor *c,
121  ICLTensor *output,
122  const GEMMInfo &gemm_info = GEMMInfo());
123  /** Static function to check if given info will lead to a valid configuration of @ref CLGEMMLowpMatrixMultiplyCore
124  *
125  * @param[in] a First input tensor info (Matrix A). Data type supported: QASYMM8.
126  * @param[in] b Second input tensor info (Matrix B). Data type supported: QASYMM8/QASYMM8_SIGNED/QSYMM8/QSYMM8_PER_CHANNEL
127  * @param[in] c Third input tensor info (Matrix C). It can be a nullptr. Data type supported: S32
128  * @param[in] output Output tensor info. Data type supported: S32 or QASYMM8/QASYMM8_SIGNED if gemm_info.gemmlowp_output_stage != NONE
129  * @param[in] gemm_info (Optional) Specifies if the matrix A and/or matrix B have been reshaped and
130  * if the reshape of matrix B should be executed only for the first run
131  *
132  * @return a status
133  */
134  static Status validate(const ITensorInfo *a,
135  const ITensorInfo *b,
136  const ITensorInfo *c,
137  const ITensorInfo *output,
138  const GEMMInfo &gemm_info = GEMMInfo());
139 
140  // Inherited methods overridden:
141  void run() override;
142  void prepare() override;
143 
144 private:
145  struct Impl;
146  std::unique_ptr<Impl> _impl;
147 };
148 } // namespace arm_compute
149 #endif /*ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYCORE_H */
arm_compute::CLGEMMLowpMatrixMultiplyCore
Basic function to execute GEMMLowpMatrixMultiplyCore on OpenCL.
Definition: CLGEMMLowpMatrixMultiplyCore.h:42
arm_compute::CLGEMMLowpMatrixMultiplyCore::validate
static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *c, const ITensorInfo *output, const GEMMInfo &gemm_info=GEMMInfo())
Static function to check if given info will lead to a valid configuration of CLGEMMLowpMatrixMultiply...
Definition: CLGEMMLowpMatrixMultiplyCore.cpp:103
arm_compute::IFunction
Base class for all functions.
Definition: IFunction.h:30
arm_compute::ICLTensor
Interface for OpenCL tensor.
Definition: ICLTensor.h:41
arm_compute::CLGEMMLowpMatrixMultiplyCore::configure
void configure(const ICLTensor *a, const ICLTensor *b, const ICLTensor *c, ICLTensor *output, const GEMMInfo &gemm_info=GEMMInfo())
Initialise the kernel's inputs, output.
Definition: CLGEMMLowpMatrixMultiplyCore.cpp:66
arm_compute::GEMMInfo
GEMM information class.
Definition: GEMMInfo.h:69
arm_compute::CLGEMMLowpMatrixMultiplyCore::prepare
void prepare() override
Prepare the function for executing.
Definition: CLGEMMLowpMatrixMultiplyCore.cpp:121
arm_compute::CLGEMMLowpMatrixMultiplyCore::CLGEMMLowpMatrixMultiplyCore
CLGEMMLowpMatrixMultiplyCore(std::shared_ptr< IMemoryManager > memory_manager=nullptr)
Constructor.
Definition: CLGEMMLowpMatrixMultiplyCore.cpp:58
MemoryGroup.h
arm_compute::CLCompileContext
CLCompileContext class.
Definition: CLCompileContext.h:204
arm_compute::CLGEMMLowpMatrixMultiplyCore::run
void run() override
Run the kernels contained in the function.
Definition: CLGEMMLowpMatrixMultiplyCore.cpp:112
arm_compute::Status
Status class.
Definition: Error.h:52
IFunction.h
arm_compute::test::validation::b
SimpleTensor< float > b
Definition: DFT.cpp:157
arm_compute::CLGEMMLowpMatrixMultiplyCore::~CLGEMMLowpMatrixMultiplyCore
~CLGEMMLowpMatrixMultiplyCore()
Default destructor.
arm_compute
Copyright (c) 2017-2023 Arm Limited.
Definition: introduction.dox:24
CLTensor.h
arm_compute::ITensorInfo
Store the tensor's metadata.
Definition: ITensorInfo.h:44
GEMMInfo.h
arm_compute::CLGEMMLowpMatrixMultiplyCore::operator=
CLGEMMLowpMatrixMultiplyCore & operator=(const CLGEMMLowpMatrixMultiplyCore &)=delete
Prevent instances of this class from being copied (As this class contains pointers)