blob: 97ee9bc97f0fb686082b3f30e94fff8a509126a7 [file] [log] [blame]
Georgios Pinitas4a578b92021-06-25 12:13:49 +01001/*
2 * Copyright (c) 2018-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_CL_GEMMLOWP_OFFSET_CONTRIBUTION_OUTPUT_STAGE_KERNEL_H
25#define ARM_COMPUTE_CL_GEMMLOWP_OFFSET_CONTRIBUTION_OUTPUT_STAGE_KERNEL_H
26
27#include "src/core/common/Macros.h"
Georgios Pinitas7891a732021-08-20 21:39:25 +010028#include "src/gpu/cl/ClCompileContext.h"
29#include "src/gpu/cl/IClKernel.h"
Georgios Pinitas4a578b92021-06-25 12:13:49 +010030
31namespace arm_compute
32{
33namespace opencl
34{
35namespace kernels
36{
37/** OpenCL kernel used to add the offset contribution after the matrix multiplication and perform the output stage.
38 *
39 * This kernel takes a final int32 accumulator value (the output of the matrix multiplication), adds to it the offset contribution
40 * of matrix A and matrix B and performs the output stage defined by the output_stage argument
41 *
42 * @note For quantized computations the output data type for auto-initialization must be passed as part of the @ref GEMMLowpOutputStageInfo.
43 */
44class ClGemmLowpOffsetContributionOutputStageKernel : public IClKernel
45{
46public:
47 ClGemmLowpOffsetContributionOutputStageKernel();
48 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(ClGemmLowpOffsetContributionOutputStageKernel);
49 /** Initialise the kernel's input and output.
50 *
51 * @param[in] compile_context The compile context to be used.
52 * @param[in] mm_result Input tensor containing the result of the matrix multiplication. Data type supported: S32
53 * @param[in] vector_sum_col Input row-vector of sums of all the entries in each column of matrix B.
54 * Note: vector_sum_col can be a nullptr in case a_offset = 0. Data type supported: same as @p mm_result
55 * @param[in] vector_sum_row Input row-vector of sums of all the entries in each row of matrix A.
56 * Note: vector_sum_row can be a nullptr in case b_offset = 0. Data type supported: same as @p mm_result
57 * @param[in] bias Biases tensor. Only shared biases supported and it can be a nullptr if the addition of biases is not required.
58 * Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p mm_result.
59 * @param[out] dst Destination tensor. Data type supported: QASYMM8/QASYMM8_SIGNED.
60 * @param[in] k Number of matrix A columns or Matrix B rows
61 * @param[in] a_offset Offset to be added to each element of the matrix A.
62 * @param[in] b_offset Offset to be added to each element of the matrix B.
63 * @param[in] output_stage GEMMLowp output stage info
64 * @param[in] output_multipliers Output multipliers tensor. In case of per-channel quantization, the number of multipliers must be equal to the number of filters (OFM).
65 * Supported data types: S32
66 * @param[in] output_shifts Output shifts tensor. In case of per-channel quantization, the number of multipliers must be equal to the number of filters (OFM).
67 * Supported data types: S32
68 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010069 void configure(const CLCompileContext &compile_context,
70 const ITensorInfo *mm_result,
71 const ITensorInfo *vector_sum_col,
72 const ITensorInfo *vector_sum_row,
73 const ITensorInfo *bias,
74 ITensorInfo *dst,
75 int32_t k,
76 int32_t a_offset,
77 int32_t b_offset,
78 const GEMMLowpOutputStageInfo &output_stage,
79 const ITensorInfo *output_multipliers,
80 const ITensorInfo *output_shifts);
Georgios Pinitas4a578b92021-06-25 12:13:49 +010081 /** Static function to check if given info will lead to a valid configuration
82 *
83 * Similar to @ref ClGemmLowpOffsetContributionOutputStageKernel::configure()
84 *
85 * @return a status
86 */
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010087 static Status validate(const ITensorInfo *mm_result,
88 const ITensorInfo *vector_sum_col,
89 const ITensorInfo *vector_sum_row,
90 const ITensorInfo *bias,
91 const ITensorInfo *dst,
92 int32_t a_offset,
93 int32_t b_offset,
94 const GEMMLowpOutputStageInfo &output_stage,
95 const ITensorInfo *output_multipliers,
96 const ITensorInfo *output_shifts);
Georgios Pinitas4a578b92021-06-25 12:13:49 +010097
98 // Inherited methods overridden:
99 void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override;
100
101private:
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +0100102 bool _is_quantized_per_channel{false};
Georgios Pinitas4a578b92021-06-25 12:13:49 +0100103};
104} // namespace kernels
105} // namespace opencl
106} // namespace arm_compute
107#endif /* ARM_COMPUTE_CL_GEMMLOWP_OFFSET_CONTRIBUTION_OUTPUT_STAGE_KERNEL_H */