ArmNN
 21.02
ProfilingUtils.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <armnn/Exceptions.hpp>
10 
12 
13 #include "ICounterDirectory.hpp"
14 #include "IPacketBuffer.hpp"
15 
16 #include <common/include/Packet.hpp>
17 
18 #include <algorithm>
19 #include <cstring>
20 #include <memory>
21 #include <string>
22 #include <thread>
23 #include <vector>
24 
25 namespace armnn
26 {
27 
28 namespace profiling
29 {
30 
31 constexpr unsigned int ThreadIdSize = sizeof(int); // Is platform dependent
32 
33 uint16_t GetNextUid(bool peekOnly = false);
34 
35 std::vector<uint16_t> GetNextCounterUids(uint16_t firstUid, uint16_t cores);
36 
37 void WriteBytes(const IPacketBuffer& packetBuffer, unsigned int offset, const void* value, unsigned int valueSize);
38 
39 uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetId);
40 
41 uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetClass, uint32_t packetType);
42 
43 void WriteUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint64_t value);
44 
45 void WriteUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint32_t value);
46 
47 void WriteUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint16_t value);
48 
49 void WriteUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint8_t value);
50 
51 void WriteBytes(unsigned char* buffer, unsigned int offset, const void* value, unsigned int valueSize);
52 
53 void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value);
54 
55 void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value);
56 
57 void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value);
58 
59 void WriteUint8(unsigned char* buffer, unsigned int offset, uint8_t value);
60 
61 void ReadBytes(const IPacketBufferPtr& packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]);
62 
63 uint64_t ReadUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset);
64 
65 uint32_t ReadUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset);
66 
67 uint16_t ReadUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset);
68 
69 uint8_t ReadUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset);
70 
71 void ReadBytes(const unsigned char* buffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]);
72 
73 uint64_t ReadUint64(unsigned const char* buffer, unsigned int offset);
74 
75 uint32_t ReadUint32(unsigned const char* buffer, unsigned int offset);
76 
77 uint16_t ReadUint16(unsigned const char* buffer, unsigned int offset);
78 
79 uint8_t ReadUint8(unsigned const char* buffer, unsigned int offset);
80 
81 std::pair<uint32_t, uint32_t> CreateTimelinePacketHeader(uint32_t packetFamily,
82  uint32_t packetClass,
83  uint32_t packetType,
84  uint32_t streamId,
85  uint32_t sequenceNumbered,
86  uint32_t dataLength);
87 
88 std::string GetSoftwareInfo();
89 
90 std::string GetSoftwareVersion();
91 
92 std::string GetHardwareVersion();
93 
94 std::string GetProcessName();
95 
97 {
98  Ok,
99  Error,
101 };
102 
104  const std::string& label,
105  unsigned char* buffer,
106  unsigned int bufferSize,
107  unsigned int& numberOfBytesWritten);
108 
109 TimelinePacketStatus WriteTimelineEntityBinary(uint64_t profilingGuid,
110  unsigned char* buffer,
111  unsigned int bufferSize,
112  unsigned int& numberOfBytesWritten);
113 
115  uint64_t relationshipGuid,
116  uint64_t headGuid,
117  uint64_t tailGuid,
118  uint64_t attributeGuid,
119  unsigned char* buffer,
120  unsigned int bufferSize,
121  unsigned int& numberOfBytesWritten);
122 
124  unsigned int bufferSize,
125  unsigned int& numberOfBytesWritten);
126 
128  uint64_t nameGuid,
129  unsigned char* buffer,
130  unsigned int bufferSize,
131  unsigned int& numberOfBytesWritten);
132 
134  int threadId,
135  uint64_t profilingGuid,
136  unsigned char* buffer,
137  unsigned int bufferSize,
138  unsigned int& numberOfBytesWritten);
139 
140 std::string CentreAlignFormatting(const std::string& stringToPass, const int spacingWidth);
141 
142 void PrintCounterDirectory(ICounterDirectory& counterDirectory);
143 
144 class BufferExhaustion : public armnn::Exception
145 {
146  using Exception::Exception;
147 };
148 
149 uint64_t GetTimestamp();
150 
151 arm::pipe::Packet ReceivePacket(const unsigned char* buffer, uint32_t length);
152 
153 } // namespace profiling
154 
155 } // namespace armnn
156 
157 namespace std
158 {
159 
160 bool operator==(const std::vector<uint8_t>& left, int right);
161 
162 } // namespace std
TimelinePacketStatus WriteTimelineMessageDirectoryPackage(unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
std::string GetHardwareVersion()
void WriteUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint16_t value)
void ReadBytes(const IPacketBufferPtr &packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[])
void WriteUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint32_t value)
uint64_t ReadUint64(const IPacketBufferPtr &packetBuffer, unsigned int offset)
std::pair< uint32_t, uint32_t > CreateTimelinePacketHeader(uint32_t packetFamily, uint32_t packetClass, uint32_t packetType, uint32_t streamId, uint32_t sequenceNumbered, uint32_t dataLength)
Creates a timeline packet header.
std::string GetProcessName()
TimelinePacketStatus WriteTimelineRelationshipBinary(ProfilingRelationshipType relationshipType, uint64_t relationshipGuid, uint64_t headGuid, uint64_t tailGuid, uint64_t attributeGuid, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
Exception(const std::string &message)
Definition: Exceptions.cpp:12
uint16_t ReadUint16(const IPacketBufferPtr &packetBuffer, unsigned int offset)
uint8_t ReadUint8(const IPacketBufferPtr &packetBuffer, unsigned int offset)
Copyright (c) 2021 ARM Limited and Contributors.
std::string GetSoftwareInfo()
arm::pipe::Packet ReceivePacket(const unsigned char *buffer, uint32_t length)
uint16_t GetNextUid(bool peekOnly)
bool operator==(const armnn::DataLayout &dataLayout, const DataLayoutIndexed &indexed)
Equality methods.
TimelinePacketStatus WriteTimelineEventBinary(uint64_t timestamp, int threadId, uint64_t profilingGuid, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
std::vector< uint16_t > GetNextCounterUids(uint16_t firstUid, uint16_t cores)
void WriteBytes(const IPacketBufferPtr &packetBuffer, unsigned int offset, const void *value, unsigned int valueSize)
uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetId)
constexpr unsigned int ThreadIdSize
TimelinePacketStatus WriteTimelineEventClassBinary(uint64_t profilingGuid, uint64_t nameGuid, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
void WriteUint8(const IPacketBufferPtr &packetBuffer, unsigned int offset, uint8_t value)
void WriteUint64(const std::unique_ptr< IPacketBuffer > &packetBuffer, unsigned int offset, uint64_t value)
uint32_t ReadUint32(const IPacketBufferPtr &packetBuffer, unsigned int offset)
std::string GetSoftwareVersion()
Base class for all ArmNN exceptions so that users can filter to just those.
Definition: Exceptions.hpp:46
TimelinePacketStatus WriteTimelineLabelBinaryPacket(uint64_t profilingGuid, const std::string &label, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
std::string CentreAlignFormatting(const std::string &stringToPass, const int spacingWidth)
TimelinePacketStatus WriteTimelineEntityBinary(uint64_t profilingGuid, unsigned char *buffer, unsigned int remainingBufferSize, unsigned int &numberOfBytesWritten)
void PrintCounterDirectory(ICounterDirectory &counterDirectory)
std::unique_ptr< IPacketBuffer > IPacketBufferPtr
uint64_t GetTimestamp()