rocprofiler-sdk/cxx/operators.hpp Source File

rocprofiler-sdk/cxx/operators.hpp Source File#

Rocprofiler SDK Developer API: rocprofiler-sdk/cxx/operators.hpp Source File
Rocprofiler SDK Developer API 0.5.0
ROCm Profiling API and tools
operators.hpp
Go to the documentation of this file.
1// MIT License
2//
3// Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
4//
5// Permission is hereby granted, free of charge, to any person obtaining a copy
6// of this software and associated documentation files (the "Software"), to deal
7// in the Software without restriction, including without limitation the rights
8// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9// copies of the Software, and to permit persons to whom the Software is
10// furnished to do so, subject to the following conditions:
11//
12// The above copyright notice and this permission notice shall be included in all
13// copies or substantial portions of the Software.
14//
15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21// SOFTWARE.
22//
23
24#pragma once
25
28#include <rocprofiler-sdk/fwd.h>
30
31#include <tuple>
32
33#define ROCPROFILER_CXX_DECLARE_OPERATORS(TYPE) \
34 bool operator==(TYPE lhs, TYPE rhs) ROCPROFILER_ATTRIBUTE(pure); \
35 bool operator!=(TYPE lhs, TYPE rhs) ROCPROFILER_ATTRIBUTE(pure); \
36 bool operator<(TYPE lhs, TYPE rhs) ROCPROFILER_ATTRIBUTE(pure); \
37 bool operator>(TYPE lhs, TYPE rhs) ROCPROFILER_ATTRIBUTE(pure); \
38 bool operator<=(TYPE lhs, TYPE rhs) ROCPROFILER_ATTRIBUTE(pure); \
39 bool operator>=(TYPE lhs, TYPE rhs) ROCPROFILER_ATTRIBUTE(pure);
40
41#define ROCPROFILER_CXX_DEFINE_NE_OPERATOR(TYPE) \
42 inline bool operator!=(TYPE lhs, TYPE rhs) { return !(lhs == rhs); }
43
44#define ROCPROFILER_CXX_DEFINE_EQ_HANDLE_OPERATOR(TYPE) \
45 inline bool operator==(TYPE lhs, TYPE rhs) \
46 { \
47 return ::rocprofiler::sdk::operators::equal(lhs, rhs); \
48 }
49
50#define ROCPROFILER_CXX_DEFINE_LT_HANDLE_OPERATOR(TYPE) \
51 inline bool operator<(TYPE lhs, TYPE rhs) \
52 { \
53 return ::rocprofiler::sdk::operators::less(lhs, rhs); \
54 }
55
56#define ROCPROFILER_CXX_DEFINE_COMPARE_OPERATORS(TYPE) \
57 inline bool operator>(TYPE lhs, TYPE rhs) { return (lhs == rhs || !(lhs < rhs)); } \
58 inline bool operator<=(TYPE lhs, TYPE rhs) { return (lhs == rhs || lhs < rhs); } \
59 inline bool operator>=(TYPE lhs, TYPE rhs) { return !(lhs < rhs); }
60
61namespace rocprofiler
62{
63namespace sdk
64{
65namespace operators
66{
67template <typename Tp>
68bool
69equal(Tp lhs, Tp rhs) ROCPROFILER_ATTRIBUTE(pure);
70
71template <typename Tp>
72bool
73less(Tp lhs, Tp rhs) ROCPROFILER_ATTRIBUTE(pure);
74
75template <typename Tp>
76bool
77equal(Tp lhs, Tp rhs)
78{
79 static_assert(sizeof(Tp) == sizeof(uint64_t), "error! only for opaque handle types");
80 return lhs.handle == rhs.handle;
81}
82
83template <typename Tp>
84bool
85less(Tp lhs, Tp rhs)
86{
87 static_assert(sizeof(Tp) == sizeof(uint64_t), "error! only for opaque handle types");
88 return lhs.handle < rhs.handle;
89}
90} // namespace operators
91} // namespace sdk
92} // namespace rocprofiler
93
94// declaration of operator== and operator!=
104ROCPROFILER_CXX_DECLARE_OPERATORS(hsa_executable_t)
107
108// definitions of operator==
119
120inline bool
121operator==(const rocprofiler_agent_v0_t& lhs, const rocprofiler_agent_v0_t& rhs)
122{
123 return (lhs.id == rhs.id);
124}
125
126inline bool
128{
129 return std::tie(lhs.x, lhs.y, lhs.z) == std::tie(rhs.x, rhs.y, rhs.z);
130}
131
132// definitions of operator!=
145
146// definitions of operator<
157
158inline bool
159operator<(const rocprofiler_agent_v0_t& lhs, const rocprofiler_agent_v0_t& rhs)
160{
161 return (lhs.id < rhs.id);
162}
163
164inline bool
166{
167 const auto magnitude = [](rocprofiler_dim3_t dim_v) { return dim_v.x * dim_v.y * dim_v.z; };
168 auto lhs_m = magnitude(lhs);
169 auto rhs_m = magnitude(rhs);
170
171 return (lhs_m == rhs_m) ? std::tie(lhs.x, lhs.y, lhs.z) < std::tie(rhs.x, rhs.y, rhs.z)
172 : (lhs_m < rhs_m);
173}
174
175// definitions of operator>, operator<=, operator>=
188
189// cleanup defines
190#undef ROCPROFILER_CXX_DECLARE_OPERATORS
191#undef ROCPROFILER_CXX_DEFINE_NE_OPERATOR
192#undef ROCPROFILER_CXX_DEFINE_EQ_HANDLE_OPERATOR
193#undef ROCPROFILER_CXX_DEFINE_LT_HANDLE_OPERATOR
194#undef ROCPROFILER_CXX_DEFINE_COMPARE_OPERATORS
Stores the properties of an agent (CPU, GPU, etc.)
Definition agent.h:111
uint32_t z
Definition fwd.h:573
uint32_t y
Definition fwd.h:572
uint32_t x
Definition fwd.h:571
Agent Identifier.
Definition fwd.h:545
Context ID.
Definition fwd.h:506
Counter ID.
Definition fwd.h:553
Multi-dimensional struct of data used to describe GPU workgroup and grid sizes.
Definition fwd.h:570
Profile Configurations.
Definition fwd.h:562
opaque handle to an internal thread identifier which delivers callbacks for buffers
bool less(Tp lhs, Tp rhs) ROCPROFILER_ATTRIBUTE(pure)
Definition operators.hpp:85
bool equal(Tp lhs, Tp rhs) ROCPROFILER_ATTRIBUTE(pure)
Definition operators.hpp:77
bool operator<(rocprofiler_context_id_t lhs, rocprofiler_context_id_t rhs) ROCPROFILER_ATTRIBUTE(pure)
bool operator==(rocprofiler_context_id_t lhs, rocprofiler_context_id_t rhs) ROCPROFILER_ATTRIBUTE(pure)
#define ROCPROFILER_CXX_DECLARE_OPERATORS(TYPE)
Definition operators.hpp:33
#define ROCPROFILER_CXX_DEFINE_LT_HANDLE_OPERATOR(TYPE)
Definition operators.hpp:50
#define ROCPROFILER_CXX_DEFINE_COMPARE_OPERATORS(TYPE)
Definition operators.hpp:56
#define ROCPROFILER_CXX_DEFINE_EQ_HANDLE_OPERATOR(TYPE)
Definition operators.hpp:44
#define ROCPROFILER_CXX_DEFINE_NE_OPERATOR(TYPE)
Definition operators.hpp:41