oacc-int.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* OpenACC Runtime - internal declarations
  2. Copyright (C) 2013-2022 Free Software Foundation, Inc.
  3. Contributed by Mentor Embedded.
  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. /* This file contains data types and function declarations that are not
  22. part of the official OpenACC user interface. There are declarations
  23. in here that are part of the GNU OpenACC ABI, in that the compiler is
  24. required to know about them and use them.
  25. The convention is that the all caps prefix "GOACC" is used group items
  26. that are part of the external ABI, and the lower case prefix "goacc"
  27. is used group items that are completely private to the library. */
  28. #ifndef OACC_INT_H
  29. #define OACC_INT_H 1
  30. #include "openacc.h"
  31. #include "config.h"
  32. #include "acc_prof.h"
  33. #include <stddef.h>
  34. #include <stdbool.h>
  35. #include <stdarg.h>
  36. #ifdef HAVE_ATTRIBUTE_VISIBILITY
  37. # pragma GCC visibility push(hidden)
  38. #endif
  39. static inline enum acc_device_t
  40. acc_device_type (enum offload_target_type type)
  41. {
  42. return (enum acc_device_t) type;
  43. }
  44. struct goacc_thread
  45. {
  46. /* The base device for the current thread. */
  47. struct gomp_device_descr *base_dev;
  48. /* The device for the current thread. */
  49. struct gomp_device_descr *dev;
  50. struct gomp_device_descr *saved_bound_dev;
  51. /* This is a linked list of data mapped by the "acc data" pragma, following
  52. strictly push/pop semantics according to lexical scope. */
  53. struct target_mem_desc *mapped_data;
  54. /* Data of the OpenACC Profiling Interface. */
  55. acc_prof_info *prof_info;
  56. acc_api_info *api_info;
  57. /* Per-thread toggle of OpenACC Profiling Interface callbacks. */
  58. bool prof_callbacks_enabled;
  59. /* These structures form a list: this is the next thread in that list. */
  60. struct goacc_thread *next;
  61. /* Target-specific data (used by plugin). */
  62. void *target_tls;
  63. };
  64. #ifdef __AMDGCN__
  65. static inline struct goacc_thread *
  66. goacc_thread (void)
  67. {
  68. /* Unused in the offload libgomp for OpenACC: return a dummy value. */
  69. return 0;
  70. }
  71. #elif defined HAVE_TLS || defined USE_EMUTLS
  72. extern __thread struct goacc_thread *goacc_tls_data;
  73. static inline struct goacc_thread *
  74. goacc_thread (void)
  75. {
  76. return goacc_tls_data;
  77. }
  78. #else
  79. extern pthread_key_t goacc_tls_key;
  80. static inline struct goacc_thread *
  81. goacc_thread (void)
  82. {
  83. return pthread_getspecific (goacc_tls_key);
  84. }
  85. #endif
  86. void goacc_register (struct gomp_device_descr *) __GOACC_NOTHROW;
  87. void goacc_attach_host_thread_to_device (int);
  88. void goacc_runtime_initialize (void);
  89. void goacc_save_and_set_bind (acc_device_t);
  90. void goacc_restore_bind (void);
  91. void goacc_lazy_initialize (void);
  92. void goacc_host_init (void);
  93. void goacc_wait (int, int, va_list *);
  94. void goacc_init_asyncqueues (struct gomp_device_descr *);
  95. bool goacc_fini_asyncqueues (struct gomp_device_descr *);
  96. void goacc_async_free (struct gomp_device_descr *, struct goacc_asyncqueue *,
  97. void *);
  98. struct goacc_asyncqueue *get_goacc_asyncqueue (int);
  99. struct goacc_asyncqueue *lookup_goacc_asyncqueue (struct goacc_thread *, bool,
  100. int);
  101. static inline bool
  102. async_valid_stream_id_p (int async)
  103. {
  104. return async >= 0;
  105. }
  106. static inline bool
  107. async_valid_p (int async)
  108. {
  109. return (async == acc_async_noval || async == acc_async_sync
  110. || async_valid_stream_id_p (async));
  111. }
  112. static inline bool
  113. async_synchronous_p (int async)
  114. {
  115. if (!async_valid_p (async))
  116. return true;
  117. return async == acc_async_sync;
  118. }
  119. extern bool goacc_prof_enabled;
  120. /* Tune for the (very common) case that profiling is not enabled. */
  121. #define GOACC_PROF_ENABLED \
  122. (__builtin_expect (__atomic_load_n (&goacc_prof_enabled, \
  123. MEMMODEL_ACQUIRE) == true, false))
  124. void goacc_profiling_initialize (void);
  125. bool _goacc_profiling_dispatch_p (bool);
  126. /* Tune for the (very common) case that profiling is not enabled. */
  127. #define GOACC_PROFILING_DISPATCH_P(...) \
  128. (GOACC_PROF_ENABLED \
  129. && _goacc_profiling_dispatch_p (__VA_ARGS__))
  130. bool _goacc_profiling_setup_p (struct goacc_thread *,
  131. acc_prof_info *, acc_api_info *);
  132. /* Tune for the (very common) case that profiling is not enabled. */
  133. #define GOACC_PROFILING_SETUP_P(...) \
  134. (GOACC_PROFILING_DISPATCH_P (false) \
  135. && _goacc_profiling_setup_p (__VA_ARGS__))
  136. void goacc_profiling_dispatch (acc_prof_info *, acc_event_info *,
  137. acc_api_info *);
  138. #ifdef HAVE_ATTRIBUTE_VISIBILITY
  139. # pragma GCC visibility pop
  140. #endif
  141. #endif