From 0745a980c6a5e2d294bcd09f3c704e6cf4fe316d Mon Sep 17 00:00:00 2001 From: Moritz Pflanzer Date: Wed, 5 Jul 2017 16:34:28 +0100 Subject: COMPMID-417: Fix assert in GEMMTranspose The assert was checking the wrong thing. Only if the window over the input is smaller than the number of processed elements, the output shape would be empty. However, the valid region will be empty if the input's first dimension is less than the number of elements processed. That required the changes in TensorShape. Change-Id: I36fed7893dfd502e26c5c776c9a2d774d6cd91c6 Reviewed-on: http://mpd-gerrit.cambridge.arm.com/79813 Tested-by: Kaizen Reviewed-by: Gian Marco Iodice --- arm_compute/core/TensorShape.h | 8 +++++++- src/core/CL/kernels/CLGEMMTranspose1xWKernel.cpp | 5 +++-- src/core/NEON/kernels/NEGEMMTranspose1xWKernel.cpp | 8 +++++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/arm_compute/core/TensorShape.h b/arm_compute/core/TensorShape.h index f8b3181686..17348e4fc6 100644 --- a/arm_compute/core/TensorShape.h +++ b/arm_compute/core/TensorShape.h @@ -73,7 +73,13 @@ public: */ void set(size_t dimension, size_t value) { - ARM_COMPUTE_ERROR_ON(value < 1); + // Clear entire shape if one dimension is zero + if(value == 0) + { + _num_dimensions = 0; + std::fill(_id.begin(), _id.end(), 0); + return; + } // Make sure all empty dimensions are filled with 1 std::fill(_id.begin() + _num_dimensions, _id.end(), 1); diff --git a/src/core/CL/kernels/CLGEMMTranspose1xWKernel.cpp b/src/core/CL/kernels/CLGEMMTranspose1xWKernel.cpp index 27b215f2c8..5057c8ff21 100644 --- a/src/core/CL/kernels/CLGEMMTranspose1xWKernel.cpp +++ b/src/core/CL/kernels/CLGEMMTranspose1xWKernel.cpp @@ -57,8 +57,7 @@ void CLGEMMTranspose1xWKernel::configure(const ICLTensor *input, ICLTensor *outp ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT(input, output); const unsigned int num_elems_processed_per_iteration = 16 / input->info()->element_size(); - const float scale_x = num_elems_processed_per_iteration; - ARM_COMPUTE_ERROR_ON((0 == static_cast(input->info()->dimension(0) * (1.f / scale_x)))); + const int scale_x = num_elems_processed_per_iteration; _input = input; _output = output; @@ -80,6 +79,8 @@ void CLGEMMTranspose1xWKernel::configure(const ICLTensor *input, ICLTensor *outp // Configure window Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration)); + ARM_COMPUTE_ERROR_ON_MSG((win.x().end() / scale_x) == 0, "Transposed shape would be 0 in the second dimension"); + AccessWindowHorizontal input_access(input->info(), 0, num_elems_processed_per_iteration); AccessWindowTranspose output_access(output->info(), 0, 0, num_elems_processed_per_iteration, 1, scale_x, 1.f / scale_x); diff --git a/src/core/NEON/kernels/NEGEMMTranspose1xWKernel.cpp b/src/core/NEON/kernels/NEGEMMTranspose1xWKernel.cpp index 881ef122a1..95063a7875 100644 --- a/src/core/NEON/kernels/NEGEMMTranspose1xWKernel.cpp +++ b/src/core/NEON/kernels/NEGEMMTranspose1xWKernel.cpp @@ -60,14 +60,16 @@ void NEGEMMTranspose1xWKernel::configure(const ITensor *input, ITensor *output) ARM_COMPUTE_ERROR_ON_MISMATCHING_FIXED_POINT(input, output); const unsigned int num_elems_processed_per_iteration = 16 / input->info()->element_size(); - const float scale_x = num_elems_processed_per_iteration; - ARM_COMPUTE_ERROR_ON((0 == static_cast(input->info()->dimension(0) * (1.f / scale_x)))); + const int scale_x = num_elems_processed_per_iteration; _input = input; _output = output; // Configure kernel window - Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration)); + Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration)); + + ARM_COMPUTE_ERROR_ON_MSG((win.x().end() / scale_x) == 0, "Transposed shape would be 0 in the second dimension"); + AccessWindowTranspose output_access(output->info(), 0, 0, num_elems_processed_per_iteration, 1, scale_x, 1.f / scale_x); update_window_and_padding(win, -- cgit v1.2.1