From b015e5db20e29825caefa05d828fbeed73119b19 Mon Sep 17 00:00:00 2001 From: David Monahan Date: Wed, 26 Feb 2020 10:24:03 +0000 Subject: Modifying the IBackendProfilingContext interface to return a bool on EnableProfiling and adding error checking to the Runtime Invocation Signed-off-by: David Monahan Change-Id: I65b8bb16c6f1c7d668de31238ce0408a48974997 --- include/armnn/Exceptions.hpp | 6 ++++++ .../armnn/backends/profiling/IBackendProfilingContext.hpp | 2 +- src/armnn/Runtime.cpp | 12 ++++++++++-- src/backends/backendsCommon/test/MockBackend.hpp | 6 ++++-- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/include/armnn/Exceptions.hpp b/include/armnn/Exceptions.hpp index 066f59f792..cb62079b76 100644 --- a/include/armnn/Exceptions.hpp +++ b/include/armnn/Exceptions.hpp @@ -137,6 +137,12 @@ class TimeoutException : public Exception using Exception::Exception; }; +class BackendProfilingException : public Exception +{ +public: + using Exception::Exception; +}; + template void ConditionalThrow(bool condition, const std::string& message) { diff --git a/include/armnn/backends/profiling/IBackendProfilingContext.hpp b/include/armnn/backends/profiling/IBackendProfilingContext.hpp index 3f54d31961..063ebc946d 100644 --- a/include/armnn/backends/profiling/IBackendProfilingContext.hpp +++ b/include/armnn/backends/profiling/IBackendProfilingContext.hpp @@ -21,7 +21,7 @@ public: virtual uint16_t RegisterCounters(uint16_t currentMaxGlobalCounterID) = 0; virtual Optional ActivateCounters(uint32_t capturePeriod, const std::vector& counterIds) = 0; virtual std::vector ReportCounterValues() = 0; - virtual void EnableProfiling(bool flag) = 0; + virtual bool EnableProfiling(bool flag) = 0; }; using IBackendProfilingContextUniquePtr = std::unique_ptr; diff --git a/src/armnn/Runtime.cpp b/src/armnn/Runtime.cpp index c1416f94d7..b1017c58ed 100644 --- a/src/armnn/Runtime.cpp +++ b/src/armnn/Runtime.cpp @@ -192,8 +192,16 @@ Runtime::Runtime(const CreationOptions& options) // Backends that don't support profiling will return a null profiling context. if (profilingContext) { - // Pass the context onto the profiling service. - armnn::profiling::ProfilingService::Instance().AddBackendProfilingContext(id, profilingContext); + // Enable profiling on the backend and assert that it returns true + if(profilingContext->EnableProfiling(true)) + { + // Pass the context onto the profiling service. + armnn::profiling::ProfilingService::Instance().AddBackendProfilingContext(id, profilingContext); + } + else + { + throw BackendProfilingException("Unable to enable profiling on Backend Id: " + id.Get()); + } } } catch (const BackendUnavailableException&) diff --git a/src/backends/backendsCommon/test/MockBackend.hpp b/src/backends/backendsCommon/test/MockBackend.hpp index 3227ce52fc..6e415b9b52 100644 --- a/src/backends/backendsCommon/test/MockBackend.hpp +++ b/src/backends/backendsCommon/test/MockBackend.hpp @@ -88,8 +88,10 @@ public: return { profiling::Timestamp{ timestamp, counterValues } }; } - void EnableProfiling(bool) - {} + bool EnableProfiling(bool) + { + return true; + } private: IBackendInternal::IBackendProfilingPtr m_BackendProfiling; -- cgit v1.2.1