Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 1 | // |
| 2 | // Copyright © 2019 Arm Ltd. All rights reserved. |
| 3 | // SPDX-License-Identifier: MIT |
| 4 | // |
| 5 | |
| 6 | #pragma once |
| 7 | |
| 8 | #include "CounterDirectory.hpp" |
| 9 | #include "DirectoryCaptureCommandHandler.hpp" |
| 10 | #include "IProfilingConnection.hpp" |
| 11 | #include "ProfilingUtils.hpp" |
| 12 | #include "Runtime.hpp" |
| 13 | |
Colm Donelan | 4cace32 | 2019-11-20 14:59:12 +0000 | [diff] [blame] | 14 | #include <condition_variable> |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 15 | #include <fstream> |
| 16 | #include <queue> |
| 17 | |
| 18 | namespace armnn |
| 19 | { |
| 20 | |
| 21 | namespace profiling |
| 22 | { |
| 23 | |
| 24 | enum class TargetEndianness |
| 25 | { |
| 26 | BeWire, |
| 27 | LeWire |
| 28 | }; |
| 29 | |
| 30 | enum class PackageActivity |
| 31 | { |
| 32 | StreamMetaData, |
| 33 | CounterDirectory, |
| 34 | Unknown |
| 35 | }; |
| 36 | |
| 37 | class FileOnlyProfilingConnection : public IProfilingConnection |
| 38 | { |
| 39 | public: |
| 40 | FileOnlyProfilingConnection(const Runtime::CreationOptions::ExternalProfilingOptions& options, |
| 41 | const bool quietOp = true) |
| 42 | : m_Options(options) |
| 43 | , m_QuietOp(quietOp) |
| 44 | , m_Endianness(TargetEndianness::LeWire) // Set a sensible default. WaitForStreamMeta will set a real value. |
| 45 | {}; |
| 46 | |
| 47 | ~FileOnlyProfilingConnection(); |
| 48 | |
| 49 | bool IsOpen() const override; |
| 50 | |
| 51 | void Close() override; |
| 52 | |
| 53 | // This is effectively receiving a data packet from ArmNN. |
| 54 | bool WritePacket(const unsigned char* buffer, uint32_t length) override; |
| 55 | |
| 56 | // Sending a packet back to ArmNN. |
| 57 | Packet ReadPacket(uint32_t timeout) override; |
| 58 | |
| 59 | private: |
| 60 | bool WaitForStreamMeta(const unsigned char* buffer, uint32_t length); |
| 61 | |
| 62 | uint32_t ToUint32(const unsigned char* data, TargetEndianness endianness); |
| 63 | |
| 64 | void SendConnectionAck(); |
| 65 | |
| 66 | bool SendCounterSelectionPacket(); |
| 67 | |
| 68 | PackageActivity GetPackageActivity(const unsigned char* buffer, uint32_t headerAsWords[2]); |
| 69 | |
| 70 | void Fail(const std::string& errorMessage); |
| 71 | |
| 72 | static const uint32_t PIPE_MAGIC = 0x45495434; |
| 73 | |
| 74 | Runtime::CreationOptions::ExternalProfilingOptions m_Options; |
| 75 | bool m_QuietOp; |
| 76 | std::vector<uint16_t> m_IdList; |
| 77 | std::queue<Packet> m_PacketQueue; |
| 78 | TargetEndianness m_Endianness; |
Colm Donelan | 4cace32 | 2019-11-20 14:59:12 +0000 | [diff] [blame] | 79 | |
| 80 | std::mutex m_PacketAvailableMutex; |
| 81 | std::condition_variable m_ConditionPacketAvailable; |
Keith Davis | 3201eea | 2019-10-24 17:30:41 +0100 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | } // namespace profiling |
| 85 | |
| 86 | } // namespace armnn |