From 5ba5e0938e68d4f90f5545a81066d56f022b376a Mon Sep 17 00:00:00 2001 From: Gian Marco Iodice Date: Thu, 6 Dec 2018 17:13:09 +0000 Subject: COMPMID-1774: Implement CLGEMMReshapeLHSMatrixKernel to reshape the LHS matrix of GEMM/GEMMLowp Change-Id: I8c5fd4c8bcdffda1522c83158981ed92baa045f4 Reviewed-on: https://review.mlplatform.org/364 Reviewed-by: Michele Di Giorgio Tested-by: Arm Jenkins --- arm_compute/core/utils/misc/ShapeCalculator.h | 37 +++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'arm_compute/core/utils') diff --git a/arm_compute/core/utils/misc/ShapeCalculator.h b/arm_compute/core/utils/misc/ShapeCalculator.h index c625a07a7f..88ce8d9e7b 100644 --- a/arm_compute/core/utils/misc/ShapeCalculator.h +++ b/arm_compute/core/utils/misc/ShapeCalculator.h @@ -101,6 +101,43 @@ inline TensorShape compute_weights_reshaped_shape(const ITensorInfo &weights, bo return weights_reshaped; } +inline TensorShape compute_lhs_reshaped_shape(const ITensorInfo &a, const GEMMLHSMatrixInfo &lhs_info, bool reinterpret_input_as_3d = false) +{ + ARM_COMPUTE_ERROR_ON(lhs_info.m0 == 0); + ARM_COMPUTE_ERROR_ON(lhs_info.k0 == 0); + ARM_COMPUTE_ERROR_ON(lhs_info.v0 == 0); + + // Input width/height + const unsigned int input_width = a.dimension(0); + const unsigned int input_height = reinterpret_input_as_3d ? a.dimension(1) * a.dimension(2) : a.dimension(1); + + // Number of horizontal/vertical blocks in the input tensor + const unsigned int num_horiz_blocks = std::ceil(input_width / static_cast(lhs_info.k0)); + const unsigned int num_vert_blocks = std::ceil(input_height / static_cast(lhs_info.m0)); + + // Block size + const unsigned int block_size = lhs_info.m0 * lhs_info.k0; + + // Output width/height + const unsigned int output_width = block_size * num_horiz_blocks * lhs_info.v0; + const unsigned int output_height = std::ceil(num_vert_blocks / static_cast(lhs_info.v0)); + + TensorShape lhs_shape{ a.tensor_shape() }; + lhs_shape.set(0, output_width); + lhs_shape.set(1, output_height); + + if((reinterpret_input_as_3d) && (lhs_shape.num_dimensions() > 2)) + { + // When the data format is NHWC and the shapes are Nx1x1 + // the tensor shape num_dimensions is automatically set to 1 instead of 3. + // To avoid failures by removing a dimension that doesn't exist + // check if the number of dimensions is greater than 2. + lhs_shape.remove_dimension(2); + } + + return lhs_shape; +} + inline TensorShape compute_interleaved_shape(const ITensorInfo &a, int mult_interleave4x4_height = 1, bool reinterpret_input_as_3d = false) { // The interleaved output matrix will have the following shape: [ a_height * W, ceil(a_width / W) ] where W = 4 * mult_interleave4x4_height -- cgit v1.2.1