Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 1 | // |
Jim Flynn | 6398a98 | 2020-05-27 17:05:21 +0100 | [diff] [blame] | 2 | // Copyright © 2019 Arm Ltd and Contributors. All rights reserved. |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 8 | #include <armnn/Exceptions.hpp> |
Colm Donelan | 5ccb33d | 2020-01-24 16:27:02 +0000 | [diff] [blame] | 9 | #include <armnn/profiling/ISendTimelinePacket.hpp> |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 10 | |
Matthew Sloyan | 371b70e | 2020-09-11 10:14:57 +0100 | [diff] [blame] | 11 | #include <armnn/utility/NumericCast.hpp> |
| 12 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 13 | #include "ICounterDirectory.hpp" |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 14 | #include "IPacketBuffer.hpp" |
Finn Williams | 0c8cb99 | 2020-05-07 10:38:15 +0100 | [diff] [blame] | 15 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 16 | #include <common/include/Packet.hpp> |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 17 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 18 | #include <algorithm> |
| 19 | #include <cstring> |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 20 | #include <memory> |
| 21 | #include <string> |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 22 | #include <thread> |
Colm Donelan | 5ccb33d | 2020-01-24 16:27:02 +0000 | [diff] [blame] | 23 | #include <vector> |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 24 | |
| 25 | namespace armnn |
| 26 | { |
| 27 | |
| 28 | namespace profiling |
| 29 | { |
| 30 | |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 31 | constexpr unsigned int ThreadIdSize = sizeof(int); // Is platform dependent |
Colm Donelan | 5bb3d8a | 2020-05-12 16:36:46 +0100 | [diff] [blame] | 32 | |
Matteo Martincigh | 6db5f20 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 33 | uint16_t GetNextUid(bool peekOnly = false); |
| 34 | |
Keith Davis | e394bd9 | 2019-12-02 15:12:19 +0000 | [diff] [blame] | 35 | std::vector<uint16_t> GetNextCounterUids(uint16_t firstUid, uint16_t cores); |
Matteo Martincigh | ab173e9 | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 36 | |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 37 | void WriteBytes(const IPacketBuffer& packetBuffer, unsigned int offset, const void* value, unsigned int valueSize); |
| 38 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 39 | uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetId); |
| 40 | |
Jim Flynn | 83d08a9 | 2020-07-09 13:48:16 +0100 | [diff] [blame] | 41 | uint32_t ConstructHeader(uint32_t packetFamily, uint32_t packetClass, uint32_t packetType); |
| 42 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 43 | void WriteUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint64_t value); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 44 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 45 | void WriteUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint32_t value); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 46 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 47 | void WriteUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint16_t value); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 48 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 49 | void WriteUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset, uint8_t value); |
| 50 | |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 51 | void WriteBytes(unsigned char* buffer, unsigned int offset, const void* value, unsigned int valueSize); |
| 52 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 53 | void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value); |
| 54 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 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 | |
Matteo Martincigh | 34a407d | 2019-11-06 15:30:54 +0000 | [diff] [blame] | 59 | void WriteUint8(unsigned char* buffer, unsigned int offset, uint8_t value); |
| 60 | |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 61 | void ReadBytes(const IPacketBufferPtr& packetBuffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]); |
| 62 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 63 | uint64_t ReadUint64(const IPacketBufferPtr& packetBuffer, unsigned int offset); |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 64 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 65 | uint32_t ReadUint32(const IPacketBufferPtr& packetBuffer, unsigned int offset); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 66 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 67 | uint16_t ReadUint16(const IPacketBufferPtr& packetBuffer, unsigned int offset); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 68 | |
Matteo Martincigh | 2ffcc41 | 2019-11-05 11:47:40 +0000 | [diff] [blame] | 69 | uint8_t ReadUint8(const IPacketBufferPtr& packetBuffer, unsigned int offset); |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 70 | |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 71 | void ReadBytes(const unsigned char* buffer, unsigned int offset, unsigned int valueSize, uint8_t outValue[]); |
| 72 | |
Narumol Prangnawarat | 404b275 | 2019-09-24 17:23:16 +0100 | [diff] [blame] | 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); |
Matteo Martincigh | 42f9d9e | 2019-09-05 12:02:04 +0100 | [diff] [blame] | 80 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 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 | |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 88 | std::string GetSoftwareInfo(); |
| 89 | |
| 90 | std::string GetSoftwareVersion(); |
| 91 | |
| 92 | std::string GetHardwareVersion(); |
| 93 | |
| 94 | std::string GetProcessName(); |
| 95 | |
Matteo Martincigh | 0aed4f9 | 2019-10-01 14:25:34 +0100 | [diff] [blame] | 96 | enum class TimelinePacketStatus |
| 97 | { |
| 98 | Ok, |
| 99 | Error, |
| 100 | BufferExhaustion |
| 101 | }; |
| 102 | |
| 103 | TimelinePacketStatus WriteTimelineLabelBinaryPacket(uint64_t profilingGuid, |
| 104 | const std::string& label, |
| 105 | unsigned char* buffer, |
| 106 | unsigned int bufferSize, |
| 107 | unsigned int& numberOfBytesWritten); |
| 108 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 109 | TimelinePacketStatus WriteTimelineEntityBinary(uint64_t profilingGuid, |
| 110 | unsigned char* buffer, |
| 111 | unsigned int bufferSize, |
| 112 | unsigned int& numberOfBytesWritten); |
| 113 | |
| 114 | TimelinePacketStatus WriteTimelineRelationshipBinary(ProfilingRelationshipType relationshipType, |
| 115 | uint64_t relationshipGuid, |
| 116 | uint64_t headGuid, |
| 117 | uint64_t tailGuid, |
Finn Williams | 0a336dc | 2020-05-11 15:39:58 +0100 | [diff] [blame] | 118 | uint64_t attributeGuid, |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 119 | unsigned char* buffer, |
| 120 | unsigned int bufferSize, |
| 121 | unsigned int& numberOfBytesWritten); |
David Monahan | f21f606 | 2019-10-07 15:11:15 +0100 | [diff] [blame] | 122 | |
Sadik Armagan | 784db77 | 2019-10-08 15:05:38 +0100 | [diff] [blame] | 123 | TimelinePacketStatus WriteTimelineMessageDirectoryPackage(unsigned char* buffer, |
| 124 | unsigned int bufferSize, |
| 125 | unsigned int& numberOfBytesWritten); |
| 126 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 127 | TimelinePacketStatus WriteTimelineEventClassBinary(uint64_t profilingGuid, |
Jim Flynn | 1892d21 | 2020-05-26 21:10:49 +0100 | [diff] [blame] | 128 | uint64_t nameGuid, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 129 | unsigned char* buffer, |
| 130 | unsigned int bufferSize, |
| 131 | unsigned int& numberOfBytesWritten); |
Jan Eilers | 92fa15b | 2019-10-15 15:23:25 +0100 | [diff] [blame] | 132 | |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 133 | TimelinePacketStatus WriteTimelineEventBinary(uint64_t timestamp, |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 134 | int threadId, |
Keith Davis | 97da5e2 | 2020-03-05 16:25:28 +0000 | [diff] [blame] | 135 | uint64_t profilingGuid, |
| 136 | unsigned char* buffer, |
| 137 | unsigned int bufferSize, |
| 138 | unsigned int& numberOfBytesWritten); |
Matteo Martincigh | 8844c2f | 2019-10-16 10:29:17 +0100 | [diff] [blame] | 139 | |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 140 | std::string CentreAlignFormatting(const std::string& stringToPass, const int spacingWidth); |
| 141 | |
| 142 | void PrintCounterDirectory(ICounterDirectory& counterDirectory); |
| 143 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 144 | class BufferExhaustion : public armnn::Exception |
| 145 | { |
| 146 | using Exception::Exception; |
| 147 | }; |
| 148 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 149 | uint64_t GetTimestamp(); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 150 | |
Jim Flynn | bbfe603 | 2020-07-20 16:57:44 +0100 | [diff] [blame] | 151 | arm::pipe::Packet ReceivePacket(const unsigned char* buffer, uint32_t length); |
Jim Flynn | 4e755a5 | 2020-03-29 17:48:26 +0100 | [diff] [blame] | 152 | |
Matteo Martincigh | 5dc816e | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 153 | } // namespace profiling |
| 154 | |
| 155 | } // namespace armnn |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 156 | |
| 157 | namespace std |
| 158 | { |
| 159 | |
Jim Flynn | 1fdeb99 | 2020-07-09 07:28:37 +0100 | [diff] [blame] | 160 | bool operator==(const std::vector<uint8_t>& left, int right); |
Matteo Martincigh | 378bbfc | 2019-11-04 14:05:28 +0000 | [diff] [blame] | 161 | |
| 162 | } // namespace std |