diff options
author | Colm Donelan <Colm.Donelan@arm.com> | 2020-02-13 20:47:08 +0000 |
---|---|---|
committer | Jim Flynn <jim.flynn@arm.com> | 2020-02-17 13:01:47 +0000 |
commit | fcb802bf62a092806041785cd6081cb99c518527 (patch) | |
tree | 58aa84ab59abeac9a31326691fbb490102f8e6fb /src/backends/backendsCommon/test/MockBackend.hpp | |
parent | cab588ac45bf1c39832d8a278ee46db851c1b015 (diff) | |
download | armnn-fcb802bf62a092806041785cd6081cb99c518527.tar.gz |
IVGCVSW-4340 Backend profiling: Add tests for Timeline functions
* Add tests for the timeline functions that are part of
IBackendProfiling: GetSendTimelinePacket & GetProfilingGuidGenerator
* Modify MockBackendProfilingService to store a
MockBackendProfilingContext shared pointer.
Signed-off-by: Colm Donelan <Colm.Donelan@arm.com>
Change-Id: I99fc4b1da019858b9f29409cd59ef8f590c0d3a2
Diffstat (limited to 'src/backends/backendsCommon/test/MockBackend.hpp')
-rw-r--r-- | src/backends/backendsCommon/test/MockBackend.hpp | 87 |
1 files changed, 43 insertions, 44 deletions
diff --git a/src/backends/backendsCommon/test/MockBackend.hpp b/src/backends/backendsCommon/test/MockBackend.hpp index 641d67ff24..3227ce52fc 100644 --- a/src/backends/backendsCommon/test/MockBackend.hpp +++ b/src/backends/backendsCommon/test/MockBackend.hpp @@ -5,16 +5,16 @@ #pragma once +#include "MockBackendId.hpp" #include "armnn/backends/profiling/IBackendProfiling.hpp" #include "armnn/backends/profiling/IBackendProfilingContext.hpp" -#include "MockBackendId.hpp" #include <LayerSupportCommon.hpp> #include <armnn/backends/IBackendInternal.hpp> #include <armnn/backends/OptimizationViews.hpp> -#include <backendsCommon/LayerSupportBase.hpp> #include <armnn/backends/profiling/IBackendProfiling.hpp> #include <backends/BackendProfiling.hpp> +#include <backendsCommon/LayerSupportBase.hpp> namespace armnn { @@ -26,35 +26,11 @@ public: ~MockBackendInitialiser(); }; -class MockBackendProfilingService -{ -public: - // Getter for the singleton instance - static MockBackendProfilingService& Instance() - { - static MockBackendProfilingService instance; - return instance; - } - - armnn::profiling::IBackendProfilingContext* GetContext() - { - return m_sharedContext.get(); - } - - void SetProfilingContextPtr(IBackendInternal::IBackendProfilingContextPtr& shared) - { - m_sharedContext = shared; - } - -private: - IBackendInternal::IBackendProfilingContextPtr m_sharedContext; -}; - class MockBackendProfilingContext : public profiling::IBackendProfilingContext { public: MockBackendProfilingContext(IBackendInternal::IBackendProfilingPtr& backendProfiling) - : m_BackendProfiling(backendProfiling) + : m_BackendProfiling(std::move(backendProfiling)) , m_CapturePeriod(0) {} @@ -70,23 +46,23 @@ public: std::unique_ptr<profiling::IRegisterBackendCounters> counterRegistrar = m_BackendProfiling->GetCounterRegistrationInterface(currentMaxGlobalCounterId); - std::string categoryName("MockCounters"); - counterRegistrar->RegisterCategory(categoryName); - uint16_t nextMaxGlobalCounterId = counterRegistrar->RegisterCounter( - 0, categoryName, 0, 0, 1.f, "Mock Counter One", "Some notional counter"); + std::string categoryName("MockCounters"); + counterRegistrar->RegisterCategory(categoryName); + uint16_t nextMaxGlobalCounterId = + counterRegistrar->RegisterCounter(0, categoryName, 0, 0, 1.f, "Mock Counter One", "Some notional counter"); - nextMaxGlobalCounterId = counterRegistrar->RegisterCounter( - 1, categoryName, 0, 0, 1.f, "Mock Counter Two", "Another notional counter"); + nextMaxGlobalCounterId = counterRegistrar->RegisterCounter(1, categoryName, 0, 0, 1.f, "Mock Counter Two", + "Another notional counter"); - std::string units("microseconds"); - nextMaxGlobalCounterId = counterRegistrar->RegisterCounter( - 2, categoryName, 0, 0, 1.f, "Mock MultiCore Counter", "A dummy four core counter", units, 4); - return nextMaxGlobalCounterId; + std::string units("microseconds"); + nextMaxGlobalCounterId = counterRegistrar->RegisterCounter(2, categoryName, 0, 0, 1.f, "Mock MultiCore Counter", + "A dummy four core counter", units, 4); + return nextMaxGlobalCounterId; } Optional<std::string> ActivateCounters(uint32_t capturePeriod, const std::vector<uint16_t>& counterIds) { - if ( capturePeriod == 0 || counterIds.size() == 0) + if (capturePeriod == 0 || counterIds.size() == 0) { m_ActiveCounters.clear(); } @@ -94,7 +70,7 @@ public: { return armnn::Optional<std::string>("ActivateCounters example test error"); } - m_CapturePeriod = capturePeriod; + m_CapturePeriod = capturePeriod; m_ActiveCounters = counterIds; return armnn::Optional<std::string>(); } @@ -103,25 +79,48 @@ public: { std::vector<profiling::CounterValue> counterValues; - for(auto counterId : m_ActiveCounters) + for (auto counterId : m_ActiveCounters) { - counterValues.emplace_back(profiling::CounterValue{counterId, counterId+1u}); + counterValues.emplace_back(profiling::CounterValue{ counterId, counterId + 1u }); } uint64_t timestamp = m_CapturePeriod; - return {profiling::Timestamp{timestamp, counterValues}}; + return { profiling::Timestamp{ timestamp, counterValues } }; } void EnableProfiling(bool) {} private: - - IBackendInternal::IBackendProfilingPtr& m_BackendProfiling; + IBackendInternal::IBackendProfilingPtr m_BackendProfiling; uint32_t m_CapturePeriod; std::vector<uint16_t> m_ActiveCounters; }; +class MockBackendProfilingService +{ +public: + // Getter for the singleton instance + static MockBackendProfilingService& Instance() + { + static MockBackendProfilingService instance; + return instance; + } + + MockBackendProfilingContext* GetContext() + { + return m_sharedContext.get(); + } + + void SetProfilingContextPtr(std::shared_ptr<MockBackendProfilingContext> shared) + { + m_sharedContext = shared; + } + +private: + std::shared_ptr<MockBackendProfilingContext> m_sharedContext; +}; + class MockBackend : public IBackendInternal { public: |