Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 1 | /* |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 ARM Limited. |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 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 | */ |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 24 | #ifndef ARM_COMPUTE_NEGEMMLOWREDUCTIONKERNEL_H |
| 25 | #define ARM_COMPUTE_NEGEMMLOWREDUCTIONKERNEL_H |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 26 | |
| 27 | #include "arm_compute/core/NEON/INEKernel.h" |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | class ITensor; |
| 32 | |
| 33 | /** Common interface for all NEON reduction kernels */ |
| 34 | class INEGEMMLowpReductionKernel : public INEKernel |
| 35 | { |
| 36 | public: |
| 37 | /** Constructor */ |
| 38 | INEGEMMLowpReductionKernel(); |
| 39 | /** Prevent instances of this class from being copied (As this class contains pointers)*/ |
| 40 | INEGEMMLowpReductionKernel(const INEGEMMLowpReductionKernel &) = delete; |
| 41 | /** Prevent instances of this class from being copied (As this class contains pointers)*/ |
| 42 | INEGEMMLowpReductionKernel &operator=(const INEGEMMLowpReductionKernel &) = delete; |
| 43 | /** Allow instances of this class to be moved */ |
| 44 | INEGEMMLowpReductionKernel(INEGEMMLowpReductionKernel &&) = default; |
| 45 | /** Allow instances of this class to be moved */ |
| 46 | INEGEMMLowpReductionKernel &operator=(INEGEMMLowpReductionKernel &&) = default; |
| 47 | |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 48 | /** Initialise the kernel's input and output. |
| 49 | * |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 50 | * @param[in] input Input tensor. Data type supported: QASYMM8/QASYMM8_SIGNED |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 51 | * @param[out] output Output row-vector of sums of all the entries in each row/col of input tensor. Data type supported: S32 |
| 52 | * @param[in] k Number of matrix A columns (or matrix B rows) |
| 53 | * @param[in] is_reshaped True if the input tensor has been reshaped |
| 54 | */ |
| 55 | virtual void configure(const ITensor *input, ITensor *output, int32_t k, bool is_reshaped) = 0; |
| 56 | |
| 57 | protected: |
| 58 | const ITensor *_input; |
| 59 | ITensor *_output; |
| 60 | int32_t _k; |
| 61 | bool _is_reshaped; |
| 62 | }; |
| 63 | |
| 64 | /** NEON kernel used to compute the row-vectors of sums of all the entries in each row of Matrix A. |
| 65 | * |
| 66 | * @note This stage is needed to handle the offset of matrix product |
| 67 | * https://github.com/google/gemmlowp/blob/master/doc/low-precision.md |
| 68 | */ |
| 69 | class NEGEMMLowpMatrixAReductionKernel : public INEGEMMLowpReductionKernel |
| 70 | { |
| 71 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 72 | const char *name() const override |
| 73 | { |
| 74 | return "NEGEMMLowpMatrixAReductionKernel"; |
| 75 | } |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 76 | /** Initialise the kernel's input and output. |
| 77 | * |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 78 | * @param[in] mtx_a Input tensor. Data type supported: QASYMM8/QASYMM8_SIGNED |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 79 | * @param[out] vector_sum_row Output row-vector of sums of all the entries in each row of mtx_a. Data type supported: S32 |
| 80 | * @param[in] num_mtx_a_cols Number of matrix A columns |
| 81 | * @param[in] is_interleaved4x4 True if the matrix A has been interleaved4x4 |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 82 | */ |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 83 | void configure(const ITensor *mtx_a, ITensor *vector_sum_row, int32_t num_mtx_a_cols, bool is_interleaved4x4) override; |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 84 | /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMLowpMatrixAReductionKernel |
| 85 | * |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 86 | * @param[in] mtx_a Input tensor. Data type supported: QASYMM8/QASYMM8_SIGNED |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 87 | * @param[in] vector_sum_row Output row-vector of sums of all the entries in each row of mtx_a. Data type supported: S32 |
| 88 | * @param[in] num_mtx_a_cols Number of matrix A columns |
| 89 | * @param[in] is_interleaved4x4 True if the matrix A has been interleaved4x4 |
| 90 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 91 | * @return a status |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 92 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 93 | static Status validate(const ITensorInfo *mtx_a, const ITensorInfo *vector_sum_row, int32_t num_mtx_a_cols, bool is_interleaved4x4); |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 94 | |
| 95 | // Inherited methods overridden: |
| 96 | void run(const Window &window, const ThreadInfo &info) override; |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 97 | |
| 98 | private: |
| 99 | /** Execution of the reduction kernel specialized on the input type |
| 100 | * |
| 101 | * @param[in] window Execution window |
| 102 | */ |
| 103 | template <typename T> |
| 104 | void run_internal(const Window &window); |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | /** NEON kernel used to compute the row-vectors of sums of all the entries in each column of Matrix B. |
| 108 | * |
| 109 | * @note This stage is needed to handle the offset of matrix product |
| 110 | * https://github.com/google/gemmlowp/blob/master/doc/low-precision.md |
| 111 | */ |
| 112 | class NEGEMMLowpMatrixBReductionKernel : public INEGEMMLowpReductionKernel |
| 113 | { |
| 114 | public: |
Anthony Barbier | e8a4983 | 2018-01-18 10:04:05 +0000 | [diff] [blame] | 115 | const char *name() const override |
| 116 | { |
| 117 | return "NEGEMMLowpMatrixBReductionKernel"; |
| 118 | } |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 119 | /** Initialise the kernel's input and output. |
| 120 | * |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 121 | * @param[in] mtx_b Input tensor. Data type supported: Data type supported: QASYMM8/QASYMM8_SIGNED |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 122 | * @param[out] vector_sum_col Output row-vector of sums of all the entries in each column of mtx_b. Data type supported: S32 |
| 123 | * @param[in] num_mtx_b_rows Number of matrix B rows |
| 124 | * @param[in] is_transposed1xW True if the input tensor is transposed 1xW |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 125 | */ |
Gian Marco | e75a02b | 2017-11-08 12:24:09 +0000 | [diff] [blame] | 126 | void configure(const ITensor *mtx_b, ITensor *vector_sum_col, int32_t num_mtx_b_rows, bool is_transposed1xW) override; |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 127 | /** Static function to check if given info will lead to a valid configuration of @ref NEGEMMLowpMatrixBReductionKernel |
| 128 | * |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 129 | * @param[in] mtx_b Input tensor. Data type supported: Data type supported: QASYMM8/QASYMM8_SIGNED |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 130 | * @param[in] vector_sum_col Output row-vector of sums of all the entries in each column of mtx_b. Data type supported: S32 |
| 131 | * @param[in] num_mtx_b_rows Number of matrix B rows |
| 132 | * @param[in] is_transposed1xW True if the input tensor is transposed 1xW |
| 133 | * |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 134 | * @return a status |
Georgios Pinitas | a3b1b46 | 2017-11-16 19:24:39 +0000 | [diff] [blame] | 135 | */ |
Georgios Pinitas | 631c41a | 2017-12-06 11:53:03 +0000 | [diff] [blame] | 136 | static Status validate(const ITensorInfo *mtx_b, const ITensorInfo *vector_sum_col, int32_t num_mtx_b_rows, bool is_transposed1xW); |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 137 | |
| 138 | // Inherited methods overridden: |
| 139 | void run(const Window &window, const ThreadInfo &info) override; |
Georgios Pinitas | dbdea0d | 2019-10-16 19:21:40 +0100 | [diff] [blame] | 140 | |
| 141 | private: |
| 142 | /** Execution of the reduction kernel specialized on the input type |
| 143 | * |
| 144 | * @param[in] window Execution window |
| 145 | * @param[in] info Thread-related information |
| 146 | */ |
| 147 | template <typename T> |
| 148 | void run_internal(const Window &window, const ThreadInfo &info); |
Gian Marco Iodice | ab18212 | 2017-10-09 15:05:40 +0100 | [diff] [blame] | 149 | }; |
| 150 | } // namespace arm_compute |
| 151 | |
Michalis Spyrou | f464337 | 2019-11-29 16:17:13 +0000 | [diff] [blame] | 152 | #endif /* ARM_COMPUTE_NEGEMMLOWREDUCTIONKERNEL_H */ |