gpu_array_info: replace read_only by read_only_scalar
[ppcg.git] / gpu.h
blob4789f04f72992fd5a0e9332293de4768dee7979f
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 /* The array data space. */
12 isl_space *space;
13 /* Element type. */
14 char *type;
15 /* Element size. */
16 int size;
17 /* Name of the array. */
18 char *name;
19 /* Extent of the array that needs to be copied. */
20 isl_set *extent;
21 /* Number of indices. */
22 unsigned n_index;
23 /* For each index, a bound on "extent" in that direction. */
24 isl_pw_aff **bound;
26 /* All references to this array; point to elements of a linked list. */
27 int n_ref;
28 struct gpu_stmt_access **refs;
30 /* The reference groups associated to this array. */
31 int n_group;
32 struct gpu_array_ref_group **groups;
34 /* Is this a scalar that is read-only within the entire program? */
35 int read_only_scalar;
37 /* Is the array local to the scop? */
38 int local;
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);
49 struct gpu_prog {
50 isl_ctx *ctx;
52 struct ppcg_scop *scop;
54 /* Set of parameter values */
55 isl_set *context;
57 /* All read accesses in the entire program */
58 isl_union_map *read;
60 /* All write accesses in the entire program */
61 isl_union_map *write;
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 */
69 int n_stmts;
70 struct gpu_stmt *stmts;
72 int n_array;
73 struct gpu_array_info *array;
76 enum ppcg_kernel_access_type {
77 ppcg_access_global,
78 ppcg_access_shared,
79 ppcg_access_private
82 enum ppcg_kernel_stmt_type {
83 ppcg_kernel_copy,
84 ppcg_kernel_domain,
85 ppcg_kernel_sync
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;
117 union {
118 struct {
119 int read;
120 isl_ast_expr *index;
121 isl_ast_expr *local_index;
122 struct gpu_array_info *array;
123 struct gpu_local_array_info *local_array;
124 } c;
125 struct {
126 struct gpu_stmt *stmt;
127 isl_id_to_ast_expr *ref2expr;
128 } d;
129 } u;
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;
137 char *name;
138 isl_vec *size;
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
146 * of the block.
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.
164 struct ppcg_kernel {
165 int id;
167 int n_block;
168 int block_dim[3];
170 isl_multi_pw_aff *grid_size;
171 isl_set *context;
173 isl_union_set *arrays;
175 isl_space *space;
177 int n_array;
178 struct gpu_local_array_info *array;
180 int n_var;
181 struct ppcg_kernel_var *var;
183 isl_ast_node *tree;
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);
198 #endif