aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Monahan <david.monahan@arm.com>2023-10-04 10:16:24 +0100
committerDavid Monahan <david.monahan@arm.com>2023-10-05 14:32:29 +0000
commit727d017aa3559cb33c97a8d77b5a32fbb98b9e35 (patch)
tree50325eeed2889d8a638d7c986d28caf4ead022af
parentb08844ad13c3b36f82ad3878222eda2ccd1f63a4 (diff)
downloadarmnn-727d017aa3559cb33c97a8d77b5a32fbb98b9e35.tar.gz
IVGCVSW-7750 DTS: Fix ElementWise isnan assert
* Removed the ASSERTS in TypesUtils.cpp in favour of InvalidArgumentExceptions instead * Added a try/catch block when calling EnqueueWorkload to catch Exceptions raised by bad inputs Signed-off-by: David Monahan <david.monahan@arm.com> Change-Id: Icade014ec75db13722eb5d8adc7bdb93c8862417
-rw-r--r--delegate/opaque/src/armnn_delegate.cpp23
-rw-r--r--src/armnn/TypesUtils.cpp20
2 files changed, 33 insertions, 10 deletions
diff --git a/delegate/opaque/src/armnn_delegate.cpp b/delegate/opaque/src/armnn_delegate.cpp
index 6abf7398cc..83e90a0026 100644
--- a/delegate/opaque/src/armnn_delegate.cpp
+++ b/delegate/opaque/src/armnn_delegate.cpp
@@ -600,14 +600,25 @@ TfLiteStatus ArmnnSubgraph::Invoke(TfLiteOpaqueContext* tfLiteContext, TfLiteOpa
}
// Run graph
- auto status = m_Runtime->EnqueueWorkload(m_NetworkId, inputTensors, outputTensors);
- // The delegate holds its own Arm NN runtime so this is our last chance to print internal profiling data.
- std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkId);
- if (profiler && profiler->IsProfilingEnabled())
+ try
{
- profiler->Print(std::cout);
+ auto status = m_Runtime->EnqueueWorkload(m_NetworkId, inputTensors, outputTensors);
+ // The delegate holds its own Arm NN runtime so this is our last chance to print internal profiling data.
+ std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkId);
+ if (profiler && profiler->IsProfilingEnabled())
+ {
+ profiler->Print(std::cout);
+ }
+ return (status == armnn::Status::Success) ? kTfLiteOk : kTfLiteError;
}
- return (status == armnn::Status::Success) ? kTfLiteOk : kTfLiteError;
+ catch (armnn::InvalidArgumentException& ex)
+ {
+ ARMNN_LOG(error) << "ArmNN Failed to EnqueueWorkload with error: " << ex.what();
+ // This should really be kTfLiteDelegateError but the Delegate Test Suite expects kTfLiteError so we return
+ // that instead
+ return kTfLiteError;
+ }
+
}
TfLiteStatus ArmnnSubgraph::VisitNode(DelegateData& delegateData,
diff --git a/src/armnn/TypesUtils.cpp b/src/armnn/TypesUtils.cpp
index 74ac231bc9..d419ef84c7 100644
--- a/src/armnn/TypesUtils.cpp
+++ b/src/armnn/TypesUtils.cpp
@@ -32,8 +32,14 @@ QuantizedType armnn::Quantize(float value, float scale, int32_t offset)
static_assert(IsQuantizedType<QuantizedType>(), "Not an integer type.");
constexpr QuantizedType max = std::numeric_limits<QuantizedType>::max();
constexpr QuantizedType min = std::numeric_limits<QuantizedType>::lowest();
- ARMNN_ASSERT(scale != 0.f);
- ARMNN_ASSERT(!std::isnan(value));
+ if (scale == 0.f)
+ {
+ throw armnn::InvalidArgumentException("Quantize: Scale cannot be 0.f");
+ }
+ if (std::isnan(value))
+ {
+ throw armnn::InvalidArgumentException("Quantize: Value is NaN");
+ }
float clampedValue = std::min(std::max((static_cast<float>(offset) + static_cast<float>(round(value/scale))),
static_cast<float>(min)), static_cast<float>(max));
@@ -46,8 +52,14 @@ template <typename QuantizedType>
float armnn::Dequantize(QuantizedType value, float scale, int32_t offset)
{
static_assert(IsQuantizedType<QuantizedType>(), "Not an integer type.");
- ARMNN_ASSERT(scale != 0.f);
- ARMNN_ASSERT(!IsNan(value));
+ if (scale == 0.f)
+ {
+ throw armnn::InvalidArgumentException("Dequantize: Scale cannot be 0.f");
+ }
+ if (std::isnan(value))
+ {
+ throw armnn::InvalidArgumentException("Dequantize: Value is NaN");
+ }
return (armnn::numeric_cast<float>(value - offset)) * scale;
}