ArmNN
 21.02
BackendProfiling.cpp
Go to the documentation of this file.
1 //
2 // Copyright © 2020 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #include "BackendProfiling.hpp"
8 
9 namespace armnn
10 {
11 
12 namespace profiling
13 {
14 
15 std::unique_ptr<IRegisterBackendCounters>
16  BackendProfiling::GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID)
17 {
18  return std::make_unique<RegisterBackendCounters>(
19  RegisterBackendCounters(currentMaxGlobalCounterID, m_BackendId, m_ProfilingService));
20 }
21 
22 std::unique_ptr<ISendTimelinePacket> BackendProfiling::GetSendTimelinePacket()
23 {
24  return m_ProfilingService.GetSendTimelinePacket();
25 }
26 
28 {
29  // The profiling service is our Guid Generator.
30  return m_ProfilingService;
31 }
32 
33 void BackendProfiling::ReportCounters(const std::vector<Timestamp>& timestamps)
34 {
35  for (const auto& timestampInfo : timestamps)
36  {
37  std::vector<CounterValue> backendCounterValues = timestampInfo.counterValues;
38  for_each(backendCounterValues.begin(), backendCounterValues.end(), [&](CounterValue& backendCounterValue)
39  {
40  // translate the counterId to globalCounterId
41  backendCounterValue.counterId = m_ProfilingService.GetCounterMappings().GetGlobalId(
42  backendCounterValue.counterId, m_BackendId);
43  });
44 
45  // Send Periodic Counter Capture Packet for the Timestamp
47  timestampInfo.timestamp, backendCounterValues);
48  }
49 }
50 
52 {
53  uint16_t globalCounterId = m_ProfilingService.GetCounterMappings().GetGlobalId(backendCounterId, m_BackendId);
54  CaptureData captureData = m_ProfilingService.GetCaptureData();
55 
56  CounterStatus counterStatus(backendCounterId, globalCounterId, false, 0);
57 
58  if (captureData.IsCounterIdInCaptureData(globalCounterId))
59  {
60  counterStatus.m_Enabled = true;
61  counterStatus.m_SamplingRateInMicroseconds = captureData.GetCapturePeriod();
62  }
63 
64  return counterStatus;
65 }
66 
67 std::vector<CounterStatus> BackendProfiling::GetActiveCounters()
68 {
69  CaptureData captureData = m_ProfilingService.GetCaptureData();
70 
71  const std::vector<uint16_t>& globalCounterIds = captureData.GetCounterIds();
72  std::vector<CounterStatus> activeCounterIds;
73 
74  for (auto globalCounterId : globalCounterIds) {
75  // Get pair of local counterId and backendId using globalCounterId
76  const std::pair<uint16_t, armnn::BackendId>& backendCounterIdPair =
77  m_ProfilingService.GetCounterMappings().GetBackendId(globalCounterId);
78  if (backendCounterIdPair.second == m_BackendId)
79  {
80  activeCounterIds.emplace_back(backendCounterIdPair.first,
81  globalCounterId,
82  true,
83  captureData.GetCapturePeriod());
84  }
85  }
86 
87  return activeCounterIds;
88 }
89 
91 {
92  return m_ProfilingService.IsProfilingEnabled();
93 }
94 
95 } // namespace profiling
96 } // namespace armnn
std::vector< CounterStatus > GetActiveCounters() override
const std::vector< uint16_t > & GetCounterIds() const
Definition: Holder.cpp:49
void ReportCounters(const std::vector< Timestamp > &) override
std::unique_ptr< IRegisterBackendCounters > GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID) override
Copyright (c) 2021 ARM Limited and Contributors.
bool IsProfilingEnabled() const override
CounterStatus GetCounterStatus(uint16_t backendCounterId) override
uint32_t GetCapturePeriod() const
Definition: Holder.cpp:44
IProfilingGuidGenerator & GetProfilingGuidGenerator() override
std::unique_ptr< ISendTimelinePacket > GetSendTimelinePacket() override
std::unique_ptr< ISendTimelinePacket > GetSendTimelinePacket() const override
const ICounterMappings & GetCounterMappings() const override
bool IsProfilingEnabled() const override
virtual void SendPeriodicCounterCapturePacket(uint64_t timestamp, const IndexValuePairsVector &values)=0
Create and write a PeriodicCounterCapturePacket from the parameters to the buffer.
bool IsCounterIdInCaptureData(uint16_t counterId)
Definition: Holder.cpp:61
ISendCounterPacket & GetSendCounterPacket() override
virtual const std::pair< uint16_t, armnn::BackendId > & GetBackendId(uint16_t globalCounterId) const =0
virtual uint16_t GetGlobalId(uint16_t backendCounterId, const armnn::BackendId &backendId) const =0