aboutsummaryrefslogtreecommitdiff
path: root/src/core/CPP/kernels
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2018-02-14 19:23:44 +0000
committerAnthony Barbier <anthony.barbier@arm.com>2018-11-02 16:47:18 +0000
commit69af6cf5ec6edce564dd5ef97baba5a1325e8763 (patch)
treec8f82cb0f5258b1f2a004631d7fa78b49b34231d /src/core/CPP/kernels
parentb99f00d44b8962c40f1de955831f8b04c15e7386 (diff)
downloadComputeLibrary-69af6cf5ec6edce564dd5ef97baba5a1325e8763.tar.gz
COMPMID-765: Sanitize permutation vector for Permute.
If permutation vector is bigger than the tensorshape to permute then infer dimensions of size one for the extra dimensions. Change-Id: I5addb292f770d925f47f756902e16073039e8f71 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/120473 Tested-by: Jenkins <bsgcomp@arm.com> Reviewed-by: Stefana Simion <stefana.simion@arm.com> Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'src/core/CPP/kernels')
-rw-r--r--src/core/CPP/kernels/CPPPermuteKernel.cpp41
1 files changed, 13 insertions, 28 deletions
diff --git a/src/core/CPP/kernels/CPPPermuteKernel.cpp b/src/core/CPP/kernels/CPPPermuteKernel.cpp
index 298c700809..6b3e855ad3 100644
--- a/src/core/CPP/kernels/CPPPermuteKernel.cpp
+++ b/src/core/CPP/kernels/CPPPermuteKernel.cpp
@@ -44,12 +44,7 @@ Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output, c
DataType::U16, DataType::S16, DataType::QS16,
DataType::U32, DataType::S32,
DataType::F16, DataType::F32);
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->num_dimensions() < 3, "Invalid input size!");
- ARM_COMPUTE_RETURN_ERROR_ON_MSG(
- (perm.num_dimensions() != 3 && ((perm[0] != 2 && perm[1] != 0 && perm[2] != 1) || (perm[0] != 1 && perm[1] != 2 && perm[2] != 0))) && (perm.num_dimensions() != 4 && ((perm[0] != 2 && perm[1] != 0
- && perm[2] != 1)
- || (perm[0] != 1 && perm[1] != 2 && perm[2] != 0))),
- "Only [2, 0, 1],[1, 2, 0] and [3, 2, 0, 1] permutation is supported");
+ ARM_COMPUTE_RETURN_ERROR_ON_MSG(perm.num_dimensions() > 4, "Only up to 4D permutation vectors are supported");
const TensorShape output_shape = misc::shape_calculator::compute_permutation_output_shape(*input, perm);
@@ -70,7 +65,8 @@ inline void permute_strides(Dimensions<T> &dimensions, const PermutationVector &
const auto old_dim = utility::make_array<Dimensions<T>::num_max_dimensions>(dimensions.begin(), dimensions.end());
for(unsigned int i = 0; i < perm.num_dimensions(); ++i)
{
- dimensions[perm[i]] = old_dim[i];
+ T dimension_val = (perm[i] < dimensions.num_dimensions()) ? old_dim[i] : 0;
+ dimensions.set(perm[i], dimension_val);
}
}
@@ -79,20 +75,23 @@ inline void permute_strides(Dimensions<T> &dimensions, const PermutationVector &
template <typename T>
void CPPPermuteKernel::run_permute(const Window &window)
{
+ // Permute strides
Strides strides = _output->info()->strides_in_bytes();
Strides perm_strides = strides;
permute_strides(perm_strides, _perm);
- const int output_stride_w = strides[3];
+
+ // Create output window
Window window_out(window);
const Window::Dimension zero_window = Window::Dimension(0, 0, 0);
for(size_t d = 0; d <= _perm.num_dimensions(); ++d)
{
window_out.set(d, zero_window);
}
+
// Create iterators
Iterator in(_input, window);
Iterator out(_output, window_out);
- ARM_COMPUTE_ERROR_ON(_perm.num_dimensions() > _input->info()->num_dimensions());
+
if(_input->info()->num_dimensions() <= 3)
{
execute_window_loop(window, [&](const Coordinates & id)
@@ -104,26 +103,12 @@ void CPPPermuteKernel::run_permute(const Window &window)
}
else if(_input->info()->num_dimensions() >= 4)
{
- if(_perm.num_dimensions() < _input->info()->num_dimensions())
- {
- // special case: perm.size = 3 and tensor size > 3, _perm[3] would be invalid so we handle this with id[3] * output_stride_w instead of id[_perm[3]]
- ARM_COMPUTE_ERROR_ON(_perm.num_dimensions() < 3);
- execute_window_loop(window, [&](const Coordinates & id)
- {
- const int idx = id[0] * perm_strides[0] + id[1] * perm_strides[1] + id[2] * perm_strides[2] + id[3] * output_stride_w;
- *(reinterpret_cast<T *>(out.ptr() + idx)) = *(reinterpret_cast<const T *>(in.ptr()));
- },
- in, out);
- }
- else
+ execute_window_loop(window, [&](const Coordinates & id)
{
- execute_window_loop(window, [&](const Coordinates & id)
- {
- const int idx = id[0] * perm_strides[0] + id[1] * perm_strides[1] + id[2] * perm_strides[2] + id[3] * perm_strides[3];
- *(reinterpret_cast<T *>(out.ptr() + idx)) = *(reinterpret_cast<const T *>(in.ptr()));
- },
- in, out);
- }
+ const int idx = id[0] * perm_strides[0] + id[1] * perm_strides[1] + id[2] * perm_strides[2] + id[3] * perm_strides[3];
+ *(reinterpret_cast<T *>(out.ptr() + idx)) = *(reinterpret_cast<const T *>(in.ptr()));
+ },
+ in, out);
}
}