ArmNN
 20.08
ProfilingGuidGenerator.hpp
Go to the documentation of this file.
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
9 
10 #include <functional>
11 #include <mutex>
12 
13 namespace armnn
14 {
15 
16 namespace profiling
17 {
18 
20 {
21 public:
22  /// Construct a generator with the default address space static/dynamic partitioning
23  ProfilingGuidGenerator() : m_Sequence(0) {}
24 
25  /// Return the next random Guid in the sequence
26  inline ProfilingDynamicGuid NextGuid() override
27  {
28  std::lock_guard<std::mutex> sequencelock(m_SequenceMutex);
29  ProfilingDynamicGuid guid(m_Sequence);
30  m_Sequence++;
31  if (m_Sequence >= MIN_STATIC_GUID)
32  {
33  // Reset the sequence to 0 when it reaches the upper bound of dynamic guid
34  m_Sequence = 0;
35  }
36  return guid;
37  }
38 
39  /// Create a ProfilingStaticGuid based on a hash of the string
40  inline ProfilingStaticGuid GenerateStaticId(const std::string& str) override
41  {
42  uint64_t staticHash = m_Hash(str) | MIN_STATIC_GUID;
43  return ProfilingStaticGuid(staticHash);
44  }
45 
46  /// Reset the generator back to zero. Used mainly for test.
47  inline void Reset()
48  {
49  std::lock_guard<std::mutex> sequencelock(m_SequenceMutex);
50  m_Sequence = 0;
51  }
52 
53 private:
54  std::hash<std::string> m_Hash;
55  uint64_t m_Sequence;
56  std::mutex m_SequenceMutex;
57 };
58 
59 } // namespace profiling
60 
61 } // namespace armnn
void Reset()
Reset the generator back to zero. Used mainly for test.
Strongly typed guids to distinguish between those generated at runtime, and those that are statically...
Definition: Types.hpp:319
Copyright (c) 2020 ARM Limited.
ProfilingStaticGuid GenerateStaticId(const std::string &str) override
Create a ProfilingStaticGuid based on a hash of the string.
ProfilingGuidGenerator()
Construct a generator with the default address space static/dynamic partitioning. ...
ProfilingDynamicGuid NextGuid() override
Return the next random Guid in the sequence.