blob: 4094bc681e48817635ee914a0badb9844d1dc732 [file] [log] [blame]
Gian Marco Iodice4b908652018-10-18 10:21:02 +01001/*
Manuel Bottini959c26d2019-12-02 16:22:35 +00002 * Copyright (c) 2018-2020 ARM Limited.
Gian Marco Iodice4b908652018-10-18 10:21:02 +01003 *
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 */
Michalis Spyrouf4643372019-11-29 16:17:13 +000024#ifndef ARM_COMPUTE_CLGEMMLOWPOFFSETCONTRIBUTIONOUTPUTSTAGEKERNEL_H
25#define ARM_COMPUTE_CLGEMMLOWPOFFSETCONTRIBUTIONOUTPUTSTAGEKERNEL_H
Gian Marco Iodice4b908652018-10-18 10:21:02 +010026
27#include "arm_compute/core/CL/ICLKernel.h"
28
29namespace arm_compute
30{
31class ICLTensor;
32
33/** OpenCL kernel used to add the offset contribution after @ref CLGEMMLowpMatrixMultiplyKernel and perform the output stage.
34 *
35 * This kernel takes a final int32 accumulator value (the output of @ref CLGEMMLowpMatrixMultiplyKernel), adds to it the offset contribution
36 * of matrix A and matrix B and performs the output stage defined by the output_stage argument
37 *
Manuel Bottini959c26d2019-12-02 16:22:35 +000038 * @note For quantized computations the output data type for auto-initialization must be passed as part of the @ref GEMMLowpOutputStageInfo.
Gian Marco Iodice4b908652018-10-18 10:21:02 +010039 */
40class CLGEMMLowpOffsetContributionOutputStageKernel : public ICLKernel
41{
42public:
43 /** Constructor */
44 CLGEMMLowpOffsetContributionOutputStageKernel();
45 /** Prevent instances of this class from being copied (As this class contains pointers)*/
46 CLGEMMLowpOffsetContributionOutputStageKernel(const CLGEMMLowpOffsetContributionOutputStageKernel &) = delete;
47 /** Prevent instances of this class from being copied (As this class contains pointers)*/
48 CLGEMMLowpOffsetContributionOutputStageKernel &operator=(const CLGEMMLowpOffsetContributionOutputStageKernel &) = delete;
49 /** Allow instances of this class to be moved */
50 CLGEMMLowpOffsetContributionOutputStageKernel(CLGEMMLowpOffsetContributionOutputStageKernel &&) = default;
51 /** Allow instances of this class to be moved */
52 CLGEMMLowpOffsetContributionOutputStageKernel &operator=(CLGEMMLowpOffsetContributionOutputStageKernel &&) = default;
53 /** Initialise the kernel's input and output.
54 *
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +000055 * @param[in] mm_result Input tensor containing the result of @ref CLGEMMLowpMatrixMultiplyKernel. Data type supported: S32
56 * @param[in] vector_sum_col Input row-vector of sums of all the entries in each column of matrix B.
57 * Note: vector_sum_col can be a nullptr in case a_offset = 0. Data type supported: same as @p mm_result
58 * @param[in] vector_sum_row Input row-vector of sums of all the entries in each row of matrix A.
59 * Note: vector_sum_row can be a nullptr in case b_offset = 0. Data type supported: same as @p mm_result
60 * @param[in] bias Biases tensor. Only shared biases supported and it can be a nullptr if the addition of biases is not required.
61 * Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p input.
Manuel Bottini959c26d2019-12-02 16:22:35 +000062 * @param[out] output Output tensor. Data type supported: QASYMM8/QASYMM8_SIGNED.
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +000063 * @param[in] k Number of matrix A columns or Matrix B rows
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_stage GEMMLowp output stage info
67 * @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).
68 * Supported data types: S32
69 * @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).
70 * Supported data types: S32
Gian Marco Iodice4b908652018-10-18 10:21:02 +010071 */
72 void configure(const ICLTensor *mm_result, const ICLTensor *vector_sum_col, const ICLTensor *vector_sum_row, const ICLTensor *bias, ICLTensor *output, int32_t k, int32_t a_offset, int32_t b_offset,
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +000073 const GEMMLowpOutputStageInfo &output_stage, const ICLTensor *output_multipliers, const ICLTensor *output_shifts);
Gian Marco Iodice4b908652018-10-18 10:21:02 +010074 /** Static function to check if given info will lead to a valid configuration of @ref CLGEMMLowpOffsetContributionKernel
75 *
Manuel Bottini959c26d2019-12-02 16:22:35 +000076 * @param[in] mm_result Input tensor containing the result of @ref CLGEMMLowpOffsetContributionKernel. Data type supported: S32
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +000077 * @param[in] vector_sum_col Input row-vector of sums of all the entries in each column of matrix B.
78 * Note: vector_sum_col can be a nullptr in case a_offset = 0. Data type supported: same as @p mm_result
79 * @param[in] vector_sum_row Input row-vector of sums of all the entries in each row of matrix A.
80 * Note: vector_sum_row can be a nullptr in case b_offset = 0. Data type supported: same as @p mm_result
81 * @param[in] bias Biases tensor. Only shared biases supported and it can be a nullptr if the addition of biases is not required.
82 * Biases are 1D tensor with dimensions [OFM]. Data type supported: Same as @p input.
Manuel Bottini959c26d2019-12-02 16:22:35 +000083 * @param[in] output Output tensor. Data type supported: QASYMM8/QASYMM8_SIGNED.
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +000084 * @param[in] a_offset Offset to be added to each element of the matrix A.
85 * @param[in] b_offset Offset to be added to each element of the matrix B.
86 * @param[in] output_stage GEMMLowp output stage info
87 * @param[in] output_multipliers Output multipliers tensor info. In case of per-channel quantization, the number of multipliers must be equal to the number of filters (OFM).
88 * Supported data types: S32
89 * @param[in] output_shifts Output shifts tensor info. In case of per-channel quantization, the number of multipliers must be equal to the number of filters (OFM).
90 * Supported data types: S32
Gian Marco Iodice4b908652018-10-18 10:21:02 +010091 *
92 * @return a status
93 */
94 static Status validate(const ITensorInfo *mm_result, const ITensorInfo *vector_sum_col, const ITensorInfo *vector_sum_row, const ITensorInfo *bias, const ITensorInfo *output, int32_t a_offset,
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +000095 int32_t b_offset, const GEMMLowpOutputStageInfo &output_stage, const ITensorInfo *output_multipliers, const ITensorInfo *output_shifts);
Gian Marco Iodice4b908652018-10-18 10:21:02 +010096
97 // Inherited methods overridden:
98 void run(const Window &window, cl::CommandQueue &queue) override;
99
100private:
101 const ICLTensor *_mm_result;
102 const ICLTensor *_vector_sum_col;
103 const ICLTensor *_vector_sum_row;
104 const ICLTensor *_bias;
105 ICLTensor *_output;
Vidhya Sudhan Loganathan951b8a42019-11-04 14:42:08 +0000106 const ICLTensor *_output_multipliers;
107 const ICLTensor *_output_shifts;
108 bool _is_quantized_per_channel;
Gian Marco Iodice4b908652018-10-18 10:21:02 +0100109};
110} // namespace arm_compute
111
Michalis Spyrouf4643372019-11-29 16:17:13 +0000112#endif /* ARM_COMPUTE_CLGEMMLOWPOFFSETCONTRIBUTIONOUTPUTSTAGEKERNEL_H */