gpu.c: compute_schedule: take domain from ppcg_scop
[ppcg.git] / gpu.h
blob0731026cbd1538a66585c6767ba963b6a70e4dd0
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;
32 /* For each index i, array->bound[i] specialized to the current kernel. */
33 struct gpu_local_array_info {
34 isl_pw_aff_list *bound;
37 struct gpu_prog {
38 isl_ctx *ctx;
40 struct ppcg_scop *scop;
42 /* Set of parameter values */
43 isl_set *context;
45 /* All read accesses in the entire program */
46 isl_union_map *read;
48 /* All write accesses in the entire program */
49 isl_union_map *write;
51 /* Uninitialized data elements (or an overapproximation) */
52 isl_union_set *copy_in;
54 /* Array of statements */
55 int n_stmts;
56 struct gpu_stmt *stmts;
58 int n_array;
59 struct gpu_array_info *array;
62 enum ppcg_kernel_access_type {
63 ppcg_access_global,
64 ppcg_access_shared,
65 ppcg_access_private
68 enum ppcg_kernel_stmt_type {
69 ppcg_kernel_copy,
70 ppcg_kernel_domain,
71 ppcg_kernel_sync
74 /* Instance specific information about an access inside a kernel statement.
76 * type indicates whether it is a global, shared or private access
77 * array is the original array information and may be NULL in case
78 * of an affine expression
79 * local_array is a pointer to the appropriate element in the "array"
80 * array of the ppcg_kernel to which this access belongs. It is
81 * NULL whenever array is NULL.
82 * local_name is the name of the array or its local copy
83 * index is the sequence of local index expressions
85 struct ppcg_kernel_access {
86 enum ppcg_kernel_access_type type;
87 struct gpu_array_info *array;
88 struct gpu_local_array_info *local_array;
89 char *local_name;
90 isl_ast_expr_list *index;
93 /* Representation of special statements, in particular copy statements
94 * and __syncthreads statements, inside a kernel.
96 * type represents the kind of statement
99 * for ppcg_kernel_copy statements we have
101 * read is set if the statement should copy data from global memory
102 * to shared memory or registers.
104 * index expresses the array element that needs to be copied as a "call"
105 * to the array
106 * local_index expresses the corresponding element in the tile
108 * array refers to the original array being copied
109 * local_array is a pointer to the appropriate element in the "array"
110 * array of the ppcg_kernel to which this copy access belongs
113 * for ppcg_kernel_domain statements we have
115 * stmt is the corresponding input statement
117 * n_access is the number of accesses in stmt
118 * access is an array of local information about the accesses
120 struct ppcg_kernel_stmt {
121 enum ppcg_kernel_stmt_type type;
123 union {
124 struct {
125 int read;
126 isl_ast_expr *index;
127 isl_ast_expr *local_index;
128 struct gpu_array_info *array;
129 struct gpu_local_array_info *local_array;
130 } c;
131 struct {
132 struct gpu_stmt *stmt;
134 int n_access;
135 struct ppcg_kernel_access *access;
136 } d;
137 } u;
140 /* Representation of a local variable in a kernel.
142 struct ppcg_kernel_var {
143 struct gpu_array_info *array;
144 enum ppcg_kernel_access_type type;
145 char *name;
146 isl_vec *size;
149 /* Representation of a kernel.
151 * id is the sequence number of the kernel.
153 * the first n_block elements of block_dim represent the size of the block.
155 * grid_size reflects the effect grid size.
157 * context is a parametric set containing the values of the parameters
158 * for which this kernel may be run.
160 * arrays is the set of accessed array elements.
162 * space is the schedule space of the AST context. That is, it represents
163 * the loops of the generated host code containing the kernel launch.
165 * n_array is the total number of arrays in the input program and also
166 * the number of element in the array array.
167 * array contains information about each array that is local
168 * to the current kernel. If an array is not ussed in a kernel,
169 * then the corresponding entry does not contain any information.
171 struct ppcg_kernel {
172 int id;
174 int n_grid;
175 int grid_dim[2];
177 int n_block;
178 int block_dim[3];
180 isl_multi_pw_aff *grid_size;
181 isl_set *context;
183 isl_union_set *arrays;
185 isl_space *space;
187 int n_array;
188 struct gpu_local_array_info *array;
190 int n_var;
191 struct ppcg_kernel_var *var;
193 isl_ast_node *tree;
196 int gpu_array_is_scalar(struct gpu_array_info *array);
197 int gpu_array_is_read_only_scalar(struct gpu_array_info *array);
199 struct gpu_prog *gpu_prog_alloc(isl_ctx *ctx, struct ppcg_scop *scop);
200 void gpu_prog_free(struct gpu_prog *prog);
202 __isl_give isl_set *add_context_from_str(__isl_take isl_set *set,
203 const char *str);
205 __isl_give isl_ast_node *generate_gpu(isl_ctx *ctx, struct gpu_prog *prog,
206 struct ppcg_options *options);
208 #endif