From ed5fe69b6612a5cf0dd52340f6781885d77afbc9 Mon Sep 17 00:00:00 2001 From: Gian Marco Iodice Date: Thu, 9 Jul 2020 08:41:10 +0100 Subject: COMPMID-3326: Update heuristic for GEMMReshaped and GEMMReshapedOnlyRHS - Update the heuristic for Arm Mali-G76 (F32) in order to use the OpenCL image2d object on GEMM - Create utility function to validate the support for image2d Change-Id: I0913ac5f27fd07992b0ac188af753a2abeb034ca Signed-off-by: Gian Marco Iodice Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3559 Tested-by: Arm Jenkins Reviewed-by: Georgios Pinitas Comments-Addressed: Arm Jenkins --- src/core/CL/gemm/CLGEMMHelpers.cpp | 48 ++++++++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 17 deletions(-) (limited to 'src/core/CL/gemm/CLGEMMHelpers.cpp') diff --git a/src/core/CL/gemm/CLGEMMHelpers.cpp b/src/core/CL/gemm/CLGEMMHelpers.cpp index 1165e70273..5734c93021 100644 --- a/src/core/CL/gemm/CLGEMMHelpers.cpp +++ b/src/core/CL/gemm/CLGEMMHelpers.cpp @@ -23,7 +23,10 @@ */ #include "arm_compute/core/CL/gemm/CLGEMMHelpers.h" +#include "arm_compute/core/CL/CLHelpers.h" #include "arm_compute/core/CL/CLKernelLibrary.h" +#include "arm_compute/core/CL/OpenCL.h" +#include "arm_compute/core/ITensorInfo.h" #include @@ -32,24 +35,13 @@ namespace arm_compute namespace cl_gemm { std::pair configure_lhs_rhs_info(unsigned int m, unsigned int n, unsigned int m0, unsigned int n0, unsigned int k0, unsigned int v0, unsigned int h0, - bool lhs_interleave, bool rhs_interleave, bool lhs_transpose, bool rhs_transpose) + bool lhs_interleave, bool rhs_interleave, bool lhs_transpose, bool rhs_transpose, bool export_to_cl_image) { - GEMMLHSMatrixInfo lhs_info; - GEMMRHSMatrixInfo rhs_info; + v0 = ((m / (m0 * v0)) == 0) ? 1 : v0; + h0 = ((n / (n0 * h0)) == 0) ? 1 : h0; - // Configure GEMMLHSMatrixInfo - lhs_info.m0 = m0; - lhs_info.k0 = k0; - lhs_info.v0 = ((m / (lhs_info.m0 * v0)) == 0) ? 1 : v0; - lhs_info.interleave = lhs_interleave; - lhs_info.transpose = lhs_transpose; - - // Configure GEMMRHSMatrixInfo - rhs_info.n0 = n0; - rhs_info.k0 = lhs_info.k0; - rhs_info.h0 = ((n / (rhs_info.n0 * h0)) == 0) ? 1 : h0; - rhs_info.interleave = rhs_interleave; - rhs_info.transpose = rhs_transpose; + const GEMMLHSMatrixInfo lhs_info(m0, k0, v0, lhs_transpose, lhs_interleave); + const GEMMRHSMatrixInfo rhs_info(n0, k0, h0, rhs_transpose, rhs_interleave, export_to_cl_image); return std::make_pair(lhs_info, rhs_info); } @@ -66,5 +58,27 @@ void update_padding_for_cl_image(ITensorInfo *tensor) tensor->extend_padding(PaddingSize(0, padding, 0, 0)); } + +Status validate_image2d_support_on_rhs(const ITensorInfo &tensor_reshaped_info, const GEMMRHSMatrixInfo &rhs_info) +{ + if(rhs_info.export_to_cl_image) + { + ARM_COMPUTE_RETURN_ERROR_ON_MSG((rhs_info.n0 == 2) || (rhs_info.n0 == 3), "Export to cl_image only supported with n0 = 4, 8 or 16"); + ARM_COMPUTE_RETURN_ERROR_ON_MSG((rhs_info.k0 == 2) || (rhs_info.k0 == 3), "Export to cl_image only supported with k0 = 4, 8 or 16"); + ARM_COMPUTE_RETURN_ERROR_ON_MSG(tensor_reshaped_info.data_type() != DataType::F32, "Export to cl_image only supported with F32 data type"); + ARM_COMPUTE_RETURN_ERROR_ON_MSG(!image2d_from_buffer_supported(CLKernelLibrary::get().get_device()), "The extension cl_khr_image2d_from_buffer is not supported on the target platform"); + ARM_COMPUTE_RETURN_ERROR_ON_MSG(get_cl_image_pitch_alignment(CLKernelLibrary::get().get_device()) == 0, "Impossible to retrieve the cl_image pitch alignment"); + + // Check the width and height of the output tensor. + // Since we cannot create a 3d image from a buffer, the third dimension is collapsed on the second dimension + const size_t max_image_w = CLKernelLibrary::get().get_device().getInfo(); + const size_t max_image_h = CLKernelLibrary::get().get_device().getInfo(); + + ARM_COMPUTE_RETURN_ERROR_ON_MSG(tensor_reshaped_info.tensor_shape()[0] > max_image_w * 4, "Not supported width for cl_image"); + ARM_COMPUTE_RETURN_ERROR_ON_MSG(tensor_reshaped_info.tensor_shape()[1] * tensor_reshaped_info.tensor_shape()[2] > max_image_h, "Not supported height for cl_image"); + } + + return Status{}; +} } // namespace cl_gemm -} // namespace arm_compute \ No newline at end of file +} // namespace arm_compute -- cgit v1.2.1