gomp-constants.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* Communication between GCC and libgomp.
  2. Copyright (C) 2014-2020 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. #ifndef GOMP_CONSTANTS_H
  22. #define GOMP_CONSTANTS_H 1
  23. /* Memory mapping types. */
  24. /* One byte. */
  25. #define GOMP_MAP_LAST (1 << 8)
  26. #define GOMP_MAP_FLAG_TO (1 << 0)
  27. #define GOMP_MAP_FLAG_FROM (1 << 1)
  28. /* Special map kinds, enumerated starting here. */
  29. #define GOMP_MAP_FLAG_SPECIAL_0 (1 << 2)
  30. #define GOMP_MAP_FLAG_SPECIAL_1 (1 << 3)
  31. #define GOMP_MAP_FLAG_SPECIAL_2 (1 << 4)
  32. #define GOMP_MAP_FLAG_SPECIAL_4 (1 << 6)
  33. #define GOMP_MAP_FLAG_SPECIAL (GOMP_MAP_FLAG_SPECIAL_1 \
  34. | GOMP_MAP_FLAG_SPECIAL_0)
  35. #define GOMP_MAP_DEEP_COPY (GOMP_MAP_FLAG_SPECIAL_4 \
  36. | GOMP_MAP_FLAG_SPECIAL_2)
  37. /* Flag to force a specific behavior (or else, trigger a run-time error). */
  38. #define GOMP_MAP_FLAG_FORCE (1 << 7)
  39. enum gomp_map_kind
  40. {
  41. /* If not already present, allocate. */
  42. GOMP_MAP_ALLOC = 0,
  43. /* ..., and copy to device. */
  44. GOMP_MAP_TO = (GOMP_MAP_ALLOC | GOMP_MAP_FLAG_TO),
  45. /* ..., and copy from device. */
  46. GOMP_MAP_FROM = (GOMP_MAP_ALLOC | GOMP_MAP_FLAG_FROM),
  47. /* ..., and copy to and from device. */
  48. GOMP_MAP_TOFROM = (GOMP_MAP_TO | GOMP_MAP_FROM),
  49. /* The following kind is an internal only map kind, used for pointer based
  50. array sections. OMP_CLAUSE_SIZE for these is not the pointer size,
  51. which is implicitly POINTER_SIZE_UNITS, but the bias. */
  52. GOMP_MAP_POINTER = (GOMP_MAP_FLAG_SPECIAL_0 | 0),
  53. /* Also internal, behaves like GOMP_MAP_TO, but additionally any
  54. GOMP_MAP_POINTER records consecutive after it which have addresses
  55. falling into that range will not be ignored if GOMP_MAP_TO_PSET wasn't
  56. mapped already.
  57. For OpenACC attach operations (e.g. copyin of struct members),
  58. GOMP_MAP_TO_PSET is followed by a single GOMP_MAP_ATTACH mapping
  59. instead. */
  60. GOMP_MAP_TO_PSET = (GOMP_MAP_FLAG_SPECIAL_0 | 1),
  61. /* Must already be present. */
  62. GOMP_MAP_FORCE_PRESENT = (GOMP_MAP_FLAG_SPECIAL_0 | 2),
  63. /* Deallocate a mapping, without copying from device. */
  64. GOMP_MAP_DELETE = (GOMP_MAP_FLAG_SPECIAL_0 | 3),
  65. /* Is a device pointer. OMP_CLAUSE_SIZE for these is unused; is implicitly
  66. POINTER_SIZE_UNITS. */
  67. GOMP_MAP_FORCE_DEVICEPTR = (GOMP_MAP_FLAG_SPECIAL_1 | 0),
  68. /* OpenACC device_resident. */
  69. GOMP_MAP_DEVICE_RESIDENT = (GOMP_MAP_FLAG_SPECIAL_1 | 1),
  70. /* OpenACC link. */
  71. GOMP_MAP_LINK = (GOMP_MAP_FLAG_SPECIAL_1 | 2),
  72. /* Use device data if present, fall back to host address otherwise. */
  73. GOMP_MAP_IF_PRESENT = (GOMP_MAP_FLAG_SPECIAL_1 | 3),
  74. /* Do not map, copy bits for firstprivate instead. */
  75. GOMP_MAP_FIRSTPRIVATE = (GOMP_MAP_FLAG_SPECIAL | 0),
  76. /* Similarly, but store the value in the pointer rather than
  77. pointed by the pointer. */
  78. GOMP_MAP_FIRSTPRIVATE_INT = (GOMP_MAP_FLAG_SPECIAL | 1),
  79. /* Pointer translate host address into device address and copy that
  80. back to host. */
  81. GOMP_MAP_USE_DEVICE_PTR = (GOMP_MAP_FLAG_SPECIAL | 2),
  82. /* Allocate a zero length array section. Prefer next non-zero length
  83. mapping over previous non-zero length mapping over zero length mapping
  84. at the address. If not already mapped, do nothing (and pointer translate
  85. to NULL). */
  86. GOMP_MAP_ZERO_LEN_ARRAY_SECTION = (GOMP_MAP_FLAG_SPECIAL | 3),
  87. /* Allocate. */
  88. GOMP_MAP_FORCE_ALLOC = (GOMP_MAP_FLAG_FORCE | GOMP_MAP_ALLOC),
  89. /* ..., and copy to device. */
  90. GOMP_MAP_FORCE_TO = (GOMP_MAP_FLAG_FORCE | GOMP_MAP_TO),
  91. /* ..., and copy from device. */
  92. GOMP_MAP_FORCE_FROM = (GOMP_MAP_FLAG_FORCE | GOMP_MAP_FROM),
  93. /* ..., and copy to and from device. */
  94. GOMP_MAP_FORCE_TOFROM = (GOMP_MAP_FLAG_FORCE | GOMP_MAP_TOFROM),
  95. /* Like GOMP_MAP_USE_DEVICE_PTR above, translate a host to a device
  96. address. If translation fails because the target is not mapped,
  97. continue using the host address. */
  98. GOMP_MAP_USE_DEVICE_PTR_IF_PRESENT = (GOMP_MAP_FLAG_SPECIAL_2 | 0),
  99. /* If not already present, allocate. And unconditionally copy to
  100. device. */
  101. GOMP_MAP_ALWAYS_TO = (GOMP_MAP_FLAG_SPECIAL_2 | GOMP_MAP_TO),
  102. /* If not already present, allocate. And unconditionally copy from
  103. device. */
  104. GOMP_MAP_ALWAYS_FROM = (GOMP_MAP_FLAG_SPECIAL_2
  105. | GOMP_MAP_FROM),
  106. /* If not already present, allocate. And unconditionally copy to and from
  107. device. */
  108. GOMP_MAP_ALWAYS_TOFROM = (GOMP_MAP_FLAG_SPECIAL_2
  109. | GOMP_MAP_TOFROM),
  110. /* Map a sparse struct; the address is the base of the structure, alignment
  111. it's required alignment, and size is the number of adjacent entries
  112. that belong to the struct. The adjacent entries should be sorted by
  113. increasing address, so it is easy to determine lowest needed address
  114. (address of the first adjacent entry) and highest needed address
  115. (address of the last adjacent entry plus its size). */
  116. GOMP_MAP_STRUCT = (GOMP_MAP_FLAG_SPECIAL_2
  117. | GOMP_MAP_FLAG_SPECIAL | 0),
  118. /* On a location of a pointer/reference that is assumed to be already mapped
  119. earlier, store the translated address of the preceeding mapping.
  120. No refcount is bumped by this, and the store is done unconditionally. */
  121. GOMP_MAP_ALWAYS_POINTER = (GOMP_MAP_FLAG_SPECIAL_2
  122. | GOMP_MAP_FLAG_SPECIAL | 1),
  123. /* Forced deallocation of zero length array section. */
  124. GOMP_MAP_DELETE_ZERO_LEN_ARRAY_SECTION
  125. = (GOMP_MAP_FLAG_SPECIAL_2
  126. | GOMP_MAP_FLAG_SPECIAL | 3),
  127. /* Decrement usage count and deallocate if zero. */
  128. GOMP_MAP_RELEASE = (GOMP_MAP_FLAG_SPECIAL_2
  129. | GOMP_MAP_DELETE),
  130. /* The attach/detach mappings below use the OMP_CLAUSE_SIZE field as a
  131. bias. This will typically be zero, except when mapping an array slice
  132. with a non-zero base. In that case the bias will indicate the
  133. (positive) difference between the start of the actual mapped data and
  134. the "virtual" origin of the array.
  135. In OpenACC, attach a pointer to a mapped struct field. */
  136. GOMP_MAP_ATTACH = (GOMP_MAP_DEEP_COPY | 0),
  137. /* In OpenACC, detach a pointer to a mapped struct field. */
  138. GOMP_MAP_DETACH = (GOMP_MAP_DEEP_COPY | 1),
  139. /* In OpenACC, detach a pointer to a mapped struct field. */
  140. GOMP_MAP_FORCE_DETACH = (GOMP_MAP_DEEP_COPY
  141. | GOMP_MAP_FLAG_FORCE | 1),
  142. /* Internal to GCC, not used in libgomp. */
  143. /* Do not map, but pointer assign a pointer instead. */
  144. GOMP_MAP_FIRSTPRIVATE_POINTER = (GOMP_MAP_LAST | 1),
  145. /* Do not map, but pointer assign a reference instead. */
  146. GOMP_MAP_FIRSTPRIVATE_REFERENCE = (GOMP_MAP_LAST | 2),
  147. /* An attach or detach operation. Rewritten to the appropriate type during
  148. gimplification, depending on directive (i.e. "enter data" or
  149. parallel/kernels region vs. "exit data"). */
  150. GOMP_MAP_ATTACH_DETACH = (GOMP_MAP_LAST | 3)
  151. };
  152. #define GOMP_MAP_COPY_TO_P(X) \
  153. (!((X) & GOMP_MAP_FLAG_SPECIAL) \
  154. && ((X) & GOMP_MAP_FLAG_TO))
  155. #define GOMP_MAP_COPY_FROM_P(X) \
  156. (!((X) & GOMP_MAP_FLAG_SPECIAL) \
  157. && ((X) & GOMP_MAP_FLAG_FROM))
  158. #define GOMP_MAP_POINTER_P(X) \
  159. ((X) == GOMP_MAP_POINTER)
  160. #define GOMP_MAP_ALWAYS_TO_P(X) \
  161. (((X) == GOMP_MAP_ALWAYS_TO) || ((X) == GOMP_MAP_ALWAYS_TOFROM))
  162. #define GOMP_MAP_ALWAYS_FROM_P(X) \
  163. (((X) == GOMP_MAP_ALWAYS_FROM) || ((X) == GOMP_MAP_ALWAYS_TOFROM))
  164. #define GOMP_MAP_ALWAYS_P(X) \
  165. (GOMP_MAP_ALWAYS_TO_P (X) || ((X) == GOMP_MAP_ALWAYS_FROM))
  166. /* Asynchronous behavior. Keep in sync with
  167. libgomp/{openacc.h,openacc.f90,openacc_lib.h}:acc_async_t. */
  168. #define GOMP_ASYNC_NOVAL -1
  169. #define GOMP_ASYNC_SYNC -2
  170. /* Device codes. Keep in sync with
  171. libgomp/{openacc.h,openacc.f90,openacc_lib.h}:acc_device_t as well as
  172. libgomp/libgomp-plugin.h. */
  173. #define GOMP_DEVICE_NONE 0
  174. #define GOMP_DEVICE_DEFAULT 1
  175. #define GOMP_DEVICE_HOST 2
  176. /* #define GOMP_DEVICE_HOST_NONSHM 3 removed. */
  177. #define GOMP_DEVICE_NOT_HOST 4
  178. #define GOMP_DEVICE_NVIDIA_PTX 5
  179. #define GOMP_DEVICE_INTEL_MIC 6
  180. #define GOMP_DEVICE_HSA 7
  181. #define GOMP_DEVICE_GCN 8
  182. #define GOMP_DEVICE_ICV -1
  183. #define GOMP_DEVICE_HOST_FALLBACK -2
  184. /* GOMP_task/GOMP_taskloop* flags argument. */
  185. #define GOMP_TASK_FLAG_UNTIED (1 << 0)
  186. #define GOMP_TASK_FLAG_FINAL (1 << 1)
  187. #define GOMP_TASK_FLAG_MERGEABLE (1 << 2)
  188. #define GOMP_TASK_FLAG_DEPEND (1 << 3)
  189. #define GOMP_TASK_FLAG_PRIORITY (1 << 4)
  190. #define GOMP_TASK_FLAG_UP (1 << 8)
  191. #define GOMP_TASK_FLAG_GRAINSIZE (1 << 9)
  192. #define GOMP_TASK_FLAG_IF (1 << 10)
  193. #define GOMP_TASK_FLAG_NOGROUP (1 << 11)
  194. #define GOMP_TASK_FLAG_REDUCTION (1 << 12)
  195. /* GOMP_target{_ext,update_ext,enter_exit_data} flags argument. */
  196. #define GOMP_TARGET_FLAG_NOWAIT (1 << 0)
  197. #define GOMP_TARGET_FLAG_EXIT_DATA (1 << 1)
  198. /* Internal to libgomp. */
  199. #define GOMP_TARGET_FLAG_UPDATE (1U << 31)
  200. /* OpenACC construct flags. */
  201. /* Force host fallback execution. */
  202. #define GOACC_FLAG_HOST_FALLBACK (1 << 0)
  203. /* For legacy reasons, in the ABI, the GOACC_FLAGs are encoded as an inverted
  204. bitmask. */
  205. #define GOACC_FLAGS_MARSHAL_OP BIT_NOT_EXPR
  206. #define GOACC_FLAGS_UNMARSHAL(X) (~(X))
  207. /* Versions of libgomp and device-specific plugins. GOMP_VERSION
  208. should be incremented whenever an ABI-incompatible change is introduced
  209. to the plugin interface defined in libgomp/libgomp.h. */
  210. #define GOMP_VERSION 1
  211. #define GOMP_VERSION_NVIDIA_PTX 1
  212. #define GOMP_VERSION_INTEL_MIC 0
  213. #define GOMP_VERSION_HSA 0
  214. #define GOMP_VERSION_GCN 1
  215. #define GOMP_VERSION_PACK(LIB, DEV) (((LIB) << 16) | (DEV))
  216. #define GOMP_VERSION_LIB(PACK) (((PACK) >> 16) & 0xffff)
  217. #define GOMP_VERSION_DEV(PACK) ((PACK) & 0xffff)
  218. #define GOMP_DIM_GANG 0
  219. #define GOMP_DIM_WORKER 1
  220. #define GOMP_DIM_VECTOR 2
  221. #define GOMP_DIM_MAX 3
  222. #define GOMP_DIM_MASK(X) (1u << (X))
  223. /* Varadic launch arguments. End of list is marked by a zero. */
  224. #define GOMP_LAUNCH_DIM 1 /* Launch dimensions, op = mask */
  225. #define GOMP_LAUNCH_ASYNC 2 /* Async, op = cst val if not MAX */
  226. #define GOMP_LAUNCH_WAIT 3 /* Waits, op = num waits. */
  227. #define GOMP_LAUNCH_CODE_SHIFT 28
  228. #define GOMP_LAUNCH_DEVICE_SHIFT 16
  229. #define GOMP_LAUNCH_OP_SHIFT 0
  230. #define GOMP_LAUNCH_PACK(CODE,DEVICE,OP) \
  231. (((CODE) << GOMP_LAUNCH_CODE_SHIFT) \
  232. | ((DEVICE) << GOMP_LAUNCH_DEVICE_SHIFT) \
  233. | ((OP) << GOMP_LAUNCH_OP_SHIFT))
  234. #define GOMP_LAUNCH_CODE(X) (((X) >> GOMP_LAUNCH_CODE_SHIFT) & 0xf)
  235. #define GOMP_LAUNCH_DEVICE(X) (((X) >> GOMP_LAUNCH_DEVICE_SHIFT) & 0xfff)
  236. #define GOMP_LAUNCH_OP(X) (((X) >> GOMP_LAUNCH_OP_SHIFT) & 0xffff)
  237. #define GOMP_LAUNCH_OP_MAX 0xffff
  238. /* Bitmask to apply in order to find out the intended device of a target
  239. argument. */
  240. #define GOMP_TARGET_ARG_DEVICE_MASK ((1 << 7) - 1)
  241. /* The target argument is significant for all devices. */
  242. #define GOMP_TARGET_ARG_DEVICE_ALL 0
  243. /* Flag set when the subsequent element in the device-specific argument
  244. values. */
  245. #define GOMP_TARGET_ARG_SUBSEQUENT_PARAM (1 << 7)
  246. /* Bitmask to apply to a target argument to find out the value identifier. */
  247. #define GOMP_TARGET_ARG_ID_MASK (((1 << 8) - 1) << 8)
  248. /* Target argument index of NUM_TEAMS. */
  249. #define GOMP_TARGET_ARG_NUM_TEAMS (1 << 8)
  250. /* Target argument index of THREAD_LIMIT. */
  251. #define GOMP_TARGET_ARG_THREAD_LIMIT (2 << 8)
  252. /* If the value is directly embeded in target argument, it should be a 16-bit
  253. at most and shifted by this many bits. */
  254. #define GOMP_TARGET_ARG_VALUE_SHIFT 16
  255. /* Dependence types in omp_depend_t objects. */
  256. #define GOMP_DEPEND_IN 1
  257. #define GOMP_DEPEND_OUT 2
  258. #define GOMP_DEPEND_INOUT 3
  259. #define GOMP_DEPEND_MUTEXINOUTSET 4
  260. /* HSA specific data structures. */
  261. /* Identifiers of device-specific target arguments. */
  262. #define GOMP_TARGET_ARG_HSA_KERNEL_ATTRIBUTES (1 << 8)
  263. #endif