update pet to version 0.03
[ppcg.git] / gpu.h
blobc48cc7d76a17249b7a268dc6940a26de85f4eefd
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 /* Number of indices. */
16 unsigned n_index;
17 /* For each index, a bound on the array in that direction. */
18 isl_pw_aff **bound;
20 /* All references to this array; point to elements of a linked list. */
21 int n_ref;
22 struct gpu_stmt_access **refs;
24 /* The reference groups associated to this array. */
25 int n_group;
26 struct gpu_array_ref_group **groups;
28 /* For scalars, is this scalar read-only within the entire program? */
29 int read_only;
31 /* Is the array local to the scop? */
32 int local;
35 /* For each index i, array->bound[i] specialized to the current kernel. */
36 struct gpu_local_array_info {
37 isl_pw_aff_list *bound;
40 struct gpu_prog {
41 isl_ctx *ctx;
43 struct ppcg_scop *scop;
45 /* Set of parameter values */
46 isl_set *context;
48 /* All read accesses in the entire program */
49 isl_union_map *read;
51 /* All write accesses in the entire program */
52 isl_union_map *write;
54 /* Uninitialized data elements (or an overapproximation) */
55 isl_union_set *copy_in;
57 /* Array of statements */
58 int n_stmts;
59 struct gpu_stmt *stmts;
61 int n_array;
62 struct gpu_array_info *array;
65 enum ppcg_kernel_access_type {
66 ppcg_access_global,
67 ppcg_access_shared,
68 ppcg_access_private
71 enum ppcg_kernel_stmt_type {
72 ppcg_kernel_copy,
73 ppcg_kernel_domain,
74 ppcg_kernel_sync
77 /* Instance specific information about an access inside a kernel statement.
79 * type indicates whether it is a global, shared or private access
80 * array is the original array information and may be NULL in case
81 * of an affine expression
82 * local_array is a pointer to the appropriate element in the "array"
83 * array of the ppcg_kernel to which this access belongs. It is
84 * NULL whenever array is NULL.
85 * local_name is the name of the array or its local copy
86 * index is the sequence of local index expressions
88 struct ppcg_kernel_access {
89 enum ppcg_kernel_access_type type;
90 struct gpu_array_info *array;
91 struct gpu_local_array_info *local_array;
92 char *local_name;
93 isl_ast_expr_list *index;
96 /* Representation of special statements, in particular copy statements
97 * and __syncthreads statements, inside a kernel.
99 * type represents the kind of statement
102 * for ppcg_kernel_copy statements we have
104 * read is set if the statement should copy data from global memory
105 * to shared memory or registers.
107 * index expresses the array element that needs to be copied as a "call"
108 * to the array
109 * local_index expresses the corresponding element in the tile
111 * array refers to the original array being copied
112 * local_array is a pointer to the appropriate element in the "array"
113 * array of the ppcg_kernel to which this copy access belongs
116 * for ppcg_kernel_domain statements we have
118 * stmt is the corresponding input statement
120 * n_access is the number of accesses in stmt
121 * access is an array of local information about the accesses
123 struct ppcg_kernel_stmt {
124 enum ppcg_kernel_stmt_type type;
126 union {
127 struct {
128 int read;
129 isl_ast_expr *index;
130 isl_ast_expr *local_index;
131 struct gpu_array_info *array;
132 struct gpu_local_array_info *local_array;
133 } c;
134 struct {
135 struct gpu_stmt *stmt;
137 int n_access;
138 struct ppcg_kernel_access *access;
139 } d;
140 } u;
143 /* Representation of a local variable in a kernel.
145 struct ppcg_kernel_var {
146 struct gpu_array_info *array;
147 enum ppcg_kernel_access_type type;
148 char *name;
149 isl_vec *size;
152 /* Representation of a kernel.
154 * id is the sequence number of the kernel.
156 * the first n_block elements of block_dim represent the size of the block.
158 * grid_size reflects the effect grid size.
160 * context is a parametric set containing the values of the parameters
161 * for which this kernel may be run.
163 * arrays is the set of accessed array elements.
165 * space is the schedule space of the AST context. That is, it represents
166 * the loops of the generated host code containing the kernel launch.
168 * n_array is the total number of arrays in the input program and also
169 * the number of element in the array array.
170 * array contains information about each array that is local
171 * to the current kernel. If an array is not ussed in a kernel,
172 * then the corresponding entry does not contain any information.
174 struct ppcg_kernel {
175 int id;
177 int n_grid;
178 int grid_dim[2];
180 int n_block;
181 int block_dim[3];
183 isl_multi_pw_aff *grid_size;
184 isl_set *context;
186 isl_union_set *arrays;
188 isl_space *space;
190 int n_array;
191 struct gpu_local_array_info *array;
193 int n_var;
194 struct ppcg_kernel_var *var;
196 isl_ast_node *tree;
199 int gpu_array_is_scalar(struct gpu_array_info *array);
200 int gpu_array_is_read_only_scalar(struct gpu_array_info *array);
202 struct gpu_prog *gpu_prog_alloc(isl_ctx *ctx, struct ppcg_scop *scop);
203 void gpu_prog_free(struct gpu_prog *prog);
205 __isl_give isl_set *add_context_from_str(__isl_take isl_set *set,
206 const char *str);
208 __isl_give isl_ast_node *generate_gpu(isl_ctx *ctx, struct gpu_prog *prog,
209 struct ppcg_options *options);
211 #endif