1 #include <isl/aff.h> 2 #include <isl/map.h> 3 4 #include "gpu_array_tile.h" 5 gpu_array_tile_free(struct gpu_array_tile * tile)6struct gpu_array_tile *gpu_array_tile_free(struct gpu_array_tile *tile) 7 { 8 int j; 9 10 if (!tile) 11 return NULL; 12 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); 18 } 19 free(tile->bound); 20 isl_multi_aff_free(tile->tiling); 21 free(tile); 22 23 return NULL; 24 } 25 26 /* Create a gpu_array_tile for an array of dimension "n_index". 27 */ gpu_array_tile_create(isl_ctx * ctx,int n_index)28struct gpu_array_tile *gpu_array_tile_create(isl_ctx *ctx, int n_index) 29 { 30 int i; 31 struct gpu_array_tile *tile; 32 33 tile = isl_calloc_type(ctx, struct gpu_array_tile); 34 if (!tile) 35 return NULL; 36 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); 41 42 tile->n = n_index; 43 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; 49 } 50 51 return tile; 52 } 53 54 /* Compute the size of the tile specified by "tile" 55 * in number of elements and return the result. 56 */ gpu_array_tile_size(struct gpu_array_tile * tile)57__isl_give isl_val *gpu_array_tile_size(struct gpu_array_tile *tile) 58 { 59 int i; 60 isl_val *size; 61 62 if (!tile) 63 return NULL; 64 65 size = isl_val_one(tile->ctx); 66 67 for (i = 0; i < tile->n; ++i) 68 size = isl_val_mul(size, isl_val_copy(tile->bound[i].size)); 69 70 return size; 71 } 72