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
;
45 __isl_give isl_ast_expr
*gpu_local_array_info_linearize_index(
46 struct gpu_local_array_info
*array
, __isl_take isl_ast_expr
*expr
);
51 struct ppcg_scop
*scop
;
53 /* Set of parameter values */
56 /* All read accesses in the entire program */
59 /* All write accesses in the entire program */
62 /* Set of array elements that need to be copied in. */
63 isl_union_set
*copy_in
;
64 /* Set of array elements that need to be copied out. */
65 isl_union_set
*copy_out
;
67 /* Array of statements */
69 struct gpu_stmt
*stmts
;
72 struct gpu_array_info
*array
;
75 enum ppcg_kernel_access_type
{
81 enum ppcg_kernel_stmt_type
{
87 /* Representation of special statements, in particular copy statements
88 * and __syncthreads statements, inside a kernel.
90 * type represents the kind of statement
93 * for ppcg_kernel_copy statements we have
95 * read is set if the statement should copy data from global memory
96 * to shared memory or registers.
98 * index expresses an access to the array element that needs to be copied
99 * local_index expresses the corresponding element in the tile
101 * array refers to the original array being copied
102 * local_array is a pointer to the appropriate element in the "array"
103 * array of the ppcg_kernel to which this copy access belongs
106 * for ppcg_kernel_domain statements we have
108 * stmt is the corresponding input statement
110 * n_access is the number of accesses in stmt
111 * access is an array of local information about the accesses
113 struct ppcg_kernel_stmt
{
114 enum ppcg_kernel_stmt_type type
;
120 isl_ast_expr
*local_index
;
121 struct gpu_array_info
*array
;
122 struct gpu_local_array_info
*local_array
;
125 struct gpu_stmt
*stmt
;
126 isl_id_to_ast_expr
*ref2expr
;
131 /* Representation of a local variable in a kernel.
133 struct ppcg_kernel_var
{
134 struct gpu_array_info
*array
;
135 enum ppcg_kernel_access_type type
;
140 /* Representation of a kernel.
142 * id is the sequence number of the kernel.
144 * the first n_block elements of block_dim represent the effective size
147 * grid_size reflects the effective grid size.
149 * context is a parametric set containing the values of the parameters
150 * for which this kernel may be run.
152 * arrays is the set of accessed array elements.
154 * space is the schedule space of the AST context. That is, it represents
155 * the loops of the generated host code containing the kernel launch.
157 * n_array is the total number of arrays in the input program and also
158 * the number of element in the array array.
159 * array contains information about each array that is local
160 * to the current kernel. If an array is not ussed in a kernel,
161 * then the corresponding entry does not contain any information.
169 isl_multi_pw_aff
*grid_size
;
172 isl_union_set
*arrays
;
177 struct gpu_local_array_info
*array
;
180 struct ppcg_kernel_var
*var
;
185 int gpu_array_is_scalar(struct gpu_array_info
*array
);
186 int gpu_array_is_read_only_scalar(struct gpu_array_info
*array
);
188 struct gpu_prog
*gpu_prog_alloc(isl_ctx
*ctx
, struct ppcg_scop
*scop
);
189 void *gpu_prog_free(struct gpu_prog
*prog
);
191 int generate_gpu(isl_ctx
*ctx
, const char *input
, FILE *out
,
192 struct ppcg_options
*options
,
193 __isl_give isl_printer
*(*print
)(__isl_take isl_printer
*p
,
194 struct gpu_prog
*prog
, __isl_keep isl_ast_node
*tree
,
195 void *user
), void *user
);