From a8e06ed540a934f966679e1ef1cf7acf295211b3 Mon Sep 17 00:00:00 2001 From: Aron Virginas-Tar Date: Fri, 19 Oct 2018 16:46:15 +0100 Subject: IVGCVSW-1955: Unify backend exceptions (wrap cl::Error) * Added wrapper function around arm_compute::IFunction::run() that catches cl::Error and wraps it into an armnn::RuntimeException * Added MakeWorkload template inside ClWorkloadFactory that catches cl::Error and wraps it into an armnn::RuntimeException * Replaced cl::Error with armnn::RuntimeException in catch statements inside LoadedNetwork Change-Id: I2340f41ae02b8db1d7ef5157824a50e7410854e3 --- src/armnn/LoadedNetwork.cpp | 56 ++++++++++++++++++--------------------------- 1 file changed, 22 insertions(+), 34 deletions(-) (limited to 'src/armnn') diff --git a/src/armnn/LoadedNetwork.cpp b/src/armnn/LoadedNetwork.cpp index 4f73bda832..f49fa7b878 100644 --- a/src/armnn/LoadedNetwork.cpp +++ b/src/armnn/LoadedNetwork.cpp @@ -11,10 +11,6 @@ #include "Profiling.hpp" #include "HeapProfiling.hpp" -#ifdef ARMCOMPUTECL_ENABLED -#include -#endif - #include #include @@ -38,15 +34,6 @@ std::string ToErrorMessage(const char * prefix, const ExceptionType & error) return ss.str(); } -#if ARMCOMPUTECL_ENABLED -std::string ToErrorMessage(const char * prefix, const cl::Error& error) -{ - std::stringstream ss; - ss << prefix << " " << error.what() << ". CL error code is: " << error.err(); - return ss.str(); -} -#endif - } // anonymous std::unique_ptr LoadedNetwork::MakeLoadedNetwork(std::unique_ptr net, @@ -54,30 +41,30 @@ std::unique_ptr LoadedNetwork::MakeLoadedNetwork(std::unique_ptr< { std::unique_ptr loadedNetwork; + auto Fail = [&](const std::exception& error) -> std::unique_ptr + { + errorMessage = ToErrorMessage("An error occurred when preparing the network workloads: ", error); + BOOST_LOG_TRIVIAL(error) << errorMessage; + + return std::unique_ptr(); + }; + try { loadedNetwork.reset(new LoadedNetwork(std::move(net))); } - catch (const std::runtime_error& error) + catch (const armnn::RuntimeException& error) { - errorMessage = ToErrorMessage("An error occurred when preparing the network workloads: ", error); - BOOST_LOG_TRIVIAL(error) << errorMessage; - return std::unique_ptr(); + return Fail(error); } catch (const armnn::Exception& error) { - errorMessage = ToErrorMessage("An error occurred when preparing the network workloads: ", error); - BOOST_LOG_TRIVIAL(error) << errorMessage; - return std::unique_ptr(); + return Fail(error); } -#if ARMCOMPUTECL_ENABLED - catch (const cl::Error& error) + catch (const std::runtime_error& error) { - errorMessage = ToErrorMessage("A CL error occurred attempting to prepare a network workload: ", error); - BOOST_LOG_TRIVIAL(error) << errorMessage; - return std::unique_ptr(); + return Fail(error); } -#endif return loadedNetwork; } @@ -420,6 +407,12 @@ bool LoadedNetwork::Execute() m_CpuAcc.Acquire(); m_GpuAcc.Acquire(); + auto Fail = [&](const std::exception& error) + { + BOOST_LOG_TRIVIAL(error) << "An error occurred attempting to execute a workload: " << error.what(); + success = false; + }; + try { for (size_t i = 0; i < m_WorkloadQueue.size(); ++i) @@ -427,18 +420,13 @@ bool LoadedNetwork::Execute() m_WorkloadQueue[i]->Execute(); } } -#if ARMCOMPUTECL_ENABLED - catch (const cl::Error& error) + catch (const RuntimeException& error) { - BOOST_LOG_TRIVIAL(error) << "A CL error occurred attempting to execute a workload: " - << error.what() << ". CL error code is: " << error.err(); - success = false; + Fail(error); } -#endif catch (const std::runtime_error& error) { - BOOST_LOG_TRIVIAL(error) << "An error occurred attempting to execute a workload: " << error.what(); - success = false; + Fail(error); } // Informs the memory managers to release memory in it's respective memory group -- cgit v1.2.1