From 2b3dd8305f1d8e3956bd63d8d521f3b5076b05be Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Mon, 29 Jun 2015 10:54:07 +0200 Subject: [PATCH] gpu backend: concentrate decision about which tile to use in a single function If both a private tile and a shared tile have been computed, then the private tile ends up being used. This choice is repeated in several places, making it difficult to chance the policy. Concentrate the decision in a single new function called gpu_array_ref_group_type. Signed-off-by: Sven Verdoolaege --- gpu.c | 39 ++++++++++++++++++++++----------------- gpu_group.c | 39 ++++++++++++++++++++++++++++----------- gpu_group.h | 7 ++++--- 3 files changed, 54 insertions(+), 31 deletions(-) diff --git a/gpu.c b/gpu.c index dbaff5a..5b91422 100644 --- a/gpu.c +++ b/gpu.c @@ -929,11 +929,11 @@ static void check_shared_memory_bound(struct ppcg_kernel *kernel) for (j = 0; j < local->n_group; ++j) { struct gpu_array_ref_group *group; + enum ppcg_group_access_type type; group = local->groups[j]; - if (group->private_tile) - continue; - if (!group->shared_tile) + type = gpu_array_ref_group_type(group); + if (type != ppcg_access_shared) continue; size = gpu_array_tile_size(group->shared_tile); @@ -1219,12 +1219,8 @@ static void create_kernel_var(isl_ctx *ctx, struct gpu_array_ref_group *group, var->array = group->array; - tile = group->private_tile; - var->type = ppcg_access_private; - if (!tile) { - tile = group->shared_tile; - var->type = ppcg_access_shared; - } + var->type = gpu_array_ref_group_type(group); + tile = gpu_array_ref_group_tile(group); p = isl_printer_to_str(ctx); p = gpu_array_ref_group_print_name(group, p); @@ -1248,7 +1244,10 @@ static int create_kernel_vars(struct ppcg_kernel *kernel) for (j = 0; j < array->n_group; ++j) { struct gpu_array_ref_group *group = array->groups[j]; - if (group->private_tile || group->shared_tile) + enum ppcg_group_access_type type; + + type = gpu_array_ref_group_type(group); + if (type != ppcg_access_global) ++n; } } @@ -1264,7 +1263,10 @@ static int create_kernel_vars(struct ppcg_kernel *kernel) for (j = 0; j < array->n_group; ++j) { struct gpu_array_ref_group *group = array->groups[j]; - if (!group->private_tile && !group->shared_tile) + enum ppcg_group_access_type type; + + type = gpu_array_ref_group_type(group); + if (type == ppcg_access_global) continue; create_kernel_var(kernel->ctx, group, &kernel->var[n]); ++n; @@ -1580,9 +1582,7 @@ static __isl_give isl_multi_pw_aff *transform_index( return index; } - tile = group->private_tile; - if (!tile) - tile = group->shared_tile; + tile = gpu_array_ref_group_tile(group); data->global = !tile; if (!tile) return index; @@ -2517,11 +2517,13 @@ static __isl_give isl_union_set *collect_non_private_tagged_writes( for (j = 0; j < array->n_group; ++j) { struct gpu_array_ref_group *group = array->groups[j]; + enum ppcg_group_access_type type; isl_union_set *writes_ij; if (!group->write) continue; - if (group->private_tile) + type = gpu_array_ref_group_type(group); + if (type == ppcg_access_private) continue; writes_ij = group_tagged_writes(group); writes = isl_union_set_union(writes, writes_ij); @@ -3390,9 +3392,12 @@ static __isl_give isl_schedule_node *add_copies_group( struct ppcg_kernel *kernel, struct gpu_array_ref_group *group, __isl_take isl_schedule_node *node, int read) { - if (group->private_tile) + enum ppcg_group_access_type type; + + type = gpu_array_ref_group_type(group); + if (type == ppcg_access_private) return add_copies_group_private(kernel, group, node, read); - if (group->shared_tile) + if (type == ppcg_access_shared) return add_copies_group_shared(kernel, group, node, read); return node; } diff --git a/gpu_group.c b/gpu_group.c index 6b940c6..04707b1 100644 --- a/gpu_group.c +++ b/gpu_group.c @@ -25,10 +25,12 @@ __isl_give isl_printer *gpu_array_ref_group_print_name( struct gpu_array_ref_group *group, __isl_take isl_printer *p) { int global = 0; + enum ppcg_group_access_type type; - if (group->private_tile) + type = gpu_array_ref_group_type(group); + if (type == ppcg_access_private) p = isl_printer_print_str(p, "private_"); - else if (group->shared_tile) + else if (type == ppcg_access_shared) p = isl_printer_print_str(p, "shared_"); else global = 1; @@ -65,19 +67,36 @@ __isl_give isl_union_map *gpu_array_ref_group_access_relation( return access; } -/* Return the effective gpu_array_tile associated to "group" or - * NULL if there is no such gpu_array_tile. +/* Should this array reference group be mapped to private, shared or global + * memory? * If we have computed both a private and a shared tile, then - * the private tile is used. + * the private tile is used, i.e., the group is mapped to private memory. */ -struct gpu_array_tile *gpu_array_ref_group_tile( +enum ppcg_group_access_type gpu_array_ref_group_type( struct gpu_array_ref_group *group) { if (group->private_tile) - return group->private_tile; + return ppcg_access_private; if (group->shared_tile) + return ppcg_access_shared; + return ppcg_access_global; +} + + +/* Return the effective gpu_array_tile associated to "group" or + * NULL if there is no such gpu_array_tile. + */ +struct gpu_array_tile *gpu_array_ref_group_tile( + struct gpu_array_ref_group *group) +{ + switch (gpu_array_ref_group_type(group)) { + case ppcg_access_global: + return NULL; + case ppcg_access_shared: return group->shared_tile; - return NULL; + case ppcg_access_private: + return group->private_tile; + } } /* Does the tile associated to "group" require unrolling of the schedule @@ -1576,9 +1595,7 @@ void gpu_array_ref_group_compute_tiling(struct gpu_array_ref_group *group) isl_printer *p; char *local_name; - tile = group->private_tile; - if (!tile) - tile = group->shared_tile; + tile = gpu_array_ref_group_tile(group); if (!tile) return; diff --git a/gpu_group.h b/gpu_group.h index dc200b4..2def75f 100644 --- a/gpu_group.h +++ b/gpu_group.h @@ -11,9 +11,8 @@ * Note that if both private_tile and shared_tile are set, then shared_tile * is only used inside group_common_shared_memory_tile. * "depth" reflects the number of schedule dimensions that affect the tile - * (private_tile if set; shared_tile if shared_tile is set and private_tile - * is not). The copying into and/or out of the tile is performed at that - * depth. + * (as selected by gpu_array_ref_group_tile). + * The copying into and/or out of the tile is performed at that depth. */ struct gpu_array_ref_group { /* The references in this group access this local array. */ @@ -59,6 +58,8 @@ void gpu_array_ref_group_compute_tiling(struct gpu_array_ref_group *group); __isl_give isl_union_map *gpu_array_ref_group_access_relation( struct gpu_array_ref_group *group, int read, int write); int gpu_array_ref_group_requires_unroll(struct gpu_array_ref_group *group); +enum ppcg_group_access_type gpu_array_ref_group_type( + struct gpu_array_ref_group *group); struct gpu_array_tile *gpu_array_ref_group_tile( struct gpu_array_ref_group *group); struct gpu_array_ref_group *gpu_array_ref_group_free( -- 2.11.4.GIT