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? */
41 /* For each index i, array->bound[i] specialized to the current kernel. */
42 struct gpu_local_array_info
{
43 isl_pw_aff_list
*bound
;
46 __isl_give isl_ast_expr
*gpu_local_array_info_linearize_index(
47 struct gpu_local_array_info
*array
, __isl_take isl_ast_expr
*expr
);
52 struct ppcg_scop
*scop
;
54 /* Set of parameter values */
57 /* All read accesses in the entire program */
60 /* All write accesses in the entire program */
63 /* Set of array elements that need to be copied in. */
64 isl_union_set
*copy_in
;
65 /* Set of array elements that need to be copied out. */
66 isl_union_set
*copy_out
;
68 /* Array of statements */
70 struct gpu_stmt
*stmts
;
73 struct gpu_array_info
*array
;
76 enum ppcg_kernel_access_type
{
82 enum ppcg_kernel_stmt_type
{
88 /* Representation of special statements, in particular copy statements
89 * and __syncthreads statements, inside a kernel.
91 * type represents the kind of statement
94 * for ppcg_kernel_copy statements we have
96 * read is set if the statement should copy data from global memory
97 * to shared memory or registers.
99 * index expresses an access to the array element that needs to be copied
100 * local_index expresses the corresponding element in the tile
102 * array refers to the original array being copied
103 * local_array is a pointer to the appropriate element in the "array"
104 * array of the ppcg_kernel to which this copy access belongs
107 * for ppcg_kernel_domain statements we have
109 * stmt is the corresponding input statement
111 * n_access is the number of accesses in stmt
112 * access is an array of local information about the accesses
114 struct ppcg_kernel_stmt
{
115 enum ppcg_kernel_stmt_type type
;
121 isl_ast_expr
*local_index
;
122 struct gpu_array_info
*array
;
123 struct gpu_local_array_info
*local_array
;
126 struct gpu_stmt
*stmt
;
127 isl_id_to_ast_expr
*ref2expr
;
132 /* Representation of a local variable in a kernel.
134 struct ppcg_kernel_var
{
135 struct gpu_array_info
*array
;
136 enum ppcg_kernel_access_type type
;
141 /* Representation of a kernel.
143 * id is the sequence number of the kernel.
145 * the first n_block elements of block_dim represent the effective size
148 * grid_size reflects the effective grid size.
150 * context is a parametric set containing the values of the parameters
151 * for which this kernel may be run.
153 * arrays is the set of accessed array elements.
155 * space is the schedule space of the AST context. That is, it represents
156 * the loops of the generated host code containing the kernel launch.
158 * n_array is the total number of arrays in the input program and also
159 * the number of element in the array array.
160 * array contains information about each array that is local
161 * to the current kernel. If an array is not used in a kernel,
162 * then the corresponding entry does not contain any information.
170 isl_multi_pw_aff
*grid_size
;
173 isl_union_set
*arrays
;
178 struct gpu_local_array_info
*array
;
181 struct ppcg_kernel_var
*var
;
186 int gpu_array_is_scalar(struct gpu_array_info
*array
);
187 int gpu_array_is_read_only_scalar(struct gpu_array_info
*array
);
189 struct gpu_prog
*gpu_prog_alloc(isl_ctx
*ctx
, struct ppcg_scop
*scop
);
190 void *gpu_prog_free(struct gpu_prog
*prog
);
192 int generate_gpu(isl_ctx
*ctx
, const char *input
, FILE *out
,
193 struct ppcg_options
*options
,
194 __isl_give isl_printer
*(*print
)(__isl_take isl_printer
*p
,
195 struct gpu_prog
*prog
, __isl_keep isl_ast_node
*tree
,
196 void *user
), void *user
);