class IBackendProfilingContext
{
-protected:
- IBackendProfilingContext(const IRuntime::CreationOptions&)
- {}
-
public:
virtual ~IBackendProfilingContext()
{}
- virtual uint16_t RegisterCounters(uint16_t currentMaxGlobalCounterID);
- virtual void ActivateCounters(uint32_t capturePeriod, const std::vector<uint16_t>& counterIds);
- virtual std::vector<Timestamp> ReportCounterValues();
- virtual void EnableProfiling(bool flag);
+ virtual uint16_t RegisterCounters(uint16_t currentMaxGlobalCounterID) = 0;
+ virtual void ActivateCounters(uint32_t capturePeriod, const std::vector<uint16_t>& counterIds) = 0;
+ virtual std::vector<Timestamp> ReportCounterValues() = 0;
+ virtual void EnableProfiling(bool flag) = 0;
};
using IBackendProfilingContextUniquePtr = std::unique_ptr<IBackendProfilingContext>;
--- /dev/null
+//
+// Copyright © 2020 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "MockBackend.hpp"
+#include "MockBackendId.hpp"
+#include "Runtime.hpp"
+
+#include <armnn/BackendId.hpp>
+#include <boost/test/unit_test.hpp>
+#include <vector>
+
+BOOST_AUTO_TEST_SUITE(BackendProfilingTestSuite)
+
+BOOST_AUTO_TEST_CASE(BackendProfilingCounterRegisterMockBackendTest)
+{
+ // Reset the profiling service to the uninitialized state
+ armnn::IRuntime::CreationOptions options;
+ options.m_ProfilingOptions.m_EnableProfiling = true;
+ armnn::profiling::ProfilingService& profilingService = armnn::profiling::ProfilingService::Instance();
+ profilingService.ConfigureProfilingService(options.m_ProfilingOptions, true);
+
+ armnn::MockBackendInitialiser initialiser;
+ // Create a runtime
+ armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
+
+ // Check if the MockBackends 3 dummy counters {0, 1, 2-5 (four cores)} are registered
+ armnn::BackendId mockId = armnn::MockBackendId();
+ const armnn::profiling::ICounterMappings& counterMap = profilingService.GetCounterMappings();
+ BOOST_CHECK(counterMap.GetGlobalId(0, mockId) == 5);
+ BOOST_CHECK(counterMap.GetGlobalId(1, mockId) == 6);
+ BOOST_CHECK(counterMap.GetGlobalId(2, mockId) == 7);
+ BOOST_CHECK(counterMap.GetGlobalId(3, mockId) == 8);
+ BOOST_CHECK(counterMap.GetGlobalId(4, mockId) == 9);
+ BOOST_CHECK(counterMap.GetGlobalId(5, mockId) == 10);
+ options.m_ProfilingOptions.m_EnableProfiling = false;
+ profilingService.ResetExternalProfilingOptions(options.m_ProfilingOptions, true);
+}
+
+BOOST_AUTO_TEST_SUITE_END()
\ No newline at end of file
factoryFunction();
BOOST_TEST(called == true);
+ BackendRegistryInstance().Deregister("HelloWorld");
}
BOOST_AUTO_TEST_CASE(TestDirectCallToRegistry)
factoryFunction();
BOOST_TEST(called == true);
+ BackendRegistryInstance().Deregister("HelloWorld");
}
BOOST_AUTO_TEST_SUITE_END()
ActivationFixture.hpp
ArgMinMaxEndToEndTestImpl.hpp
BackendIdTests.cpp
+ BackendProfilingTests.cpp
BackendRegistryTests.cpp
CommonTestUtils.cpp
CommonTestUtils.hpp
#include "MockBackend.hpp"
#include "MockBackendId.hpp"
+#include "armnn/backends/profiling/IBackendProfilingContext.hpp"
#include <armnn/BackendRegistry.hpp>
namespace armnn
{
-namespace
+MockBackendInitialiser::MockBackendInitialiser()
{
+ BackendRegistryInstance().Register(MockBackend::GetIdStatic(),
+ []()
+ {
+ return IBackendInternalUniquePtr(new MockBackend);
+ });
+}
-static BackendRegistry::StaticRegistryInitializer g_RegisterHelper
+MockBackendInitialiser::~MockBackendInitialiser()
{
- BackendRegistryInstance(),
- MockBackend::GetIdStatic(),
- []()
+ try
{
- return IBackendInternalUniquePtr(new MockBackend);
+ BackendRegistryInstance().Deregister(MockBackend::GetIdStatic());
+ }
+ catch (...)
+ {
+ std::cerr << "could not deregister mock backend" << std::endl;
}
-};
-
}
const BackendId& MockBackend::GetIdStatic()
}
IBackendInternal::IBackendProfilingContextPtr MockBackend::CreateBackendProfilingContext(
- const IRuntime::CreationOptions&, IBackendProfilingPtr&)
+ const IRuntime::CreationOptions& options, IBackendProfilingPtr& backendProfiling)
{
- return IBackendProfilingContextPtr{};
+ boost::ignore_unused(options);
+ IBackendInternal::IBackendProfilingContextPtr context =
+ std::make_shared<MockBackendProfilingContext>(MockBackendProfilingContext(backendProfiling));
+ MockBackendProfilingService::Instance().SetProfilingContextPtr(context);
+ return context;
}
IBackendInternal::IMemoryManagerUniquePtr MockBackend::CreateMemoryManager() const
#pragma once
+#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>
namespace armnn
{
+class MockBackendInitialiser
+{
+public:
+ MockBackendInitialiser();
+ ~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)
+ {}
+
+ ~MockBackendProfilingContext() = default;
+
+ IBackendInternal::IBackendProfilingPtr& GetBackendProfiling()
+ {
+ return m_BackendProfiling;
+ }
+
+ uint16_t RegisterCounters(uint16_t currentMaxGlobalCounterId)
+ {
+ 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");
+
+ 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;
+ }
+
+ void ActivateCounters(uint32_t, const std::vector<uint16_t>&)
+ {}
+
+ std::vector<profiling::Timestamp> ReportCounterValues()
+ {
+ return std::vector<profiling::Timestamp>();
+ }
+
+ void EnableProfiling(bool)
+ {}
+
+private:
+ IBackendInternal::IBackendProfilingPtr& m_BackendProfiling;
+};
class MockBackend : public IBackendInternal
{
input1->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 1, 1, 4, 4 }, armnn::DataType::Float32));
addition->GetOutputSlot(0).SetTensorInfo(armnn::TensorInfo({ 1, 1, 4, 4 }, armnn::DataType::Float32));
+ armnn::MockBackendInitialiser initialiser;
armnn::IRuntime::CreationOptions options;
armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
BOOST_TEST(Contains(layersInGraph, "pooling layer"));
// Create a mock backend object
+ MockBackendInitialiser initialiser; // Register the Mock Backend
auto backendObjPtr = CreateBackendObject(MockBackendId());
BOOST_TEST((backendObjPtr != nullptr));
BOOST_TEST(Contains(layersInGraph, "pooling3 layer"));
// Create a mock backend object
+ MockBackendInitialiser initialiser; // Register the Mock Backend
auto backendObjPtr = CreateBackendObject(MockBackendId());
BOOST_TEST((backendObjPtr != nullptr));
BOOST_TEST(Contains(layersInGraph, "conv layer"));
// Create a mock backend object
+ MockBackendInitialiser initialiser; // Register the Mock Backend
auto backendObjPtr = CreateBackendObject(MockBackendId());
BOOST_TEST((backendObjPtr != nullptr));
BOOST_TEST(Contains(layersInGraph, "conv5 layer"));
// Create a mock backend object
+ MockBackendInitialiser initialiser; // Register the Mock Backend
auto backendObjPtr = CreateBackendObject(MockBackendId());
BOOST_TEST((backendObjPtr != nullptr));
BOOST_TEST(Contains(layersInGraph, "pooling3 layer"));
// Create a mock backend object
+ MockBackendInitialiser initialiser; // Register the Mock Backend
auto backendObjPtr = CreateBackendObject(MockBackendId());
BOOST_TEST((backendObjPtr != nullptr));
BOOST_TEST(Contains(layersInGraph, "conv layer unoptimizable"));
// Create a mock backend object
+ MockBackendInitialiser initialiser; // Register the Mock Backend
auto backendObjPtr = CreateBackendObject(MockBackendId());
BOOST_TEST((backendObjPtr != nullptr));
BOOST_TEST(Contains(layersInGraph, "conv5 layer"));
// Create a mock backend object
+ MockBackendInitialiser initialiser; // Register the Mock Backend
auto backendObjPtr = CreateBackendObject(MockBackendId());
BOOST_TEST((backendObjPtr != nullptr));
BOOST_TEST(Contains(layersInGraph, "add layer"));
// Create a mock backend object
+ MockBackendInitialiser initialiser; // Register the Mock Backend
auto backendObjPtr = CreateBackendObject(MockBackendId());
BOOST_TEST((backendObjPtr != nullptr));
}
}
+// Store a profiling context returned from a backend that support profiling, and register its counters
+void ProfilingService::AddBackendProfilingContext(const BackendId backendId,
+ std::shared_ptr<armnn::profiling::IBackendProfilingContext> profilingContext)
+{
+ BOOST_ASSERT(profilingContext != nullptr);
+ // Register the backend counters
+ m_MaxGlobalCounterId = profilingContext->RegisterCounters(m_MaxGlobalCounterId);
+ m_BackendProfilingContexts.emplace(backendId, std::move(profilingContext));
+}
const ICounterDirectory& ProfilingService::GetCounterDirectory() const
{
return m_CounterDirectory;
BOOST_ASSERT(inferencesRunCounter);
InitializeCounterValue(inferencesRunCounter->m_Uid);
}
- // Register the backend counters
- uint16_t maxGlobalCounterId = armnn::profiling::INFERENCES_RUN;
- for (auto&& profilingContext : m_BackendProfilingContexts)
- {
- BOOST_ASSERT(profilingContext.second != nullptr);
- maxGlobalCounterId = profilingContext.second->RegisterCounters(maxGlobalCounterId);
- }
}
void ProfilingService::InitializeCounterValue(uint16_t counterUid)
// ...finally reset the profiling state machine
m_StateMachine.Reset();
m_BackendProfilingContexts.clear();
+ m_MaxGlobalCounterId = armnn::profiling::INFERENCES_RUN;
}
void ProfilingService::Stop()
// Store a profiling context returned from a backend that support profiling.
void AddBackendProfilingContext(const BackendId backendId,
- std::shared_ptr<armnn::profiling::IBackendProfilingContext> profilingContext)
- {
- m_BackendProfilingContexts.emplace(backendId, std::move(profilingContext));
- }
+ std::shared_ptr<armnn::profiling::IBackendProfilingContext> profilingContext);
const ICounterDirectory& GetCounterDirectory() const;
ICounterRegistry& GetCounterRegistry();
TimelinePacketWriterFactory m_TimelinePacketWriterFactory;
std::unordered_map<BackendId,
std::shared_ptr<armnn::profiling::IBackendProfilingContext>> m_BackendProfilingContexts;
+ uint16_t m_MaxGlobalCounterId;
protected:
// Default constructor/destructor kept protected for testing
m_PacketVersionResolver.ResolvePacketVersion(0, 5).GetEncodedValue(),
m_StateMachine)
, m_TimelinePacketWriterFactory(m_BufferManager)
+ , m_MaxGlobalCounterId(armnn::profiling::INFERENCES_RUN)
{
// Register the "Connection Acknowledged" command handler
m_CommandHandlerRegistry.RegisterFunctor(&m_ConnectionAcknowledgedCommandHandler);
// Create runtime in which test will run
armnn::IRuntime::CreationOptions options;
options.m_ProfilingOptions.m_EnableProfiling = true;
+ armnn::profiling::ProfilingService& profilingService = armnn::profiling::ProfilingService::Instance();
+ profilingService.ConfigureProfilingService(options.m_ProfilingOptions, true);
armnn::IRuntimePtr runtime(armnn::IRuntime::Create(options));
// build up the structure of the network