acc_prof.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /* OpenACC Profiling Interface
  2. Copyright (C) 2019-2022 Free Software Foundation, Inc.
  3. Contributed by Mentor, a Siemens Business.
  4. This file is part of the GNU Offloading and Multi Processing Library
  5. (libgomp).
  6. Libgomp is free software; you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3, or (at your option)
  9. any later version.
  10. Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. more details.
  14. Under Section 7 of GPL version 3, you are granted additional
  15. permissions described in the GCC Runtime Library Exception, version
  16. 3.1, as published by the Free Software Foundation.
  17. You should have received a copy of the GNU General Public License and
  18. a copy of the GCC Runtime Library Exception along with this program;
  19. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  20. <http://www.gnu.org/licenses/>. */
  21. #ifndef _ACC_PROF_H
  22. #define _ACC_PROF_H 1
  23. /* The OpenACC specification doesn't say so explicitly, but as its Profiling
  24. Interface explicitly makes use of, for example, <openacc.h>'s
  25. 'acc_device_t', we supposedly are to '#include' that file here. */
  26. #include <openacc.h>
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. /* Events. */
  31. typedef enum acc_event_t
  32. {
  33. acc_ev_none = 0,
  34. acc_ev_device_init_start,
  35. acc_ev_device_init_end,
  36. acc_ev_device_shutdown_start,
  37. acc_ev_device_shutdown_end,
  38. acc_ev_runtime_shutdown,
  39. acc_ev_create,
  40. acc_ev_delete,
  41. acc_ev_alloc,
  42. acc_ev_free,
  43. acc_ev_enter_data_start,
  44. acc_ev_enter_data_end,
  45. acc_ev_exit_data_start,
  46. acc_ev_exit_data_end,
  47. acc_ev_update_start,
  48. acc_ev_update_end,
  49. acc_ev_compute_construct_start,
  50. acc_ev_compute_construct_end,
  51. acc_ev_enqueue_launch_start,
  52. acc_ev_enqueue_launch_end,
  53. acc_ev_enqueue_upload_start,
  54. acc_ev_enqueue_upload_end,
  55. acc_ev_enqueue_download_start,
  56. acc_ev_enqueue_download_end,
  57. acc_ev_wait_start,
  58. acc_ev_wait_end,
  59. acc_ev_last
  60. } acc_event_t;
  61. /* Callbacks Signature. */
  62. /* "The datatype 'ssize_t' means a signed 32-bit integer for a 32-bit binary
  63. and a 64-bit integer for a 64-bit binary". */
  64. typedef signed long int _acc_prof_ssize_t;
  65. /* "The datatype 'size_t' means an unsigned 32-bit integer for a 32-bit binary
  66. and a 64-bit integer for a 64-bit binary". */
  67. typedef unsigned long int _acc_prof_size_t;
  68. /* "The datatype 'int' means a 32-bit integer for both 32-bit and 64-bit
  69. binaries". */
  70. typedef int _acc_prof_int_t;
  71. /* Internal helpers: a struct's 'valid_bytes' may be less than its 'sizeof'. */
  72. #define _ACC_PROF_VALID_BYTES_STRUCT(_struct, _lastfield, _valid_bytes_lastfield) \
  73. offsetof (_struct, _lastfield) + (_valid_bytes_lastfield)
  74. #if 0 /* Untested. */
  75. #define _ACC_PROF_VALID_BYTES_TYPE_N(_type, _n, _valid_bytes_type) \
  76. ((_n - 1) * sizeof (_type) + (_valid_bytes_type))
  77. #endif
  78. #define _ACC_PROF_VALID_BYTES_BASICTYPE(_basictype) \
  79. (sizeof (_basictype))
  80. typedef struct acc_prof_info
  81. {
  82. acc_event_t event_type;
  83. _acc_prof_int_t valid_bytes;
  84. _acc_prof_int_t version;
  85. acc_device_t device_type;
  86. _acc_prof_int_t device_number;
  87. _acc_prof_int_t thread_id;
  88. _acc_prof_ssize_t async;
  89. _acc_prof_ssize_t async_queue;
  90. const char *src_file;
  91. const char *func_name;
  92. _acc_prof_int_t line_no, end_line_no;
  93. _acc_prof_int_t func_line_no, func_end_line_no;
  94. #define _ACC_PROF_INFO_VALID_BYTES \
  95. _ACC_PROF_VALID_BYTES_STRUCT (acc_prof_info, func_end_line_no, \
  96. _ACC_PROF_VALID_BYTES_BASICTYPE (_acc_prof_int_t))
  97. } acc_prof_info;
  98. /* We implement the OpenACC 2.6 Profiling Interface. */
  99. #define _ACC_PROF_INFO_VERSION 201711
  100. typedef enum acc_construct_t
  101. {
  102. acc_construct_parallel = 0,
  103. acc_construct_kernels,
  104. acc_construct_loop,
  105. acc_construct_data,
  106. acc_construct_enter_data,
  107. acc_construct_exit_data,
  108. acc_construct_host_data,
  109. acc_construct_atomic,
  110. acc_construct_declare,
  111. acc_construct_init,
  112. acc_construct_shutdown,
  113. acc_construct_set,
  114. acc_construct_update,
  115. acc_construct_routine,
  116. acc_construct_wait,
  117. acc_construct_runtime_api,
  118. acc_construct_serial
  119. } acc_construct_t;
  120. typedef struct acc_data_event_info
  121. {
  122. acc_event_t event_type;
  123. _acc_prof_int_t valid_bytes;
  124. acc_construct_t parent_construct;
  125. _acc_prof_int_t implicit;
  126. void *tool_info;
  127. const char *var_name;
  128. _acc_prof_size_t bytes;
  129. const void *host_ptr;
  130. const void *device_ptr;
  131. #define _ACC_DATA_EVENT_INFO_VALID_BYTES \
  132. _ACC_PROF_VALID_BYTES_STRUCT (acc_data_event_info, device_ptr, \
  133. _ACC_PROF_VALID_BYTES_BASICTYPE (void *))
  134. } acc_data_event_info;
  135. typedef struct acc_launch_event_info
  136. {
  137. acc_event_t event_type;
  138. _acc_prof_int_t valid_bytes;
  139. acc_construct_t parent_construct;
  140. _acc_prof_int_t implicit;
  141. void *tool_info;
  142. const char *kernel_name;
  143. _acc_prof_size_t num_gangs, num_workers, vector_length;
  144. #define _ACC_LAUNCH_EVENT_INFO_VALID_BYTES \
  145. _ACC_PROF_VALID_BYTES_STRUCT (acc_launch_event_info, vector_length, \
  146. _ACC_PROF_VALID_BYTES_BASICTYPE (_acc_prof_size_t))
  147. } acc_launch_event_info;
  148. typedef struct acc_other_event_info
  149. {
  150. acc_event_t event_type;
  151. _acc_prof_int_t valid_bytes;
  152. acc_construct_t parent_construct;
  153. _acc_prof_int_t implicit;
  154. void *tool_info;
  155. #define _ACC_OTHER_EVENT_INFO_VALID_BYTES \
  156. _ACC_PROF_VALID_BYTES_STRUCT (acc_other_event_info, tool_info, \
  157. _ACC_PROF_VALID_BYTES_BASICTYPE (void *))
  158. } acc_other_event_info;
  159. typedef union acc_event_info
  160. {
  161. acc_event_t event_type;
  162. acc_data_event_info data_event;
  163. acc_launch_event_info launch_event;
  164. acc_other_event_info other_event;
  165. } acc_event_info;
  166. typedef enum acc_device_api
  167. {
  168. acc_device_api_none = 0,
  169. acc_device_api_cuda,
  170. acc_device_api_opencl,
  171. acc_device_api_coi,
  172. acc_device_api_other
  173. } acc_device_api;
  174. typedef struct acc_api_info
  175. {
  176. acc_device_api device_api;
  177. _acc_prof_int_t valid_bytes;
  178. acc_device_t device_type;
  179. _acc_prof_int_t vendor;
  180. const void *device_handle;
  181. const void *context_handle;
  182. const void *async_handle;
  183. #define _ACC_API_INFO_VALID_BYTES \
  184. _ACC_PROF_VALID_BYTES_STRUCT (acc_api_info, async_handle, \
  185. _ACC_PROF_VALID_BYTES_BASICTYPE (void *))
  186. } acc_api_info;
  187. /* Don't tag 'acc_prof_callback' as '__GOACC_NOTHROW': these functions are
  188. provided by user code, and must be expected to do anything. */
  189. typedef void (*acc_prof_callback) (acc_prof_info *, acc_event_info *,
  190. acc_api_info *);
  191. /* Loading the Library. */
  192. typedef enum acc_register_t
  193. {
  194. acc_reg = 0,
  195. acc_toggle = 1,
  196. acc_toggle_per_thread = 2
  197. } acc_register_t;
  198. typedef void (*acc_prof_reg) (acc_event_t, acc_prof_callback, acc_register_t);
  199. extern void acc_prof_register (acc_event_t, acc_prof_callback,
  200. acc_register_t) __GOACC_NOTHROW;
  201. extern void acc_prof_unregister (acc_event_t, acc_prof_callback,
  202. acc_register_t) __GOACC_NOTHROW;
  203. typedef void (*acc_query_fn) ();
  204. typedef acc_query_fn (*acc_prof_lookup_func) (const char *);
  205. extern acc_query_fn acc_prof_lookup (const char *) __GOACC_NOTHROW;
  206. /* Don't tag 'acc_register_library' as '__GOACC_NOTHROW': this function can be
  207. overridden by user code, and must be expected to do anything. */
  208. extern void acc_register_library (acc_prof_reg, acc_prof_reg,
  209. acc_prof_lookup_func);
  210. #ifdef __cplusplus
  211. }
  212. #endif
  213. #endif /* _ACC_PROF_H */