ArmNN
 20.02
FileOnlyProfilingConnection.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include "CounterDirectory.hpp"
10 #include "IProfilingConnection.hpp"
11 #include "ProfilingUtils.hpp"
12 #include "Runtime.hpp"
13 
14 #include <condition_variable>
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 {
34  Unknown
35 };
36 
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 
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;
79 
80  std::mutex m_PacketAvailableMutex;
81  std::condition_variable m_ConditionPacketAvailable;
82 };
83 
84 } // namespace profiling
85 
86 } // namespace armnn
Copyright (c) 2020 ARM Limited.
FileOnlyProfilingConnection(const Runtime::CreationOptions::ExternalProfilingOptions &options, const bool quietOp=true)
armnn::Runtime::CreationOptions::ExternalProfilingOptions options