-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathnvtx_profile.c
53 lines (38 loc) · 1.1 KB
/
nvtx_profile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/* https://devblogs.nvidia.com/cuda-pro-tip-generate-custom-application-profile-timelines-nvtx */
#include "nvtx_profile.h"
#ifndef NO_GPU
#ifndef USE_HIP
#include "nvToolsExt.h"
const uint32_t colors[] = {0xff00ff00, 0xff0000ff, 0xffffff00, 0xffff00ff, 0xff00ffff, 0xffff0000, 0xffffffff};
const int num_colors = sizeof(colors)/sizeof(uint32_t);
#define PUSH_RANGE(name,cid) { \
int color_id = cid; \
color_id = color_id%num_colors; \
nvtxEventAttributes_t eventAttrib = {0}; \
eventAttrib.version = NVTX_VERSION; \
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE; \
eventAttrib.colorType = NVTX_COLOR_ARGB; \
eventAttrib.color = colors[color_id]; \
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII; \
eventAttrib.message.ascii = name; \
nvtxRangePushEx(&eventAttrib); \
}
#define POP_RANGE nvtxRangePop();
#else
#define PUSH_RANGE(name,cid)
#define POP_RANGE
#endif
#else
#define PUSH_RANGE(name,cid)
#define POP_RANGE
#endif /*NO_GPU*/
void prof_push(const char * annotation, int color)
{
PUSH_RANGE(annotation,color)
return;
}
void prof_pop()
{
POP_RANGE
return;
}