From 6a90b69d2e0a2d3be8c88d65aa4ee228605344da Mon Sep 17 00:00:00 2001 From: Giuseppe Rossini Date: Thu, 23 Aug 2018 11:29:59 +0100 Subject: [COMPMID-1301] Add validate() method to NEReshapeLayer Change-Id: Idc3b15f2421858bbf726cd9da82487ff2e1f2910 Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/145335 Tested-by: Jenkins Reviewed-by: Georgios Pinitas Reviewed-by: Anthony Barbier --- .../core/NEON/kernels/NEReshapeLayerKernel.h | 9 ++++++ .../runtime/NEON/functions/NEReshapeLayer.h | 9 ++++++ src/core/NEON/kernels/NEReshapeLayerKernel.cpp | 37 ++++++++++++++-------- src/runtime/NEON/functions/NEReshapeLayer.cpp | 11 ++++++- 4 files changed, 52 insertions(+), 14 deletions(-) diff --git a/arm_compute/core/NEON/kernels/NEReshapeLayerKernel.h b/arm_compute/core/NEON/kernels/NEReshapeLayerKernel.h index 08b4e11189..1c6c780207 100644 --- a/arm_compute/core/NEON/kernels/NEReshapeLayerKernel.h +++ b/arm_compute/core/NEON/kernels/NEReshapeLayerKernel.h @@ -45,6 +45,15 @@ public: */ void configure(const ITensor *input, ITensor *output); + /** Static function to check if given info will lead to a valid configuration of @ref NEReshapeLayerKernel + * + * @param[in] input Source tensor info. Data type supported: U8/S8/U16/S16/QASYMM8/U32/S32/F16/F32 + * @param[in] output Destination tensor info. Data type supported: Same as @p input + * + * @return a status + */ + static Status validate(const ITensorInfo *input, const ITensorInfo *output); + // Inherited methods overridden: void run(const Window &window, const ThreadInfo &info) override; }; diff --git a/arm_compute/runtime/NEON/functions/NEReshapeLayer.h b/arm_compute/runtime/NEON/functions/NEReshapeLayer.h index a77a5f30dc..01fe3bd091 100644 --- a/arm_compute/runtime/NEON/functions/NEReshapeLayer.h +++ b/arm_compute/runtime/NEON/functions/NEReshapeLayer.h @@ -41,6 +41,15 @@ public: * @param[out] output Output tensor. Data type supported: Same as @p input */ void configure(const ITensor *input, ITensor *output); + + /** Static function to check if given info will lead to a valid configuration of @ref NEReshapeLayer + * + * @param[in] input First tensor info. Data type supported: U8/S8/QASYMM8//U16/S16/U32/S32/F16/F32 + * @param[in] output Output tensor info. Data type supported: Same as @p input + * + * @return a status + */ + static Status validate(const ITensorInfo *input, const ITensorInfo *output); }; } #endif /*__ARM_COMPUTE_NERESHAPELAYER_H__ */ diff --git a/src/core/NEON/kernels/NEReshapeLayerKernel.cpp b/src/core/NEON/kernels/NEReshapeLayerKernel.cpp index 8043e8b2d7..298f50b93d 100644 --- a/src/core/NEON/kernels/NEReshapeLayerKernel.cpp +++ b/src/core/NEON/kernels/NEReshapeLayerKernel.cpp @@ -39,6 +39,18 @@ using namespace arm_compute; namespace { +Status validate_arguments(const ITensorInfo *input, const ITensorInfo *output) +{ + ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); + ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S8, DataType::QASYMM8, DataType::U16, DataType::S16, + DataType::U32, DataType::S32, DataType::F16, DataType::F32); + + ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); + ARM_COMPUTE_RETURN_ERROR_ON(input->tensor_shape().total_size() != output->tensor_shape().total_size()); + + return Status{}; +} + template inline void reshape_tensor(const Window &window, const ITensor *input, ITensor *output) { @@ -59,29 +71,28 @@ inline void reshape_tensor(const Window &window, const ITensor *input, ITensor * void NEReshapeLayerKernel::configure(const ITensor *input, ITensor *output) { - ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(input, 1, DataType::U8, DataType::S8, DataType::QASYMM8, DataType::U16, DataType::S16, - DataType::U32, DataType::S32, DataType::F16, DataType::F32); - ARM_COMPUTE_ERROR_ON_NULLPTR(output); - ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(input, output); - ARM_COMPUTE_ERROR_ON(input->info()->tensor_shape().total_size() != output->info()->tensor_shape().total_size()); + ARM_COMPUTE_ERROR_ON_NULLPTR(input, output); + ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info())); _input = input; _output = output; - constexpr unsigned int num_elems_processed_per_iteration = 1; - // Configure kernel window - Window win = calculate_max_window(*input->info(), Steps(num_elems_processed_per_iteration)); + Window win = calculate_max_window(*input->info()); - AccessWindowHorizontal input_access(input->info(), 0, num_elems_processed_per_iteration); - AccessWindowStatic output_access(output->info(), 0, 0, output->info()->tensor_shape().x(), output->info()->tensor_shape().y()); - update_window_and_padding(win, input_access, output_access); - - output_access.set_valid_region(win, ValidRegion(Coordinates(), output->info()->tensor_shape())); + // Set the output valid region + output->info()->set_valid_region(ValidRegion(Coordinates(), output->info()->tensor_shape())); INEKernel::configure(win); } +Status NEReshapeLayerKernel::validate(const ITensorInfo *input, const ITensorInfo *output) +{ + ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output)); + + return Status{}; +} + void NEReshapeLayerKernel::run(const Window &window, const ThreadInfo &info) { ARM_COMPUTE_UNUSED(info); diff --git a/src/runtime/NEON/functions/NEReshapeLayer.cpp b/src/runtime/NEON/functions/NEReshapeLayer.cpp index fef4e0cc19..4600f36660 100644 --- a/src/runtime/NEON/functions/NEReshapeLayer.cpp +++ b/src/runtime/NEON/functions/NEReshapeLayer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -24,6 +24,7 @@ #include "arm_compute/runtime/NEON/functions/NEReshapeLayer.h" #include "arm_compute/core/NEON/kernels/NEReshapeLayerKernel.h" +#include "arm_compute/core/Validate.h" #include "support/ToolchainSupport.h" #include @@ -36,3 +37,11 @@ void NEReshapeLayer::configure(const ITensor *input, ITensor *output) k->configure(input, output); _kernel = std::move(k); } + +Status NEReshapeLayer::validate(const ITensorInfo *input, const ITensorInfo *output) +{ + ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(input, output); + ARM_COMPUTE_RETURN_ON_ERROR(NEReshapeLayerKernel::validate(input, output)); + + return Status{}; +} -- cgit v1.2.1