xref: /netbsd-src/external/gpl3/gcc.old/dist/libhsail-rt/include/internal/phsa-rt.h (revision 4c3eb207d36f67d31994830c0a694161fc1ca39b)
1 /* phsa-rt.h -- Data structures and functions of the PHSA device side runtime
2    scheduler, and HSAIL 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_H
29 #define PHSA_RT_H
30 
31 #include <stdbool.h>
32 #include <stdint.h>
33 #include "hsa.h"
34 
35 #define PHSA_MAX_WG_SIZE 1024 * 10
36 
37 /* Pointer type for the public facing kernel launcher function generated
38    by gccbrig.  This launches the actual kernel for all work groups and
39    work items in the grid.  */
40 typedef void (*gccbrigKernelLauncherFunc) (void *context, void *);
41 
42 /* Pointer type for kernel functions produced by gccbrig from the HSAIL.
43    This is private from outside the device binary and only called by
44    the launcher.  */
45 typedef void (*gccbrigKernelFunc) (unsigned char *, void *, void *, uint32_t,
46 				   void *);
47 
48 /* Context data that is passed to the kernel function, initialized
49    by the runtime to the current launch information.  The data is
50    used by different id functions etc.
51 
52    The struct is used by both the launcher and the targeted device,
53    thus the fields must have the same alignment/padding in both sides.
54 */
55 typedef struct
56 {
57   /* Data set by the HSA Runtime's kernel launcher.  */
58   hsa_kernel_dispatch_packet_t *dp;
59 
60   size_t packet_id;
61 
62   /* Data set by the device-side launcher.  */
63   gccbrigKernelFunc kernel;
64 
65   /* The range of a work groups this dispatch should execute.  */
66   size_t wg_min_x;
67   size_t wg_min_y;
68   size_t wg_min_z;
69 
70   size_t wg_max_x;
71   size_t wg_max_y;
72   size_t wg_max_z;
73 
74   /* The barrier used to synch the work-items before executing a new WG.  */
75   void *wg_start_barrier;
76 
77   /* The barrier to wait at after executing a work-group.  */
78   void *wg_completion_barrier;
79 
80   /* The barrier used to synchronize WIs in case of the 'barrier' HSAIL
81      instruction.  */
82   void *wg_sync_barrier;
83 
84   /* This should be set to the flat address of the beginning of the group
85      segment.  */
86   size_t group_segment_start_addr;
87 
88   /* This must be set to the correct aligned flat address space location from
89      where the kernel can actually read its arguments.  Might point to the
90      original global kernarg space.  */
91   void *kernarg_addr;
92 } PHSAKernelLaunchData;
93 
94 #endif
95