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_RHS_MATRIX_KERNEL_H 25 #define ARM_COMPUTE_CL_GEMM_RESHAPE_RHS_MATRIX_KERNEL_H 26 27 #include "src/core/common/Macros.h" 28 #include "src/gpu/cl/ClCompileContext.h" 29 #include "src/gpu/cl/IClKernel.h" 30 31 namespace arm_compute 32 { 33 namespace opencl 34 { 35 namespace kernels 36 { 37 /** OpenCL kernel to reshape the RHS matrix when performing the matrix multiplication 38 * In particular, this kernel splits the src matrix in blocks of size K0xN0 and stores each one in 39 * the dst matrix unrolling the values */ 40 class ClGemmReshapeRhsMatrixKernel : public ICLKernel 41 { 42 public: 43 ClGemmReshapeRhsMatrixKernel(); 44 ARM_COMPUTE_DISALLOW_COPY_ALLOW_MOVE(ClGemmReshapeRhsMatrixKernel); 45 /** Initialise the kernel's input and output. 46 * 47 * @note If rhs_info.export_to_cl_image = true, this OpenCL kernel will guarantee the OpenCL pitch alignment for the output tensor, 48 * required to create a OpenCL image object from buffer in @ref ClGemmMatrixMultiplyReshapedKernel and in @ref ClGemmMatrixMultiplyReshapedOnlyRhsKernel 49 * Since the OpenCL image object is created importing the OpenCL buffer, the following conditions are required: 50 * -# rhs_info.n0 can only be 4, 8 and 16 51 * -# rhs_info.k0 can only be 4, 8 and 16 52 * -# Data type can only be F32, F16 53 * -# The platform should support the OpenCL cl_khr_image2d_from_buffer extension 54 * -# output width should be less or equal to (CL_DEVICE_IMAGE2D_MAX_WIDTH * 4) 55 * -# output (height * depth) should be less or equal to CL_DEVICE_IMAGE2D_MAX_HEIGHT 56 * -# The output tensor should be only consumed by @ref ClGemmMatrixMultiplyReshapedKernel or @ref ClGemmMatrixMultiplyReshapedOnlyRhsKernel 57 * 58 * @param[in] compile_context The compile context to be used. 59 * @param[in] src Input tensor. Data types supported: All 60 * @param[out] dst Output tensor. Data type supported: same as @p src 61 * @param[in] rhs_info RHS matrix information to be used for reshaping. This object contains all the necessary 62 * information to reshape the src tensor. Only the following values are supported: 63 * rhs_info.n0: 2,3,4,8,16 (only 4, 8 and 16 if rhs_info.export_to_cl_image == true) 64 * rhs_info.k0: 1,2,3,4,8,16 (k0 = 1 only if rhs_info.transpose = false), (only 4, 8 and 16 if rhs_info.export_to_cl_image == true) 65 * rhs_info.h0: greater than 0 66 * rhs_info.transpose: true, false 67 * rhs_info.interleave: true, false 68 */ 69 void configure(const ClCompileContext &compile_context, ITensorInfo *src, ITensorInfo *dst, const GEMMRHSMatrixInfo &rhs_info); 70 /** Static function to check if given info will lead to a valid configuration 71 * 72 * Similar to @ref ClGemmReshapeRhsMatrixKernel::configure() 73 * 74 * @return a status 75 */ 76 static Status validate(const ITensorInfo *src, const ITensorInfo *dst, const GEMMRHSMatrixInfo &rhs_info); 77 78 // Inherited methods overridden: 79 void run_op(ITensorPack &tensors, const Window &window, cl::CommandQueue &queue) override; 80 }; 81 } // namespace kernels 82 } // namespace opencl 83 } // namespace arm_compute 84 #endif /* ARM_COMPUTE_CL_GEMM_RESHAPE_RHS_MATRIX_KERNEL_H */