xref: /aosp_15_r20/external/armnn/profiling/common/include/ProfilingGuid.hpp (revision 89c4ff92f2867872bb9e2354d150bf0c8c502810)
1 //
2 // Copyright © 2021 Arm Ltd and Contributors. All rights reserved.
3 // SPDX-License-Identifier: MIT
4 //
5 
6 #pragma once
7 
8 #include <memory>
9 #include <stdint.h>
10 
11 namespace arm
12 {
13 
14 namespace pipe
15 {
16 
17 static constexpr uint64_t MIN_STATIC_GUID = 1llu << 63;
18 
19 class ProfilingGuid
20 {
21 public:
ProfilingGuid()22     ProfilingGuid() : m_Guid(0) {}
23 
ProfilingGuid(uint64_t guid)24     ProfilingGuid(uint64_t guid) : m_Guid(guid) {}
25 
operator uint64_t() const26     operator uint64_t() const { return m_Guid; }
27 
operator ==(const ProfilingGuid & other) const28     bool operator==(const ProfilingGuid& other) const
29     {
30         return m_Guid == other.m_Guid;
31     }
32 
operator !=(const ProfilingGuid & other) const33     bool operator!=(const ProfilingGuid& other) const
34     {
35         return m_Guid != other.m_Guid;
36     }
37 
operator <(const ProfilingGuid & other) const38     bool operator<(const ProfilingGuid& other) const
39     {
40         return m_Guid < other.m_Guid;
41     }
42 
operator <=(const ProfilingGuid & other) const43     bool operator<=(const ProfilingGuid& other) const
44     {
45         return m_Guid <= other.m_Guid;
46     }
47 
operator >(const ProfilingGuid & other) const48     bool operator>(const ProfilingGuid& other) const
49     {
50         return m_Guid > other.m_Guid;
51     }
52 
operator >=(const ProfilingGuid & other) const53     bool operator>=(const ProfilingGuid& other) const
54     {
55         return m_Guid >= other.m_Guid;
56     }
57 
58     protected:
59         uint64_t m_Guid;
60 };
61 
62 /// Strongly typed guids to distinguish between those generated at runtime, and those that are statically defined.
63 struct ProfilingDynamicGuid : public ProfilingGuid
64 {
65     using ProfilingGuid::ProfilingGuid;
66 };
67 
68 struct ProfilingStaticGuid : public ProfilingGuid
69 {
70     using ProfilingGuid::ProfilingGuid;
71 };
72 
73 } // namespace pipe
74 
75 } // namespace arm
76 
77 
78 
79 namespace std
80 {
81 /// make ProfilingGuid hashable
82 template <>
83 struct hash<arm::pipe::ProfilingGuid>
84 {
operator ()std::hash85     std::size_t operator()(arm::pipe::ProfilingGuid const& guid) const noexcept
86     {
87         return hash<uint64_t>()(uint64_t(guid));
88     }
89 };
90 
91 /// make ProfilingDynamicGuid hashable
92 template <>
93 struct hash<arm::pipe::ProfilingDynamicGuid>
94 {
operator ()std::hash95     std::size_t operator()(arm::pipe::ProfilingDynamicGuid const& guid) const noexcept
96     {
97         return hash<uint64_t>()(uint64_t(guid));
98     }
99 };
100 
101 /// make ProfilingStaticGuid hashable
102 template <>
103 struct hash<arm::pipe::ProfilingStaticGuid>
104 {
operator ()std::hash105     std::size_t operator()(arm::pipe::ProfilingStaticGuid const& guid) const noexcept
106     {
107         return hash<uint64_t>()(uint64_t(guid));
108     }
109 };
110 
111 }  // namespace std