diff options
author | Ryan OShea <ryan.oshea3@arm.com> | 2023-06-27 22:34:54 +0100 |
---|---|---|
committer | TeresaARM <teresa.charlinreyes@arm.com> | 2023-08-04 08:34:55 +0000 |
commit | c229b3fd81b42140c0fa8731e90bc07323cec794 (patch) | |
tree | 1962789e2810be81cd56a2084b0f7a962f0e4e38 /delegate/opaque | |
parent | c377eb8305e6fdc0f4d00bb4766827fc3087bf25 (diff) | |
download | armnn-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/opaque')
-rw-r--r-- | delegate/opaque/src/Split.hpp | 18 | ||||
-rw-r--r-- | delegate/opaque/src/Transpose.hpp | 16 | ||||
-rw-r--r-- | delegate/opaque/src/armnn_delegate.cpp | 7 |
3 files changed, 34 insertions, 7 deletions
diff --git a/delegate/opaque/src/Split.hpp b/delegate/opaque/src/Split.hpp index aec0fb674a..2dbfa602fb 100644 --- a/delegate/opaque/src/Split.hpp +++ b/delegate/opaque/src/Split.hpp @@ -68,7 +68,11 @@ TfLiteStatus VisitSplitOperator(DelegateData& delegateData, const armnn::TensorInfo& inputTensorInfo = GetTensorInfoForTfLiteOpaqueTensor(tfLiteInputTensor); - ARMNN_ASSERT(GetTensorInfoForTfLiteOpaqueTensor(tfLiteAxisTensor).GetNumElements() == 1); + if (GetTensorInfoForTfLiteOpaqueTensor(tfLiteAxisTensor).GetNumElements() != 1) + { + return kTfLiteError; + } + auto* axisTensorDataPtr = static_cast<uint32_t*>(TfLiteOpaqueTensorData(tfLiteAxisTensor)); std::vector<int32_t> axisTensorData(axisTensorDataPtr, axisTensorDataPtr + 1); int32_t axis = axisTensorData[0]; @@ -230,8 +234,16 @@ TfLiteStatus VisitSplitVOperator(DelegateData& delegateData, const armnn::TensorInfo& inputTensorInfo = GetTensorInfoForTfLiteOpaqueTensor(tfLiteInputTensor); const armnn::TensorInfo& splitsTensorInfo = GetTensorInfoForTfLiteOpaqueTensor(tfLiteSplitsTensor); - ARMNN_ASSERT(splitsTensorInfo.GetNumDimensions() == 1); - ARMNN_ASSERT(GetTensorInfoForTfLiteOpaqueTensor(tfLiteAxisTensor).GetNumElements() == 1); + + if (splitsTensorInfo.GetNumDimensions() != 1) + { + return kTfLiteError; + } + + if (GetTensorInfoForTfLiteOpaqueTensor(tfLiteAxisTensor).GetNumElements() != 1) + { + return kTfLiteError; + } auto* axisTensorDataPtr = static_cast<uint32_t*>(TfLiteOpaqueTensorData(tfLiteAxisTensor)); std::vector<int32_t> axisTensorData(axisTensorDataPtr, axisTensorDataPtr + 1); diff --git a/delegate/opaque/src/Transpose.hpp b/delegate/opaque/src/Transpose.hpp index 5af03b3790..4b2bdf376a 100644 --- a/delegate/opaque/src/Transpose.hpp +++ b/delegate/opaque/src/Transpose.hpp @@ -65,9 +65,16 @@ TfLiteStatus VisitTransposeOperator(DelegateData& delegateData, auto* permTensorDataPtr = static_cast<int32_t*>(TfLiteOpaqueTensorData(tfLiteInputTensor1)); unsigned int numEl = TfLiteOpaqueTensorDim(tfLiteInputTensor1, 0); - ARMNN_ASSERT( numEl <= static_cast<int>(armnn::MaxNumOfTensorDimensions) ); + if ( numEl > static_cast<int>(armnn::MaxNumOfTensorDimensions) ) + { + return kTfLiteError; + } + // Ensure only single dimension to the permutation tensor - ARMNN_ASSERT( TfLiteOpaqueTensorNumDims(tfLiteInputTensor1) == 1 ); + if ( TfLiteOpaqueTensorNumDims(tfLiteInputTensor1) != 1 ) + { + return kTfLiteError; + } armnn::TransposeDescriptor descriptor(armnn::PermutationVector( reinterpret_cast<const armnn::PermutationVector::ValueType *> (permTensorDataPtr), @@ -99,7 +106,10 @@ TfLiteStatus VisitTransposeOperator(DelegateData& delegateData, transposeLayer->SetBackendId(setBackend); ARMNN_ASSERT(transposeLayer != nullptr); // Permutation vector given to descriptor object - ARMNN_ASSERT(transposeLayer->GetNumInputSlots() == 1); + if (transposeLayer->GetNumInputSlots() != 1) + { + return kTfLiteError; + } armnn::IOutputSlot& outputSlot = transposeLayer->GetOutputSlot(0); outputSlot.SetTensorInfo(outputTensorInfo); diff --git a/delegate/opaque/src/armnn_delegate.cpp b/delegate/opaque/src/armnn_delegate.cpp index 60da293eb2..bad1abaa59 100644 --- a/delegate/opaque/src/armnn_delegate.cpp +++ b/delegate/opaque/src/armnn_delegate.cpp @@ -368,7 +368,12 @@ TfLiteStatus ArmnnSubgraph::AddOutputLayer(DelegateData& delegateData, armnn::IConnectableLayer* layer = delegateData.m_Network->AddOutputLayer(bindingId); auto tensorInfo = GetTensorInfoForTfLiteOpaqueTensor(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)); } |