From c229b3fd81b42140c0fa8731e90bc07323cec794 Mon Sep 17 00:00:00 2001 From: Ryan OShea Date: Tue, 27 Jun 2023 22:34:54 +0100 Subject: IVGCVSW-7676 Audit the use of ARMNN_ASSERT * Replace most ARMNN_ASSERT's from tflite parser * Replace most ARMNN_ASSERT's from onnx parser * Replace some ARMNN_ASSERT's from tflite delegate * Replace some ARMNN_ASSERT;s from include files Signed-off-by: Ryan OShea Change-Id: Ie052e0180060203f28f64ebf54acad298f431caf --- include/armnn/backends/Workload.hpp | 53 +++++++++++++++++++------------- include/armnnUtils/DataLayoutIndexed.hpp | 29 ++++++++++++----- 2 files changed, 53 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/include/armnn/backends/Workload.hpp b/include/armnn/backends/Workload.hpp index 9d5fec98cd..e0647c24d5 100644 --- a/include/armnn/backends/Workload.hpp +++ b/include/armnn/backends/Workload.hpp @@ -114,14 +114,16 @@ public: if (std::find(dataTypes.begin(), dataTypes.end(), expectedInputType) == dataTypes.end()) { - ARMNN_ASSERT_MSG(false, "Trying to create workload with incorrect type"); + throw armnn::Exception("Trying to create workload with incorrect type"); } - ARMNN_ASSERT_MSG(std::all_of(std::next(info.m_InputTensorInfos.begin()), + if (std::all_of(std::next(info.m_InputTensorInfos.begin()), info.m_InputTensorInfos.end(), [&](auto it){ return it.GetDataType() == expectedInputType; - }), - "Trying to create workload with incorrect type"); + }) == false) + { + throw armnn::Exception("Trying to create workload with incorrect type"); + } } armnn::DataType expectedOutputType; @@ -135,19 +137,21 @@ public: if (expectedOutputType != expectedInputType) { - ARMNN_ASSERT_MSG(false, "Trying to create workload with incorrect type"); + throw armnn::Exception( "Trying to create workload with incorrect type"); } } else if (std::find(dataTypes.begin(), dataTypes.end(), expectedOutputType) == dataTypes.end()) { - ARMNN_ASSERT_MSG(false, "Trying to create workload with incorrect type"); + throw armnn::Exception("Trying to create workload with incorrect type"); } - ARMNN_ASSERT_MSG(std::all_of(std::next(info.m_OutputTensorInfos.begin()), + if (std::all_of(std::next(info.m_OutputTensorInfos.begin()), info.m_OutputTensorInfos.end(), [&](auto it){ return it.GetDataType() == expectedOutputType; - }), - "Trying to create workload with incorrect type"); + }) == false) + { + throw armnn::Exception("Trying to create workload with incorrect type"); + } } } }; @@ -160,19 +164,22 @@ public: MultiTypedWorkload(const QueueDescriptor& descriptor, const WorkloadInfo& info) : BaseWorkload(descriptor, info) { - ARMNN_ASSERT_MSG(std::all_of(info.m_InputTensorInfos.begin(), + if (std::all_of(info.m_InputTensorInfos.begin(), info.m_InputTensorInfos.end(), [&](auto it){ return it.GetDataType() == InputDataType; - }), - "Trying to create workload with incorrect type"); - - ARMNN_ASSERT_MSG(std::all_of(info.m_OutputTensorInfos.begin(), + }) == false) + { + throw armnn::Exception("Trying to create workload with incorrect type"); + } + if (std::all_of(info.m_OutputTensorInfos.begin(), info.m_OutputTensorInfos.end(), [&](auto it){ return it.GetDataType() == OutputDataType; - }), - "Trying to create workload with incorrect type"); + }) == false) + { + throw armnn::Exception("Trying to create workload with incorrect type"); + } } }; @@ -187,16 +194,20 @@ public: { if (!info.m_InputTensorInfos.empty()) { - ARMNN_ASSERT_MSG(info.m_InputTensorInfos.front().GetDataType() == DataType, - "Trying to create workload with incorrect type"); + if (info.m_InputTensorInfos.front().GetDataType() != DataType) + { + throw armnn::Exception("Trying to create workload with incorrect type"); + } } - ARMNN_ASSERT_MSG(std::all_of(info.m_OutputTensorInfos.begin(), + if (std::all_of(info.m_OutputTensorInfos.begin(), info.m_OutputTensorInfos.end(), [&](auto it){ return it.GetDataType() == DataType; - }), - "Trying to create workload with incorrect type"); + }) == false) + { + throw armnn::Exception("Trying to create workload with incorrect type"); + } } }; diff --git a/include/armnnUtils/DataLayoutIndexed.hpp b/include/armnnUtils/DataLayoutIndexed.hpp index 163d34b159..e57cec531f 100644 --- a/include/armnnUtils/DataLayoutIndexed.hpp +++ b/include/armnnUtils/DataLayoutIndexed.hpp @@ -1,5 +1,5 @@ // -// Copyright © 2019 Arm Ltd. All rights reserved. +// Copyright © 2018-2021,2023 Arm Ltd. All rights reserved. // SPDX-License-Identifier: MIT // @@ -29,13 +29,26 @@ public: unsigned int batchIndex, unsigned int channelIndex, unsigned int heightIndex, unsigned int widthIndex) const { - ARMNN_ASSERT( batchIndex < shape[0] || ( shape[0] == 0 && batchIndex == 0 ) ); - ARMNN_ASSERT( channelIndex < shape[m_ChannelsIndex] || - ( shape[m_ChannelsIndex] == 0 && channelIndex == 0) ); - ARMNN_ASSERT( heightIndex < shape[m_HeightIndex] || - ( shape[m_HeightIndex] == 0 && heightIndex == 0) ); - ARMNN_ASSERT( widthIndex < shape[m_WidthIndex] || - ( shape[m_WidthIndex] == 0 && widthIndex == 0) ); + if (batchIndex >= shape[0] && !( shape[0] == 0 && batchIndex == 0)) + { + throw armnn::Exception("Unable to get batch index", CHECK_LOCATION()); + } + if (channelIndex >= shape[m_ChannelsIndex] && + !(shape[m_ChannelsIndex] == 0 && channelIndex == 0)) + { + throw armnn::Exception("Unable to get channel index", CHECK_LOCATION()); + + } + if (heightIndex >= shape[m_HeightIndex] && + !( shape[m_HeightIndex] == 0 && heightIndex == 0)) + { + throw armnn::Exception("Unable to get height index", CHECK_LOCATION()); + } + if (widthIndex >= shape[m_WidthIndex] && + ( shape[m_WidthIndex] == 0 && widthIndex == 0)) + { + throw armnn::Exception("Unable to get width index", CHECK_LOCATION()); + } /// Offset the given indices appropriately depending on the data layout switch (m_DataLayout) -- cgit v1.2.1