Georgios Pinitas | 856f66e | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 1 | /* |
| 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_GEMM_RESHAPE_LHS_MATRIX_KERNEL_H |
| 25 | #define ARM_COMPUTE_CL_GEMM_RESHAPE_LHS_MATRIX_KERNEL_H |
| 26 | |
| 27 | #include "src/core/common/Macros.h" |
| 28 | #include "src/core/gpu/cl/ClCompileContext.h" |
| 29 | #include "src/core/gpu/cl/IClKernel.h" |
| 30 | |
| 31 | namespace arm_compute |
| 32 | { |
| 33 | namespace opencl |
| 34 | { |
| 35 | namespace kernels |
| 36 | { |
| 37 | /** OpenCL kernel to reshape the LHS matrix when performing the matrix multiplication. |
| 38 | * In particular, this function splits the src matrix in blocks of size M0xK0 (defined through GEMMLHSInfo) and |
| 39 | * stores each one in the dst matrix unrolling the values |
| 40 | */ |
| 41 | class ClGemmReshapeLhsMatrixKernel : public ICLKernel |
| 42 | { |
| 43 | public: |
Giorgio Arena | 4a95bba | 2021-06-28 11:00:27 +0100 | [diff] [blame] | 44 | ClGemmReshapeLhsMatrixKernel(); |
Georgios Pinitas | 856f66e | 2021-04-22 21:13:21 +0100 | [diff] [blame] | 45 | ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(ClGemmReshapeLhsMatrixKernel); |
| 46 | /** Initialise the kernel's input and output. |
| 47 | * |
| 48 | * @param[in] compile_context The compile context to be used. |
| 49 | * @param[in] src Input tensor. Data types supported: All |
| 50 | * @param[out] dst Output tensor. Data type supported: same as @p src |
| 51 | * @param[in] lhs_info LHS matrix information to be used for reshaping. This object contains all the necessary |
| 52 | * information to reshape the src tensor. Only the following values are supported: |
| 53 | * lhs_info.m0: 2,3,4,5,6,7,8 |
| 54 | * lhs_info.k0: 2,3,4,8,16 |
| 55 | * lhs_info.v0: greater than 0 |
| 56 | * lhs_info.transpose: true, false |
| 57 | * lhs_info.interleave: true, false |
| 58 | * @param[in] reinterpret_src_as_3d (Optional) True if the src has to be reinterpreted as 3D tensor |
| 59 | */ |
| 60 | void configure(const ClCompileContext &compile_context, ITensorInfo *src, ITensorInfo *dst, const GEMMLHSMatrixInfo &lhs_info, bool reinterpret_src_as_3d = false); |
| 61 | /** Static function to check if given info will lead to a valid configuration |
| 62 | * |
| 63 | * Similar to @ref ClGemmReshapeLhsMatrixKernel::configure() |
| 64 | * |
| 65 | * @return a status |
| 66 | */ |
| 67 | static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const GEMMLHSMatrixInfo &lhs_info, bool reinterpret_src_as_3d); |
| 68 | |
| 69 | // Inherited methods overridden: |
| 70 | void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override; |
| 71 | |
| 72 | private: |
| 73 | bool _reinterpret_input_as_3d{ false }; |
| 74 | }; |
| 75 | } // namespace kernels |
| 76 | } // namespace opencl |
| 77 | } // namespace arm_compute |
| 78 | #endif /* ARM_COMPUTE_CL_GEMM_RESHAPE_LHS_MATRIX_KERNEL_H */ |