[gcc/testsuite]
[official-gcc.git] / libhsail-rt / include / internal / workitems.h
blobe7d386d32ec337b5e4add3a6ce0fad8846d95e98
1 /* workitems.h -- Types for context data passed as hidden parameters to special
2 built-ins.
4 Copyright (C) 2015-2017 Free Software Foundation, Inc.
5 Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com>
6 for General Processor Tech.
8 Permission is hereby granted, free of charge, to any person obtaining a
9 copy of this software and associated documentation files
10 (the "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
16 The above copyright notice and this permission notice shall be included
17 in all copies or substantial portions of the Software.
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
23 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
25 USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #ifndef PHSA_RT_WORKITEMS_H
29 #define PHSA_RT_WORKITEMS_H
31 /* As the simple fibers implementation relies only on ucontext, we can
32 assume is found by default as it is part of glibc. However, for partial
33 HSAIL support on platforms without having it available, the following define
34 can be undefined. */
35 #define HAVE_FIBERS
37 #ifdef HAVE_FIBERS
38 #include "fibers.h"
39 #endif
41 #include <stdint.h>
42 #include "phsa-rt.h"
44 /* Data identifying a single work-group instance. */
46 typedef struct
48 /* The group id of the currently executed WG. */
49 size_t x;
50 size_t y;
51 size_t z;
53 /* This is 1 in case there are more work groups to execute.
54 If 0, the work-item threads should finish themselves. */
55 int more_wgs;
57 /* If the local size does not evenly divide the grid size, will have
58 leftover WIs in the last execution. */
59 int leftover_wg;
60 int last_wg;
62 /* (Flat) pointer to the beginning of the group segment allocated
63 to the work-group. */
64 void *group_base_ptr;
66 /* Similarly to the private segment that gets space allocated for all
67 WIs in the work-group. */
68 void *private_base_ptr;
69 uint32_t private_segment_total_size;
71 /* The first flat address of the group segment allocated for
72 the given work group. */
73 uint64_t group_segment_base_addr;
75 /* Offset from the beginning of the private segment to the start of
76 the previously allocated chunk of dynamic work-item memory (alloca)
77 by any WI in the WG.
79 Initially set to private_segment_total_size to denote no dynamic
80 allocations have been made. The dynamic allocations are done downwards
81 from the private segment end. */
82 uint32_t alloca_stack_p;
83 /* The position of the first word in the current function's alloca
84 stack frame. Initialized to point outside the private segment. */
85 uint32_t alloca_frame_p;
87 } PHSAWorkGroup;
89 /* Data identifying a single work-item, passed to the work-item thread in case
90 of a fiber based work-group execution. */
92 typedef struct
94 PHSAKernelLaunchData *launch_data;
95 /* Identifies and keeps book of the currently executed WG of the WI swarm. */
96 volatile PHSAWorkGroup *wg;
97 /* The local id of the current WI. */
98 size_t x;
99 size_t y;
100 size_t z;
101 #ifdef HAVE_FIBERS
102 fiber_t fiber;
103 #endif
104 } PHSAWorkItem;
107 #endif