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.6.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>
29#include <rocprofiler-sdk/hsa.h>
31
32#include <tuple>
33
34#define ROCPROFILER_CXX_DECLARE_OPERATORS(TYPE) \
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 bool operator>=(TYPE lhs, TYPE rhs) ROCPROFILER_ATTRIBUTE(pure);
41
42#define ROCPROFILER_CXX_DEFINE_NE_OPERATOR(TYPE) \
43 inline bool operator!=(TYPE lhs, TYPE rhs) { return !(lhs == rhs); }
44
45#define ROCPROFILER_CXX_DEFINE_EQ_HANDLE_OPERATOR(TYPE) \
46 inline bool operator==(TYPE lhs, TYPE rhs) \
47 { \
48 return ::rocprofiler::sdk::operators::equal(lhs, rhs); \
49 }
50
51#define ROCPROFILER_CXX_DEFINE_LT_HANDLE_OPERATOR(TYPE) \
52 inline bool operator<(TYPE lhs, TYPE rhs) \
53 { \
54 return ::rocprofiler::sdk::operators::less(lhs, rhs); \
55 }
56
57#define ROCPROFILER_CXX_DEFINE_COMPARE_OPERATORS(TYPE) \
58 inline bool operator>(TYPE lhs, TYPE rhs) { return (lhs == rhs || !(lhs < rhs)); } \
59 inline bool operator<=(TYPE lhs, TYPE rhs) { return (lhs == rhs || lhs < rhs); } \
60 inline bool operator>=(TYPE lhs, TYPE rhs) { return !(lhs < rhs); }
61
62namespace rocprofiler
63{
64namespace sdk
65{
66namespace operators
67{
68template <typename Tp>
69bool
70equal(Tp lhs, Tp rhs) ROCPROFILER_ATTRIBUTE(pure);
71
72template <typename Tp>
73bool
74less(Tp lhs, Tp rhs) ROCPROFILER_ATTRIBUTE(pure);
75
76template <typename Tp>
77bool
78equal(Tp lhs, Tp rhs)
79{
80 static_assert(sizeof(Tp) == sizeof(uint64_t), "error! only for opaque handle types");
81 return lhs.handle == rhs.handle;
82}
83
84template <typename Tp>
85bool
86less(Tp lhs, Tp rhs)
87{
88 static_assert(sizeof(Tp) == sizeof(uint64_t), "error! only for opaque handle types");
89 return lhs.handle < rhs.handle;
90}
91} // namespace operators
92} // namespace sdk
93} // namespace rocprofiler
94
95// declaration of operator== and operator!=
105ROCPROFILER_CXX_DECLARE_OPERATORS(hsa_executable_t)
109ROCPROFILER_CXX_DECLARE_OPERATORS(hsa_amd_memory_pool_t)
110
111// definitions of operator==
124
125inline bool
126operator==(const rocprofiler_agent_v0_t& lhs, const rocprofiler_agent_v0_t& rhs)
127{
128 return (lhs.id == rhs.id);
129}
130
131inline bool
133{
134 return std::tie(lhs.x, lhs.y, lhs.z) == std::tie(rhs.x, rhs.y, rhs.z);
135}
136
137// definitions of operator!=
152
153// definitions of operator<
166
167inline bool
168operator<(const rocprofiler_agent_v0_t& lhs, const rocprofiler_agent_v0_t& rhs)
169{
170 return (lhs.id < rhs.id);
171}
172
173inline bool
175{
176 const auto magnitude = [](rocprofiler_dim3_t dim_v) { return dim_v.x * dim_v.y * dim_v.z; };
177 auto lhs_m = magnitude(lhs);
178 auto rhs_m = magnitude(rhs);
179
180 return (lhs_m == rhs_m) ? std::tie(lhs.x, lhs.y, lhs.z) < std::tie(rhs.x, rhs.y, rhs.z)
181 : (lhs_m < rhs_m);
182}
183
184// definitions of operator>, operator<=, operator>=
199
200// cleanup defines
201#undef ROCPROFILER_CXX_DECLARE_OPERATORS
202#undef ROCPROFILER_CXX_DEFINE_NE_OPERATOR
203#undef ROCPROFILER_CXX_DEFINE_EQ_HANDLE_OPERATOR
204#undef ROCPROFILER_CXX_DEFINE_LT_HANDLE_OPERATOR
205#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:606
uint32_t y
Definition fwd.h:605
uint32_t x
Definition fwd.h:604
Agent Identifier.
Definition fwd.h:578
Context ID.
Definition fwd.h:539
Counter ID.
Definition fwd.h:586
Multi-dimensional struct of data used to describe GPU workgroup and grid sizes.
Definition fwd.h:603
Profile Configurations.
Definition fwd.h:595
opaque handle to an internal thread identifier which delivers callbacks for buffers
bool less(Tp lhs, Tp rhs) ROCPROFILER_ATTRIBUTE(pure)
Definition operators.hpp:86
bool equal(Tp lhs, Tp rhs) ROCPROFILER_ATTRIBUTE(pure)
Definition operators.hpp:78
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:34
#define ROCPROFILER_CXX_DEFINE_LT_HANDLE_OPERATOR(TYPE)
Definition operators.hpp:51
#define ROCPROFILER_CXX_DEFINE_COMPARE_OPERATORS(TYPE)
Definition operators.hpp:57
#define ROCPROFILER_CXX_DEFINE_EQ_HANDLE_OPERATOR(TYPE)
Definition operators.hpp:45
#define ROCPROFILER_CXX_DEFINE_NE_OPERATOR(TYPE)
Definition operators.hpp:42