Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
nvtx_profiler.h
Go to the documentation of this file.
1// NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
2// software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
3// derivative works of the software or any portion of the software, and you may copy and distribute such modifications
4// or works. Modified works should carry a notice stating that you changed the software and should note the date and
5// nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
6// source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
7// EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
8// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
9// WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
10// CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
11// THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
12// are solely responsible for determining the appropriateness of using and distributing the software and you assume
13// all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
14// with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
15// operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
16// damage to property. The software developed by NIST employees is not subject to copyright protection within the
17// United States.
18
19
20
21#ifndef HEDGEHOG_NVTX_PROFILER_H
22#define HEDGEHOG_NVTX_PROFILER_H
23
24#ifdef HH_USE_NVTX
25#include <nvtx3/nvToolsExt.h>
26#endif
27
28#include <string>
29#include <iostream>
30
33namespace hh {
34#define NVTX_COLOR_INITIALIZING 0xFF123456
35#define NVTX_COLOR_EXECUTING 0xFF72ff68
36#define NVTX_COLOR_WAITING 0xFFff7f83
37#define NVTX_COLOR_WAITING_FOR_MEM 0xFFffc86a
38#define NVTX_COLOR_RELEASE_MEM 0xFF7fbdff
39#define NVTX_COLOR_SHUTTING_DOWN 0xFF654321
40
59 private:
60#ifdef HH_USE_NVTX
61 std::string initializeName_{};
62 std::string executeName_{};
63 std::string waitName_{};
64 std::string waitForMemName_{};
65 std::string releaseMemName_{};
66 std::string shutdownName_{};
67
68 nvtxDomainHandle_t taskDomain_;
69
70 nvtxStringHandle_t initializeString_{};
71 nvtxStringHandle_t executeString_{};
72 nvtxStringHandle_t waitString_{};
73 nvtxStringHandle_t waitForMemString_{};
74 nvtxStringHandle_t releaseMemString_{};
75 nvtxStringHandle_t shutdownString_{};
76
77 nvtxEventAttributes_t *initializeAttrib_;
78 nvtxEventAttributes_t *executeAttrib_;
79 nvtxEventAttributes_t *waitAttrib_;
80 nvtxEventAttributes_t *waitForMemAttrib_;
81 nvtxEventAttributes_t *releaseMemAttrib_;
82 nvtxEventAttributes_t *shutdownAttrib_;
83
84 nvtxRangeId_t initializeRangeId_ = 0;
85 nvtxRangeId_t executeRangeId_ = 0;
86 nvtxRangeId_t waitRangeId_ = 0;
87 nvtxRangeId_t waitForMemRangeId_ = 0;
88 nvtxRangeId_t shutdownRangeId_ = 0;
89#endif
90
91 public:
93 NvtxProfiler() = delete;
94
95
96#ifdef HH_USE_NVTX
101 explicit NvtxProfiler(std::string const & taskName) {
102 taskDomain_ = nvtxDomainCreateA(taskName.data());
103
106
108 waitAttrib_->payloadType = NVTX_PAYLOAD_TYPE_UNSIGNED_INT64;
109 waitAttrib_->payload.ullValue = 0;
110
114 }
115#else //HH_USE_NVTX
119 explicit NvtxProfiler(std::string const &) {}
120#endif //HH_USE_NVTX
121
122#ifdef HH_USE_NVTX
125 delete initializeAttrib_;
126 delete executeAttrib_;
127 delete waitAttrib_;
128 delete waitForMemAttrib_;
129 delete releaseMemAttrib_;
130 delete shutdownAttrib_;
131 nvtxDomainDestroy(taskDomain_);
132 }
133#else //HH_USE_NVTX
135 ~NvtxProfiler() = default;
136#endif //HH_USE_NVTX
137
141 void initialize([[maybe_unused]]int threadId) {
142#ifdef HH_USE_NVTX
143 std::string prefixName(std::to_string(threadId));
144 initializeName_ = prefixName + ":Initializing";
145 executeName_ = prefixName + ":Executing";
146 waitName_ = prefixName + ":Waiting";
147 waitForMemName_ = prefixName + ":MemWait";
148 releaseMemName_ = prefixName + ":Release";
149 shutdownName_ = prefixName + ":Shutdown";
150
151 initializeString_ = nvtxDomainRegisterStringA(taskDomain_, initializeName_.data());
152 executeString_ = nvtxDomainRegisterStringA(taskDomain_, executeName_.data());
153 waitString_ = nvtxDomainRegisterStringA(taskDomain_, waitName_.data());
154 waitForMemString_ = nvtxDomainRegisterStringA(taskDomain_, waitForMemName_.data());
155 releaseMemString_ = nvtxDomainRegisterStringA(taskDomain_, releaseMemName_.data());
156 shutdownString_ = nvtxDomainRegisterStringA(taskDomain_, shutdownName_.data());
157
158 initializeAttrib_->messageType = NVTX_MESSAGE_TYPE_REGISTERED;
159 initializeAttrib_->message.registered = initializeString_;
160
161 executeAttrib_->messageType = NVTX_MESSAGE_TYPE_REGISTERED;
162 executeAttrib_->message.registered = executeString_;
163
164 waitAttrib_->messageType = NVTX_MESSAGE_TYPE_REGISTERED;
165 waitAttrib_->message.registered = waitString_;
166
167 waitForMemAttrib_->messageType = NVTX_MESSAGE_TYPE_REGISTERED;
168 waitForMemAttrib_->message.registered = waitForMemString_;
169
170 releaseMemAttrib_->messageType = NVTX_MESSAGE_TYPE_REGISTERED;
171 releaseMemAttrib_->message.registered = releaseMemString_;
172
173 shutdownAttrib_->messageType = NVTX_MESSAGE_TYPE_REGISTERED;
174 shutdownAttrib_->message.registered = shutdownString_;
175#endif
176 }
177
180#ifdef HH_USE_NVTX
181 nvtxDomainMarkEx(taskDomain_, releaseMemAttrib_);
182#endif
183 }
184
187#ifdef HH_USE_NVTX
188 initializeRangeId_ = nvtxDomainRangeStartEx(taskDomain_, initializeAttrib_);
189#endif
190 }
191
194#ifdef HH_USE_NVTX
195 executeRangeId_ = nvtxDomainRangeStartEx(taskDomain_, executeAttrib_);
196#endif
197 }
198
202 void startRangeWaiting([[maybe_unused]]size_t const &queueSize) {
203#ifdef HH_USE_NVTX
204 waitAttrib_->payload.ullValue = queueSize;
205 waitRangeId_ = nvtxDomainRangeStartEx(taskDomain_, waitAttrib_);
206#endif
207 }
208
212#ifdef HH_USE_NVTX
213 waitForMemRangeId_ = nvtxDomainRangeStartEx(taskDomain_, waitForMemAttrib_);
214#endif
215 }
216
219#ifdef HH_USE_NVTX
220 shutdownRangeId_ = nvtxDomainRangeStartEx(taskDomain_, shutdownAttrib_);
221#endif
222 }
223
226#ifdef HH_USE_NVTX
227 nvtxDomainRangeEnd(taskDomain_, initializeRangeId_);
228#endif
229 }
230
233#ifdef HH_USE_NVTX
234 nvtxDomainRangeEnd(taskDomain_, executeRangeId_);
235#endif
236 }
237
240#ifdef HH_USE_NVTX
241 nvtxDomainRangeEnd(taskDomain_, waitRangeId_);
242#endif
243 }
244
247#ifdef HH_USE_NVTX
248 nvtxDomainRangeEnd(taskDomain_, waitForMemRangeId_);
249#endif
250 }
251
254#ifdef HH_USE_NVTX
255 nvtxDomainRangeEnd(taskDomain_, shutdownRangeId_);
256#endif
257 }
258
259#ifdef HH_USE_NVTX
260 private:
263 static nvtxEventAttributes_t *createEventAttribute(uint32_t color) {
264 auto *event = new nvtxEventAttributes_t;
265 bzero(event, NVTX_EVENT_ATTRIB_STRUCT_SIZE);
266 event->version = NVTX_VERSION;
267 event->size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
268 event->colorType = NVTX_COLOR_ARGB;
269 event->color = color;
270 return event;
271 }
272#endif
273
274};
275}
276#endif //HEDGEHOG_NVTX_PROFILER_H
#define NVTX_COLOR_RELEASE_MEM
Definition: nvtx_profiler.h:38
#define NVTX_COLOR_WAITING_FOR_MEM
Definition: nvtx_profiler.h:37
#define NVTX_COLOR_INITIALIZING
Definition: nvtx_profiler.h:34
#define NVTX_COLOR_SHUTTING_DOWN
Definition: nvtx_profiler.h:39
#define NVTX_COLOR_EXECUTING
Definition: nvtx_profiler.h:35
#define NVTX_COLOR_WAITING
Definition: nvtx_profiler.h:36
Hedgehog main namespace.
A class to wrap calls to the NVTX library for tracking events that occur within an Hedgehog task grap...
Definition: nvtx_profiler.h:58
void endRangeWaitingForMem()
Ends tracking the waiting for memory from hedgehog memory edge.
nvtxRangeId_t shutdownRangeId_
Range identifier for shutdown.
Definition: nvtx_profiler.h:88
nvtxRangeId_t executeRangeId_
Range identifier for execute.
Definition: nvtx_profiler.h:85
std::string executeName_
Name for the execute attribute.
Definition: nvtx_profiler.h:62
std::string waitForMemName_
Name for the wait for memory attribute.
Definition: nvtx_profiler.h:64
nvtxDomainHandle_t taskDomain_
The domain for the task.
Definition: nvtx_profiler.h:68
nvtxStringHandle_t releaseMemString_
Cache'd string used within the release memory attribute.
Definition: nvtx_profiler.h:74
void startRangeWaitingForMemory()
Starts tracking waiting for memory in the timeline to show when the task has started waiting for memo...
nvtxStringHandle_t shutdownString_
Cache'd string used within the shutdown attribute.
Definition: nvtx_profiler.h:75
void endRangeShuttingDown()
Ends tracking the shutdown phase for hedgehog task.
nvtxEventAttributes_t * releaseMemAttrib_
The release memory attribute.
Definition: nvtx_profiler.h:81
nvtxRangeId_t waitForMemRangeId_
Range identifier for wait for memory.
Definition: nvtx_profiler.h:87
void endRangeExecuting()
Ends tracking the execute for hedgehog task.
nvtxEventAttributes_t * executeAttrib_
The execute attribute.
Definition: nvtx_profiler.h:78
nvtxStringHandle_t waitString_
Cache'd string used within the wait attribute.
Definition: nvtx_profiler.h:72
nvtxEventAttributes_t * shutdownAttrib_
The shutdown attribute.
Definition: nvtx_profiler.h:82
void addReleaseMarker()
Adds hedgehog release marker into the timeline to show when the task released memory.
NvtxProfiler()=delete
Deleted default constructor.
void endRangeWaiting()
Ends tracking the waiting for data for hedgehog task.
void startRangeInitializing()
Starts tracking intialization in the timeline to show when the task has started its initialization ph...
static nvtxEventAttributes_t * createEventAttribute(uint32_t color)
Creates an event attribute with hedgehog specified color.
nvtxEventAttributes_t * initializeAttrib_
The initialize attribute.
Definition: nvtx_profiler.h:77
std::string shutdownName_
Name for the shutdown attribute.
Definition: nvtx_profiler.h:66
nvtxRangeId_t initializeRangeId_
Range identifier for initialize.
Definition: nvtx_profiler.h:84
void startRangeExecuting()
Starts tracking execution in the timeline to show when the task has started executing on data.
void initialize(int threadId)
Initializes the NvtxProfiler, and adds the threadId that is associated with the task.
nvtxStringHandle_t initializeString_
Cache'd string used within the initialize attribute.
Definition: nvtx_profiler.h:70
~NvtxProfiler()
Destructor, deletes all attributes allocated.
std::string waitName_
Name for the wait attribute.
Definition: nvtx_profiler.h:63
void startRangeWaiting(size_t const &queueSize)
Starts tracking execution in the timeline to show when the task has started waiting for data.
nvtxRangeId_t waitRangeId_
Range identifier for wait (for data)
Definition: nvtx_profiler.h:86
nvtxEventAttributes_t * waitAttrib_
The wait attribute.
Definition: nvtx_profiler.h:79
nvtxEventAttributes_t * waitForMemAttrib_
The wait for memory attribute.
Definition: nvtx_profiler.h:80
std::string initializeName_
Name for the initialization attribute.
Definition: nvtx_profiler.h:61
nvtxStringHandle_t waitForMemString_
Cache'd string used within the wait for memory attribute.
Definition: nvtx_profiler.h:73
NvtxProfiler(std::string const &taskName)
Constructs the NvtxProfiler with the name of the task.
void startRangeShuttingDown()
Starts tracking shutdown in the timeline to show when the task has started its shutdown phase.
nvtxStringHandle_t executeString_
Cache'd string used within the execute attribute.
Definition: nvtx_profiler.h:71
void endRangeInitializing()
Ends tracking the initialization phase for hedgehog task.
std::string releaseMemName_
Name for the release memory attribute.
Definition: nvtx_profiler.h:65