• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright © 2019 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include "armnn/profiling/IProfilingGuidGenerator.hpp"
9 
10 #include <functional>
11 #include <mutex>
12 
13 namespace armnn
14 {
15 
16 namespace profiling
17 {
18 
19 class ProfilingGuidGenerator : public IProfilingGuidGenerator
20 {
21 public:
22     /// Construct a generator with the default address space static/dynamic partitioning
ProfilingGuidGenerator()23     ProfilingGuidGenerator() : m_Sequence(0) {}
24 
25     /// Return the next random Guid in the sequence
NextGuid()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
GenerateStaticId(const std::string & str)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.
Reset()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
62