Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2020 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "BackendProfiling.hpp" |
| 7 | #include "RegisterBackendCounters.hpp" |
| 8 | |
| 9 | namespace armnn |
| 10 | { |
| 11 | |
| 12 | namespace profiling |
| 13 | { |
| 14 | |
| 15 | std::unique_ptr<IRegisterBackendCounters> |
| 16 | BackendProfiling::GetCounterRegistrationInterface(uint16_t currentMaxGlobalCounterID) |
| 17 | { |
James Conroy | 2dcd3fe | 2020-02-06 18:34:52 +0000 | [diff] [blame] | 18 | return std::make_unique<RegisterBackendCounters>(RegisterBackendCounters(currentMaxGlobalCounterID, m_BackendId)); |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | std::unique_ptr<ISendTimelinePacket> BackendProfiling::GetSendTimelinePacket() |
| 22 | { |
| 23 | return m_ProfilingService.GetSendTimelinePacket(); |
| 24 | } |
| 25 | |
| 26 | IProfilingGuidGenerator& BackendProfiling::GetProfilingGuidGenerator() |
| 27 | { |
| 28 | // The profiling service is our Guid Generator. |
| 29 | return m_ProfilingService; |
| 30 | } |
| 31 | |
Jim Flynn | 6406355 | 2020-02-14 10:18:08 +0000 | [diff] [blame^] | 32 | void BackendProfiling::ReportCounters(const std::vector<Timestamp>& timestamps) |
| 33 | { |
| 34 | for (const auto timestampInfo : timestamps) |
| 35 | { |
| 36 | std::vector<CounterValue> backendCounterValues = timestampInfo.counterValues; |
| 37 | for_each(backendCounterValues.begin(), backendCounterValues.end(), [&](CounterValue& backendCounterValue) |
| 38 | { |
| 39 | // translate the counterId to globalCounterId |
| 40 | backendCounterValue.counterId = m_ProfilingService.GetCounterMappings().GetGlobalId( |
| 41 | backendCounterValue.counterId, m_BackendId); |
| 42 | }); |
| 43 | |
| 44 | // Send Periodic Counter Capture Packet for the Timestamp |
| 45 | m_ProfilingService.GetSendCounterPacket().SendPeriodicCounterCapturePacket( |
| 46 | timestampInfo.timestamp, backendCounterValues); |
| 47 | } |
| 48 | } |
| 49 | |
James Conroy | 2dcd3fe | 2020-02-06 18:34:52 +0000 | [diff] [blame] | 50 | CounterStatus BackendProfiling::GetCounterStatus(uint16_t backendCounterId) |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 51 | { |
James Conroy | 2dcd3fe | 2020-02-06 18:34:52 +0000 | [diff] [blame] | 52 | uint16_t globalCounterId = m_ProfilingService.GetCounterMappings().GetGlobalId(backendCounterId, m_BackendId); |
| 53 | CaptureData captureData = m_ProfilingService.GetCaptureData(); |
| 54 | |
| 55 | CounterStatus counterStatus(backendCounterId, globalCounterId, false, 0); |
| 56 | |
| 57 | if (captureData.IsCounterIdInCaptureData(globalCounterId)) |
| 58 | { |
| 59 | counterStatus.m_Enabled = true; |
| 60 | counterStatus.m_SamplingRateInMicroseconds = captureData.GetCapturePeriod(); |
| 61 | } |
| 62 | |
| 63 | return counterStatus; |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | std::vector<CounterStatus> BackendProfiling::GetActiveCounters() |
| 67 | { |
James Conroy | 2dcd3fe | 2020-02-06 18:34:52 +0000 | [diff] [blame] | 68 | CaptureData captureData = m_ProfilingService.GetCaptureData(); |
| 69 | |
| 70 | const std::vector<uint16_t>& globalCounterIds = captureData.GetCounterIds(); |
| 71 | std::vector<CounterStatus> activeCounterIds; |
| 72 | |
| 73 | for (auto globalCounterId : globalCounterIds) { |
| 74 | // Get pair of local counterId and backendId using globalCounterId |
| 75 | const std::pair<uint16_t, armnn::BackendId>& backendCounterIdPair = |
| 76 | ProfilingService::Instance().GetCounterMappings().GetBackendId(globalCounterId); |
| 77 | if (backendCounterIdPair.second == m_BackendId) |
| 78 | { |
| 79 | activeCounterIds.emplace_back(backendCounterIdPair.first, |
| 80 | globalCounterId, |
| 81 | true, |
| 82 | captureData.GetCapturePeriod()); |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | return activeCounterIds; |
Colm Donelan | 1aff393 | 2020-02-05 17:48:59 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | bool BackendProfiling::IsProfilingEnabled() const |
| 90 | { |
| 91 | return m_ProfilingService.IsProfilingEnabled(); |
| 92 | } |
| 93 | |
| 94 | } // namespace profiling |
| 95 | } // namespace armnn |