gpu.c: use pet_stmt_build_ast_exprs and pet_stmt_print_body to print statements
[ppcg.git] / gpu.h
blob5bd773ab25311bcb962c0c8b5ae2d11904bd4487
1 #ifndef _GPU_H
2 #define _GPU_H
4 #include <isl/ast.h>
5 #include <isl/id_to_ast_expr.h>
7 #include "ppcg.h"
8 #include "ppcg_options.h"
10 struct gpu_array_info {
11 isl_space *dim;
12 /* Element type. */
13 char *type;
14 /* Element size. */
15 int size;
16 /* Name of the array. */
17 char *name;
18 /* Extent of the array that needs to be copied. */
19 isl_set *extent;
20 /* Number of indices. */
21 unsigned n_index;
22 /* For each index, a bound on "extent" in that direction. */
23 isl_pw_aff **bound;
25 /* All references to this array; point to elements of a linked list. */
26 int n_ref;
27 struct gpu_stmt_access **refs;
29 /* The reference groups associated to this array. */
30 int n_group;
31 struct gpu_array_ref_group **groups;
33 /* For scalars, is this scalar read-only within the entire program? */
34 int read_only;
36 /* Is the array local to the scop? */
37 int local;
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 struct gpu_prog {
46 isl_ctx *ctx;
48 struct ppcg_scop *scop;
50 /* Set of parameter values */
51 isl_set *context;
53 /* All read accesses in the entire program */
54 isl_union_map *read;
56 /* All write accesses in the entire program */
57 isl_union_map *write;
59 /* Set of array elements that need to be copied in. */
60 isl_union_set *copy_in;
61 /* Set of array elements that need to be copied out. */
62 isl_union_set *copy_out;
64 /* Array of statements */
65 int n_stmts;
66 struct gpu_stmt *stmts;
68 int n_array;
69 struct gpu_array_info *array;
72 enum ppcg_kernel_access_type {
73 ppcg_access_global,
74 ppcg_access_shared,
75 ppcg_access_private
78 enum ppcg_kernel_stmt_type {
79 ppcg_kernel_copy,
80 ppcg_kernel_domain,
81 ppcg_kernel_sync
84 /* Representation of special statements, in particular copy statements
85 * and __syncthreads statements, inside a kernel.
87 * type represents the kind of statement
90 * for ppcg_kernel_copy statements we have
92 * read is set if the statement should copy data from global memory
93 * to shared memory or registers.
95 * index expresses the array element that needs to be copied as a "call"
96 * to the array
97 * local_index expresses the corresponding element in the tile
99 * array refers to the original array being copied
100 * local_array is a pointer to the appropriate element in the "array"
101 * array of the ppcg_kernel to which this copy access belongs
104 * for ppcg_kernel_domain statements we have
106 * stmt is the corresponding input statement
108 * n_access is the number of accesses in stmt
109 * access is an array of local information about the accesses
111 struct ppcg_kernel_stmt {
112 enum ppcg_kernel_stmt_type type;
114 union {
115 struct {
116 int read;
117 isl_ast_expr *index;
118 isl_ast_expr *local_index;
119 struct gpu_array_info *array;
120 struct gpu_local_array_info *local_array;
121 } c;
122 struct {
123 struct gpu_stmt *stmt;
124 isl_id_to_ast_expr *ref2expr;
125 } d;
126 } u;
129 /* Representation of a local variable in a kernel.
131 struct ppcg_kernel_var {
132 struct gpu_array_info *array;
133 enum ppcg_kernel_access_type type;
134 char *name;
135 isl_vec *size;
138 /* Representation of a kernel.
140 * id is the sequence number of the kernel.
142 * the first n_block elements of block_dim represent the effective size
143 * of the block.
145 * grid_size reflects the effective grid size.
147 * context is a parametric set containing the values of the parameters
148 * for which this kernel may be run.
150 * arrays is the set of accessed array elements.
152 * space is the schedule space of the AST context. That is, it represents
153 * the loops of the generated host code containing the kernel launch.
155 * n_array is the total number of arrays in the input program and also
156 * the number of element in the array array.
157 * array contains information about each array that is local
158 * to the current kernel. If an array is not ussed in a kernel,
159 * then the corresponding entry does not contain any information.
161 struct ppcg_kernel {
162 int id;
164 int n_block;
165 int block_dim[3];
167 isl_multi_pw_aff *grid_size;
168 isl_set *context;
170 isl_union_set *arrays;
172 isl_space *space;
174 int n_array;
175 struct gpu_local_array_info *array;
177 int n_var;
178 struct ppcg_kernel_var *var;
180 isl_ast_node *tree;
183 int gpu_array_is_scalar(struct gpu_array_info *array);
184 int gpu_array_is_read_only_scalar(struct gpu_array_info *array);
186 struct gpu_prog *gpu_prog_alloc(isl_ctx *ctx, struct ppcg_scop *scop);
187 void *gpu_prog_free(struct gpu_prog *prog);
189 int generate_gpu(isl_ctx *ctx, const char *input, FILE *out,
190 struct ppcg_scop *scop, struct ppcg_options *options,
191 __isl_give isl_printer *(*print)(__isl_take isl_printer *p,
192 struct gpu_prog *prog, __isl_keep isl_ast_node *tree,
193 void *user), void *user);
195 #endif