blob: f84d0638da9e4bf22c38eae59f3fd3f3dfd20be3 [file] [log] [blame]
Anthony Barbier6ff3b192017-09-04 18:44:23 +01001/*
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_CLGEMMLOWPMATRIXMULTIPLYKERNEL_H__
25#define __ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYKERNEL_H__
26
27#include "arm_compute/core/CL/ICLKernel.h"
28
29namespace arm_compute
30{
31class ICLTensor;
32
33/** OpenCL kernel to compute low precision matrix multiplication kernel
34 *
35 * This kernel performs the following computation:
36 * -# Convert a values from uint8 to int32 and add a_offset to each of them.
37 * -# Convert b values from uint8 to int32 and add b_offset to each of them.
38 * -# Compute the int32 matrix product of the resulting a * b.
39 * -# Add output_offset to each entry of the result.
40 * -# Multiply each entry of the result and round to the nearest integer
41 * -# Clamp the resulting int32 values to the [0..255] range and cast to uint8.
42 */
43class CLGEMMLowpMatrixMultiplyKernel : public ICLKernel
44{
45public:
46 /** Default Constructor */
47 CLGEMMLowpMatrixMultiplyKernel();
48 /** Prevent instances of this class from being copied (As this class contains pointers) */
49 CLGEMMLowpMatrixMultiplyKernel(const CLGEMMLowpMatrixMultiplyKernel &) = delete;
50 /** Prevent instances of this class from being copied (As this class contains pointers) */
51 CLGEMMLowpMatrixMultiplyKernel &operator=(const CLGEMMLowpMatrixMultiplyKernel &) = delete;
52 /** Allow instances of this class to be moved */
53 CLGEMMLowpMatrixMultiplyKernel(CLGEMMLowpMatrixMultiplyKernel &&) = default;
54 /** Allow instances of this class to be moved */
55 CLGEMMLowpMatrixMultiplyKernel &operator=(CLGEMMLowpMatrixMultiplyKernel &&) = default;
56 /** Initialise the kernel's input and output.
57 *
58 * The input matrices @p input0 and @p input1 must be the output of the kernels: @ref CLGEMMInterleave4x4Kernel and @ref CLGEMMTranspose1xWKernel.
59 * These two kernels change the layout of the original matrices to be more cache-friendly.
60 *
61 * @param[in] input0 Input tensor containing the interleaved Matrix A. Data types supported: U8
62 * @param[in] input1 Input tensor containing the transposed Matrix B. Data types supported: same as @p input0
63 * @param[out] output Output tensor to store the result of matrix multiplication, Data types supported: same as @p input0
64 * @param[in] a_offset Offset to be added to each element of the matrix A.
65 * @param[in] b_offset Offset to be added to each element of the matrix B.
66 * @param[in] output_offset Offset to be added to each element of the output matrix
67 * @param[in] output_mult_int Offset to be added to each element of the output matrix
68 * @param[in] shift Number of bits to shift right the result.
69 */
70 void configure(const ICLTensor *input0, const ICLTensor *input1, ICLTensor *output, int32_t a_offset, int32_t b_offset, int32_t output_offset, int32_t output_mult_int, int32_t shift);
71
72 // Inherited methods overridden:
73 void run(const Window &window, cl::CommandQueue &queue) override;
74
75private:
76 const ICLTensor *_input0;
77 const ICLTensor *_input1;
78 ICLTensor *_output;
79};
80}
81#endif /*__ARM_COMPUTE_CLGEMMLOWPMATRIXMULTIPLYKERNEL_H__*/