From 1f567afcdfb2919fab417f0060155deda7132df8 Mon Sep 17 00:00:00 2001 From: Sheri Zhang Date: Tue, 5 May 2020 11:47:36 +0100 Subject: COMPMID-3442: Add support of negative axis in NESoftmaxLayer and reference code Signed-off-by: Sheri Zhang Change-Id: I285cc3b74ac0a45f0ad5830baed5237cea568f15 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3147 Tested-by: Arm Jenkins Reviewed-by: Michele Di Giorgio Comments-Addressed: Arm Jenkins --- src/runtime/NEON/functions/NESoftmaxLayer.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/runtime/NEON/functions/NESoftmaxLayer.cpp') diff --git a/src/runtime/NEON/functions/NESoftmaxLayer.cpp b/src/runtime/NEON/functions/NESoftmaxLayer.cpp index f530a87d05..57d75af779 100644 --- a/src/runtime/NEON/functions/NESoftmaxLayer.cpp +++ b/src/runtime/NEON/functions/NESoftmaxLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017-2019 ARM Limited. + * Copyright (c) 2017-2020 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -41,7 +41,7 @@ NESoftmaxLayerGeneric::NESoftmaxLayerGeneric(std::shared_ptr -void NESoftmaxLayerGeneric::configure_reshape_input_kernel(const ITensor *input, const ITensor *output, size_t axis) +void NESoftmaxLayerGeneric::configure_reshape_input_kernel(const ITensor *input, const ITensor *output, int32_t axis) { // Flatten the input const TensorShape shape_flatten = misc::shape_calculator::compute_softmax_shape(input->info(), axis); @@ -71,12 +71,15 @@ void NESoftmaxLayerGeneric::configure_reshape_input_kernel(const ITensor } template -void NESoftmaxLayerGeneric::configure(ITensor *input, ITensor *output, float beta, size_t axis) +void NESoftmaxLayerGeneric::configure(ITensor *input, ITensor *output, float beta, int32_t axis) { // Perform validation step ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); ARM_COMPUTE_ERROR_THROW_ON(NESoftmaxLayerGeneric::validate(input->info(), output->info(), beta, axis)); + // Handle negative axis, negative index is used to specify axis from the end (e.g. -1 for the last axis). + axis = wrap_around(axis, static_cast(input->info()->num_dimensions())); + // We don't need flattening only in the case the input is 2D and axis is 1 _needs_flattening = axis != 1; @@ -142,13 +145,16 @@ void NESoftmaxLayerGeneric::configure(ITensor *input, ITensor *output, f } template -Status NESoftmaxLayerGeneric::validate(const ITensorInfo *input, const ITensorInfo *output, float beta, size_t axis) +Status NESoftmaxLayerGeneric::validate(const ITensorInfo *input, const ITensorInfo *output, float beta, int32_t axis) { // Perform validation step ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); ARM_COMPUTE_RETURN_ERROR_ON_MSG(input->num_dimensions() > 4, "Only up to 4 dimensions are supported"); ARM_COMPUTE_UNUSED(beta); - ARM_COMPUTE_RETURN_ERROR_ON(axis < 1 || input->num_dimensions() < axis); + ARM_COMPUTE_RETURN_ERROR_ON(axis < static_cast(-input->num_dimensions()) || static_cast(input->num_dimensions()) <= axis); + + // Handle negative axis, negative index is used to specify axis from the end (e.g. -1 for the last axis). + axis = wrap_around(axis, static_cast(input->num_dimensions())); // Create intermediate tensor info DataType tmp_data_type = input->data_type(); -- cgit v1.2.1