5 #include <isl/id_to_ast_expr.h>
8 #include "ppcg_options.h"
10 /* Represents an outer array accessed by a gpu_prog.
11 * If this outer array contains structures, then the references are not
12 * collected and the reference groups are not computed.
14 struct gpu_array_info
{
15 /* The array data space. */
21 /* Name of the array. */
23 /* Extent of the array that needs to be copied. */
25 /* Number of indices. */
27 /* For each index, a bound on "extent" in that direction. */
30 /* All references to this array; point to elements of a linked list. */
32 struct gpu_stmt_access
**refs
;
34 /* The reference groups associated to this array. */
36 struct gpu_array_ref_group
**groups
;
38 /* Is this a scalar that is read-only within the entire program? */
41 /* Are the elements of the array structures? */
42 int has_compound_element
;
44 /* Is the array local to the scop? */
47 /* Should the array be linearized? */
51 /* For each index i, array->bound[i] specialized to the current kernel. */
52 struct gpu_local_array_info
{
53 isl_pw_aff_list
*bound
;
56 __isl_give isl_ast_expr
*gpu_local_array_info_linearize_index(
57 struct gpu_local_array_info
*array
, __isl_take isl_ast_expr
*expr
);
59 /* A sequence of "n" names of types.
66 /* "read" and "write" contain the original access relations, possibly
67 * involving member accesses.
69 * The elements of "array", as well as the ranges of "copy_in" and "copy_out"
70 * only refer to the outer arrays of any possible member accesses.
75 struct ppcg_scop
*scop
;
77 /* Set of parameter values */
80 /* All read accesses in the entire program */
83 /* All write accesses in the entire program */
86 /* Set of outer array elements that need to be copied in. */
87 isl_union_set
*copy_in
;
88 /* Set of outer array elements that need to be copied out. */
89 isl_union_set
*copy_out
;
91 /* A mapping from all innermost arrays to their outer arrays. */
92 isl_union_map
*to_outer
;
93 /* A mapping from the outer arrays to all corresponding inner arrays. */
94 isl_union_map
*to_inner
;
96 /* Array of statements */
98 struct gpu_stmt
*stmts
;
101 struct gpu_array_info
*array
;
104 enum ppcg_kernel_access_type
{
110 enum ppcg_kernel_stmt_type
{
116 /* Representation of special statements, in particular copy statements
117 * and __syncthreads statements, inside a kernel.
119 * type represents the kind of statement
122 * for ppcg_kernel_copy statements we have
124 * read is set if the statement should copy data from global memory
125 * to shared memory or registers.
127 * index expresses an access to the array element that needs to be copied
128 * local_index expresses the corresponding element in the tile
130 * array refers to the original array being copied
131 * local_array is a pointer to the appropriate element in the "array"
132 * array of the ppcg_kernel to which this copy access belongs
135 * for ppcg_kernel_domain statements we have
137 * stmt is the corresponding input statement
139 * n_access is the number of accesses in stmt
140 * access is an array of local information about the accesses
142 struct ppcg_kernel_stmt
{
143 enum ppcg_kernel_stmt_type type
;
149 isl_ast_expr
*local_index
;
150 struct gpu_array_info
*array
;
151 struct gpu_local_array_info
*local_array
;
154 struct gpu_stmt
*stmt
;
155 isl_id_to_ast_expr
*ref2expr
;
160 /* Representation of a local variable in a kernel.
162 struct ppcg_kernel_var
{
163 struct gpu_array_info
*array
;
164 enum ppcg_kernel_access_type type
;
169 /* Representation of a kernel.
171 * id is the sequence number of the kernel.
173 * the first n_block elements of block_dim represent the effective size
176 * grid_size reflects the effective grid size.
178 * context is a parametric set containing the values of the parameters
179 * for which this kernel may be run.
181 * arrays is the set of accessed outer array elements.
183 * space is the schedule space of the AST context. That is, it represents
184 * the loops of the generated host code containing the kernel launch.
186 * n_array is the total number of arrays in the input program and also
187 * the number of element in the array array.
188 * array contains information about each array that is local
189 * to the current kernel. If an array is not used in a kernel,
190 * then the corresponding entry does not contain any information.
198 isl_multi_pw_aff
*grid_size
;
201 isl_union_set
*arrays
;
206 struct gpu_local_array_info
*array
;
209 struct ppcg_kernel_var
*var
;
214 int gpu_array_is_scalar(struct gpu_array_info
*array
);
215 int gpu_array_is_read_only_scalar(struct gpu_array_info
*array
);
217 struct gpu_prog
*gpu_prog_alloc(isl_ctx
*ctx
, struct ppcg_scop
*scop
);
218 void *gpu_prog_free(struct gpu_prog
*prog
);
220 int generate_gpu(isl_ctx
*ctx
, const char *input
, FILE *out
,
221 struct ppcg_options
*options
,
222 __isl_give isl_printer
*(*print
)(__isl_take isl_printer
*p
,
223 struct gpu_prog
*prog
, __isl_keep isl_ast_node
*tree
,
224 struct gpu_types
*types
, void *user
), void *user
);