(root)/
gcc-13.2.0/
include/
gomp-constants.h
       1  /* Communication between GCC and libgomp.
       2  
       3     Copyright (C) 2014-2023 Free Software Foundation, Inc.
       4  
       5     Contributed by Mentor Embedded.
       6  
       7     This file is part of the GNU Offloading and Multi Processing Library
       8     (libgomp).
       9  
      10     Libgomp is free software; you can redistribute it and/or modify it
      11     under the terms of the GNU General Public License as published by
      12     the Free Software Foundation; either version 3, or (at your option)
      13     any later version.
      14  
      15     Libgomp is distributed in the hope that it will be useful, but WITHOUT ANY
      16     WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      17     FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
      18     more details.
      19  
      20     Under Section 7 of GPL version 3, you are granted additional
      21     permissions described in the GCC Runtime Library Exception, version
      22     3.1, as published by the Free Software Foundation.
      23  
      24     You should have received a copy of the GNU General Public License and
      25     a copy of the GCC Runtime Library Exception along with this program;
      26     see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
      27     <http://www.gnu.org/licenses/>.  */
      28  
      29  #ifndef GOMP_CONSTANTS_H
      30  #define GOMP_CONSTANTS_H 1
      31  
      32  /* Memory mapping types.  */
      33  
      34  /* One byte.  */
      35  #define GOMP_MAP_LAST			(1 << 8)
      36  
      37  #define GOMP_MAP_FLAG_TO		(1 << 0)
      38  #define GOMP_MAP_FLAG_FROM		(1 << 1)
      39  /* Special map kinds, enumerated starting here.  */
      40  #define GOMP_MAP_FLAG_SPECIAL_0		(1 << 2)
      41  #define GOMP_MAP_FLAG_SPECIAL_1		(1 << 3)
      42  #define GOMP_MAP_FLAG_SPECIAL_2		(1 << 4)
      43  #define GOMP_MAP_FLAG_SPECIAL_3		(1 << 5)
      44  #define GOMP_MAP_FLAG_SPECIAL_4		(1 << 6)
      45  #define GOMP_MAP_FLAG_SPECIAL		(GOMP_MAP_FLAG_SPECIAL_1 \
      46  					 | GOMP_MAP_FLAG_SPECIAL_0)
      47  #define GOMP_MAP_DEEP_COPY		(GOMP_MAP_FLAG_SPECIAL_4 \
      48  					 | GOMP_MAP_FLAG_SPECIAL_2)
      49  /* This value indicates the map was created implicitly according to
      50     OpenMP rules.  */
      51  #define GOMP_MAP_IMPLICIT		(GOMP_MAP_FLAG_SPECIAL_3 \
      52  					 | GOMP_MAP_FLAG_SPECIAL_4)
      53  /* Mask for entire set of special map kind bits.  */
      54  #define GOMP_MAP_FLAG_SPECIAL_BITS	(GOMP_MAP_FLAG_SPECIAL_0 \
      55  					 | GOMP_MAP_FLAG_SPECIAL_1 \
      56  					 | GOMP_MAP_FLAG_SPECIAL_2 \
      57  					 | GOMP_MAP_FLAG_SPECIAL_3 \
      58  					 | GOMP_MAP_FLAG_SPECIAL_4)
      59  /* Flag to force a specific behavior (or else, trigger a run-time error).  */
      60  #define GOMP_MAP_FLAG_FORCE		(1 << 7)
      61  
      62  enum gomp_map_kind
      63    {
      64      /* If not already present, allocate.  */
      65      GOMP_MAP_ALLOC =			0,
      66      /* ..., and copy to device.  */
      67      GOMP_MAP_TO =			(GOMP_MAP_ALLOC | GOMP_MAP_FLAG_TO),
      68      /* ..., and copy from device.  */
      69      GOMP_MAP_FROM =			(GOMP_MAP_ALLOC | GOMP_MAP_FLAG_FROM),
      70      /* ..., and copy to and from device.  */
      71      GOMP_MAP_TOFROM =			(GOMP_MAP_TO | GOMP_MAP_FROM),
      72      /* The following kind is an internal only map kind, used for pointer based
      73         array sections.  OMP_CLAUSE_SIZE for these is not the pointer size,
      74         which is implicitly POINTER_SIZE_UNITS, but the bias.  */
      75      GOMP_MAP_POINTER =			(GOMP_MAP_FLAG_SPECIAL_0 | 0),
      76      /* Also internal, behaves like GOMP_MAP_TO, but additionally any
      77         GOMP_MAP_POINTER records consecutive after it which have addresses
      78         falling into that range will not be ignored if GOMP_MAP_TO_PSET wasn't
      79         mapped already.
      80         For OpenACC attach operations (e.g. copyin of struct members),
      81         GOMP_MAP_TO_PSET is followed by a single GOMP_MAP_ATTACH mapping
      82         instead.  */
      83      GOMP_MAP_TO_PSET =			(GOMP_MAP_FLAG_SPECIAL_0 | 1),
      84      /* Must already be present.  */
      85      GOMP_MAP_FORCE_PRESENT =		(GOMP_MAP_FLAG_SPECIAL_0 | 2),
      86      /* Deallocate a mapping, without copying from device.  */
      87      GOMP_MAP_DELETE =			(GOMP_MAP_FLAG_SPECIAL_0 | 3),
      88      /* Is a device pointer.  OMP_CLAUSE_SIZE for these is unused; is implicitly
      89         POINTER_SIZE_UNITS.  */
      90      GOMP_MAP_FORCE_DEVICEPTR =		(GOMP_MAP_FLAG_SPECIAL_1 | 0),
      91      /* OpenACC device_resident.  */
      92      GOMP_MAP_DEVICE_RESIDENT =		(GOMP_MAP_FLAG_SPECIAL_1 | 1),
      93      /* OpenACC link.  */
      94      GOMP_MAP_LINK =			(GOMP_MAP_FLAG_SPECIAL_1 | 2),
      95      /* Use device data if present, fall back to host address otherwise.  */
      96      GOMP_MAP_IF_PRESENT =		(GOMP_MAP_FLAG_SPECIAL_1 | 3),
      97      /* Do not map, copy bits for firstprivate instead.  */
      98      GOMP_MAP_FIRSTPRIVATE =		(GOMP_MAP_FLAG_SPECIAL | 0),
      99      /* Similarly, but store the value in the pointer rather than
     100         pointed by the pointer.  */
     101      GOMP_MAP_FIRSTPRIVATE_INT =		(GOMP_MAP_FLAG_SPECIAL | 1),
     102      /* Pointer translate host address into device address and copy that
     103         back to host.  */
     104      GOMP_MAP_USE_DEVICE_PTR =		(GOMP_MAP_FLAG_SPECIAL | 2),
     105      /* Allocate a zero length array section.  Prefer next non-zero length
     106         mapping over previous non-zero length mapping over zero length mapping
     107         at the address.  If not already mapped, do nothing (and pointer translate
     108         to NULL).  */
     109      GOMP_MAP_ZERO_LEN_ARRAY_SECTION = 	(GOMP_MAP_FLAG_SPECIAL | 3),
     110      /* Allocate.  */
     111      GOMP_MAP_FORCE_ALLOC =		(GOMP_MAP_FLAG_FORCE | GOMP_MAP_ALLOC),
     112      /* ..., and copy to device.  */
     113      GOMP_MAP_FORCE_TO =			(GOMP_MAP_FLAG_FORCE | GOMP_MAP_TO),
     114      /* ..., and copy from device.  */
     115      GOMP_MAP_FORCE_FROM =		(GOMP_MAP_FLAG_FORCE | GOMP_MAP_FROM),
     116      /* ..., and copy to and from device.  */
     117      GOMP_MAP_FORCE_TOFROM =		(GOMP_MAP_FLAG_FORCE | GOMP_MAP_TOFROM),
     118      /* Like GOMP_MAP_USE_DEVICE_PTR above, translate a host to a device
     119         address.  If translation fails because the target is not mapped,
     120         continue using the host address. */
     121      GOMP_MAP_USE_DEVICE_PTR_IF_PRESENT = (GOMP_MAP_FLAG_SPECIAL_2 | 0),
     122      /* If not already present, allocate.  And unconditionally copy to
     123         device.  */
     124      GOMP_MAP_ALWAYS_TO =		(GOMP_MAP_FLAG_SPECIAL_2 | GOMP_MAP_TO),
     125      /* If not already present, allocate.  And unconditionally copy from
     126         device.  */
     127      GOMP_MAP_ALWAYS_FROM =		(GOMP_MAP_FLAG_SPECIAL_2
     128  					 | GOMP_MAP_FROM),
     129      /* If not already present, allocate.  And unconditionally copy to and from
     130         device.  */
     131      GOMP_MAP_ALWAYS_TOFROM =		(GOMP_MAP_FLAG_SPECIAL_2
     132  					 | GOMP_MAP_TOFROM),
     133      /* Map a sparse struct; the address is the base of the structure, alignment
     134         it's required alignment, and size is the number of adjacent entries
     135         that belong to the struct.  The adjacent entries should be sorted by
     136         increasing address, so it is easy to determine lowest needed address
     137         (address of the first adjacent entry) and highest needed address
     138         (address of the last adjacent entry plus its size).  */
     139      GOMP_MAP_STRUCT =			(GOMP_MAP_FLAG_SPECIAL_2
     140  					 | GOMP_MAP_FLAG_SPECIAL | 0),
     141      /* On a location of a pointer/reference that is assumed to be already mapped
     142         earlier, store the translated address of the preceeding mapping.
     143         No refcount is bumped by this, and the store is done unconditionally.  */
     144      GOMP_MAP_ALWAYS_POINTER =		(GOMP_MAP_FLAG_SPECIAL_2
     145  					 | GOMP_MAP_FLAG_SPECIAL | 1),
     146      /* Like GOMP_MAP_POINTER, but allow zero-length array section, i.e. set to
     147         NULL if target is not mapped.  */
     148      GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION
     149        =					(GOMP_MAP_FLAG_SPECIAL_2
     150  					 | GOMP_MAP_FLAG_SPECIAL | 2),
     151      /* Forced deallocation of zero length array section.  */
     152      GOMP_MAP_DELETE_ZERO_LEN_ARRAY_SECTION
     153        =					(GOMP_MAP_FLAG_SPECIAL_2
     154  					 | GOMP_MAP_FLAG_SPECIAL | 3),
     155      /* Decrement usage count and deallocate if zero.  */
     156      GOMP_MAP_RELEASE =			(GOMP_MAP_FLAG_SPECIAL_2
     157  					 | GOMP_MAP_DELETE),
     158      /* The attach/detach mappings below use the OMP_CLAUSE_SIZE field as a
     159         bias.  This will typically be zero, except when mapping an array slice
     160         with a non-zero base.  In that case the bias will indicate the
     161         (positive) difference between the start of the actual mapped data and
     162         the "virtual" origin of the array.
     163         In OpenACC, attach a pointer to a mapped struct field.  */
     164      GOMP_MAP_ATTACH =			(GOMP_MAP_DEEP_COPY | 0),
     165      /* In OpenACC, detach a pointer to a mapped struct field.  */
     166      GOMP_MAP_DETACH =			(GOMP_MAP_DEEP_COPY | 1),
     167      /* In OpenACC, detach a pointer to a mapped struct field.  */
     168      GOMP_MAP_FORCE_DETACH =		(GOMP_MAP_DEEP_COPY
     169  					 | GOMP_MAP_FLAG_FORCE | 1),
     170  
     171      /* Like GOMP_MAP_ATTACH, but allow attaching to zero-length array sections
     172         (i.e. set to NULL when array section is not mapped) Currently only used
     173         by OpenMP.  */
     174      GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION
     175        =					(GOMP_MAP_DEEP_COPY | 2),
     176  
     177      /* Internal to GCC, not used in libgomp.  */
     178      /* Do not map, but pointer assign a pointer instead.  */
     179      GOMP_MAP_FIRSTPRIVATE_POINTER =	(GOMP_MAP_LAST | 1),
     180      /* Do not map, but pointer assign a reference instead.  */
     181      GOMP_MAP_FIRSTPRIVATE_REFERENCE =	(GOMP_MAP_LAST | 2),
     182      /* An attach or detach operation.  Rewritten to the appropriate type during
     183         gimplification, depending on directive (i.e. "enter data" or
     184         parallel/kernels region vs. "exit data").  */
     185      GOMP_MAP_ATTACH_DETACH =		(GOMP_MAP_LAST | 3)
     186    };
     187  
     188  #define GOMP_MAP_COPY_TO_P(X) \
     189    (!((X) & GOMP_MAP_FLAG_SPECIAL) \
     190     && ((X) & GOMP_MAP_FLAG_TO))
     191  
     192  #define GOMP_MAP_COPY_FROM_P(X) \
     193    (!((X) & GOMP_MAP_FLAG_SPECIAL) \
     194     && ((X) & GOMP_MAP_FLAG_FROM))
     195  
     196  #define GOMP_MAP_ALWAYS_POINTER_P(X) \
     197    ((X) == GOMP_MAP_ALWAYS_POINTER)
     198  
     199  #define GOMP_MAP_POINTER_P(X) \
     200    ((X) == GOMP_MAP_POINTER \
     201     || (X) == GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION)
     202  
     203  #define GOMP_MAP_ALWAYS_TO_P(X) \
     204    (((X) == GOMP_MAP_ALWAYS_TO) || ((X) == GOMP_MAP_ALWAYS_TOFROM))
     205  
     206  #define GOMP_MAP_ALWAYS_FROM_P(X) \
     207    (((X) == GOMP_MAP_ALWAYS_FROM) || ((X) == GOMP_MAP_ALWAYS_TOFROM))
     208  
     209  #define GOMP_MAP_ALWAYS_P(X) \
     210    (GOMP_MAP_ALWAYS_TO_P (X) || ((X) == GOMP_MAP_ALWAYS_FROM))
     211  
     212  #define GOMP_MAP_IMPLICIT_P(X) \
     213    (((X) & GOMP_MAP_FLAG_SPECIAL_BITS) == GOMP_MAP_IMPLICIT)
     214  
     215  
     216  /* Asynchronous behavior.  Keep in sync with
     217     libgomp/{openacc.h,openacc.f90,openacc_lib.h}:acc_async_t.  */
     218  
     219  #define GOMP_ASYNC_NOVAL		-1
     220  #define GOMP_ASYNC_SYNC			-2
     221  
     222  
     223  /* Device codes.  Keep in sync with
     224     libgomp/{openacc.h,openacc.f90,openacc_lib.h}:acc_device_t as well as
     225     libgomp/libgomp-plugin.h.  */
     226  #define GOMP_DEVICE_NONE		0
     227  #define GOMP_DEVICE_DEFAULT		1
     228  #define GOMP_DEVICE_HOST		2
     229  /* #define GOMP_DEVICE_HOST_NONSHM	3 removed.  */
     230  #define GOMP_DEVICE_NOT_HOST		4
     231  #define GOMP_DEVICE_NVIDIA_PTX		5
     232  /* #define GOMP_DEVICE_INTEL_MIC	6 removed.  */
     233  /* #define GOMP_DEVICE_HSA		7 removed.  */
     234  #define GOMP_DEVICE_GCN			8
     235  
     236  /* We have a compatibility issue.  OpenMP 5.2 introduced
     237     omp_initial_device with value of -1 which clashes with our
     238     GOMP_DEVICE_ICV, so we need to remap user supplied device
     239     ids, -1 (aka omp_initial_device) to GOMP_DEVICE_HOST_FALLBACK,
     240     and -2 (one of many non-conforming device numbers, but with
     241     OMP_TARGET_OFFLOAD=mandatory needs to be treated a
     242     omp_invalid_device) to -3 (so that for dev_num >= -2U we can
     243     subtract 1).  -4 is then what we use for omp_invalid_device,
     244     which unlike the other non-conforming device numbers results
     245     in fatal error regardless of OMP_TARGET_OFFLOAD.  */
     246  #define GOMP_DEVICE_ICV			-1
     247  #define GOMP_DEVICE_HOST_FALLBACK	-2
     248  #define GOMP_DEVICE_INVALID		-4
     249  
     250  /* GOMP_task/GOMP_taskloop* flags argument.  */
     251  #define GOMP_TASK_FLAG_UNTIED		(1 << 0)
     252  #define GOMP_TASK_FLAG_FINAL		(1 << 1)
     253  #define GOMP_TASK_FLAG_MERGEABLE	(1 << 2)
     254  #define GOMP_TASK_FLAG_DEPEND		(1 << 3)
     255  #define GOMP_TASK_FLAG_PRIORITY		(1 << 4)
     256  #define GOMP_TASK_FLAG_UP		(1 << 8)
     257  #define GOMP_TASK_FLAG_GRAINSIZE	(1 << 9)
     258  #define GOMP_TASK_FLAG_IF		(1 << 10)
     259  #define GOMP_TASK_FLAG_NOGROUP		(1 << 11)
     260  #define GOMP_TASK_FLAG_REDUCTION	(1 << 12)
     261  #define GOMP_TASK_FLAG_DETACH		(1 << 13)
     262  #define GOMP_TASK_FLAG_STRICT		(1 << 14)
     263  
     264  /* GOMP_target{_ext,update_ext,enter_exit_data} flags argument.  */
     265  #define GOMP_TARGET_FLAG_NOWAIT		(1 << 0)
     266  #define GOMP_TARGET_FLAG_EXIT_DATA	(1 << 1)
     267  /* Internal to libgomp.  */
     268  #define GOMP_TARGET_FLAG_UPDATE		(1U << 31)
     269  
     270  
     271  /* OpenACC construct flags.  */
     272  
     273  /* Force host fallback execution.  */
     274  #define GOACC_FLAG_HOST_FALLBACK	(1 << 0)
     275  
     276  /* For legacy reasons, in the ABI, the GOACC_FLAGs are encoded as an inverted
     277     bitmask.  */
     278  #define GOACC_FLAGS_MARSHAL_OP		BIT_NOT_EXPR
     279  #define GOACC_FLAGS_UNMARSHAL(X)	(~(X))
     280  
     281  
     282  /* Versions of libgomp and device-specific plugins.  GOMP_VERSION
     283     should be incremented whenever an ABI-incompatible change is introduced
     284     to the plugin interface defined in libgomp/libgomp.h.  */
     285  #define GOMP_VERSION	2
     286  #define GOMP_VERSION_NVIDIA_PTX 1
     287  #define GOMP_VERSION_GCN 3
     288  
     289  #define GOMP_VERSION_PACK(LIB, DEV) (((LIB) << 16) | (DEV))
     290  #define GOMP_VERSION_LIB(PACK) (((PACK) >> 16) & 0xffff)
     291  #define GOMP_VERSION_DEV(PACK) ((PACK) & 0xffff)
     292  
     293  #define GOMP_DIM_GANG	0
     294  #define GOMP_DIM_WORKER	1
     295  #define GOMP_DIM_VECTOR	2
     296  #define GOMP_DIM_MAX	3
     297  #define GOMP_DIM_MASK(X) (1u << (X))
     298  
     299  /* Varadic launch arguments.  End of list is marked by a zero.  */
     300  #define GOMP_LAUNCH_DIM		1  /* Launch dimensions, op = mask */
     301  #define GOMP_LAUNCH_ASYNC	2  /* Async, op = cst val if not MAX  */
     302  #define GOMP_LAUNCH_WAIT	3  /* Waits, op = num waits.  */
     303  #define GOMP_LAUNCH_CODE_SHIFT	28
     304  #define GOMP_LAUNCH_DEVICE_SHIFT 16
     305  #define GOMP_LAUNCH_OP_SHIFT 0
     306  #define GOMP_LAUNCH_PACK(CODE,DEVICE,OP)	\
     307    (((CODE) << GOMP_LAUNCH_CODE_SHIFT)		\
     308     | ((DEVICE) << GOMP_LAUNCH_DEVICE_SHIFT)	\
     309     | ((OP) << GOMP_LAUNCH_OP_SHIFT))
     310  #define GOMP_LAUNCH_CODE(X) (((X) >> GOMP_LAUNCH_CODE_SHIFT) & 0xf)
     311  #define GOMP_LAUNCH_DEVICE(X) (((X) >> GOMP_LAUNCH_DEVICE_SHIFT) & 0xfff)
     312  #define GOMP_LAUNCH_OP(X) (((X) >> GOMP_LAUNCH_OP_SHIFT) & 0xffff)
     313  #define GOMP_LAUNCH_OP_MAX 0xffff
     314  
     315  /* Bitmask to apply in order to find out the intended device of a target
     316     argument.  */
     317  #define GOMP_TARGET_ARG_DEVICE_MASK		((1 << 7) - 1)
     318  /* The target argument is significant for all devices.  */
     319  #define GOMP_TARGET_ARG_DEVICE_ALL		0
     320  
     321  /* Flag set when the subsequent element in the device-specific argument
     322     values.  */
     323  #define GOMP_TARGET_ARG_SUBSEQUENT_PARAM	(1 << 7)
     324  
     325  /* Bitmask to apply to a target argument to find out the value identifier.  */
     326  #define GOMP_TARGET_ARG_ID_MASK			(((1 << 8) - 1) << 8)
     327  /* Target argument index of NUM_TEAMS.  */
     328  #define GOMP_TARGET_ARG_NUM_TEAMS		(1 << 8)
     329  /* Target argument index of THREAD_LIMIT.  */
     330  #define GOMP_TARGET_ARG_THREAD_LIMIT		(2 << 8)
     331  
     332  /* If the value is directly embeded in target argument, it should be a 16-bit
     333     at most and shifted by this many bits.  */
     334  #define GOMP_TARGET_ARG_VALUE_SHIFT		16
     335  
     336  /* Dependence types in omp_depend_t objects.  */
     337  #define GOMP_DEPEND_IN			1
     338  #define GOMP_DEPEND_OUT			2
     339  #define GOMP_DEPEND_INOUT		3
     340  #define GOMP_DEPEND_MUTEXINOUTSET	4
     341  #define GOMP_DEPEND_INOUTSET		5
     342  
     343  /* Flag values for OpenMP 'requires' directive features.  */
     344  #define GOMP_REQUIRES_UNIFIED_ADDRESS       0x10
     345  #define GOMP_REQUIRES_UNIFIED_SHARED_MEMORY 0x20
     346  #define GOMP_REQUIRES_REVERSE_OFFLOAD       0x80
     347  #define GOMP_REQUIRES_TARGET_USED           0x200
     348  
     349  /* HSA specific data structures.  */
     350  
     351  /* Identifiers of device-specific target arguments.  */
     352  #define GOMP_TARGET_ARG_HSA_KERNEL_ATTRIBUTES	(1 << 8)
     353  
     354  #endif