-
Notifications
You must be signed in to change notification settings - Fork 1
/
openacc-nvtx.c
150 lines (143 loc) · 4.93 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
/*
* 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>
#include <nvToolsExtCudaRt.h>
#define bufsize 1024
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))
snprintf(name, bufsize, "%s:%d", profinfo->funcname, profinfo->lineno);
#else
snprintf(name, bufsize, "%s:%d", profinfo->func_name, profinfo->line_no);
#endif
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
switch(profinfo->eventtype)
#else
switch(profinfo->event_type)
#endif
{
case acc_ev_compute_construct_start :
eventAttrib.color = 0x00ff00;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
#ifdef _DEBUG
fprintf(stderr,"PUSH COMPUTE: %s\n", name);
#endif
break;
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
case acc_ev_data_construct_enter_start :
#endif
case acc_ev_enter_data_start :
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
case acc_ev_update_construct_start :
#else
case acc_ev_update_start :
#endif
#ifdef _DEBUG
fprintf(stderr, "PUSH DATA: %s\n", name);
#endif
eventAttrib.color = 0xff0000;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
break;
case acc_ev_wait_start :
eventAttrib.color = 0xff00ff;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
#ifdef _DEBUG
fprintf(stderr,"PUSH WAIT: %s\n", name);
#endif
break;
case acc_ev_implicit_wait_start :
eventAttrib.color = 0xffff00;
eventAttrib.messageType = NVTX_MESSAGE_TYPE_ASCII;
eventAttrib.message.ascii = name;
nvtxRangePushEx(&eventAttrib);
#ifdef _DEBUG
fprintf(stderr,"PUSH WAIT: %s\n", name);
#endif
break;
case acc_ev_compute_construct_end :
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
case acc_ev_data_construct_exit_end :
#endif
case acc_ev_exit_data_end :
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
case acc_ev_update_construct_end :
#else
case acc_ev_update_end :
#endif
case acc_ev_wait_end :
case acc_ev_implicit_wait_end :
#ifdef _DEBUG
fprintf(stderr, "POP\n");
#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_compute_construct_start, oaccNvtxRegister, 0);
regFunc(acc_ev_enter_data_start, oaccNvtxRegister, 0);
#if defined(__PGIC__) && ((__PGIC__ <= 15) && (__PGIC_MINOR__ < 7))
regFunc(acc_ev_data_construct_enter_start, oaccNvtxRegister, 0);
regFunc(acc_ev_data_construct_exit_end, oaccNvtxRegister, 0);
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_wait_start, oaccNvtxRegister, 0);
regFunc(acc_ev_implicit_wait_start, oaccNvtxRegister, 0);
regFunc(acc_ev_compute_construct_end, oaccNvtxRegister, 0);
regFunc(acc_ev_exit_data_end, oaccNvtxRegister, 0);
regFunc(acc_ev_wait_end, oaccNvtxRegister, 0);
regFunc(acc_ev_implicit_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