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 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? */
50 /* Order dependences on this array.
51 * Only used if live_range_reordering option is set.
52 * It is set to NULL otherwise.
54 isl_union_map
*dep_order
;
55 /* Should the array (scalar) be forcibly mapped to a register? */
59 /* For each index i with 0 <= i < n_index,
60 * bound[i] is equal to array->bound[i] specialized to the current kernel.
62 struct gpu_local_array_info
{
64 isl_pw_aff_list
*bound
;
67 __isl_give isl_ast_expr
*gpu_local_array_info_linearize_index(
68 struct gpu_local_array_info
*array
, __isl_take isl_ast_expr
*expr
);
70 /* A sequence of "n" names of types.
77 /* "read" and "write" contain the original access relations, possibly
78 * involving member accesses.
80 * The elements of "array", as well as the ranges of "copy_in" and "copy_out"
81 * only refer to the outer arrays of any possible member accesses.
86 struct ppcg_scop
*scop
;
88 /* Set of parameter values */
91 /* All potential read accesses in the entire program */
94 /* All potential write accesses in the entire program */
95 isl_union_map
*may_write
;
96 /* All definite write accesses in the entire program */
97 isl_union_map
*must_write
;
99 /* Set of outer array elements that need to be copied in. */
100 isl_union_set
*copy_in
;
101 /* Set of outer array elements that need to be copied out. */
102 isl_union_set
*copy_out
;
104 /* A mapping from all innermost arrays to their outer arrays. */
105 isl_union_map
*to_outer
;
106 /* A mapping from the outer arrays to all corresponding inner arrays. */
107 isl_union_map
*to_inner
;
108 /* A mapping from all intermediate arrays to their outer arrays,
109 * including an identity mapping from the anoymous 1D space to itself.
111 isl_union_map
*any_to_outer
;
113 /* Order dependences on non-scalars. */
114 isl_union_map
*array_order
;
116 /* Array of statements */
118 struct gpu_stmt
*stmts
;
121 struct gpu_array_info
*array
;
124 enum ppcg_kernel_access_type
{
130 enum ppcg_kernel_stmt_type
{
136 /* Representation of special statements, in particular copy statements
137 * and __syncthreads statements, inside a kernel.
139 * type represents the kind of statement
142 * for ppcg_kernel_copy statements we have
144 * read is set if the statement should copy data from global memory
145 * to shared memory or registers.
147 * index expresses an access to the array element that needs to be copied
148 * local_index expresses the corresponding element in the tile
150 * array refers to the original array being copied
151 * local_array is a pointer to the appropriate element in the "array"
152 * array of the ppcg_kernel to which this copy access belongs
155 * for ppcg_kernel_domain statements we have
157 * stmt is the corresponding input statement
159 * n_access is the number of accesses in stmt
160 * access is an array of local information about the accesses
162 struct ppcg_kernel_stmt
{
163 enum ppcg_kernel_stmt_type type
;
169 isl_ast_expr
*local_index
;
170 struct gpu_array_info
*array
;
171 struct gpu_local_array_info
*local_array
;
174 struct gpu_stmt
*stmt
;
175 isl_id_to_ast_expr
*ref2expr
;
180 /* Representation of a local variable in a kernel.
182 struct ppcg_kernel_var
{
183 struct gpu_array_info
*array
;
184 enum ppcg_kernel_access_type type
;
189 /* Representation of a kernel.
191 * id is the sequence number of the kernel.
193 * the first n_block elements of block_dim represent the effective size
196 * grid_size reflects the effective grid size.
198 * context is a parametric set containing the values of the parameters
199 * for which this kernel may be run.
201 * arrays is the set of possibly accessed outer array elements.
203 * space is the schedule space of the AST context. That is, it represents
204 * the loops of the generated host code containing the kernel launch.
206 * n_array is the total number of arrays in the input program and also
207 * the number of element in the array array.
208 * array contains information about each array that is local
209 * to the current kernel. If an array is not used in a kernel,
210 * then the corresponding entry does not contain any information.
218 isl_multi_pw_aff
*grid_size
;
221 isl_union_set
*arrays
;
226 struct gpu_local_array_info
*array
;
229 struct ppcg_kernel_var
*var
;
234 int gpu_array_is_scalar(struct gpu_array_info
*array
);
235 int gpu_array_is_read_only_scalar(struct gpu_array_info
*array
);
236 __isl_give isl_set
*gpu_array_positive_size_guard(struct gpu_array_info
*array
);
238 struct gpu_prog
*gpu_prog_alloc(isl_ctx
*ctx
, struct ppcg_scop
*scop
);
239 void *gpu_prog_free(struct gpu_prog
*prog
);
241 int generate_gpu(isl_ctx
*ctx
, const char *input
, FILE *out
,
242 struct ppcg_options
*options
,
243 __isl_give isl_printer
*(*print
)(__isl_take isl_printer
*p
,
244 struct gpu_prog
*prog
, __isl_keep isl_ast_node
*tree
,
245 struct gpu_types
*types
, void *user
), void *user
);