blob: 6eee54a9f0e2434665d51ab4556a9cb9cfa78039 [file] [log] [blame]
Gian Marco Iodiceab182122017-10-09 15:05:40 +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_NEGEMMLOWREDUCTIONKERNEL_H__
25#define __ARM_COMPUTE_NEGEMMLOWREDUCTIONKERNEL_H__
26
27#include "arm_compute/core/NEON/INEKernel.h"
28
29namespace arm_compute
30{
31class ITensor;
32
33/** Common interface for all NEON reduction kernels */
34class INEGEMMLowpReductionKernel : public INEKernel
35{
36public:
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 Iodiceab182122017-10-09 15:05:40 +010048 /** Initialise the kernel's input and output.
49 *
Gian Marcoe75a02b2017-11-08 12:24:09 +000050 * @param[in] input Input tensor. Data type supported: S8
Gian Marco Iodiceab182122017-10-09 15:05:40 +010051 * @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
57protected:
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 */
69class NEGEMMLowpMatrixAReductionKernel : public INEGEMMLowpReductionKernel
70{
71public:
72 /** Initialise the kernel's input and output.
73 *
Gian Marcoe75a02b2017-11-08 12:24:09 +000074 * @param[in] mtx_a Input tensor. Data type supported: QASYMM8
75 * @param[out] vector_sum_row Output row-vector of sums of all the entries in each row of mtx_a. Data type supported: S32
76 * @param[in] num_mtx_a_cols Number of matrix A columns
77 * @param[in] is_interleaved4x4 True if the matrix A has been interleaved4x4
Gian Marco Iodiceab182122017-10-09 15:05:40 +010078 */
Gian Marcoe75a02b2017-11-08 12:24:09 +000079 void configure(const ITensor *mtx_a, ITensor *vector_sum_row, int32_t num_mtx_a_cols, bool is_interleaved4x4) override;
Gian Marco Iodiceab182122017-10-09 15:05:40 +010080
81 // Inherited methods overridden:
82 void run(const Window &window, const ThreadInfo &info) override;
83};
84
85/** NEON kernel used to compute the row-vectors of sums of all the entries in each column of Matrix B.
86 *
87 * @note This stage is needed to handle the offset of matrix product
88 * https://github.com/google/gemmlowp/blob/master/doc/low-precision.md
89 */
90class NEGEMMLowpMatrixBReductionKernel : public INEGEMMLowpReductionKernel
91{
92public:
93 /** Initialise the kernel's input and output.
94 *
Gian Marcoe75a02b2017-11-08 12:24:09 +000095 * @param[in] mtx_b Input tensor. Data type supported: Data type supported: QASYMM8
96 * @param[out] vector_sum_col Output row-vector of sums of all the entries in each column of mtx_b. Data type supported: S32
97 * @param[in] num_mtx_b_rows Number of matrix B rows
98 * @param[in] is_transposed1xW True if the input tensor is transposed 1xW
Gian Marco Iodiceab182122017-10-09 15:05:40 +010099 */
Gian Marcoe75a02b2017-11-08 12:24:09 +0000100 void configure(const ITensor *mtx_b, ITensor *vector_sum_col, int32_t num_mtx_b_rows, bool is_transposed1xW) override;
Gian Marco Iodiceab182122017-10-09 15:05:40 +0100101
102 // Inherited methods overridden:
103 void run(const Window &window, const ThreadInfo &info) override;
104};
105} // namespace arm_compute
106
107#endif /* __ARM_COMPUTE_NEGEMMLOWREDUCTIONKERNEL_H__ */