update isl for isl_map_affine_hull optimization
[ppcg.git] / gpu.h
blob4376876e11d701f7f036c3257f0e69dbcfb8761d
1 #ifndef _GPU_H
2 #define _GPU_H
4 #include "ppcg.h"
5 #include "ppcg_options.h"
7 struct gpu_array_info {
8 isl_space *dim;
9 /* Element type. */
10 char *type;
11 /* Element size. */
12 int size;
13 /* Name of the array. */
14 char *name;
15 /* Extent of the array that needs to be copied. */
16 isl_set *extent;
17 /* Number of indices. */
18 unsigned n_index;
19 /* For each index, a bound on "extent" in that direction. */
20 isl_pw_aff **bound;
22 /* All references to this array; point to elements of a linked list. */
23 int n_ref;
24 struct gpu_stmt_access **refs;
26 /* The reference groups associated to this array. */
27 int n_group;
28 struct gpu_array_ref_group **groups;
30 /* For scalars, is this scalar read-only within the entire program? */
31 int read_only;
33 /* Is the array local to the scop? */
34 int local;
37 /* For each index i, array->bound[i] specialized to the current kernel. */
38 struct gpu_local_array_info {
39 isl_pw_aff_list *bound;
42 struct gpu_prog {
43 isl_ctx *ctx;
45 struct ppcg_scop *scop;
47 /* Set of parameter values */
48 isl_set *context;
50 /* All read accesses in the entire program */
51 isl_union_map *read;
53 /* All write accesses in the entire program */
54 isl_union_map *write;
56 /* Set of array elements that need to be copied in. */
57 isl_union_set *copy_in;
58 /* Set of array elements that need to be copied out. */
59 isl_union_set *copy_out;
61 /* Array of statements */
62 int n_stmts;
63 struct gpu_stmt *stmts;
65 int n_array;
66 struct gpu_array_info *array;
69 enum ppcg_kernel_access_type {
70 ppcg_access_global,
71 ppcg_access_shared,
72 ppcg_access_private
75 enum ppcg_kernel_stmt_type {
76 ppcg_kernel_copy,
77 ppcg_kernel_domain,
78 ppcg_kernel_sync
81 /* Instance specific information about an access inside a kernel statement.
83 * type indicates whether it is a global, shared or private access
84 * array is the original array information and may be NULL in case
85 * of an affine expression
86 * local_array is a pointer to the appropriate element in the "array"
87 * array of the ppcg_kernel to which this access belongs. It is
88 * NULL whenever array is NULL.
89 * local_name is the name of the array or its local copy
90 * index is the sequence of local index expressions
92 struct ppcg_kernel_access {
93 enum ppcg_kernel_access_type type;
94 struct gpu_array_info *array;
95 struct gpu_local_array_info *local_array;
96 char *local_name;
97 isl_ast_expr_list *index;
100 /* Representation of special statements, in particular copy statements
101 * and __syncthreads statements, inside a kernel.
103 * type represents the kind of statement
106 * for ppcg_kernel_copy statements we have
108 * read is set if the statement should copy data from global memory
109 * to shared memory or registers.
111 * index expresses the array element that needs to be copied as a "call"
112 * to the array
113 * local_index expresses the corresponding element in the tile
115 * array refers to the original array being copied
116 * local_array is a pointer to the appropriate element in the "array"
117 * array of the ppcg_kernel to which this copy access belongs
120 * for ppcg_kernel_domain statements we have
122 * stmt is the corresponding input statement
124 * n_access is the number of accesses in stmt
125 * access is an array of local information about the accesses
127 struct ppcg_kernel_stmt {
128 enum ppcg_kernel_stmt_type type;
130 union {
131 struct {
132 int read;
133 isl_ast_expr *index;
134 isl_ast_expr *local_index;
135 struct gpu_array_info *array;
136 struct gpu_local_array_info *local_array;
137 } c;
138 struct {
139 struct gpu_stmt *stmt;
141 int n_access;
142 struct ppcg_kernel_access *access;
143 } d;
144 } u;
147 /* Representation of a local variable in a kernel.
149 struct ppcg_kernel_var {
150 struct gpu_array_info *array;
151 enum ppcg_kernel_access_type type;
152 char *name;
153 isl_vec *size;
156 /* Representation of a kernel.
158 * id is the sequence number of the kernel.
160 * the first n_block elements of block_dim represent the size of the block.
162 * grid_size reflects the effect grid size.
164 * context is a parametric set containing the values of the parameters
165 * for which this kernel may be run.
167 * arrays is the set of accessed array elements.
169 * space is the schedule space of the AST context. That is, it represents
170 * the loops of the generated host code containing the kernel launch.
172 * n_array is the total number of arrays in the input program and also
173 * the number of element in the array array.
174 * array contains information about each array that is local
175 * to the current kernel. If an array is not ussed in a kernel,
176 * then the corresponding entry does not contain any information.
178 struct ppcg_kernel {
179 int id;
181 int n_grid;
182 int grid_dim[2];
184 int n_block;
185 int block_dim[3];
187 isl_multi_pw_aff *grid_size;
188 isl_set *context;
190 isl_union_set *arrays;
192 isl_space *space;
194 int n_array;
195 struct gpu_local_array_info *array;
197 int n_var;
198 struct ppcg_kernel_var *var;
200 isl_ast_node *tree;
203 int gpu_array_is_scalar(struct gpu_array_info *array);
204 int gpu_array_is_read_only_scalar(struct gpu_array_info *array);
206 struct gpu_prog *gpu_prog_alloc(isl_ctx *ctx, struct ppcg_scop *scop);
207 void gpu_prog_free(struct gpu_prog *prog);
209 __isl_give isl_ast_node *generate_gpu(isl_ctx *ctx, struct gpu_prog *prog,
210 struct ppcg_options *options);
212 #endif