ArmNN
 20.02
DirectoryCaptureCommandHandler.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 
9 #include "CounterDirectory.hpp"
10 
11 #include <atomic>
12 
13 namespace armnn
14 {
15 
16 namespace profiling
17 {
18 
20 {
21  uint16_t m_CounterClass;
22  std::string m_CounterDescription;
25  std::string m_CounterName;
26  uint16_t m_CounterSetUid;
27  uint16_t m_CounterUid;
28  std::string m_CounterUnits;
29  uint16_t m_DeviceUid;
30  uint16_t m_MaxCounterUid;
31 };
32 
34 {
35 
36 public:
37  DirectoryCaptureCommandHandler(uint32_t familyId, uint32_t packetId, uint32_t version, bool quietOperation = true)
38  : CommandHandlerFunctor(familyId, packetId, version)
39  , m_QuietOperation(quietOperation)
40  , m_AlreadyParsed(false)
41  {}
42 
43  void operator()(const armnn::profiling::Packet& packet) override;
44 
45  const ICounterDirectory& GetCounterDirectory() const;
46 
48  {
49  return m_AlreadyParsed.load();
50  }
51 
52  /**
53  * Given a Uid that came from a copy of the counter directory translate it to the original.
54  *
55  * @param copyUid
56  * @return the original Uid that the copy maps to.
57  */
58  uint16_t TranslateUIDCopyToOriginal(uint16_t copyUid)
59  {
60  return m_UidTranslation[copyUid];
61  }
62 
63 private:
64  void ParseData(const armnn::profiling::Packet& packet);
65 
66  void ReadCategoryRecords(const unsigned char* data, uint32_t offset, std::vector<uint32_t> categoryOffsets);
67 
68  std::vector<CounterDirectoryEventRecord>
69  ReadEventRecords(const unsigned char* data, uint32_t offset, std::vector<uint32_t> eventRecordsOffsets);
70 
71  std::string GetStringNameFromBuffer(const unsigned char* data, uint32_t offset);
72  bool IsValidChar(unsigned char c);
73 
74  CounterDirectory m_CounterDirectory;
75  std::unordered_map<uint16_t, uint16_t> m_UidTranslation;
76  bool m_QuietOperation;
77  // We can only parse the counter directory once per instance. It won't change anyway as it's static
78  // per instance of ArmNN.
79  std::atomic<bool> m_AlreadyParsed;
80 };
81 
82 } // namespace profiling
83 
84 } // namespace armnn
DirectoryCaptureCommandHandler(uint32_t familyId, uint32_t packetId, uint32_t version, bool quietOperation=true)
uint16_t TranslateUIDCopyToOriginal(uint16_t copyUid)
Given a Uid that came from a copy of the counter directory translate it to the original.
Copyright (c) 2020 ARM Limited.
DataLayout::NHWC false