gpu_print: make linearization of fixed sized arrays optional
[ppcg.git] / gpu.h
blob8c00bbd468c13616c6edb3cd566de65c9acad07d
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;
40 /* Should the array be linearized? */
41 int linearize;
44 /* For each index i, array->bound[i] specialized to the current kernel. */
45 struct gpu_local_array_info {
46 isl_pw_aff_list *bound;
49 __isl_give isl_ast_expr *gpu_local_array_info_linearize_index(
50 struct gpu_local_array_info *array, __isl_take isl_ast_expr *expr);
52 struct gpu_prog {
53 isl_ctx *ctx;
55 struct ppcg_scop *scop;
57 /* Set of parameter values */
58 isl_set *context;
60 /* All read accesses in the entire program */
61 isl_union_map *read;
63 /* All write accesses in the entire program */
64 isl_union_map *write;
66 /* Set of array elements that need to be copied in. */
67 isl_union_set *copy_in;
68 /* Set of array elements that need to be copied out. */
69 isl_union_set *copy_out;
71 /* Array of statements */
72 int n_stmts;
73 struct gpu_stmt *stmts;
75 int n_array;
76 struct gpu_array_info *array;
79 enum ppcg_kernel_access_type {
80 ppcg_access_global,
81 ppcg_access_shared,
82 ppcg_access_private
85 enum ppcg_kernel_stmt_type {
86 ppcg_kernel_copy,
87 ppcg_kernel_domain,
88 ppcg_kernel_sync
91 /* Representation of special statements, in particular copy statements
92 * and __syncthreads statements, inside a kernel.
94 * type represents the kind of statement
97 * for ppcg_kernel_copy statements we have
99 * read is set if the statement should copy data from global memory
100 * to shared memory or registers.
102 * index expresses an access to the array element that needs to be copied
103 * local_index expresses the corresponding element in the tile
105 * array refers to the original array being copied
106 * local_array is a pointer to the appropriate element in the "array"
107 * array of the ppcg_kernel to which this copy access belongs
110 * for ppcg_kernel_domain statements we have
112 * stmt is the corresponding input statement
114 * n_access is the number of accesses in stmt
115 * access is an array of local information about the accesses
117 struct ppcg_kernel_stmt {
118 enum ppcg_kernel_stmt_type type;
120 union {
121 struct {
122 int read;
123 isl_ast_expr *index;
124 isl_ast_expr *local_index;
125 struct gpu_array_info *array;
126 struct gpu_local_array_info *local_array;
127 } c;
128 struct {
129 struct gpu_stmt *stmt;
130 isl_id_to_ast_expr *ref2expr;
131 } d;
132 } u;
135 /* Representation of a local variable in a kernel.
137 struct ppcg_kernel_var {
138 struct gpu_array_info *array;
139 enum ppcg_kernel_access_type type;
140 char *name;
141 isl_vec *size;
144 /* Representation of a kernel.
146 * id is the sequence number of the kernel.
148 * the first n_block elements of block_dim represent the effective size
149 * of the block.
151 * grid_size reflects the effective grid size.
153 * context is a parametric set containing the values of the parameters
154 * for which this kernel may be run.
156 * arrays is the set of accessed array elements.
158 * space is the schedule space of the AST context. That is, it represents
159 * the loops of the generated host code containing the kernel launch.
161 * n_array is the total number of arrays in the input program and also
162 * the number of element in the array array.
163 * array contains information about each array that is local
164 * to the current kernel. If an array is not used in a kernel,
165 * then the corresponding entry does not contain any information.
167 struct ppcg_kernel {
168 int id;
170 int n_block;
171 int block_dim[3];
173 isl_multi_pw_aff *grid_size;
174 isl_set *context;
176 isl_union_set *arrays;
178 isl_space *space;
180 int n_array;
181 struct gpu_local_array_info *array;
183 int n_var;
184 struct ppcg_kernel_var *var;
186 isl_ast_node *tree;
189 int gpu_array_is_scalar(struct gpu_array_info *array);
190 int gpu_array_is_read_only_scalar(struct gpu_array_info *array);
192 struct gpu_prog *gpu_prog_alloc(isl_ctx *ctx, struct ppcg_scop *scop);
193 void *gpu_prog_free(struct gpu_prog *prog);
195 int generate_gpu(isl_ctx *ctx, const char *input, FILE *out,
196 struct ppcg_options *options,
197 __isl_give isl_printer *(*print)(__isl_take isl_printer *p,
198 struct gpu_prog *prog, __isl_keep isl_ast_node *tree,
199 void *user), void *user);
201 #endif