aboutsummaryrefslogtreecommitdiff
path: root/src/armnn
diff options
context:
space:
mode:
Diffstat (limited to 'src/armnn')
-rw-r--r--src/armnn/ArmNNProfilingServiceInitialiser.cpp121
-rw-r--r--src/armnn/ArmNNProfilingServiceInitialiser.hpp20
-rw-r--r--src/armnn/Runtime.cpp17
-rw-r--r--src/armnn/Runtime.hpp8
-rw-r--r--src/armnn/test/RuntimeTests.cpp10
5 files changed, 170 insertions, 6 deletions
diff --git a/src/armnn/ArmNNProfilingServiceInitialiser.cpp b/src/armnn/ArmNNProfilingServiceInitialiser.cpp
new file mode 100644
index 0000000000..d23cce5634
--- /dev/null
+++ b/src/armnn/ArmNNProfilingServiceInitialiser.cpp
@@ -0,0 +1,121 @@
+//
+// Copyright © 2022 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ArmNNProfilingServiceInitialiser.hpp"
+
+#include <armnn/BackendRegistry.hpp>
+#include <armnn/profiling/ArmNNProfiling.hpp>
+#include <Counter.hpp>
+
+namespace armnn
+{
+
+void ArmNNProfilingServiceInitialiser::InitialiseProfilingService(arm::pipe::IProfilingService& profilingService)
+{
+ uint16_t ZERO = 0;
+ double ONE = 1.0;
+ std::string ArmNN_Runtime("ArmNN_Runtime");
+ // Register a category for the basic runtime counters
+ if (!profilingService.IsCategoryRegistered(ArmNN_Runtime))
+ {
+ profilingService.GetCounterRegistry().RegisterCategory(ArmNN_Runtime);
+ }
+
+ std::string networks("networks");
+ std::string networkLoads("Network loads");
+ // Register a counter for the number of Network loads
+ if (!profilingService.IsCounterRegistered(networkLoads))
+ {
+ const arm::pipe::Counter* loadedNetworksCounter =
+ profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(),
+ arm::pipe::NETWORK_LOADS,
+ ArmNN_Runtime,
+ ZERO,
+ ZERO,
+ ONE,
+ networkLoads,
+ "The number of networks loaded at runtime",
+ networks);
+ ARMNN_ASSERT(loadedNetworksCounter);
+ profilingService.InitializeCounterValue(loadedNetworksCounter->m_Uid);
+ }
+ // Register a counter for the number of unloaded networks
+ std::string networkUnloads("Network unloads");
+ if (!profilingService.IsCounterRegistered(networkUnloads))
+ {
+ const arm::pipe::Counter* unloadedNetworksCounter =
+ profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(),
+ arm::pipe::NETWORK_UNLOADS,
+ ArmNN_Runtime,
+ ZERO,
+ ZERO,
+ ONE,
+ networkUnloads,
+ "The number of networks unloaded at runtime",
+ networks);
+ ARMNN_ASSERT(unloadedNetworksCounter);
+ profilingService.InitializeCounterValue(unloadedNetworksCounter->m_Uid);
+ }
+ std::string backends("backends");
+ // Register a counter for the number of registered backends
+ std::string backendsRegistered("Backends registered");
+ if (!profilingService.IsCounterRegistered(backendsRegistered))
+ {
+ const arm::pipe::Counter* registeredBackendsCounter =
+ profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(),
+ arm::pipe::REGISTERED_BACKENDS,
+ ArmNN_Runtime,
+ ZERO,
+ ZERO,
+ ONE,
+ backendsRegistered,
+ "The number of registered backends",
+ backends);
+ ARMNN_ASSERT(registeredBackendsCounter);
+ profilingService.InitializeCounterValue(registeredBackendsCounter->m_Uid);
+
+ // Due to backends being registered before the profiling service becomes active,
+ // we need to set the counter to the correct value here
+ profilingService.SetCounterValue(arm::pipe::REGISTERED_BACKENDS, static_cast<uint32_t>(
+ armnn::BackendRegistryInstance().Size()));
+ }
+ // Register a counter for the number of registered backends
+ std::string backendsUnregistered("Backends unregistered");
+ if (!profilingService.IsCounterRegistered(backendsUnregistered))
+ {
+ const arm::pipe::Counter* unregisteredBackendsCounter =
+ profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(),
+ arm::pipe::UNREGISTERED_BACKENDS,
+ ArmNN_Runtime,
+ ZERO,
+ ZERO,
+ ONE,
+ backendsUnregistered,
+ "The number of unregistered backends",
+ backends);
+ ARMNN_ASSERT(unregisteredBackendsCounter);
+ profilingService.InitializeCounterValue(unregisteredBackendsCounter->m_Uid);
+ }
+ // Register a counter for the number of inferences run
+ std::string inferences("inferences");
+ std::string inferencesRun("Inferences run");
+ if (!profilingService.IsCounterRegistered(inferencesRun))
+ {
+ const arm::pipe::Counter* inferencesRunCounter =
+ profilingService.GetCounterRegistry().RegisterCounter(armnn::profiling::BACKEND_ID.Get(),
+ arm::pipe::INFERENCES_RUN,
+ ArmNN_Runtime,
+ ZERO,
+ ZERO,
+ ONE,
+ inferencesRun,
+ "The number of inferences run",
+ inferences);
+ ARMNN_ASSERT(inferencesRunCounter);
+ profilingService.InitializeCounterValue(inferencesRunCounter->m_Uid);
+ }
+}
+
+} // namespace armnn
diff --git a/src/armnn/ArmNNProfilingServiceInitialiser.hpp b/src/armnn/ArmNNProfilingServiceInitialiser.hpp
new file mode 100644
index 0000000000..e8a0ae0649
--- /dev/null
+++ b/src/armnn/ArmNNProfilingServiceInitialiser.hpp
@@ -0,0 +1,20 @@
+//
+// Copyright © 2022 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <IInitialiseProfilingService.hpp>
+#include <IProfilingService.hpp>
+
+namespace armnn
+{
+
+class ArmNNProfilingServiceInitialiser : public arm::pipe::IInitialiseProfilingService
+{
+public:
+ void InitialiseProfilingService(arm::pipe::IProfilingService& profilingService) override;
+};
+
+} // namespace armnn
diff --git a/src/armnn/Runtime.cpp b/src/armnn/Runtime.cpp
index 4cc34ff6ac..af257e1be5 100644
--- a/src/armnn/Runtime.cpp
+++ b/src/armnn/Runtime.cpp
@@ -2,6 +2,8 @@
// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
// SPDX-License-Identifier: MIT
//
+
+#include "ArmNNProfilingServiceInitialiser.hpp"
#include "Runtime.hpp"
#include <armnn/Version.hpp>
@@ -115,7 +117,11 @@ Status IRuntime::Execute(IWorkingMemHandle& workingMemHandle,
std::vector<ImportedInputId> preImportedInputs,
std::vector<ImportedOutputId> preImportedOutputs)
{
- return pRuntimeImpl->Execute(workingMemHandle, inputTensors, outputTensors, preImportedInputs, preImportedOutputs);
+ return pRuntimeImpl->Execute(workingMemHandle,
+ inputTensors,
+ outputTensors,
+ preImportedInputs,
+ preImportedOutputs);
}
Status IRuntime::UnloadNetwork(NetworkId networkId)
@@ -295,10 +301,17 @@ void RuntimeImpl::ReportStructure() // arm::pipe::IProfilingService& profilingSe
}
}
+void RuntimeImpl::InitialiseProfilingService(arm::pipe::IProfilingService& profilingService)
+{
+ ArmNNProfilingServiceInitialiser initialiser;
+ initialiser.InitialiseProfilingService(profilingService);
+}
+
RuntimeImpl::RuntimeImpl(const IRuntime::CreationOptions& options)
: m_NetworkIdCounter(0)
{
- m_ProfilingService = arm::pipe::IProfilingService::CreateProfilingService(*this);
+ m_ProfilingService = arm::pipe::IProfilingService::CreateProfilingService(
+ arm::pipe::MAX_ARMNN_COUNTER, *this, *this);
const auto start_time = armnn::GetTimeNow();
ARMNN_LOG(info) << "ArmNN v" << ARMNN_VERSION;
if ( options.m_ProfilingOptions.m_TimelineEnabled && !options.m_ProfilingOptions.m_EnableProfiling )
diff --git a/src/armnn/Runtime.hpp b/src/armnn/Runtime.hpp
index a8fa5fd5c5..f2462b15d2 100644
--- a/src/armnn/Runtime.hpp
+++ b/src/armnn/Runtime.hpp
@@ -14,6 +14,7 @@
#include <armnn/backends/DynamicBackend.hpp>
+#include <IInitialiseProfilingService.hpp>
#include <IProfilingService.hpp>
#include <IReportStructure.hpp>
@@ -24,8 +25,9 @@ namespace armnn
{
using LoadedNetworks = std::unordered_map<NetworkId, std::unique_ptr<LoadedNetwork>>;
using IReportStructure = arm::pipe::IReportStructure;
+ using IInitialiseProfilingService = arm::pipe::IInitialiseProfilingService;
-struct RuntimeImpl final : public IReportStructure
+struct RuntimeImpl final : public IReportStructure, public IInitialiseProfilingService
{
public:
/// Loads a complete network into the Runtime.
@@ -108,7 +110,9 @@ public:
//NOTE: we won't need the profiling service reference but it is good to pass the service
// in this way to facilitate other implementations down the road
- void ReportStructure();
+ void ReportStructure() override;
+
+ void InitialiseProfilingService(arm::pipe::IProfilingService& profilingService) override;
private:
friend void RuntimeLoadedNetworksReserve(RuntimeImpl* runtime); // See RuntimeTests.cpp
diff --git a/src/armnn/test/RuntimeTests.cpp b/src/armnn/test/RuntimeTests.cpp
index 73e36eaf56..afe4bc7ea0 100644
--- a/src/armnn/test/RuntimeTests.cpp
+++ b/src/armnn/test/RuntimeTests.cpp
@@ -6,6 +6,8 @@
#include <armnn/Descriptors.hpp>
#include <armnn/IRuntime.hpp>
#include <armnn/INetwork.hpp>
+#include <armnn/profiling/ArmNNProfiling.hpp>
+#include <ArmNNProfilingServiceInitialiser.hpp>
#include <ProfilingOptionsConverter.hpp>
#include <Processes.hpp>
#include <Runtime.hpp>
@@ -627,7 +629,9 @@ TEST_CASE("ProfilingDisable")
armnn::NetworkId netId;
CHECK(runtime.LoadNetwork(netId, std::move(optNet)) == Status::Success);
- ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
+ armnn::ArmNNProfilingServiceInitialiser initialiser;
+ ProfilingServiceRuntimeHelper profilingServiceHelper(
+ arm::pipe::MAX_ARMNN_COUNTER, initialiser, GetProfilingService(&runtime));
BufferManager& bufferManager = profilingServiceHelper.GetProfilingBufferManager();
auto readableBuffer = bufferManager.GetReadableBuffer();
@@ -649,7 +653,9 @@ TEST_CASE("ProfilingEnableCpuRef")
GetProfilingService(&runtime).ResetExternalProfilingOptions(
ConvertExternalProfilingOptions(options.m_ProfilingOptions), false);
- ProfilingServiceRuntimeHelper profilingServiceHelper(GetProfilingService(&runtime));
+ armnn::ArmNNProfilingServiceInitialiser initialiser;
+ ProfilingServiceRuntimeHelper profilingServiceHelper(
+ arm::pipe::MAX_ARMNN_COUNTER, initialiser, GetProfilingService(&runtime));
profilingServiceHelper.ForceTransitionToState(ProfilingState::NotConnected);
profilingServiceHelper.ForceTransitionToState(ProfilingState::WaitingForAck);
profilingServiceHelper.ForceTransitionToState(ProfilingState::Active);