blob: 3976704907f99f2947d7da0633c90fbe5b0820a5 [file] [log] [blame]
Gian Marco05288a22017-11-21 10:57:50 +00001/*
2 * Copyright (c) 2017 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
27#include "arm_compute/core/CL/kernels/CLGEMMInterleave4x4Kernel.h"
28#include "arm_compute/core/CL/kernels/CLGEMMLowpMatrixMultiplyKernel.h"
29#include "arm_compute/core/CL/kernels/CLGEMMLowpOffsetContributionKernel.h"
30#include "arm_compute/core/CL/kernels/CLGEMMLowpReductionKernel.h"
31#include "arm_compute/core/CL/kernels/CLGEMMTranspose1xWKernel.h"
32#include "arm_compute/runtime/CL/CLMemoryGroup.h"
33#include "arm_compute/runtime/CL/CLTensor.h"
34#include "arm_compute/runtime/IFunction.h"
35
36namespace arm_compute
37{
38class IMemoryManager;
39class ICLTensor;
40
41/** Basic function to execute GEMMLowpMatrixMultiplyCore on OpenCL. This function calls the following OpenCL kernels:
42 *
43 * -# @ref CLGEMMInterleave4x4Kernel (if the output tensor is a matrix)
44 * -# @ref CLGEMMTranspose1xWKernel (if the output tensor is a matrix)
45 * -# @ref CLGEMMLowpMatrixMultiplyKernel
46 * -# @ref CLGEMMLowpMatrixAReductionKernel (if the offset of matrix B is not 0)
47 * -# @ref CLGEMMLowpMatrixBReductionKernel (if the offset of matrix A is not 0)
48 * -# @ref CLGEMMLowpOffsetContributionKernel
49 *
50*/
51class CLGEMMLowpMatrixMultiplyCore : public IFunction
52{
53public:
54 /** Constructor */
55 CLGEMMLowpMatrixMultiplyCore(std::shared_ptr<IMemoryManager> memory_manager = nullptr);
56 /** Initialise the kernel's inputs, output
57 *
58 * @note GEMM_LOWP: low precision GEMM kernel
59 * This kernel performs the following computations:
60 *
61 * -# Convert a values from QASYMM8 to int32 and add a_offset to each of them.
62 * -# Convert b values from QASYMM8 to int32 add b_offset to each of them.
63 * -# Compute the matrix product of the resulting a * b in int32.
64 *
Chunosov5124be52017-11-22 20:42:13 +070065 * @param[in] a First input tensor (Matrix A). Data type supported: QASYMM8.
66 * @param[in] b Second input tensor (Matrix B). Data type supported: same as @p a
67 * @param[out] output Output tensor. Data type supported: Data type supported: S32
68 * @param[in] gemm_info (Optional) Specifies if the matrix A and/or matrix B have been reshaped and
69 * if the reshape of matrix B should be executed only for the first run
Gian Marco05288a22017-11-21 10:57:50 +000070 */
Chunosov5124be52017-11-22 20:42:13 +070071 void configure(const ICLTensor *a, const ICLTensor *b, ICLTensor *output, const GEMMInfo &gemm_info = GEMMInfo());
Georgios Pinitas358ca202017-12-07 16:47:52 +000072 /** Static function to check if given info will lead to a valid configuration of @ref CLGEMMLowpMatrixMultiplyCore
73 *
74 * @param[in] a First input tensor (Matrix A). Data type supported: QASYMM8.
75 * @param[in] b Second input tensor (Matrix B). Data type supported: same as @p a
76 * @param[in] output Output tensor. Data type supported: Data type supported: S32
77 * @param[in] gemm_info (Optional) Specifies if the matrix A and/or matrix B have been reshaped and
78 * if the reshape of matrix B should be executed only for the first run
79 *
80 * @return a status
81 */
82 static Status validate(const ITensorInfo *a, const ITensorInfo *b, const ITensorInfo *output, const GEMMInfo &gemm_info = GEMMInfo());
Gian Marco05288a22017-11-21 10:57:50 +000083
84 // Inherited methods overridden:
85 void run() override;
86
87private:
88 CLMemoryGroup _memory_group;
89 CLGEMMLowpMatrixMultiplyKernel _mm_kernel;
90 CLGEMMInterleave4x4Kernel _mtx_a_reshape_kernel;
91 CLGEMMTranspose1xWKernel _mtx_b_reshape_kernel;
92 CLGEMMLowpMatrixAReductionKernel _mtx_a_reduction_kernel;
93 CLGEMMLowpMatrixBReductionKernel _mtx_b_reduction_kernel;
94 CLGEMMLowpOffsetContributionKernel _offset_contribution_kernel;
95 CLTensor _vector_sum_col;
96 CLTensor _vector_sum_row;
97 CLTensor _tmp_a;
98 CLTensor _tmp_b;
99 int32_t _a_offset;
100 int32_t _b_offset;
101 bool _is_interleaved_transposed;
Chunosov5124be52017-11-22 20:42:13 +0700102 bool _is_first_run;
103 bool _reshape_b_only_on_first_run;
Gian Marco05288a22017-11-21 10:57:50 +0000104};
105}
106#endif /*__ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYCORE_H__ */