aboutsummaryrefslogtreecommitdiff
path: root/delegate/classic
diff options
context:
space:
mode:
authorRyan OShea <ryan.oshea3@arm.com>2023-06-27 22:34:54 +0100
committerTeresaARM <teresa.charlinreyes@arm.com>2023-08-04 08:34:55 +0000
commitc229b3fd81b42140c0fa8731e90bc07323cec794 (patch)
tree1962789e2810be81cd56a2084b0f7a962f0e4e38 /delegate/classic
parentc377eb8305e6fdc0f4d00bb4766827fc3087bf25 (diff)
downloadarmnn-c229b3fd81b42140c0fa8731e90bc07323cec794.tar.gz
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 <ryan.oshea3@arm.com> Change-Id: Ie052e0180060203f28f64ebf54acad298f431caf
Diffstat (limited to 'delegate/classic')
-rw-r--r--delegate/classic/src/ClassicDelegateUtils.hpp5
-rw-r--r--delegate/classic/src/Split.hpp18
-rw-r--r--delegate/classic/src/Transpose.hpp18
-rw-r--r--delegate/classic/src/armnn_delegate.cpp7
4 files changed, 40 insertions, 8 deletions
diff --git a/delegate/classic/src/ClassicDelegateUtils.hpp b/delegate/classic/src/ClassicDelegateUtils.hpp
index 8a9409df6a..8d6f0495f8 100644
--- a/delegate/classic/src/ClassicDelegateUtils.hpp
+++ b/delegate/classic/src/ClassicDelegateUtils.hpp
@@ -193,7 +193,10 @@ TfLiteStatus Connect(armnn::IConnectableLayer* layer,
TfLiteNode* tfLiteNode,
armnnDelegate::DelegateData& data)
{
- ARMNN_ASSERT(static_cast<unsigned int>(tfLiteNode->outputs->size) == layer->GetNumOutputSlots());
+ if (static_cast<unsigned int>(tfLiteNode->outputs->size) != layer->GetNumOutputSlots())
+ {
+ return kTfLiteError;
+ }
// Connect the input slots
for (unsigned int inputIndex = 0; inputIndex < layer->GetNumInputSlots(); ++inputIndex)
diff --git a/delegate/classic/src/Split.hpp b/delegate/classic/src/Split.hpp
index fcd901b23e..aaa610259f 100644
--- a/delegate/classic/src/Split.hpp
+++ b/delegate/classic/src/Split.hpp
@@ -44,7 +44,11 @@ TfLiteStatus VisitSplitOperator(DelegateData& delegateData,
const armnn::TensorInfo& inputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteInputTensor);
- ARMNN_ASSERT(GetTensorInfoForTfLiteTensor(tfLiteAxisTensor).GetNumElements() == 1);
+ if (GetTensorInfoForTfLiteTensor(tfLiteAxisTensor).GetNumElements() != 1)
+ {
+ return kTfLiteError;
+ }
+
auto* axisTensorDataPtr = tflite::GetTensorData<int32_t>(&tfLiteAxisTensor);
std::vector<int32_t> axisTensorData(axisTensorDataPtr, axisTensorDataPtr + 1);
int32_t axis = axisTensorData[0];
@@ -183,8 +187,16 @@ TfLiteStatus VisitSplitVOperator(DelegateData& delegateData,
const armnn::TensorInfo& inputTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteInputTensor);
const armnn::TensorInfo& splitsTensorInfo = GetTensorInfoForTfLiteTensor(tfLiteSplitsTensor);
- ARMNN_ASSERT(splitsTensorInfo.GetNumDimensions() == 1);
- ARMNN_ASSERT(GetTensorInfoForTfLiteTensor(tfLiteAxisTensor).GetNumElements() == 1);
+
+ if (splitsTensorInfo.GetNumDimensions() != 1)
+ {
+ return kTfLiteError;
+ }
+
+ if (GetTensorInfoForTfLiteTensor(tfLiteAxisTensor).GetNumElements() != 1)
+ {
+ return kTfLiteError;
+ }
auto* axisTensorDataPtr = tflite::GetTensorData<int32_t>(&tfLiteAxisTensor);
std::vector<int32_t> axisTensorData(axisTensorDataPtr, axisTensorDataPtr + 1);
diff --git a/delegate/classic/src/Transpose.hpp b/delegate/classic/src/Transpose.hpp
index 247ddf7e9e..9aa316d8c3 100644
--- a/delegate/classic/src/Transpose.hpp
+++ b/delegate/classic/src/Transpose.hpp
@@ -63,8 +63,15 @@ TfLiteStatus VisitTransposeOperator(DelegateData& delegateData,
auto* permTensorDataPtr = tflite::GetTensorData<int32_t>(&tfLiteInputTensor1);
unsigned int numEl = tfLiteInputTensor1.dims->data[0];
- ARMNN_ASSERT( numEl <= static_cast<int>(armnn::MaxNumOfTensorDimensions));
- ARMNN_ASSERT( tfLiteInputTensor1.dims->size == 1); // ensure only single dimension to the permutation tensor
+ if (numEl > static_cast<int>(armnn::MaxNumOfTensorDimensions))
+ {
+ return kTfLiteError;
+ }
+
+ if (tfLiteInputTensor1.dims->size != 1)
+ {
+ return kTfLiteError;
+ }
armnn::TransposeDescriptor descriptor(armnn::PermutationVector(
reinterpret_cast<const armnn::PermutationVector::ValueType *> (permTensorDataPtr),
@@ -95,7 +102,12 @@ TfLiteStatus VisitTransposeOperator(DelegateData& delegateData,
armnn::IConnectableLayer* transposeLayer = delegateData.m_Network->AddTransposeLayer(descriptor, layerName.c_str());
transposeLayer->SetBackendId(setBackend);
ARMNN_ASSERT(transposeLayer != nullptr);
- ARMNN_ASSERT(transposeLayer->GetNumInputSlots() == 1); // permutation vector given to descriptor object
+
+ // permutation vector given to descriptor object
+ if (transposeLayer->GetNumInputSlots() != 1)
+ {
+ return kTfLiteError;
+ }
armnn::IOutputSlot& outputSlot = transposeLayer->GetOutputSlot(0);
outputSlot.SetTensorInfo(outputTensorInfo);
diff --git a/delegate/classic/src/armnn_delegate.cpp b/delegate/classic/src/armnn_delegate.cpp
index 2483835989..de2aa0c632 100644
--- a/delegate/classic/src/armnn_delegate.cpp
+++ b/delegate/classic/src/armnn_delegate.cpp
@@ -312,7 +312,12 @@ TfLiteStatus ArmnnSubgraph::AddOutputLayer(DelegateData& delegateData,
armnn::IConnectableLayer* layer = delegateData.m_Network->AddOutputLayer(bindingId);
auto tensorInfo = GetTensorInfoForTfLiteTensor(tensor);
- ARMNN_ASSERT(delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)] != nullptr);
+
+ if (delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)] == nullptr)
+ {
+ return kTfLiteError;
+ }
+
delegateData.m_OutputSlotForNode[static_cast<unsigned long>(tensorId)]->Connect(layer->GetInputSlot(0));
outputBindings.push_back(std::make_pair(bindingId, tensorInfo));
}