1 /* workitems.h -- Types for context data passed as hidden parameters to special 2 built-ins. 3 4 Copyright (C) 2015-2020 Free Software Foundation, Inc. 5 Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com> 6 for General Processor Tech. 7 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: 15 16 The above copyright notice and this permission notice shall be included 17 in all copies or substantial portions of the Software. 18 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. 26 */ 27 28 #ifndef PHSA_RT_WORKITEMS_H 29 #define PHSA_RT_WORKITEMS_H 30 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 36 37 #ifdef HAVE_FIBERS 38 #include "fibers.h" 39 #endif 40 41 #include <stdint.h> 42 #include "phsa-rt.h" 43 44 /* Data identifying a single work-group instance. */ 45 46 typedef struct 47 { 48 /* This is 1 in case there are more work groups to execute. 49 If 0, the work-item threads should finish themselves. */ 50 int more_wgs; 51 52 /* If the local size does not evenly divide the grid size, will have 53 leftover WIs in the last execution. */ 54 int leftover_wg; 55 int last_wg; 56 57 /* (Flat) pointer to the beginning of the group segment allocated 58 to the work-group. */ 59 void *group_base_ptr; 60 61 /* The offset in the group memory for the kernel local group variables. 62 To support module scope group variables, there might be need to preseve 63 room for them in the beginning of the group segment. */ 64 uint32_t initial_group_offset; 65 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; 70 71 /* The first flat address of the group segment allocated for 72 the given work group. */ 73 uint64_t group_segment_base_addr; 74 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. 78 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; 86 87 /* The group id of the currently executed WG. This is for fiber based 88 execution. The group ids are duplicated also to the per WI context 89 struct for simplified single pointer access in the GCCBRIG produced 90 code. 91 */ 92 93 uint32_t x; 94 uint32_t y; 95 uint32_t z; 96 97 } PHSAWorkGroup; 98 99 /* Data identifying a single work-item, passed to the work-item thread in case 100 of a fiber based work-group execution. */ 101 102 typedef struct 103 { 104 /* NOTE: These members STARTing here should not be moved as they are 105 accessed directly by code emitted by BRIG FE. */ 106 107 /* The local id of the current WI. */ 108 109 uint32_t x; 110 uint32_t y; 111 uint32_t z; 112 113 /* The group id of the currently executed WG. */ 114 115 uint32_t group_x; 116 uint32_t group_y; 117 uint32_t group_z; 118 119 /* The local size of a complete WG. */ 120 121 uint32_t wg_size_x; 122 uint32_t wg_size_y; 123 uint32_t wg_size_z; 124 125 /* The local size of the current WG. */ 126 127 uint32_t cur_wg_size_x; 128 uint32_t cur_wg_size_y; 129 uint32_t cur_wg_size_z; 130 131 /* NOTE: Fixed members END here. */ 132 133 PHSAKernelLaunchData *launch_data; 134 /* Identifies and keeps book of the currently executed WG of the WI swarm. */ 135 volatile PHSAWorkGroup *wg; 136 #ifdef HAVE_FIBERS 137 fiber_t fiber; 138 #endif 139 } __attribute__((packed)) PHSAWorkItem; 140 141 142 #endif 143