gpu.c: accessed_by_domain: clarify nature of domain argument
[ppcg.git] / gpu_array_tile.c
blobb358f2b8e4a7261e70487e9f9e8930bec6334c76
1 #include <isl/aff.h>
2 #include <isl/map.h>
4 #include "gpu_array_tile.h"
6 struct gpu_array_tile *gpu_array_tile_free(struct gpu_array_tile *tile)
8 int j;
10 if (!tile)
11 return NULL;
13 for (j = 0; j < tile->n; ++j) {
14 isl_val_free(tile->bound[j].size);
15 isl_val_free(tile->bound[j].stride);
16 isl_aff_free(tile->bound[j].lb);
17 isl_aff_free(tile->bound[j].shift);
19 free(tile->bound);
20 isl_multi_aff_free(tile->tiling);
21 free(tile);
23 return NULL;
26 /* Create a gpu_array_tile for an array of dimension "n_index".
28 struct gpu_array_tile *gpu_array_tile_create(isl_ctx *ctx, int n_index)
30 int i;
31 struct gpu_array_tile *tile;
33 tile = isl_calloc_type(ctx, struct gpu_array_tile);
34 if (!tile)
35 return NULL;
37 tile->ctx = ctx;
38 tile->bound = isl_alloc_array(ctx, struct gpu_array_bound, n_index);
39 if (!tile->bound)
40 return gpu_array_tile_free(tile);
42 tile->n = n_index;
44 for (i = 0; i < n_index; ++i) {
45 tile->bound[i].size = NULL;
46 tile->bound[i].lb = NULL;
47 tile->bound[i].stride = NULL;
48 tile->bound[i].shift = NULL;
51 return tile;
54 /* Compute the size of the tile specified by "tile"
55 * in number of elements and return the result.
57 __isl_give isl_val *gpu_array_tile_size(struct gpu_array_tile *tile)
59 int i;
60 isl_val *size;
62 if (!tile)
63 return NULL;
65 size = isl_val_one(tile->ctx);
67 for (i = 0; i < tile->n; ++i)
68 size = isl_val_mul(size, isl_val_copy(tile->bound[i].size));
70 return size;