separate out CUDA printing
[ppcg.git] / gpu.h
blob50f1284291c9cf27d64953c8128e1362d4e5bacd
1 #ifndef _GPU_H
2 #define _GPU_H
4 #include <pet.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 pet_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 * domain is the (parametric) domain of index and local_index
106 * index expresses the array element that needs to be copied in terms
107 * of parameters
108 * local_index expresses the corresponding element in the tile
110 * array refers to the original array being copied
111 * local_array is a pointer to the appropriate element in the "array"
112 * array of the ppcg_kernel to which this copy access belongs
115 * for ppcg_kernel_domain statements we have
117 * stmt is the corresponding input statement
119 * n_access is the number of accesses in stmt
120 * access is an array of local information about the accesses
122 struct ppcg_kernel_stmt {
123 enum ppcg_kernel_stmt_type type;
125 union {
126 struct {
127 int read;
128 isl_set *domain;
129 isl_pw_multi_aff *index;
130 isl_pw_multi_aff *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 contains the values of the block ids.
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_set *grid;
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 pet_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