• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include "Runtime.hpp"
9 
10 #include <client/src/BufferManager.hpp>
11 #include <client/src/ProfilingService.hpp>
12 #include <client/src/ProfilingUtils.hpp>
13 
14 
15 #include <armnn/profiling/ArmNNProfiling.hpp>
16 
17 #include <common/include/Optional.hpp>
18 #include <common/include/ProfilingGuid.hpp>
19 
20 using namespace armnn;
21 using namespace arm::pipe;
22 
23 const static uint32_t bodyHeaderSize = 6;
24 
25 uint32_t GetStreamMetaDataPacketSize();
26 
27 /// Returns a vector of CpuRef, CpuAcc or GpuAcc backends if they where registered
28 std::vector<BackendId> GetSuitableBackendRegistered();
29 
30 inline unsigned int OffsetToNextWord(unsigned int numberOfBytes);
31 
32 void VerifyTimelineHeaderBinary(const unsigned char* readableData,
33                                 unsigned int& offset,
34                                 uint32_t packetDataLength);
35 
36 ProfilingGuid VerifyTimelineLabelBinaryPacketData(arm::pipe::Optional<ProfilingGuid> guid,
37                                                   const std::string& label,
38                                                   const unsigned char* readableData,
39                                                   unsigned int& offset);
40 
41 void VerifyTimelineEventClassBinaryPacketData(ProfilingGuid guid,
42                                               ProfilingGuid nameGuid,
43                                               const unsigned char* readableData,
44                                               unsigned int& offset);
45 
46 void VerifyTimelineRelationshipBinaryPacketData(ProfilingRelationshipType relationshipType,
47                                                 arm::pipe::Optional<ProfilingGuid> relationshipGuid,
48                                                 arm::pipe::Optional<ProfilingGuid> headGuid,
49                                                 arm::pipe::Optional<ProfilingGuid> tailGuid,
50                                                 arm::pipe::Optional<ProfilingGuid> attributeGuid,
51                                                 const unsigned char* readableData,
52                                                 unsigned int& offset);
53 
54 ProfilingGuid VerifyTimelineEntityBinaryPacketData(arm::pipe::Optional<ProfilingGuid> guid,
55                                                    const unsigned char* readableData,
56                                                    unsigned int& offset);
57 
58 ProfilingGuid VerifyTimelineEventBinaryPacket(arm::pipe::Optional<uint64_t> timestamp,
59                                               arm::pipe::Optional<int> threadId,
60                                               arm::pipe::Optional<ProfilingGuid> eventGuid,
61                                               const unsigned char* readableData,
62                                               unsigned int& offset);
63 
64 void VerifyPostOptimisationStructureTestImpl(armnn::BackendId backendId);
65 
66 bool CompareOutput(std::vector<std::string> output, std::vector<std::string> expectedOutput);
67 
68 namespace arm
69 {
70 
71 namespace pipe
72 {
73 
74 class ProfilingServiceRuntimeHelper : public ProfilingService
75 {
76 public:
ProfilingServiceRuntimeHelper(uint16_t maxGlobalCounterId,IInitialiseProfilingService & initialiser,arm::pipe::IProfilingService & profilingService)77     ProfilingServiceRuntimeHelper(uint16_t maxGlobalCounterId,
78                                   IInitialiseProfilingService& initialiser,
79                                   arm::pipe::IProfilingService& profilingService)
80         : ProfilingService(maxGlobalCounterId,
81                            initialiser,
82                            arm::pipe::ARMNN_SOFTWARE_INFO,
83                            arm::pipe::ARMNN_SOFTWARE_VERSION,
84                            arm::pipe::ARMNN_HARDWARE_VERSION),
85           m_ProfilingService(profilingService) {}
86     ~ProfilingServiceRuntimeHelper() = default;
87 
GetProfilingBufferManager()88     BufferManager& GetProfilingBufferManager()
89     {
90         return GetBufferManager(static_cast<arm::pipe::ProfilingService&>(m_ProfilingService));
91     }
92     arm::pipe::IProfilingService& m_ProfilingService;
93 
ForceTransitionToState(ProfilingState newState)94     void ForceTransitionToState(ProfilingState newState)
95     {
96         TransitionToState(static_cast<arm::pipe::ProfilingService&>(m_ProfilingService), newState);
97     }
98 };
99 
100 struct LogLevelSwapper
101 {
102 public:
LogLevelSwapperarm::pipe::LogLevelSwapper103     LogLevelSwapper(arm::pipe::LogSeverity severity)
104     {
105         // Set the new log level
106         arm::pipe::ConfigureLogging(true, true, severity);
107     }
~LogLevelSwapperarm::pipe::LogLevelSwapper108     ~LogLevelSwapper()
109     {
110         // The default log level for unit tests is "Fatal"
111         arm::pipe::ConfigureLogging(true, true, arm::pipe::LogSeverity::Fatal);
112     }
113 };
114 
115 struct StreamRedirector
116 {
117 public:
StreamRedirectorarm::pipe::StreamRedirector118     StreamRedirector(std::ostream& stream, std::streambuf* newStreamBuffer)
119         : m_Stream(stream)
120         , m_BackupBuffer(m_Stream.rdbuf(newStreamBuffer))
121     {}
122 
~StreamRedirectorarm::pipe::StreamRedirector123     ~StreamRedirector() { CancelRedirect(); }
124 
CancelRedirectarm::pipe::StreamRedirector125     void CancelRedirect()
126     {
127         // Only cancel the redirect once.
128         if (m_BackupBuffer != nullptr )
129         {
130             m_Stream.rdbuf(m_BackupBuffer);
131             m_BackupBuffer = nullptr;
132         }
133     }
134 
135 private:
136     std::ostream& m_Stream;
137     std::streambuf* m_BackupBuffer;
138 };
139 
140 } // namespace pipe
141 
142 } // namespace arm
143