| // |
| // Copyright © 2017 Arm Ltd. All rights reserved. |
| // SPDX-License-Identifier: MIT |
| // |
| |
| #include "ProfilingUtils.hpp" |
| |
| #include <armnn/Version.hpp> |
| |
| #include <boost/assert.hpp> |
| |
| #include <fstream> |
| |
| namespace armnn |
| { |
| |
| namespace profiling |
| { |
| |
| void WriteUint64(unsigned char* buffer, unsigned int offset, uint64_t value) |
| { |
| BOOST_ASSERT(buffer); |
| |
| buffer[offset] = static_cast<unsigned char>(value & 0xFF); |
| buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF); |
| buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF); |
| buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF); |
| buffer[offset + 4] = static_cast<unsigned char>((value >> 32) & 0xFF); |
| buffer[offset + 5] = static_cast<unsigned char>((value >> 40) & 0xFF); |
| buffer[offset + 6] = static_cast<unsigned char>((value >> 48) & 0xFF); |
| buffer[offset + 7] = static_cast<unsigned char>((value >> 56) & 0xFF); |
| } |
| |
| void WriteUint32(unsigned char* buffer, unsigned int offset, uint32_t value) |
| { |
| BOOST_ASSERT(buffer); |
| |
| buffer[offset] = static_cast<unsigned char>(value & 0xFF); |
| buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF); |
| buffer[offset + 2] = static_cast<unsigned char>((value >> 16) & 0xFF); |
| buffer[offset + 3] = static_cast<unsigned char>((value >> 24) & 0xFF); |
| } |
| |
| void WriteUint16(unsigned char* buffer, unsigned int offset, uint16_t value) |
| { |
| BOOST_ASSERT(buffer != nullptr); |
| |
| buffer[offset] = static_cast<unsigned char>(value & 0xFF); |
| buffer[offset + 1] = static_cast<unsigned char>((value >> 8) & 0xFF); |
| } |
| |
| uint64_t ReadUint64(const unsigned char* buffer, unsigned int offset) |
| { |
| BOOST_ASSERT(buffer); |
| |
| uint64_t value = 0; |
| value = static_cast<uint64_t>(buffer[offset]); |
| value |= static_cast<uint64_t>(buffer[offset + 1]) << 8; |
| value |= static_cast<uint64_t>(buffer[offset + 2]) << 16; |
| value |= static_cast<uint64_t>(buffer[offset + 3]) << 24; |
| value |= static_cast<uint64_t>(buffer[offset + 4]) << 32; |
| value |= static_cast<uint64_t>(buffer[offset + 5]) << 40; |
| value |= static_cast<uint64_t>(buffer[offset + 6]) << 48; |
| value |= static_cast<uint64_t>(buffer[offset + 7]) << 56; |
| |
| return value; |
| } |
| |
| uint32_t ReadUint32(const unsigned char* buffer, unsigned int offset) |
| { |
| BOOST_ASSERT(buffer); |
| |
| uint32_t value = 0; |
| value = static_cast<uint32_t>(buffer[offset]); |
| value |= static_cast<uint32_t>(buffer[offset + 1]) << 8; |
| value |= static_cast<uint32_t>(buffer[offset + 2]) << 16; |
| value |= static_cast<uint32_t>(buffer[offset + 3]) << 24; |
| return value; |
| } |
| |
| uint16_t ReadUint16(const unsigned char* buffer, unsigned int offset) |
| { |
| BOOST_ASSERT(buffer); |
| |
| uint32_t value = 0; |
| value = static_cast<uint32_t>(buffer[offset]); |
| value |= static_cast<uint32_t>(buffer[offset + 1]) << 8; |
| return static_cast<uint16_t>(value); |
| } |
| |
| std::string GetSoftwareInfo() |
| { |
| return std::string("ArmNN"); |
| } |
| |
| std::string GetHardwareVersion() |
| { |
| return std::string(); |
| } |
| |
| std::string GetSoftwareVersion() |
| { |
| std::string armnnVersion(ARMNN_VERSION); |
| std::string result = "Armnn " + armnnVersion.substr(2,2) + "." + armnnVersion.substr(4,2); |
| return result; |
| } |
| |
| std::string GetProcessName() |
| { |
| std::ifstream comm("/proc/self/comm"); |
| std::string name; |
| getline(comm, name); |
| return name; |
| } |
| |
| } // namespace profiling |
| |
| } // namespace armnn |