From 460a179b53d5543d98d3e72c60458d4b0e3225a4 Mon Sep 17 00:00:00 2001 From: Mike Kelly Date: Tue, 1 Aug 2023 11:31:55 +0100 Subject: IVGCVSW-7899 Cannot handle tensors with more than 5 dimensions * Fixed issue where then dimensions specificity didn't match the number of dimensions. Signed-off-by: Mike Kelly Change-Id: Ic4da6f23c1e8ca38f321aa88c69ef57558a8f393 --- delegate/classic/src/ClassicDelegateUtils.hpp | 16 ++++++++-------- delegate/opaque/src/OpaqueDelegateUtils.hpp | 14 +++++++------- shim/sl/canonical/CanonicalUtils.cpp | 8 +++++--- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/delegate/classic/src/ClassicDelegateUtils.hpp b/delegate/classic/src/ClassicDelegateUtils.hpp index 52e9f5cf63..2806716334 100644 --- a/delegate/classic/src/ClassicDelegateUtils.hpp +++ b/delegate/classic/src/ClassicDelegateUtils.hpp @@ -371,7 +371,7 @@ armnn::TensorInfo GetTensorInfoForTfLiteTensor(const TfLiteTensor& tfLiteTensor, { std::vector safeShape = { 1 }; bool dimensionsSpecificity[1] = { true }; - armnn::TensorShape tensorShape(armnn::numeric_cast(safeShape.size()), + armnn::TensorShape tensorShape(safeShape.size(), safeShape.data(), dimensionsSpecificity); ret = armnn::TensorInfo(tensorShape, type); @@ -388,21 +388,21 @@ armnn::TensorInfo GetTensorInfoForTfLiteTensor(const TfLiteTensor& tfLiteTensor, } else { - std::vector tensorDims(static_cast(tensorDimensionSize)); - bool dimensionsSpecificity[5] = { true, true, true, true, true }; - for (unsigned int i = 0; i < static_cast(tensorDimensionSize); ++i) { + std::vector tensorDims(tensorDimensionSize); + std::vector dimensionsSpecificity(tensorDimensionSize, true); + for (int i = 0; i < tensorDimensionSize; ++i) { auto dim = tfLiteTensor.dims->data[i]; - if (dim == 0) + if (dim <= 0) { dimensionsSpecificity[i] = false; } tensorDims[i] = static_cast(dim); } - armnn::TensorShape tensorShape(static_cast(tensorDimensionSize), + armnn::TensorShape tensorShape(tensorDimensionSize, tensorDims.data(), - dimensionsSpecificity); + reinterpret_cast(dimensionsSpecificity.data())); - if(tflite::IsConstantTensor(&tfLiteTensor)) + if (tflite::IsConstantTensor(&tfLiteTensor)) { ret = armnn::TensorInfo(tensorShape, type); ret.SetConstant(true); diff --git a/delegate/opaque/src/OpaqueDelegateUtils.hpp b/delegate/opaque/src/OpaqueDelegateUtils.hpp index fd943c8ec9..1c90ee0722 100644 --- a/delegate/opaque/src/OpaqueDelegateUtils.hpp +++ b/delegate/opaque/src/OpaqueDelegateUtils.hpp @@ -443,7 +443,7 @@ armnn::TensorInfo GetTensorInfoForTfLiteOpaqueTensor(const TfLiteOpaqueTensor* t std::vector safeShape = { 1 }; bool dimensionsSpecificity[1] = { true }; - armnn::TensorShape tensorShape(armnn::numeric_cast(safeShape.size()), + armnn::TensorShape tensorShape(safeShape.size(), safeShape.data(), dimensionsSpecificity); ret = armnn::TensorInfo(tensorShape, type); @@ -461,25 +461,25 @@ armnn::TensorInfo GetTensorInfoForTfLiteOpaqueTensor(const TfLiteOpaqueTensor* t } else { - std::vector tensorDims(static_cast(tensorDimensionSize)); - bool dimensionsSpecificity[5] = { true, true, true, true, true }; + std::vector tensorDims(tensorDimensionSize); + std::vector dimensionsSpecificity(tensorDimensionSize, true); for (int32_t i = 0; i < tensorDimensionSize; ++i) { int32_t dim = TfLiteOpaqueTensorDim(tfLiteTensor, i); - if (dim == 0) + if (dim <= 0) { dimensionsSpecificity[i] = false; } tensorDims[i] = static_cast(dim); } - armnn::TensorShape tensorShape(static_cast(tensorDimensionSize), + armnn::TensorShape tensorShape(tensorDimensionSize, tensorDims.data(), - dimensionsSpecificity); + reinterpret_cast(dimensionsSpecificity.data())); - if(IsConstantTensor(tfLiteTensor)) + if (IsConstantTensor(tfLiteTensor)) { ret = armnn::TensorInfo(tensorShape, type); ret.SetConstant(true); diff --git a/shim/sl/canonical/CanonicalUtils.cpp b/shim/sl/canonical/CanonicalUtils.cpp index 622d4b111d..08a728c293 100644 --- a/shim/sl/canonical/CanonicalUtils.cpp +++ b/shim/sl/canonical/CanonicalUtils.cpp @@ -1,5 +1,5 @@ // -// Copyright © 2022 Arm Ltd and Contributors. All rights reserved. +// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // @@ -152,7 +152,7 @@ armnn::TensorInfo GetTensorInfoForOperand(const Operand& operand) } else { - bool dimensionsSpecificity[5] = { true, true, true, true, true }; + std::vector dimensionsSpecificity(operand.dimensions.size(), true); int count = 0; std::for_each(operand.dimensions.data(), operand.dimensions.data() + operand.dimensions.size(), @@ -165,7 +165,9 @@ armnn::TensorInfo GetTensorInfoForOperand(const Operand& operand) count++; }); - TensorShape tensorShape(operand.dimensions.size(), operand.dimensions.data(), dimensionsSpecificity); + TensorShape tensorShape(operand.dimensions.size(), + operand.dimensions.data(), + reinterpret_cast(dimensionsSpecificity.data())); ret = TensorInfo(tensorShape, type); } } -- cgit v1.2.1