From f0755de796bbe6a763fbfc349465484c88b9b3eb Mon Sep 17 00:00:00 2001 From: Colm Donelan Date: Tue, 4 Apr 2023 21:41:29 +0100 Subject: IVGCVSW-6681 Improve error handling in TfLiteExecutor. The initial model load and tensor allocation operations against the TfLiteInterpreter were not checking return codes resulting in segmentation faults. Signed-off-by: Colm Donelan Change-Id: I812785f0af9012c97570065d200f72eaf781165a --- tests/ExecuteNetwork/TfliteExecutor.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/ExecuteNetwork/TfliteExecutor.cpp b/tests/ExecuteNetwork/TfliteExecutor.cpp index f365623d62..87731c2f83 100644 --- a/tests/ExecuteNetwork/TfliteExecutor.cpp +++ b/tests/ExecuteNetwork/TfliteExecutor.cpp @@ -18,10 +18,14 @@ TfLiteExecutor::TfLiteExecutor(const ExecuteNetworkParams& params, armnn::IRunti tflite::ops::builtin::BuiltinOpResolver resolver; tflite::InterpreterBuilder builder(*m_Model, resolver); - builder(&m_TfLiteInterpreter); - m_TfLiteInterpreter->AllocateTensors(); - - int status = kTfLiteError; + if (builder(&m_TfLiteInterpreter) != kTfLiteOk) + { + LogAndThrow("Error loading the model into the TfLiteInterpreter."); + } + if (m_TfLiteInterpreter->AllocateTensors() != kTfLiteOk) + { + LogAndThrow("Failed to allocate tensors in the TfLiteInterpreter."); + } if (m_Params.m_TfLiteExecutor == ExecuteNetworkParams::TfLiteExecutor::ArmNNTfLiteDelegate) { // Create the Armnn Delegate @@ -32,10 +36,9 @@ TfLiteExecutor::TfLiteExecutor(const ExecuteNetworkParams& params, armnn::IRunti theArmnnDelegate(armnnDelegate::TfLiteArmnnDelegateCreate(delegateOptions), armnnDelegate::TfLiteArmnnDelegateDelete); // Register armnn_delegate to TfLiteInterpreter - status = m_TfLiteInterpreter->ModifyGraphWithDelegate(std::move(theArmnnDelegate)); - if (status != kTfLiteOk) + if (m_TfLiteInterpreter->ModifyGraphWithDelegate(std::move(theArmnnDelegate)) != kTfLiteOk) { - LogAndThrow("Could not register ArmNN TfLite Delegate to TfLiteInterpreter"); + LogAndThrow("Could not register ArmNN TfLite Delegate to TfLiteInterpreter."); } } else -- cgit v1.2.1