2017-10-08 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / libhsail-rt / include / internal / workitems.h
blob2abfc61d8678df4d03726f9419706a78458577cd
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 /* The offset in the group memory for the kernel local group variables.
67 To support module scope group variables, there might be need to preseve
68 room for them in the beginning of the group segment. */
69 uint32_t initial_group_offset;
71 /* Similarly to the private segment that gets space allocated for all
72 WIs in the work-group. */
73 void *private_base_ptr;
74 uint32_t private_segment_total_size;
76 /* The first flat address of the group segment allocated for
77 the given work group. */
78 uint64_t group_segment_base_addr;
80 /* Offset from the beginning of the private segment to the start of
81 the previously allocated chunk of dynamic work-item memory (alloca)
82 by any WI in the WG.
84 Initially set to private_segment_total_size to denote no dynamic
85 allocations have been made. The dynamic allocations are done downwards
86 from the private segment end. */
87 uint32_t alloca_stack_p;
88 /* The position of the first word in the current function's alloca
89 stack frame. Initialized to point outside the private segment. */
90 uint32_t alloca_frame_p;
92 } PHSAWorkGroup;
94 /* Data identifying a single work-item, passed to the work-item thread in case
95 of a fiber based work-group execution. */
97 typedef struct
99 PHSAKernelLaunchData *launch_data;
100 /* Identifies and keeps book of the currently executed WG of the WI swarm. */
101 volatile PHSAWorkGroup *wg;
102 /* The local id of the current WI. */
103 size_t x;
104 size_t y;
105 size_t z;
106 #ifdef HAVE_FIBERS
107 fiber_t fiber;
108 #endif
109 } PHSAWorkItem;
112 #endif