5 #include <isl/id_to_ast_expr.h>
8 #include "ppcg_options.h"
10 /* Represents an outer array possibly 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 array accessed at all by the program? */
41 /* Is this a scalar that is read-only within the entire program? */
44 /* Are the elements of the array structures? */
45 int has_compound_element
;
47 /* Is the array local to the scop? */
50 /* Should the array be linearized? */
53 /* Order dependences on this array.
54 * Only used if live_range_reordering option is set.
55 * It is set to NULL otherwise.
57 isl_union_map
*dep_order
;
58 /* Should the array (scalar) be forcibly mapped to a register? */
62 /* For each index i with 0 <= i < n_index,
63 * bound[i] is equal to array->bound[i] specialized to the current kernel.
65 struct gpu_local_array_info
{
67 isl_pw_aff_list
*bound
;
70 __isl_give isl_ast_expr
*gpu_local_array_info_linearize_index(
71 struct gpu_local_array_info
*array
, __isl_take isl_ast_expr
*expr
);
73 /* A sequence of "n" names of types.
80 /* "read" and "write" contain the original access relations, possibly
81 * involving member accesses.
83 * The elements of "array", as well as the ranges of "copy_in" and "copy_out"
84 * only refer to the outer arrays of any possible member accesses.
89 struct ppcg_scop
*scop
;
91 /* Set of parameter values */
94 /* All potential read accesses in the entire program */
97 /* All potential write accesses in the entire program */
98 isl_union_map
*may_write
;
99 /* All definite write accesses in the entire program */
100 isl_union_map
*must_write
;
101 /* All tagged definite kills in the entire program */
102 isl_union_map
*tagged_must_kill
;
104 /* The set of inner array elements that may be preserved. */
105 isl_union_set
*may_persist
;
107 /* Set of outer array elements that need to be copied in. */
108 isl_union_set
*copy_in
;
109 /* Set of outer array elements that need to be copied out. */
110 isl_union_set
*copy_out
;
112 /* A mapping from all innermost arrays to their outer arrays. */
113 isl_union_map
*to_outer
;
114 /* A mapping from the outer arrays to all corresponding inner arrays. */
115 isl_union_map
*to_inner
;
116 /* A mapping from all intermediate arrays to their outer arrays,
117 * including an identity mapping from the anoymous 1D space to itself.
119 isl_union_map
*any_to_outer
;
121 /* Order dependences on non-scalars. */
122 isl_union_map
*array_order
;
124 /* Array of statements */
126 struct gpu_stmt
*stmts
;
129 struct gpu_array_info
*array
;
132 enum ppcg_kernel_access_type
{
138 enum ppcg_kernel_stmt_type
{
144 /* Representation of special statements, in particular copy statements
145 * and __syncthreads statements, inside a kernel.
147 * type represents the kind of statement
150 * for ppcg_kernel_copy statements we have
152 * read is set if the statement should copy data from global memory
153 * to shared memory or registers.
155 * index expresses an access to the array element that needs to be copied
156 * local_index expresses the corresponding element in the tile
158 * array refers to the original array being copied
159 * local_array is a pointer to the appropriate element in the "array"
160 * array of the ppcg_kernel to which this copy access belongs
163 * for ppcg_kernel_domain statements we have
165 * stmt is the corresponding input statement
167 * n_access is the number of accesses in stmt
168 * access is an array of local information about the accesses
170 struct ppcg_kernel_stmt
{
171 enum ppcg_kernel_stmt_type type
;
177 isl_ast_expr
*local_index
;
178 struct gpu_array_info
*array
;
179 struct gpu_local_array_info
*local_array
;
182 struct gpu_stmt
*stmt
;
183 isl_id_to_ast_expr
*ref2expr
;
188 /* Representation of a local variable in a kernel.
190 struct ppcg_kernel_var
{
191 struct gpu_array_info
*array
;
192 enum ppcg_kernel_access_type type
;
197 /* Representation of a kernel.
199 * id is the sequence number of the kernel.
201 * block_ids contains the list of block identifiers for this kernel.
202 * thread_ids contains the list of thread identifiers for this kernel.
204 * the first n_block elements of block_dim represent the effective size
207 * grid_size reflects the effective grid size.
209 * context is a parametric set containing the values of the parameters
210 * for which this kernel may be run.
212 * arrays is the set of possibly accessed outer array elements.
214 * space is the schedule space of the AST context. That is, it represents
215 * the loops of the generated host code containing the kernel launch.
217 * n_array is the total number of arrays in the input program and also
218 * the number of element in the array array.
219 * array contains information about each array that is local
220 * to the current kernel. If an array is not used in a kernel,
221 * then the corresponding entry does not contain any information.
226 isl_id_list
*block_ids
;
227 isl_id_list
*thread_ids
;
232 isl_multi_pw_aff
*grid_size
;
235 isl_union_set
*arrays
;
240 struct gpu_local_array_info
*array
;
243 struct ppcg_kernel_var
*var
;
248 int gpu_array_is_scalar(struct gpu_array_info
*array
);
249 int gpu_array_is_read_only_scalar(struct gpu_array_info
*array
);
250 __isl_give isl_set
*gpu_array_positive_size_guard(struct gpu_array_info
*array
);
252 struct gpu_prog
*gpu_prog_alloc(isl_ctx
*ctx
, struct ppcg_scop
*scop
);
253 void *gpu_prog_free(struct gpu_prog
*prog
);
255 int generate_gpu(isl_ctx
*ctx
, const char *input
, FILE *out
,
256 struct ppcg_options
*options
,
257 __isl_give isl_printer
*(*print
)(__isl_take isl_printer
*p
,
258 struct gpu_prog
*prog
, __isl_keep isl_ast_node
*tree
,
259 struct gpu_types
*types
, void *user
), void *user
);