5 #include <isl/id_to_ast_expr.h>
8 #include "ppcg_options.h"
10 struct gpu_array_info
{
16 /* Name of the array. */
18 /* Extent of the array that needs to be copied. */
20 /* Number of indices. */
22 /* For each index, a bound on "extent" in that direction. */
25 /* All references to this array; point to elements of a linked list. */
27 struct gpu_stmt_access
**refs
;
29 /* The reference groups associated to this array. */
31 struct gpu_array_ref_group
**groups
;
33 /* For scalars, is this scalar read-only within the entire program? */
36 /* Is the array local to the scop? */
40 /* For each index i, array->bound[i] specialized to the current kernel. */
41 struct gpu_local_array_info
{
42 isl_pw_aff_list
*bound
;
48 struct ppcg_scop
*scop
;
50 /* Set of parameter values */
53 /* All read accesses in the entire program */
56 /* All write accesses in the entire program */
59 /* Set of array elements that need to be copied in. */
60 isl_union_set
*copy_in
;
61 /* Set of array elements that need to be copied out. */
62 isl_union_set
*copy_out
;
64 /* Array of statements */
66 struct gpu_stmt
*stmts
;
69 struct gpu_array_info
*array
;
72 enum ppcg_kernel_access_type
{
78 enum ppcg_kernel_stmt_type
{
84 /* Representation of special statements, in particular copy statements
85 * and __syncthreads statements, inside a kernel.
87 * type represents the kind of statement
90 * for ppcg_kernel_copy statements we have
92 * read is set if the statement should copy data from global memory
93 * to shared memory or registers.
95 * index expresses the array element that needs to be copied as a "call"
97 * local_index expresses the corresponding element in the tile
99 * array refers to the original array being copied
100 * local_array is a pointer to the appropriate element in the "array"
101 * array of the ppcg_kernel to which this copy access belongs
104 * for ppcg_kernel_domain statements we have
106 * stmt is the corresponding input statement
108 * n_access is the number of accesses in stmt
109 * access is an array of local information about the accesses
111 struct ppcg_kernel_stmt
{
112 enum ppcg_kernel_stmt_type type
;
118 isl_ast_expr
*local_index
;
119 struct gpu_array_info
*array
;
120 struct gpu_local_array_info
*local_array
;
123 struct gpu_stmt
*stmt
;
124 isl_id_to_ast_expr
*ref2expr
;
129 /* Representation of a local variable in a kernel.
131 struct ppcg_kernel_var
{
132 struct gpu_array_info
*array
;
133 enum ppcg_kernel_access_type type
;
138 /* Representation of a kernel.
140 * id is the sequence number of the kernel.
142 * the first n_block elements of block_dim represent the effective size
145 * grid_size reflects the effective grid size.
147 * context is a parametric set containing the values of the parameters
148 * for which this kernel may be run.
150 * arrays is the set of accessed array elements.
152 * space is the schedule space of the AST context. That is, it represents
153 * the loops of the generated host code containing the kernel launch.
155 * n_array is the total number of arrays in the input program and also
156 * the number of element in the array array.
157 * array contains information about each array that is local
158 * to the current kernel. If an array is not ussed in a kernel,
159 * then the corresponding entry does not contain any information.
167 isl_multi_pw_aff
*grid_size
;
170 isl_union_set
*arrays
;
175 struct gpu_local_array_info
*array
;
178 struct ppcg_kernel_var
*var
;
183 int gpu_array_is_scalar(struct gpu_array_info
*array
);
184 int gpu_array_is_read_only_scalar(struct gpu_array_info
*array
);
186 struct gpu_prog
*gpu_prog_alloc(isl_ctx
*ctx
, struct ppcg_scop
*scop
);
187 void *gpu_prog_free(struct gpu_prog
*prog
);
189 int generate_gpu(isl_ctx
*ctx
, const char *input
, FILE *out
,
190 struct ppcg_scop
*scop
, struct ppcg_options
*options
,
191 __isl_give isl_printer
*(*print
)(__isl_take isl_printer
*p
,
192 struct gpu_prog
*prog
, __isl_keep isl_ast_node
*tree
,
193 void *user
), void *user
);