diff options
author | Gian Marco Iodice <gianmarco.iodice@arm.com> | 2018-07-26 11:44:03 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:54:54 +0000 |
commit | 68a3f56627b04acdefebe67d645727dd83889766 (patch) | |
tree | 4a3f4dc0facfda861a5ba7afa29d84d82d0829c2 /arm_compute/core/utils | |
parent | 4e0d3819be6c61cc00c7e0fa9b4b740738c703b7 (diff) | |
download | ComputeLibrary-68a3f56627b04acdefebe67d645727dd83889766.tar.gz |
COMPMID-1276 - Allow GEMM to work with 3D input tensor
Skipped im2col in CLGEMMConvolutionLayer for 1x1 convolutions with NHWC data layout
Change-Id: I894e6b952ed8605e8f3ffc0ffc25c24730d4664c
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/141909
Tested-by: Jenkins <bsgcomp@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Reviewed-by: Georgios Pinitas <georgios.pinitas@arm.com>
Diffstat (limited to 'arm_compute/core/utils')
-rw-r--r-- | arm_compute/core/utils/misc/ShapeCalculator.h | 31 |
1 files changed, 22 insertions, 9 deletions
diff --git a/arm_compute/core/utils/misc/ShapeCalculator.h b/arm_compute/core/utils/misc/ShapeCalculator.h index dbf26a423d..bf55add1d2 100644 --- a/arm_compute/core/utils/misc/ShapeCalculator.h +++ b/arm_compute/core/utils/misc/ShapeCalculator.h @@ -66,14 +66,24 @@ inline TensorShape compute_weights_reshaped_shape(const ITensorInfo &weights, bo return weights_reshaped; } -inline TensorShape compute_interleaved_shape(const ITensorInfo &a, int mult_interleave4x4_height = 1) +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 ARM_COMPUTE_ERROR_ON(mult_interleave4x4_height < 1); const int interleave_width = 4 * mult_interleave4x4_height; TensorShape shape_interleaved_a{ a.tensor_shape() }; shape_interleaved_a.set(0, a.dimension(0) * interleave_width); - shape_interleaved_a.set(1, std::ceil(a.dimension(1) / static_cast<float>(interleave_width))); + if(reinterpret_input_as_3d) + { + const int M = a.dimension(1) * a.dimension(2); + const int height = std::ceil(M / static_cast<float>(interleave_width)); + shape_interleaved_a.set(1, height); + shape_interleaved_a.remove_dimension(2); + } + else + { + shape_interleaved_a.set(1, std::ceil(a.dimension(1) / static_cast<float>(interleave_width))); + } return shape_interleaved_a; } @@ -374,23 +384,26 @@ inline TensorShape compute_rnn_shape(const ITensorInfo *input, const unsigned in inline TensorShape compute_mm_shape(const ITensorInfo &input0, const ITensorInfo &input1, bool is_interleaved_transposed, const GEMMReshapeInfo &reshape_info) { ARM_COMPUTE_ERROR_ON_MSG(input0.num_dimensions() > 4, "The number of dimensions for the matrix A must be <= 4"); + ARM_COMPUTE_ERROR_ON_MSG(is_interleaved_transposed && reshape_info.reinterpret_input_as_3d(), "The first input tensor cannot be reinterpreted as 3D if is_interleaved_transposed is true"); - const bool is_gemm3d = reshape_info.depth_output_gemm3d() != 1; + const bool reinterpret_input_as_3d = reshape_info.reinterpret_input_as_3d(); + const bool reinterpret_output_as_3d = reshape_info.depth_output_gemm3d() != 1; + const int m = reshape_info.reinterpret_input_as_3d() ? input0.dimension(1) * input0.dimension(2) : input0.dimension(1); // If the output of GEMM has to be reinterpreted as 3D, the number of input0 rows (M) is obtained collapsing the second and third // dimension of the output tensor const int dim0 = is_interleaved_transposed ? reshape_info.n() : input1.dimension(0); - const int dim1 = is_interleaved_transposed ? reshape_info.m() / reshape_info.depth_output_gemm3d() : input0.dimension(1) / reshape_info.depth_output_gemm3d(); - const int dim2 = input0.tensor_shape()[2]; - const int dim3 = input0.tensor_shape()[3]; + const int dim1 = is_interleaved_transposed ? reshape_info.m() / reshape_info.depth_output_gemm3d() : m / reshape_info.depth_output_gemm3d(); + const int dim2 = reinterpret_input_as_3d ? input0.tensor_shape()[3] : input0.tensor_shape()[2]; + const int dim3 = reinterpret_input_as_3d ? 1 : input0.tensor_shape()[3]; TensorShape output_shape{ input0.tensor_shape() }; output_shape.set(0, dim0); output_shape.set(1, dim1); - output_shape.set(2, is_gemm3d ? reshape_info.depth_output_gemm3d() : dim2); - output_shape.set(3, is_gemm3d ? dim2 : dim3); - output_shape.set(4, is_gemm3d ? dim3 : 1); + output_shape.set(2, reinterpret_output_as_3d ? reshape_info.depth_output_gemm3d() : dim2); + output_shape.set(3, reinterpret_output_as_3d ? dim2 : dim3); + output_shape.set(4, reinterpret_output_as_3d ? dim3 : 1); return output_shape; } |