blob: 9944afeac7f74626ac933e716d8036f9cb1572ba [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 *
65 * @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 */
69 void configure(const ICLTensor *a, const ICLTensor *b, ICLTensor *output);
70
71 // Inherited methods overridden:
72 void run() override;
73
74private:
75 CLMemoryGroup _memory_group;
76 CLGEMMLowpMatrixMultiplyKernel _mm_kernel;
77 CLGEMMInterleave4x4Kernel _mtx_a_reshape_kernel;
78 CLGEMMTranspose1xWKernel _mtx_b_reshape_kernel;
79 CLGEMMLowpMatrixAReductionKernel _mtx_a_reduction_kernel;
80 CLGEMMLowpMatrixBReductionKernel _mtx_b_reduction_kernel;
81 CLGEMMLowpOffsetContributionKernel _offset_contribution_kernel;
82 CLTensor _vector_sum_col;
83 CLTensor _vector_sum_row;
84 CLTensor _tmp_a;
85 CLTensor _tmp_b;
86 int32_t _a_offset;
87 int32_t _b_offset;
88 bool _is_interleaved_transposed;
89};
90}
91#endif /*__ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYCORE_H__ */