forked from jefflarkin/openacc-nvtx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenacc-nvtx.c
249 lines (232 loc) · 8.52 KB
/
openacc-nvtx.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/*
* Copyright 2015 NVIDIA Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdio.h>
#include <openacc.h>
// Prior to PGI 15.7 the profiling interface prototype was based on TR-14-2.
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
#include <pgi_acc_prof.h>
#else
#include <acc_prof.h>
#endif
#include <wchar.h>
#include <nvToolsExt.h>
#define bufsize 1024
void oaccNvtxName(acc_prof_info *profinfo, char* name, char* event)
{
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
snprintf(name, bufsize, "%s (%s:%d)",
event, profinfo->funcname, profinfo->lineno);
#else
snprintf(name, bufsize, "%s (%s:%d)",
event, profinfo->func_name, profinfo->line_no);
#endif
}
void oaccNvtxRegister(acc_prof_info *profinfo,
acc_event_info *eventinfo,
acc_api_info *apiinfo)
{
char name[bufsize];
nvtxEventAttributes_t eventAttrib = {0};
eventAttrib.version = NVTX_VERSION;
eventAttrib.size = NVTX_EVENT_ATTRIB_STRUCT_SIZE;
eventAttrib.colorType = NVTX_COLOR_ARGB;
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
switch(profinfo->eventtype)
#else
switch(profinfo->event_type)
#endif
{
#if defined(__PGIC__) && ((__PGIC__ <= 16) && (__PGIC_MINOR__ < 4))
case acc_ev_init_start :
#else
case acc_ev_device_init_start :
#endif
oaccNvtxName(profinfo, name, "device init");
eventAttrib.color = 0xffff00;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
break;
case acc_ev_device_shutdown_start :
oaccNvtxName(profinfo, name, "device shutdown");
eventAttrib.color = 0xffbf00;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
break;
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
case acc_ev_data_construct_enter_start :
#else
case acc_ev_enter_data_start :
#endif
oaccNvtxName(profinfo, name, "enter data");
eventAttrib.color = 0xff8000;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
break;
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
case acc_ev_data_construct_exit_end :
#else
case acc_ev_exit_data_start :
#endif
oaccNvtxName(profinfo, name, "exit data");
eventAttrib.color = 0xff4000;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
break;
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
case acc_ev_update_construct_start :
#else
case acc_ev_update_start :
#endif
oaccNvtxName(profinfo, name, "update");
eventAttrib.color = 0xff0080;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
break;
case acc_ev_compute_construct_start :
oaccNvtxName(profinfo, name, "kernels");
eventAttrib.color = 0xbf00ff;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
break;
case acc_ev_enqueue_launch_start :
oaccNvtxName(profinfo, name, "launch");
eventAttrib.color = 0x8000ff;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
break;
case acc_ev_enqueue_upload_start :
oaccNvtxName(profinfo, name, "upload");
eventAttrib.color = 0xbfff00;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
break;
case acc_ev_enqueue_download_start :
oaccNvtxName(profinfo, name, "download");
eventAttrib.color = 0x80ff00;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
break;
case acc_ev_wait_start :
oaccNvtxName(profinfo, name, "wait");
eventAttrib.color = 0x0000ff;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
break;
#if defined(__PGI__) && ((__PGI__ <= 15) && (__PGI_MINOR__ < 7))
case acc_ev_implicit_wait_start :
oaccNvtxName(profinfo, name, "implicit wait");
eventAttrib.color = 0xffff00;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
break;
#endif
#if defined(__PGIC__) && ((__PGIC__ <= 16) && (__PGIC_MINOR__ < 4))
case acc_ev_init_end :
#else
case acc_ev_device_init_end :
#endif
case acc_ev_device_shutdown_end :
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
case acc_ev_data_construct_enter_end :
#else
case acc_ev_enter_data_end :
#endif
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
case acc_ev_data_construct_exit_end :
#else
case acc_ev_exit_data_end :
#endif
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
case acc_ev_update_construct_end :
#else
case acc_ev_update_end :
#endif
case acc_ev_compute_construct_end :
case acc_ev_enqueue_launch_end :
case acc_ev_enqueue_upload_end :
case acc_ev_enqueue_download_end :
case acc_ev_wait_end :
#if defined(__PGI__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
case acc_ev_implicit_wait_end :
#endif
nvtxRangePop();
break;
}
}
typedef void (*regroutine)( acc_event_t, acc_prof_callback_t, int );
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
void acc_register_library(regroutine regFunc, regroutine unregFunc)
#else
void acc_register_library(acc_prof_reg regFunc, acc_prof_reg unregFunc, acc_prof_lookup lookup)
#endif
{
fprintf(stderr, "REGISTERING NVTX LIBRARY\n");
regFunc(acc_ev_device_init_start, oaccNvtxRegister, 0);
regFunc(acc_ev_device_init_end, oaccNvtxRegister, 0);
regFunc(acc_ev_device_shutdown_end, oaccNvtxRegister, 0);
regFunc(acc_ev_device_shutdown_end, oaccNvtxRegister, 0);
regFunc(acc_ev_device_init_end, oaccNvtxRegister, 0);
regFunc(acc_ev_device_init_end, oaccNvtxRegister, 0);
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
regFunc(acc_ev_data_construct_enter_start, oaccNvtxRegister, 0);
regFunc(acc_ev_data_construct_enter_end, oaccNvtxRegister, 0);
#else
regFunc(acc_ev_enter_data_start, oaccNvtxRegister, 0);
regFunc(acc_ev_enter_data_end, oaccNvtxRegister, 0);
#endif
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
regFunc(acc_ev_data_construct_exit_start, oaccNvtxRegister, 0);
regFunc(acc_ev_data_construct_exit_end, oaccNvtxRegister, 0);
#else
regFunc(acc_ev_exit_data_start, oaccNvtxRegister, 0);
regFunc(acc_ev_exit_data_end, oaccNvtxRegister, 0);
#endif
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
regFunc(acc_ev_update_construct_start, oaccNvtxRegister, 0);
regFunc(acc_ev_update_construct_end, oaccNvtxRegister, 0);
#else
regFunc(acc_ev_update_start, oaccNvtxRegister, 0);
regFunc(acc_ev_update_end, oaccNvtxRegister, 0);
#endif
regFunc(acc_ev_compute_construct_start, oaccNvtxRegister, 0);
regFunc(acc_ev_compute_construct_end, oaccNvtxRegister, 0);
regFunc(acc_ev_enqueue_launch_start, oaccNvtxRegister, 0);
regFunc(acc_ev_enqueue_launch_end, oaccNvtxRegister, 0);
regFunc(acc_ev_enqueue_upload_start, oaccNvtxRegister, 0);
regFunc(acc_ev_enqueue_upload_end, oaccNvtxRegister, 0);
regFunc(acc_ev_enqueue_download_start, oaccNvtxRegister, 0);
regFunc(acc_ev_enqueue_download_end, oaccNvtxRegister, 0);
regFunc(acc_ev_wait_start, oaccNvtxRegister, 0);
regFunc(acc_ev_wait_end, oaccNvtxRegister, 0);
}
#if 0
void __acc_prof_register
( acc_prof_register_t acc_register, acc_prof_register_t acc_unregister )
{
acc_register_library(acc_register, acc_unregister);
}
#endif