5 #include <isl/id_to_ast_expr.h>
8 #include "ppcg_options.h"
10 struct gpu_array_info
{
11 /* The array data space. */
17 /* Name of the array. */
19 /* Extent of the array that needs to be copied. */
21 /* Number of indices. */
23 /* For each index, a bound on "extent" in that direction. */
26 /* All references to this array; point to elements of a linked list. */
28 struct gpu_stmt_access
**refs
;
30 /* The reference groups associated to this array. */
32 struct gpu_array_ref_group
**groups
;
34 /* Is this a scalar that is read-only within the entire program? */
37 /* Is the array local to the scop? */
40 /* Should the array be linearized? */
44 /* For each index i, array->bound[i] specialized to the current kernel. */
45 struct gpu_local_array_info
{
46 isl_pw_aff_list
*bound
;
49 __isl_give isl_ast_expr
*gpu_local_array_info_linearize_index(
50 struct gpu_local_array_info
*array
, __isl_take isl_ast_expr
*expr
);
55 struct ppcg_scop
*scop
;
57 /* Set of parameter values */
60 /* All read accesses in the entire program */
63 /* All write accesses in the entire program */
66 /* Set of array elements that need to be copied in. */
67 isl_union_set
*copy_in
;
68 /* Set of array elements that need to be copied out. */
69 isl_union_set
*copy_out
;
71 /* Array of statements */
73 struct gpu_stmt
*stmts
;
76 struct gpu_array_info
*array
;
79 enum ppcg_kernel_access_type
{
85 enum ppcg_kernel_stmt_type
{
91 /* Representation of special statements, in particular copy statements
92 * and __syncthreads statements, inside a kernel.
94 * type represents the kind of statement
97 * for ppcg_kernel_copy statements we have
99 * read is set if the statement should copy data from global memory
100 * to shared memory or registers.
102 * index expresses an access to the array element that needs to be copied
103 * local_index expresses the corresponding element in the tile
105 * array refers to the original array being copied
106 * local_array is a pointer to the appropriate element in the "array"
107 * array of the ppcg_kernel to which this copy access belongs
110 * for ppcg_kernel_domain statements we have
112 * stmt is the corresponding input statement
114 * n_access is the number of accesses in stmt
115 * access is an array of local information about the accesses
117 struct ppcg_kernel_stmt
{
118 enum ppcg_kernel_stmt_type type
;
124 isl_ast_expr
*local_index
;
125 struct gpu_array_info
*array
;
126 struct gpu_local_array_info
*local_array
;
129 struct gpu_stmt
*stmt
;
130 isl_id_to_ast_expr
*ref2expr
;
135 /* Representation of a local variable in a kernel.
137 struct ppcg_kernel_var
{
138 struct gpu_array_info
*array
;
139 enum ppcg_kernel_access_type type
;
144 /* Representation of a kernel.
146 * id is the sequence number of the kernel.
148 * the first n_block elements of block_dim represent the effective size
151 * grid_size reflects the effective grid size.
153 * context is a parametric set containing the values of the parameters
154 * for which this kernel may be run.
156 * arrays is the set of accessed array elements.
158 * space is the schedule space of the AST context. That is, it represents
159 * the loops of the generated host code containing the kernel launch.
161 * n_array is the total number of arrays in the input program and also
162 * the number of element in the array array.
163 * array contains information about each array that is local
164 * to the current kernel. If an array is not used in a kernel,
165 * then the corresponding entry does not contain any information.
173 isl_multi_pw_aff
*grid_size
;
176 isl_union_set
*arrays
;
181 struct gpu_local_array_info
*array
;
184 struct ppcg_kernel_var
*var
;
189 int gpu_array_is_scalar(struct gpu_array_info
*array
);
190 int gpu_array_is_read_only_scalar(struct gpu_array_info
*array
);
192 struct gpu_prog
*gpu_prog_alloc(isl_ctx
*ctx
, struct ppcg_scop
*scop
);
193 void *gpu_prog_free(struct gpu_prog
*prog
);
195 int generate_gpu(isl_ctx
*ctx
, const char *input
, FILE *out
,
196 struct ppcg_options
*options
,
197 __isl_give isl_printer
*(*print
)(__isl_take isl_printer
*p
,
198 struct gpu_prog
*prog
, __isl_keep isl_ast_node
*tree
,
199 void *user
), void *user
);