From eb5696d99d85e1d402188151e021bc4b14f93969 Mon Sep 17 00:00:00 2001 From: Anitha Raj Date: Fri, 14 Jul 2023 11:19:34 +0100 Subject: Optimize CpuReshapeKernel Resolves COMPMID-5279 Change-Id: Id9b007eed62c200702bbfcc83b94dab7b5de1714 Signed-off-by: Anitha Raj Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/9962 Comments-Addressed: Arm Jenkins Tested-by: Arm Jenkins Reviewed-by: SiCong Li Reviewed-by: Viet-Hoa Do Benchmark: Arm Jenkins --- src/core/helpers/Utils.h | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'src/core') diff --git a/src/core/helpers/Utils.h b/src/core/helpers/Utils.h index 326dc962c7..641d536c13 100644 --- a/src/core/helpers/Utils.h +++ b/src/core/helpers/Utils.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2020-2021 Arm Limited. +* Copyright (c) 2020-2021, 2023 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -25,7 +25,6 @@ #define SRC_CORE_HELPERS_UTILS_H #include "arm_compute/core/ITensorInfo.h" - namespace arm_compute { /** Create a strides object based on the provided strides and the tensor dimensions. @@ -38,7 +37,7 @@ namespace arm_compute * calculated based on the tensor shape and the strides of lower dimensions. */ template -inline Strides compute_strides(const ITensorInfo &info, T stride_x, Ts &&... fixed_strides) +inline Strides compute_strides(const ITensorInfo &info, T stride_x, Ts &&...fixed_strides) { const TensorShape &shape = info.tensor_shape(); @@ -92,6 +91,32 @@ inline unsigned int get_next_power_two(unsigned int x) return x; } + +/** Check if the tensor has any holes. + * + * @param[in] info Tensor info object defining the shape of the input tensor. + * @param[in] dimension Highest dimension to check. + * + * @note This function checks for holes in all the dimensions upto and including the highest dimension. + * + */ +inline bool has_holes(const ITensorInfo &info, size_t dimension) +{ + const auto &shape = info.tensor_shape(); + const auto &strides = info.strides_in_bytes(); + size_t squashed_bytes = info.element_size(); + + for(size_t dim = 0; dim <= dimension; ++dim) + { + if(strides[dim] != squashed_bytes) + { + return true; + } + squashed_bytes *= shape[dim]; + } + return false; +} + } // namespace arm_compute #endif /* SRC_CORE_HELPERS_UTILS_H */ -- cgit v1.2.1