13ad841b2Smrg /* workitems.h -- Types for context data passed as hidden parameters to special 23ad841b2Smrg built-ins. 33ad841b2Smrg 4*4c3eb207Smrg Copyright (C) 2015-2020 Free Software Foundation, Inc. 53ad841b2Smrg Contributed by Pekka Jaaskelainen <pekka.jaaskelainen@parmance.com> 63ad841b2Smrg for General Processor Tech. 73ad841b2Smrg 83ad841b2Smrg Permission is hereby granted, free of charge, to any person obtaining a 93ad841b2Smrg copy of this software and associated documentation files 103ad841b2Smrg (the "Software"), to deal in the Software without restriction, including 113ad841b2Smrg without limitation the rights to use, copy, modify, merge, publish, 123ad841b2Smrg distribute, sublicense, and/or sell copies of the Software, and to 133ad841b2Smrg permit persons to whom the Software is furnished to do so, subject to 143ad841b2Smrg the following conditions: 153ad841b2Smrg 163ad841b2Smrg The above copyright notice and this permission notice shall be included 173ad841b2Smrg in all copies or substantial portions of the Software. 183ad841b2Smrg 193ad841b2Smrg THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 203ad841b2Smrg OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 213ad841b2Smrg MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 223ad841b2Smrg IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 233ad841b2Smrg DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 243ad841b2Smrg OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 253ad841b2Smrg USE OR OTHER DEALINGS IN THE SOFTWARE. 263ad841b2Smrg */ 273ad841b2Smrg 283ad841b2Smrg #ifndef PHSA_RT_WORKITEMS_H 293ad841b2Smrg #define PHSA_RT_WORKITEMS_H 303ad841b2Smrg 313ad841b2Smrg /* As the simple fibers implementation relies only on ucontext, we can 323ad841b2Smrg assume is found by default as it is part of glibc. However, for partial 333ad841b2Smrg HSAIL support on platforms without having it available, the following define 343ad841b2Smrg can be undefined. */ 353ad841b2Smrg #define HAVE_FIBERS 363ad841b2Smrg 373ad841b2Smrg #ifdef HAVE_FIBERS 383ad841b2Smrg #include "fibers.h" 393ad841b2Smrg #endif 403ad841b2Smrg 413ad841b2Smrg #include <stdint.h> 423ad841b2Smrg #include "phsa-rt.h" 433ad841b2Smrg 443ad841b2Smrg /* Data identifying a single work-group instance. */ 453ad841b2Smrg 463ad841b2Smrg typedef struct 473ad841b2Smrg { 483ad841b2Smrg /* This is 1 in case there are more work groups to execute. 493ad841b2Smrg If 0, the work-item threads should finish themselves. */ 503ad841b2Smrg int more_wgs; 513ad841b2Smrg 523ad841b2Smrg /* If the local size does not evenly divide the grid size, will have 533ad841b2Smrg leftover WIs in the last execution. */ 543ad841b2Smrg int leftover_wg; 553ad841b2Smrg int last_wg; 563ad841b2Smrg 573ad841b2Smrg /* (Flat) pointer to the beginning of the group segment allocated 583ad841b2Smrg to the work-group. */ 593ad841b2Smrg void *group_base_ptr; 603ad841b2Smrg 61cef8759bSmrg /* The offset in the group memory for the kernel local group variables. 62cef8759bSmrg To support module scope group variables, there might be need to preseve 63cef8759bSmrg room for them in the beginning of the group segment. */ 64cef8759bSmrg uint32_t initial_group_offset; 65cef8759bSmrg 663ad841b2Smrg /* Similarly to the private segment that gets space allocated for all 673ad841b2Smrg WIs in the work-group. */ 683ad841b2Smrg void *private_base_ptr; 693ad841b2Smrg uint32_t private_segment_total_size; 703ad841b2Smrg 713ad841b2Smrg /* The first flat address of the group segment allocated for 723ad841b2Smrg the given work group. */ 733ad841b2Smrg uint64_t group_segment_base_addr; 743ad841b2Smrg 753ad841b2Smrg /* Offset from the beginning of the private segment to the start of 763ad841b2Smrg the previously allocated chunk of dynamic work-item memory (alloca) 773ad841b2Smrg by any WI in the WG. 783ad841b2Smrg 793ad841b2Smrg Initially set to private_segment_total_size to denote no dynamic 803ad841b2Smrg allocations have been made. The dynamic allocations are done downwards 813ad841b2Smrg from the private segment end. */ 823ad841b2Smrg uint32_t alloca_stack_p; 833ad841b2Smrg /* The position of the first word in the current function's alloca 843ad841b2Smrg stack frame. Initialized to point outside the private segment. */ 853ad841b2Smrg uint32_t alloca_frame_p; 863ad841b2Smrg 87627f7eb2Smrg /* The group id of the currently executed WG. This is for fiber based 88627f7eb2Smrg execution. The group ids are duplicated also to the per WI context 89627f7eb2Smrg struct for simplified single pointer access in the GCCBRIG produced 90627f7eb2Smrg code. 91627f7eb2Smrg */ 92627f7eb2Smrg 93627f7eb2Smrg uint32_t x; 94627f7eb2Smrg uint32_t y; 95627f7eb2Smrg uint32_t z; 96627f7eb2Smrg 973ad841b2Smrg } PHSAWorkGroup; 983ad841b2Smrg 993ad841b2Smrg /* Data identifying a single work-item, passed to the work-item thread in case 1003ad841b2Smrg of a fiber based work-group execution. */ 1013ad841b2Smrg 1023ad841b2Smrg typedef struct 1033ad841b2Smrg { 104627f7eb2Smrg /* NOTE: These members STARTing here should not be moved as they are 105627f7eb2Smrg accessed directly by code emitted by BRIG FE. */ 106627f7eb2Smrg 107627f7eb2Smrg /* The local id of the current WI. */ 108627f7eb2Smrg 109627f7eb2Smrg uint32_t x; 110627f7eb2Smrg uint32_t y; 111627f7eb2Smrg uint32_t z; 112627f7eb2Smrg 113627f7eb2Smrg /* The group id of the currently executed WG. */ 114627f7eb2Smrg 115627f7eb2Smrg uint32_t group_x; 116627f7eb2Smrg uint32_t group_y; 117627f7eb2Smrg uint32_t group_z; 118627f7eb2Smrg 119627f7eb2Smrg /* The local size of a complete WG. */ 120627f7eb2Smrg 121627f7eb2Smrg uint32_t wg_size_x; 122627f7eb2Smrg uint32_t wg_size_y; 123627f7eb2Smrg uint32_t wg_size_z; 124627f7eb2Smrg 125627f7eb2Smrg /* The local size of the current WG. */ 126627f7eb2Smrg 127627f7eb2Smrg uint32_t cur_wg_size_x; 128627f7eb2Smrg uint32_t cur_wg_size_y; 129627f7eb2Smrg uint32_t cur_wg_size_z; 130627f7eb2Smrg 131627f7eb2Smrg /* NOTE: Fixed members END here. */ 132627f7eb2Smrg 1333ad841b2Smrg PHSAKernelLaunchData *launch_data; 1343ad841b2Smrg /* Identifies and keeps book of the currently executed WG of the WI swarm. */ 1353ad841b2Smrg volatile PHSAWorkGroup *wg; 1363ad841b2Smrg #ifdef HAVE_FIBERS 1373ad841b2Smrg fiber_t fiber; 1383ad841b2Smrg #endif 139627f7eb2Smrg } __attribute__((packed)) PHSAWorkItem; 1403ad841b2Smrg 1413ad841b2Smrg 1423ad841b2Smrg #endif 143