Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2017 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #include "ProfilingUtils.hpp" |
| 7 | |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 8 | #include <armnn/Version.hpp> |
| 9 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 10 | #include <boost/assert.hpp> |
| 11 | |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 12 | #include <fstream> |
| 13 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 14 | namespace armnn |
| 15 | { |
| 16 | |
| 17 | namespace profiling |
| 18 | { |
| 19 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 20 | void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value) |
| 21 | { |
| 22 | BOOST_ASSERT(buffer); |
| 23 | |
| 24 | buffer[offset] = static_cast<unsigned char>(value & 0xFF); |
| 25 | buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF); |
| 26 | buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF); |
| 27 | buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF); |
| 28 | buffer[offset + 4] = static_cast<unsigned char>((value >> 32) & 0xFF); |
| 29 | buffer[offset + 5] = static_cast<unsigned char>((value >> 40) & 0xFF); |
| 30 | buffer[offset + 6] = static_cast<unsigned char>((value >> 48) & 0xFF); |
| 31 | buffer[offset + 7] = static_cast<unsigned char>((value >> 56) & 0xFF); |
| 32 | } |
| 33 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 34 | void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value) |
| 35 | { |
| 36 | BOOST_ASSERT(buffer); |
| 37 | |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame^] | 38 | buffer[offset] = static_cast<unsigned char>(value & 0xFF); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 39 | buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF); |
| 40 | buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF); |
| 41 | buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF); |
| 42 | } |
| 43 | |
| 44 | void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value) |
| 45 | { |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame^] | 46 | BOOST_ASSERT(buffer); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 47 | |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame^] | 48 | buffer[offset] = static_cast<unsigned char>(value & 0xFF); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 49 | buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF); |
| 50 | } |
| 51 | |
Francis Murtagh | 3a16198 | 2019-09-04 15:25:02 +0100 | [diff] [blame] | 52 | uint64_t ReadUint64(const unsigned char* buffer, unsigned int offset) |
| 53 | { |
| 54 | BOOST_ASSERT(buffer); |
| 55 | |
| 56 | uint64_t value = 0; |
| 57 | value = static_cast<uint64_t>(buffer[offset]); |
| 58 | value |= static_cast<uint64_t>(buffer[offset + 1]) << 8; |
| 59 | value |= static_cast<uint64_t>(buffer[offset + 2]) << 16; |
| 60 | value |= static_cast<uint64_t>(buffer[offset + 3]) << 24; |
| 61 | value |= static_cast<uint64_t>(buffer[offset + 4]) << 32; |
| 62 | value |= static_cast<uint64_t>(buffer[offset + 5]) << 40; |
| 63 | value |= static_cast<uint64_t>(buffer[offset + 6]) << 48; |
| 64 | value |= static_cast<uint64_t>(buffer[offset + 7]) << 56; |
| 65 | |
| 66 | return value; |
| 67 | } |
| 68 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 69 | uint32_t ReadUint32(const unsigned char* buffer, unsigned int offset) |
| 70 | { |
| 71 | BOOST_ASSERT(buffer); |
| 72 | |
| 73 | uint32_t value = 0; |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame^] | 74 | value = static_cast<uint32_t>(buffer[offset]); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 75 | value |= static_cast<uint32_t>(buffer[offset + 1]) << 8; |
| 76 | value |= static_cast<uint32_t>(buffer[offset + 2]) << 16; |
| 77 | value |= static_cast<uint32_t>(buffer[offset + 3]) << 24; |
| 78 | return value; |
| 79 | } |
| 80 | |
| 81 | uint16_t ReadUint16(const unsigned char* buffer, unsigned int offset) |
| 82 | { |
| 83 | BOOST_ASSERT(buffer); |
| 84 | |
| 85 | uint32_t value = 0; |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame^] | 86 | value = static_cast<uint32_t>(buffer[offset]); |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 87 | value |= static_cast<uint32_t>(buffer[offset + 1]) << 8; |
| 88 | return static_cast<uint16_t>(value); |
| 89 | } |
| 90 | |
Ferran Balaguer | 47d0fe9 | 2019-09-04 16:47:34 +0100 | [diff] [blame] | 91 | std::string GetSoftwareInfo() |
| 92 | { |
| 93 | return std::string("ArmNN"); |
| 94 | } |
| 95 | |
| 96 | std::string GetHardwareVersion() |
| 97 | { |
| 98 | return std::string(); |
| 99 | } |
| 100 | |
| 101 | std::string GetSoftwareVersion() |
| 102 | { |
| 103 | std::string armnnVersion(ARMNN_VERSION); |
| 104 | std::string result = "Armnn " + armnnVersion.substr(2,2) + "." + armnnVersion.substr(4,2); |
| 105 | return result; |
| 106 | } |
| 107 | |
| 108 | std::string GetProcessName() |
| 109 | { |
| 110 | std::ifstream comm("/proc/self/comm"); |
| 111 | std::string name; |
| 112 | getline(comm, name); |
| 113 | return name; |
| 114 | } |
| 115 | |
Ferran Balaguer | 7388217 | 2019-09-02 16:39:42 +0100 | [diff] [blame] | 116 | } // namespace profiling |
| 117 | |
Matteo Martincigh | 149528e | 2019-09-05 12:02:04 +0100 | [diff] [blame^] | 118 | } // namespace armnn |