Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 1 | /* |
Gian Marco Iodice | bacfec5 | 2019-01-11 11:30:55 +0000 | [diff] [blame] | 2 | * Copyright (c) 2018-2019 ARM Limited. |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [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 | */ |
| 24 | #ifndef __ARM_COMPUTE_CLGEMMRESHAPERHSMATRIXKERNEL_H__ |
| 25 | #define __ARM_COMPUTE_CLGEMMRESHAPERHSMATRIXKERNEL_H__ |
| 26 | |
| 27 | #include "arm_compute/core/CL/ICLKernel.h" |
| 28 | |
| 29 | namespace arm_compute |
| 30 | { |
| 31 | class ICLTensor; |
| 32 | |
| 33 | /** OpenCL kernel to reshape the RHS matrix when performing the matrix multiplication |
| 34 | * In particular, this kernel splits the input matrix in blocks of size K0xN0 and stores each one in |
| 35 | * the output matrix unrolling the values */ |
| 36 | class CLGEMMReshapeRHSMatrixKernel : public ICLKernel |
| 37 | { |
| 38 | public: |
| 39 | /** Default constructor */ |
| 40 | CLGEMMReshapeRHSMatrixKernel(); |
| 41 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 42 | CLGEMMReshapeRHSMatrixKernel(const CLGEMMReshapeRHSMatrixKernel &) = delete; |
| 43 | /** Prevent instances of this class from being copied (As this class contains pointers) */ |
| 44 | CLGEMMReshapeRHSMatrixKernel &operator=(const CLGEMMReshapeRHSMatrixKernel &) = delete; |
| 45 | /** Allow instances of this class to be moved */ |
| 46 | CLGEMMReshapeRHSMatrixKernel(CLGEMMReshapeRHSMatrixKernel &&) = default; |
| 47 | /** Allow instances of this class to be moved */ |
| 48 | CLGEMMReshapeRHSMatrixKernel &operator=(CLGEMMReshapeRHSMatrixKernel &&) = default; |
| 49 | /** Initialise the kernel's input and output. |
| 50 | * |
| 51 | * @param[in] input Input tensor. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32 |
| 52 | * @param[out] output Output tensor. Data type supported: same as @p input |
| 53 | * @param[in] rhs_info RHS matrix information to be used for reshaping. This object contains all the necessary |
| 54 | * information to reshape the input tensor. Only the following values are supported: |
Gian Marco Iodice | bacfec5 | 2019-01-11 11:30:55 +0000 | [diff] [blame] | 55 | * rhs_info.n0: 2,3,4,8,16 |
| 56 | * rhs_info.k0: 1,2,3,4,8,16 (k0 = 1 only if rhs_info.transpose = false) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 57 | * rhs_info.h0: greater than 0 |
| 58 | * rhs_info.transpose: true, false |
| 59 | * rhs_info.interleave: true, false |
| 60 | */ |
| 61 | void configure(const ICLTensor *input, ICLTensor *output, const GEMMRHSMatrixInfo &rhs_info); |
| 62 | /** Static function to check if given info will lead to a valid configuration of @ref CLGEMMReshapeRHSMatrixKernel |
| 63 | * |
| 64 | * @param[in] input Input tensor info. Data types supported: U8/S8/QASYMM8/U16/S16/F16/U32/S32/F32 |
| 65 | * @param[in] output Output tensor info which stores the interleaved matrix. Data type supported: same as @p input. |
| 66 | * @param[in] rhs_info RHS matrix information to be used for reshaping. This object contains all the necessary |
| 67 | * information to reshape the input tensor. Only the following values are supported: |
Gian Marco Iodice | bacfec5 | 2019-01-11 11:30:55 +0000 | [diff] [blame] | 68 | * rhs_info.n0: 2,3,4,8,16 |
| 69 | * rhs_info.k0: 1,2,3,4,8,16 (k0 = 1 only if rhs_info.transpose = false) |
Gian Marco Iodice | 3b0a265 | 2018-12-07 11:18:09 +0000 | [diff] [blame] | 70 | * rhs_info.h0: greater than 0 |
| 71 | * rhs_info.transpose: true, false |
| 72 | * rhs_info.interleave: true, false |
| 73 | * |
| 74 | * @return a status |
| 75 | */ |
| 76 | static Status validate(const ITensorInfo *input, const ITensorInfo *output, const GEMMRHSMatrixInfo &rhs_info); |
| 77 | |
| 78 | // Inherited methods overridden |
| 79 | void run(const Window &window, cl::CommandQueue &queue) override; |
| 80 | |
| 81 | private: |
| 82 | const ICLTensor *_input; |
| 83 | ICLTensor *_output; |
| 84 | }; |
| 85 | } // namespace arm_compute |
| 86 | #endif /* __ARM_COMPUTE_CLGEMMRESHAPERHSMATRIXKERNEL_H__ */ |