blob: 015a66ed9328ceac0229cea59b232e55f3698ee2 [file] [log] [blame]
Ferran Balaguer73882172019-09-02 16:39:42 +01001//
2// Copyright © 2017 Arm Ltd. All rights reserved.
3// SPDX-License-Identifier: MIT
4//
5
6#include "ProfilingUtils.hpp"
7
Ferran Balaguer47d0fe92019-09-04 16:47:34 +01008#include <armnn/Version.hpp>
9
Ferran Balaguer73882172019-09-02 16:39:42 +010010#include <boost/assert.hpp>
11
Ferran Balaguer47d0fe92019-09-04 16:47:34 +010012#include <fstream>
13
Ferran Balaguer73882172019-09-02 16:39:42 +010014namespace armnn
15{
16
17namespace profiling
18{
19
Francis Murtagh3a161982019-09-04 15:25:02 +010020void 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 Balaguer73882172019-09-02 16:39:42 +010034void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value)
35{
36 BOOST_ASSERT(buffer);
37
Matteo Martincigh149528e2019-09-05 12:02:04 +010038 buffer[offset] = static_cast<unsigned char>(value & 0xFF);
Ferran Balaguer73882172019-09-02 16:39:42 +010039 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
44void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value)
45{
Matteo Martincigh149528e2019-09-05 12:02:04 +010046 BOOST_ASSERT(buffer);
Ferran Balaguer73882172019-09-02 16:39:42 +010047
Matteo Martincigh149528e2019-09-05 12:02:04 +010048 buffer[offset] = static_cast<unsigned char>(value & 0xFF);
Ferran Balaguer73882172019-09-02 16:39:42 +010049 buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF);
50}
51
Francis Murtagh3a161982019-09-04 15:25:02 +010052uint64_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 Balaguer73882172019-09-02 16:39:42 +010069uint32_t ReadUint32(const unsigned char* buffer, unsigned int offset)
70{
71 BOOST_ASSERT(buffer);
72
73 uint32_t value = 0;
Matteo Martincigh149528e2019-09-05 12:02:04 +010074 value = static_cast<uint32_t>(buffer[offset]);
Ferran Balaguer73882172019-09-02 16:39:42 +010075 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
81uint16_t ReadUint16(const unsigned char* buffer, unsigned int offset)
82{
83 BOOST_ASSERT(buffer);
84
85 uint32_t value = 0;
Matteo Martincigh149528e2019-09-05 12:02:04 +010086 value = static_cast<uint32_t>(buffer[offset]);
Ferran Balaguer73882172019-09-02 16:39:42 +010087 value |= static_cast<uint32_t>(buffer[offset + 1]) << 8;
88 return static_cast<uint16_t>(value);
89}
90
Ferran Balaguer47d0fe92019-09-04 16:47:34 +010091std::string GetSoftwareInfo()
92{
93 return std::string("ArmNN");
94}
95
96std::string GetHardwareVersion()
97{
98 return std::string();
99}
100
101std::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
108std::string GetProcessName()
109{
110 std::ifstream comm("/proc/self/comm");
111 std::string name;
112 getline(comm, name);
113 return name;
114}
115
Ferran Balaguer73882172019-09-02 16:39:42 +0100116} // namespace profiling
117
Matteo Martincigh149528e2019-09-05 12:02:04 +0100118} // namespace armnn