2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "ProfilingUtils.hpp"
8 #include <armnn/Version.hpp>
10 #include <boost/assert.hpp>
24 // Static mutex for reading and modifying the global UID a single thread at the time
25 static std::mutex mutex;
26 std::unique_lock<std::mutex> lock(mutex);
28 // The UID used for profiling objects and events. The first valid UID is 1, as 0 is a reserved value
29 // (it is used to indicate that a record is not associated with any device)
30 static uint16_t uid{ 0 };
32 // Check that it is possible to generate the next UID without causing an overflow
33 if (uid == std::numeric_limits<uint16_t>::max())
35 throw RuntimeException("Generating the next UID for profiling would result in an overflow");
38 // Thread safe increment, the value that is incremented is the value checked for overflow,
39 // as this whole function is mutexed
43 void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value)
47 buffer[offset] = static_cast<unsigned char>(value & 0xFF);
48 buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
49 buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF);
50 buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF);
51 buffer[offset + 4] = static_cast<unsigned char>((value >> 32) & 0xFF);
52 buffer[offset + 5] = static_cast<unsigned char>((value >> 40) & 0xFF);
53 buffer[offset + 6] = static_cast<unsigned char>((value >> 48) & 0xFF);
54 buffer[offset + 7] = static_cast<unsigned char>((value >> 56) & 0xFF);
57 void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value)
61 buffer[offset] = static_cast<unsigned char>(value & 0xFF);
62 buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
63 buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF);
64 buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF);
67 void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value)
71 buffer[offset] = static_cast<unsigned char>(value & 0xFF);
72 buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
75 uint64_t ReadUint64(const unsigned char* buffer, unsigned int offset)
80 value = static_cast<uint64_t>(buffer[offset]);
81 value |= static_cast<uint64_t>(buffer[offset + 1]) << 8;
82 value |= static_cast<uint64_t>(buffer[offset + 2]) << 16;
83 value |= static_cast<uint64_t>(buffer[offset + 3]) << 24;
84 value |= static_cast<uint64_t>(buffer[offset + 4]) << 32;
85 value |= static_cast<uint64_t>(buffer[offset + 5]) << 40;
86 value |= static_cast<uint64_t>(buffer[offset + 6]) << 48;
87 value |= static_cast<uint64_t>(buffer[offset + 7]) << 56;
92 uint32_t ReadUint32(const unsigned char* buffer, unsigned int offset)
97 value = static_cast<uint32_t>(buffer[offset]);
98 value |= static_cast<uint32_t>(buffer[offset + 1]) << 8;
99 value |= static_cast<uint32_t>(buffer[offset + 2]) << 16;
100 value |= static_cast<uint32_t>(buffer[offset + 3]) << 24;
104 uint16_t ReadUint16(const unsigned char* buffer, unsigned int offset)
106 BOOST_ASSERT(buffer);
109 value = static_cast<uint32_t>(buffer[offset]);
110 value |= static_cast<uint32_t>(buffer[offset + 1]) << 8;
111 return static_cast<uint16_t>(value);
114 std::string GetSoftwareInfo()
116 return std::string("ArmNN");
119 std::string GetHardwareVersion()
121 return std::string();
124 std::string GetSoftwareVersion()
126 std::string armnnVersion(ARMNN_VERSION);
127 std::string result = "Armnn " + armnnVersion.substr(2,2) + "." + armnnVersion.substr(4,2);
131 std::string GetProcessName()
133 std::ifstream comm("/proc/self/comm");
139 } // namespace profiling