summaryrefslogtreecommitdiff
path: root/libgomp/acc_prof.h
blob: d8ae415bcbe0e146cf181a2644aea24e4e05e3bc (plain)
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
250
251
252
/* OpenACC Profiling Interface

   Copyright (C) 2019-2020 Free Software Foundation, Inc.

   Contributed by Mentor, a Siemens Business.

   This file is part of the GNU Offloading and Multi Processing Library
   (libgomp).

   Libgomp is free software; you can redistribute it and/or modify it
   under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3, or (at your option)
   any later version.

   Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
   WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
   FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
   more details.

   Under Section 7 of GPL version 3, you are granted additional
   permissions described in the GCC Runtime Library Exception, version
   3.1, as published by the Free Software Foundation.

   You should have received a copy of the GNU General Public License and
   a copy of the GCC Runtime Library Exception along with this program;
   see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
   <http://www.gnu.org/licenses/>.  */

#ifndef _ACC_PROF_H
#define _ACC_PROF_H 1


/* The OpenACC specification doesn't say so explicitly, but as its Profiling
   Interface explicitly makes use of, for example, <openacc.h>'s
   'acc_device_t', we supposedly are to '#include' that file here.  */

#include <openacc.h>


#ifdef __cplusplus
extern "C" {
#endif


/* Events.  */

typedef enum acc_event_t
{
  acc_ev_none = 0,
  acc_ev_device_init_start,
  acc_ev_device_init_end,
  acc_ev_device_shutdown_start,
  acc_ev_device_shutdown_end,
  acc_ev_runtime_shutdown,
  acc_ev_create,
  acc_ev_delete,
  acc_ev_alloc,
  acc_ev_free,
  acc_ev_enter_data_start,
  acc_ev_enter_data_end,
  acc_ev_exit_data_start,
  acc_ev_exit_data_end,
  acc_ev_update_start,
  acc_ev_update_end,
  acc_ev_compute_construct_start,
  acc_ev_compute_construct_end,
  acc_ev_enqueue_launch_start,
  acc_ev_enqueue_launch_end,
  acc_ev_enqueue_upload_start,
  acc_ev_enqueue_upload_end,
  acc_ev_enqueue_download_start,
  acc_ev_enqueue_download_end,
  acc_ev_wait_start,
  acc_ev_wait_end,
  acc_ev_last
} acc_event_t;


/* Callbacks Signature.  */

/* "The datatype 'ssize_t' means a signed 32-bit integer for a 32-bit binary
   and a 64-bit integer for a 64-bit binary".  */
typedef signed long int _acc_prof_ssize_t;
/* "The datatype 'size_t' means an unsigned 32-bit integer for a 32-bit binary
   and a 64-bit integer for a 64-bit binary".  */
typedef unsigned long int _acc_prof_size_t;
/* "The datatype 'int' means a 32-bit integer for both 32-bit and 64-bit
   binaries".  */
typedef int _acc_prof_int_t;

/* Internal helpers: a struct's 'valid_bytes' may be less than its 'sizeof'.  */
#define _ACC_PROF_VALID_BYTES_STRUCT(_struct, _lastfield, _valid_bytes_lastfield) \
  offsetof (_struct, _lastfield) + (_valid_bytes_lastfield)
#if 0 /* Untested.  */
#define _ACC_PROF_VALID_BYTES_TYPE_N(_type, _n, _valid_bytes_type) \
  ((_n - 1) * sizeof (_type) + (_valid_bytes_type))
#endif
#define _ACC_PROF_VALID_BYTES_BASICTYPE(_basictype) \
  (sizeof (_basictype))

typedef struct acc_prof_info
{
  acc_event_t event_type;
  _acc_prof_int_t valid_bytes;
  _acc_prof_int_t version;
  acc_device_t device_type;
  _acc_prof_int_t device_number;
  _acc_prof_int_t thread_id;
  _acc_prof_ssize_t async;
  _acc_prof_ssize_t async_queue;
  const char *src_file;
  const char *func_name;
  _acc_prof_int_t line_no, end_line_no;
  _acc_prof_int_t func_line_no, func_end_line_no;
#define _ACC_PROF_INFO_VALID_BYTES \
  _ACC_PROF_VALID_BYTES_STRUCT (acc_prof_info, func_end_line_no, \
				_ACC_PROF_VALID_BYTES_BASICTYPE (_acc_prof_int_t))
} acc_prof_info;

/* We implement the OpenACC 2.6 Profiling Interface.  */

#define _ACC_PROF_INFO_VERSION 201711

typedef enum acc_construct_t
{
  acc_construct_parallel = 0,
  acc_construct_kernels,
  acc_construct_loop,
  acc_construct_data,
  acc_construct_enter_data,
  acc_construct_exit_data,
  acc_construct_host_data,
  acc_construct_atomic,
  acc_construct_declare,
  acc_construct_init,
  acc_construct_shutdown,
  acc_construct_set,
  acc_construct_update,
  acc_construct_routine,
  acc_construct_wait,
  acc_construct_runtime_api,
  acc_construct_serial
} acc_construct_t;

typedef struct acc_data_event_info
{
  acc_event_t event_type;
  _acc_prof_int_t valid_bytes;
  acc_construct_t parent_construct;
  _acc_prof_int_t implicit;
  void *tool_info;
  const char *var_name;
  _acc_prof_size_t bytes;
  const void *host_ptr;
  const void *device_ptr;
#define _ACC_DATA_EVENT_INFO_VALID_BYTES \
  _ACC_PROF_VALID_BYTES_STRUCT (acc_data_event_info, device_ptr, \
				_ACC_PROF_VALID_BYTES_BASICTYPE (void *))
} acc_data_event_info;

typedef struct acc_launch_event_info
{
  acc_event_t event_type;
  _acc_prof_int_t valid_bytes;
  acc_construct_t parent_construct;
  _acc_prof_int_t implicit;
  void *tool_info;
  const char *kernel_name;
  _acc_prof_size_t num_gangs, num_workers, vector_length;
#define _ACC_LAUNCH_EVENT_INFO_VALID_BYTES \
  _ACC_PROF_VALID_BYTES_STRUCT (acc_launch_event_info, vector_length, \
				_ACC_PROF_VALID_BYTES_BASICTYPE (_acc_prof_size_t))
} acc_launch_event_info;

typedef struct acc_other_event_info
{
  acc_event_t event_type;
  _acc_prof_int_t valid_bytes;
  acc_construct_t parent_construct;
  _acc_prof_int_t implicit;
  void *tool_info;
#define _ACC_OTHER_EVENT_INFO_VALID_BYTES \
  _ACC_PROF_VALID_BYTES_STRUCT (acc_other_event_info, tool_info, \
				_ACC_PROF_VALID_BYTES_BASICTYPE (void *))
} acc_other_event_info;

typedef union acc_event_info
{
  acc_event_t event_type;
  acc_data_event_info data_event;
  acc_launch_event_info launch_event;
  acc_other_event_info other_event;
} acc_event_info;

typedef enum acc_device_api
{
  acc_device_api_none = 0,
  acc_device_api_cuda,
  acc_device_api_opencl,
  acc_device_api_coi,
  acc_device_api_other
} acc_device_api;

typedef struct acc_api_info
{
  acc_device_api device_api;
  _acc_prof_int_t valid_bytes;
  acc_device_t device_type;
  _acc_prof_int_t vendor;
  const void *device_handle;
  const void *context_handle;
  const void *async_handle;
#define _ACC_API_INFO_VALID_BYTES \
  _ACC_PROF_VALID_BYTES_STRUCT (acc_api_info, async_handle, \
				_ACC_PROF_VALID_BYTES_BASICTYPE (void *))
} acc_api_info;

/* Don't tag 'acc_prof_callback' as '__GOACC_NOTHROW': these functions are
   provided by user code, and must be expected to do anything.  */
typedef void (*acc_prof_callback) (acc_prof_info *, acc_event_info *,
				   acc_api_info *);


/* Loading the Library.  */

typedef enum acc_register_t
{
  acc_reg = 0,
  acc_toggle = 1,
  acc_toggle_per_thread = 2
} acc_register_t;

typedef void (*acc_prof_reg) (acc_event_t, acc_prof_callback, acc_register_t);
extern void acc_prof_register (acc_event_t, acc_prof_callback,
			       acc_register_t) __GOACC_NOTHROW;
extern void acc_prof_unregister (acc_event_t, acc_prof_callback,
				 acc_register_t) __GOACC_NOTHROW;
typedef void (*acc_query_fn) ();
typedef acc_query_fn (*acc_prof_lookup_func) (const char *);
extern acc_query_fn acc_prof_lookup (const char *) __GOACC_NOTHROW;
/* Don't tag 'acc_register_library' as '__GOACC_NOTHROW': this function can be
   overridden by user code, and must be expected to do anything.  */
extern void acc_register_library (acc_prof_reg, acc_prof_reg,
				  acc_prof_lookup_func);


#ifdef __cplusplus
}
#endif


#endif /* _ACC_PROF_H */