aboutsummaryrefslogtreecommitdiff
path: root/arm_compute/core/utils
diff options
context:
space:
mode:
authorGian Marco Iodice <gianmarco.iodice@arm.com>2018-12-06 17:13:09 +0000
committerGian Marco Iodice <gianmarco.iodice@arm.com>2018-12-10 15:58:54 +0000
commit5ba5e0938e68d4f90f5545a81066d56f022b376a (patch)
treed828f8b3fd52e6d5b8f732a7ec41f832f0b921d8 /arm_compute/core/utils
parent1d7cbb99d2a34abd15f3b6c2e017115736cd90cc (diff)
downloadComputeLibrary-5ba5e0938e68d4f90f5545a81066d56f022b376a.tar.gz
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 <michele.digiorgio@arm.com> Tested-by: Arm Jenkins <bsgcomp@arm.com>
Diffstat (limited to 'arm_compute/core/utils')
-rw-r--r--arm_compute/core/utils/misc/ShapeCalculator.h37
1 files changed, 37 insertions, 0 deletions
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<float>(lhs_info.k0));
+ const unsigned int num_vert_blocks = std::ceil(input_height / static_cast<float>(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<float>(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