diff options
author | Jim Flynn <jim.flynn@arm.com> | 2023-09-17 09:02:23 +0100 |
---|---|---|
committer | TeresaARM <teresa.charlinreyes@arm.com> | 2023-09-18 13:57:00 +0000 |
commit | 39faea8ee9a503e0ae5d642c27c08255de92bb1a (patch) | |
tree | fc1a00bee4f85ef7c5c672fa8ed20b5f9cdc2856 | |
parent | 244887412338073c56af5feb7a5c0dbe2c351b8f (diff) | |
download | armnn-39faea8ee9a503e0ae5d642c27c08255de92bb1a.tar.gz |
IVGCVSW-7855 removed ASSERTs from armnnUtils code
Signed-off-by: Jim Flynn <jim.flynn@arm.com>
Change-Id: Ie26ea2ac4a82d7460ae719fc3154c6a88b079606
-rw-r--r-- | src/armnnUtils/FloatingPointConverter.cpp | 21 | ||||
-rw-r--r-- | src/armnnUtils/ModelAccuracyChecker.cpp | 8 | ||||
-rw-r--r-- | src/armnnUtils/TensorUtils.cpp | 48 |
3 files changed, 64 insertions, 13 deletions
diff --git a/src/armnnUtils/FloatingPointConverter.cpp b/src/armnnUtils/FloatingPointConverter.cpp index 024b74eea4..102ad09832 100644 --- a/src/armnnUtils/FloatingPointConverter.cpp +++ b/src/armnnUtils/FloatingPointConverter.cpp @@ -8,6 +8,7 @@ #include "BFloat16.hpp" #include "Half.hpp" +#include <armnn/Exceptions.hpp> #include <armnn/utility/Assert.hpp> namespace armnnUtils @@ -17,8 +18,14 @@ void FloatingPointConverter::ConvertFloat32To16(const float* srcFloat32Buffer, size_t numElements, void* dstFloat16Buffer) { - ARMNN_ASSERT(srcFloat32Buffer != nullptr); - ARMNN_ASSERT(dstFloat16Buffer != nullptr); + if (srcFloat32Buffer == nullptr) + { + throw armnn::InvalidArgumentException("ConvertFloat32To16: source float32 buffer pointer is null"); + } + if (dstFloat16Buffer == nullptr) + { + throw armnn::InvalidArgumentException("ConvertFloat32To16: destination float16 buffer pointer is null"); + } armnn::Half* pHalf = static_cast<armnn::Half*>(dstFloat16Buffer); @@ -37,8 +44,14 @@ void FloatingPointConverter::ConvertFloat16To32(const void* srcFloat16Buffer, size_t numElements, float* dstFloat32Buffer) { - ARMNN_ASSERT(srcFloat16Buffer != nullptr); - ARMNN_ASSERT(dstFloat32Buffer != nullptr); + if (srcFloat16Buffer == nullptr) + { + throw armnn::InvalidArgumentException("ConvertFloat16To32: source float16 buffer pointer is null"); + } + if (dstFloat32Buffer == nullptr) + { + throw armnn::InvalidArgumentException("ConvertFloat16To32: destination float32 buffer pointer is null"); + } const armnn::Half* pHalf = static_cast<const armnn::Half*>(srcFloat16Buffer); diff --git a/src/armnnUtils/ModelAccuracyChecker.cpp b/src/armnnUtils/ModelAccuracyChecker.cpp index 418737c0f6..83cd0cbcc6 100644 --- a/src/armnnUtils/ModelAccuracyChecker.cpp +++ b/src/armnnUtils/ModelAccuracyChecker.cpp @@ -5,6 +5,7 @@ #include "ModelAccuracyChecker.hpp" +#include <armnn/Exceptions.hpp> #include <armnn/Logging.hpp> #include <map> @@ -63,7 +64,10 @@ std::vector<std::string> // Remove any preceding and trailing character specified in the characterSet. std::string Strip(const std::string& originalString, const std::string& characterSet) { - ARMNN_ASSERT(!characterSet.empty()); + if (characterSet.empty()) + { + throw armnn::InvalidArgumentException("Strip: string of characters to strip is empty"); + } const std::size_t firstFound = originalString.find_first_not_of(characterSet); const std::size_t lastFound = originalString.find_last_not_of(characterSet); // Return empty if the originalString is empty or the originalString contains only to-be-striped characters @@ -73,4 +77,4 @@ std::string Strip(const std::string& originalString, const std::string& characte } return originalString.substr(firstFound, lastFound + 1 - firstFound); } -} // namespace armnnUtils
\ No newline at end of file +} // namespace armnnUtils diff --git a/src/armnnUtils/TensorUtils.cpp b/src/armnnUtils/TensorUtils.cpp index cb73d92ef8..3e703a563a 100644 --- a/src/armnnUtils/TensorUtils.cpp +++ b/src/armnnUtils/TensorUtils.cpp @@ -5,6 +5,8 @@ #include <armnnUtils/TensorUtils.hpp> +#include <armnn/Exceptions.hpp> + #include <armnn/backends/ITensorHandle.hpp> #include <armnn/utility/Assert.hpp> #include <armnn/utility/NumericCast.hpp> @@ -208,8 +210,21 @@ unsigned int GetNumElementsBetween(const TensorShape& shape, const unsigned int firstAxisInclusive, const unsigned int lastAxisExclusive) { - ARMNN_ASSERT(firstAxisInclusive <= lastAxisExclusive); - ARMNN_ASSERT(lastAxisExclusive <= shape.GetNumDimensions()); + if (firstAxisInclusive > lastAxisExclusive) + { + throw armnn::InvalidArgumentException(fmt::format( + "GetNumElementsBetween: firstAxisInclusive [{}D] is greater than lastAxisExclusive [{}D]", + firstAxisInclusive, + lastAxisExclusive)); + } + if (lastAxisExclusive > shape.GetNumDimensions()) + { + throw armnn::InvalidArgumentException(fmt::format( + "{}: lastAxisExclusive [{}D] is greater than the number of dimensions of the tensor shape [{}D]" + "GetNumElementsBetween", + lastAxisExclusive, + shape.GetNumDimensions())); + } unsigned int count = 1; for (unsigned int i = firstAxisInclusive; i < lastAxisExclusive; i++) { @@ -220,10 +235,22 @@ unsigned int GetNumElementsBetween(const TensorShape& shape, unsigned int GetUnsignedAxis(const unsigned int inputDimension, const int axis) { - ARMNN_ASSERT_MSG(axis < armnn::numeric_cast<int>(inputDimension), - "Required axis index greater than number of dimensions."); - ARMNN_ASSERT_MSG(axis >= -armnn::numeric_cast<int>(inputDimension), - "Required axis index lower than negative of the number of dimensions"); + if (axis >= armnn::numeric_cast<int>(inputDimension)) + { + throw armnn::InvalidArgumentException(fmt::format( + "{}: axis index [{}] is not less than the number of dimensions [{}D]", + "GetUnsignedAxis", + axis, + inputDimension)); + } + if (axis < -armnn::numeric_cast<int>(inputDimension)) + { + throw armnn::InvalidArgumentException(fmt::format( + "{}: axis index [{}] lower than the negative of the number of dimensions [{}]", + "GetUnsignedAxis", + axis, + -armnn::numeric_cast<int>(inputDimension))); + } unsigned int uAxis = axis < 0 ? inputDimension - armnn::numeric_cast<unsigned int>(abs(axis)) @@ -234,7 +261,14 @@ unsigned int GetUnsignedAxis(const unsigned int inputDimension, const int axis) unsigned int GetNumElementsAfter(const armnn::TensorShape& shape, unsigned int axis) { unsigned int numDim = shape.GetNumDimensions(); - ARMNN_ASSERT(axis <= numDim - 1); + if (axis >= numDim) + { + throw armnn::InvalidArgumentException(fmt::format( + "{}: axis index [{}D] indexes beyond the number of dimesions of the tensor shape [{}D]", + "GetNumElementsAfter", + axis, + numDim)); + } unsigned int count = 1; for (unsigned int i = axis+1; i < numDim; i++) { |