2 // Copyright © 2017 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
6 #include "ProfilingUtils.hpp"
8 #include <armnn/Version.hpp>
9 #include <armnn/Conversion.hpp>
11 #include <boost/assert.hpp>
25 void ThrowIfCantGenerateNextUid(uint16_t uid, uint16_t cores = 0)
27 // Check that it is possible to generate the next UID without causing an overflow
32 // Number of cores not specified or set to 1 (a value of zero indicates the device is not capable of
33 // running multiple parallel workloads and will not provide multiple streams of data for each event)
34 if (uid == std::numeric_limits<uint16_t>::max())
36 throw RuntimeException("Generating the next UID for profiling would result in an overflow");
40 // Multiple cores available, as max_counter_uid has to be set to: counter_uid + cores - 1, the maximum
41 // allowed value for a counter UID is consequently: uint16_t_max - cores + 1
42 if (uid >= std::numeric_limits<uint16_t>::max() - cores + 1)
44 throw RuntimeException("Generating the next UID for profiling would result in an overflow");
50 } // Anonymous namespace
52 uint16_t GetNextUid(bool peekOnly)
54 // The UID used for profiling objects and events. The first valid UID is 1, as 0 is a reserved value
55 static uint16_t uid = 1;
57 // Check that it is possible to generate the next UID without causing an overflow (throws in case of error)
58 ThrowIfCantGenerateNextUid(uid);
72 std::vector<uint16_t> GetNextCounterUids(uint16_t cores)
74 // The UID used for counters only. The first valid UID is 0
75 static uint16_t counterUid = 0;
77 // Check that it is possible to generate the next counter UID without causing an overflow (throws in case of error)
78 ThrowIfCantGenerateNextUid(counterUid, cores);
80 // Get the next counter UIDs
81 size_t counterUidsSize = cores == 0 ? 1 : cores;
82 std::vector<uint16_t> counterUids(counterUidsSize, 0);
83 for (size_t i = 0; i < counterUidsSize; i++)
85 counterUids[i] = counterUid++;
90 void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value)
94 buffer[offset] = static_cast<unsigned char>(value & 0xFF);
95 buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
96 buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF);
97 buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF);
98 buffer[offset + 4] = static_cast<unsigned char>((value >> 32) & 0xFF);
99 buffer[offset + 5] = static_cast<unsigned char>((value >> 40) & 0xFF);
100 buffer[offset + 6] = static_cast<unsigned char>((value >> 48) & 0xFF);
101 buffer[offset + 7] = static_cast<unsigned char>((value >> 56) & 0xFF);
104 void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value)
106 BOOST_ASSERT(buffer);
108 buffer[offset] = static_cast<unsigned char>(value & 0xFF);
109 buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
110 buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF);
111 buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF);
114 void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value)
116 BOOST_ASSERT(buffer);
118 buffer[offset] = static_cast<unsigned char>(value & 0xFF);
119 buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
122 uint64_t ReadUint64(const unsigned char* buffer, unsigned int offset)
124 BOOST_ASSERT(buffer);
127 value = static_cast<uint64_t>(buffer[offset]);
128 value |= static_cast<uint64_t>(buffer[offset + 1]) << 8;
129 value |= static_cast<uint64_t>(buffer[offset + 2]) << 16;
130 value |= static_cast<uint64_t>(buffer[offset + 3]) << 24;
131 value |= static_cast<uint64_t>(buffer[offset + 4]) << 32;
132 value |= static_cast<uint64_t>(buffer[offset + 5]) << 40;
133 value |= static_cast<uint64_t>(buffer[offset + 6]) << 48;
134 value |= static_cast<uint64_t>(buffer[offset + 7]) << 56;
139 uint32_t ReadUint32(const unsigned char* buffer, unsigned int offset)
141 BOOST_ASSERT(buffer);
144 value = static_cast<uint32_t>(buffer[offset]);
145 value |= static_cast<uint32_t>(buffer[offset + 1]) << 8;
146 value |= static_cast<uint32_t>(buffer[offset + 2]) << 16;
147 value |= static_cast<uint32_t>(buffer[offset + 3]) << 24;
151 uint16_t ReadUint16(const unsigned char* buffer, unsigned int offset)
153 BOOST_ASSERT(buffer);
156 value = static_cast<uint32_t>(buffer[offset]);
157 value |= static_cast<uint32_t>(buffer[offset + 1]) << 8;
158 return static_cast<uint16_t>(value);
161 std::string GetSoftwareInfo()
163 return std::string("ArmNN");
166 std::string GetHardwareVersion()
168 return std::string();
171 std::string GetSoftwareVersion()
173 std::string armnnVersion(ARMNN_VERSION);
174 std::string result = "Armnn " + armnnVersion.substr(2,2) + "." + armnnVersion.substr(4,2);
178 std::string GetProcessName()
180 std::ifstream comm("/proc/self/comm");
186 } // namespace profiling