extract out gpu_local_array_info_linearize_index
[ppcg.git] / gpu.h
blobec29cf2fd0551126b10aa038b6ea5e83e4dc3b4b
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 __isl_give isl_ast_expr *gpu_local_array_info_linearize_index(
46 struct gpu_local_array_info *array, __isl_take isl_ast_expr *expr);
48 struct gpu_prog {
49 isl_ctx *ctx;
51 struct ppcg_scop *scop;
53 /* Set of parameter values */
54 isl_set *context;
56 /* All read accesses in the entire program */
57 isl_union_map *read;
59 /* All write accesses in the entire program */
60 isl_union_map *write;
62 /* Set of array elements that need to be copied in. */
63 isl_union_set *copy_in;
64 /* Set of array elements that need to be copied out. */
65 isl_union_set *copy_out;
67 /* Array of statements */
68 int n_stmts;
69 struct gpu_stmt *stmts;
71 int n_array;
72 struct gpu_array_info *array;
75 enum ppcg_kernel_access_type {
76 ppcg_access_global,
77 ppcg_access_shared,
78 ppcg_access_private
81 enum ppcg_kernel_stmt_type {
82 ppcg_kernel_copy,
83 ppcg_kernel_domain,
84 ppcg_kernel_sync
87 /* Representation of special statements, in particular copy statements
88 * and __syncthreads statements, inside a kernel.
90 * type represents the kind of statement
93 * for ppcg_kernel_copy statements we have
95 * read is set if the statement should copy data from global memory
96 * to shared memory or registers.
98 * index expresses an access to the array element that needs to be copied
99 * local_index expresses the corresponding element in the tile
101 * array refers to the original array being copied
102 * local_array is a pointer to the appropriate element in the "array"
103 * array of the ppcg_kernel to which this copy access belongs
106 * for ppcg_kernel_domain statements we have
108 * stmt is the corresponding input statement
110 * n_access is the number of accesses in stmt
111 * access is an array of local information about the accesses
113 struct ppcg_kernel_stmt {
114 enum ppcg_kernel_stmt_type type;
116 union {
117 struct {
118 int read;
119 isl_ast_expr *index;
120 isl_ast_expr *local_index;
121 struct gpu_array_info *array;
122 struct gpu_local_array_info *local_array;
123 } c;
124 struct {
125 struct gpu_stmt *stmt;
126 isl_id_to_ast_expr *ref2expr;
127 } d;
128 } u;
131 /* Representation of a local variable in a kernel.
133 struct ppcg_kernel_var {
134 struct gpu_array_info *array;
135 enum ppcg_kernel_access_type type;
136 char *name;
137 isl_vec *size;
140 /* Representation of a kernel.
142 * id is the sequence number of the kernel.
144 * the first n_block elements of block_dim represent the effective size
145 * of the block.
147 * grid_size reflects the effective grid size.
149 * context is a parametric set containing the values of the parameters
150 * for which this kernel may be run.
152 * arrays is the set of accessed array elements.
154 * space is the schedule space of the AST context. That is, it represents
155 * the loops of the generated host code containing the kernel launch.
157 * n_array is the total number of arrays in the input program and also
158 * the number of element in the array array.
159 * array contains information about each array that is local
160 * to the current kernel. If an array is not ussed in a kernel,
161 * then the corresponding entry does not contain any information.
163 struct ppcg_kernel {
164 int id;
166 int n_block;
167 int block_dim[3];
169 isl_multi_pw_aff *grid_size;
170 isl_set *context;
172 isl_union_set *arrays;
174 isl_space *space;
176 int n_array;
177 struct gpu_local_array_info *array;
179 int n_var;
180 struct ppcg_kernel_var *var;
182 isl_ast_node *tree;
185 int gpu_array_is_scalar(struct gpu_array_info *array);
186 int gpu_array_is_read_only_scalar(struct gpu_array_info *array);
188 struct gpu_prog *gpu_prog_alloc(isl_ctx *ctx, struct ppcg_scop *scop);
189 void *gpu_prog_free(struct gpu_prog *prog);
191 int generate_gpu(isl_ctx *ctx, const char *input, FILE *out,
192 struct ppcg_options *options,
193 __isl_give isl_printer *(*print)(__isl_take isl_printer *p,
194 struct gpu_prog *prog, __isl_keep isl_ast_node *tree,
195 void *user), void *user);
197 #endif