diff options
author | Aron Virginas-Tar <Aron.Virginas-Tar@arm.com> | 2018-10-19 16:46:15 +0100 |
---|---|---|
committer | Matthew Bentham <matthew.bentham@arm.com> | 2018-10-22 16:57:54 +0100 |
commit | a8e06ed540a934f966679e1ef1cf7acf295211b3 (patch) | |
tree | 247035d1bce6ddb8543081a88294a85e34968035 /src/armnn/LoadedNetwork.cpp | |
parent | f0b4845c1c6f24f59d4c88473b852cf69a3c7ae9 (diff) | |
download | armnn-a8e06ed540a934f966679e1ef1cf7acf295211b3.tar.gz |
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
Diffstat (limited to 'src/armnn/LoadedNetwork.cpp')
-rw-r--r-- | src/armnn/LoadedNetwork.cpp | 56 |
1 files changed, 22 insertions, 34 deletions
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 <arm_compute/core/CL/OpenCL.h> -#endif - #include <backends/CpuTensorHandle.hpp> #include <boost/polymorphic_cast.hpp> @@ -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> LoadedNetwork::MakeLoadedNetwork(std::unique_ptr<OptimizedNetwork> net, @@ -54,30 +41,30 @@ std::unique_ptr<LoadedNetwork> LoadedNetwork::MakeLoadedNetwork(std::unique_ptr< { std::unique_ptr<LoadedNetwork> loadedNetwork; + auto Fail = [&](const std::exception& error) -> std::unique_ptr<LoadedNetwork> + { + errorMessage = ToErrorMessage("An error occurred when preparing the network workloads: ", error); + BOOST_LOG_TRIVIAL(error) << errorMessage; + + return std::unique_ptr<LoadedNetwork>(); + }; + 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<LoadedNetwork>(); + 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<LoadedNetwork>(); + 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<LoadedNetwork>(); + 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 |