scheduler: allow to bound the coefficients in the calculated schedule
authorTobias Grosser <tobias@grosser.es>
Sun, 19 Feb 2012 13:05:50 +0000 (14:05 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Sun, 19 Feb 2012 17:30:29 +0000 (18:30 +0100)
isl already supports the bounding of the constant term of the calculated
schedule, but within polybench there are several cases where bounding
the coefficients of parameter and variable dimensions is also needed.

With a bound of 20 Polly can run the isl scheduler on all polybench 2.0 kernels
and takes for each less than 5 seconds, whereas without the bound five test
cases had scheduling times larger than 40 seconds. This is still slower, than
scheduling with gist simplified dependences but it yields better results.
The bounded, non-gist-simplified schedule yields for dynprog, lu, reg_detect
and trmm to faster code compared to scheduling with gist simplified
dependences. For gramschmidt it yields slower code.

Signed-off-by: Tobias Grosser <tobias@grosser.es>
Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>
doc/user.pod
include/isl/schedule.h
isl_options.c
isl_options_private.h
isl_schedule.c

index 53371c5..ddbdd56 100644 (file)
@@ -4206,6 +4206,10 @@ A representation of the band can be printed using
 =head3 Options
 
        #include <isl/schedule.h>
+       int isl_options_set_schedule_max_coefficient(
+               isl_ctx *ctx, int val);
+       int isl_options_get_schedule_max_coefficient(
+               isl_ctx *ctx);
        int isl_options_set_schedule_max_constant_term(
                isl_ctx *ctx, int val);
        int isl_options_get_schedule_max_constant_term(
@@ -4230,6 +4234,15 @@ A representation of the band can be printed using
 
 =over
 
+=item * schedule_max_coefficient
+
+This option enforces that the coefficients for variable and parameter
+dimensions in the calculated schedule are not larger than the specified value.
+This option can significantly increase the speed of the scheduling calculation
+and may also prevent fusing of unrelated dimensions. A value of -1 means that
+this option does not introduce bounds on the variable or parameter
+coefficients.
+
 =item * schedule_max_constant_term
 
 This option enforces that the constant coefficients in the calculated schedule
index a4fee32..027bc1c 100644 (file)
@@ -12,6 +12,9 @@ extern "C" {
 struct isl_schedule;
 typedef struct isl_schedule isl_schedule;
 
+int isl_options_set_schedule_max_coefficient(isl_ctx *ctx, int val);
+int isl_options_get_schedule_max_coefficient(isl_ctx *ctx);
+
 int isl_options_set_schedule_max_constant_term(isl_ctx *ctx, int val);
 int isl_options_get_schedule_max_constant_term(isl_ctx *ctx);
 
index 7d82b08..ad3c280 100644 (file)
@@ -137,6 +137,10 @@ ISL_ARG_BOOL(struct isl_options, pip_symmetry, 0, "pip-symmetry", 1,
        "detect simple symmetries in PIP input")
 ISL_ARG_CHOICE(struct isl_options, convex, 0, "convex-hull", \
        convex, ISL_CONVEX_HULL_WRAP, "convex hull algorithm to use")
+ISL_ARG_INT(struct isl_options, schedule_max_coefficient, 0,
+       "schedule-max-coefficient", "limit", -1, "Only consider schedules "
+       "where the coefficients of the variable and parameter dimensions "
+        "do not exceed <limit>. A value of -1 allows arbitrary coefficients.")
 ISL_ARG_INT(struct isl_options, schedule_max_constant_term, 0,
        "schedule-max-constant-term", "limit", -1, "Only consider schedules "
        "where the coefficients of the constant dimension do not exceed "
@@ -179,6 +183,11 @@ ISL_CTX_GET_BOOL_DEF(isl_options, struct isl_options, isl_options_args,
        gbr_only_first)
 
 ISL_CTX_SET_INT_DEF(isl_options, struct isl_options, isl_options_args,
+       schedule_max_coefficient)
+ISL_CTX_GET_INT_DEF(isl_options, struct isl_options, isl_options_args,
+       schedule_max_coefficient)
+
+ISL_CTX_SET_INT_DEF(isl_options, struct isl_options, isl_options_args,
        schedule_max_constant_term)
 ISL_CTX_GET_INT_DEF(isl_options, struct isl_options, isl_options_args,
        schedule_max_constant_term)
index 60a6524..e6dce11 100644 (file)
@@ -45,6 +45,7 @@ struct isl_options {
        #define                 ISL_CONVEX_HULL_FM      1
        int                     convex;
 
+       int                     schedule_max_coefficient;
        int                     schedule_max_constant_term;
        int                     schedule_parametric;
        int                     schedule_outer_zero_distance;
index 9a2d757..fae08f4 100644 (file)
@@ -1094,6 +1094,43 @@ static int count_constraints(struct isl_sched_graph *graph,
        return 0;
 }
 
+/* Add constraints that bound the values of the variable and parameter
+ * coefficients of the schedule.
+ *
+ * The maximal value of the coefficients is defined by the option
+ * 'schedule_max_coefficient'.
+ */
+static int add_bound_coefficient_constraints(isl_ctx *ctx,
+       struct isl_sched_graph *graph)
+{
+       int i, j, k;
+       int max_coefficient;
+       int total;
+
+       max_coefficient = ctx->opt->schedule_max_coefficient;
+
+       if (max_coefficient == -1)
+               return 0;
+
+       total = isl_basic_set_total_dim(graph->lp);
+
+       for (i = 0; i < graph->n; ++i) {
+               struct isl_sched_node *node = &graph->node[i];
+               for (j = 0; j < 2 * node->nparam + 2 * node->nvar; ++j) {
+                       int dim;
+                       k = isl_basic_set_alloc_inequality(graph->lp);
+                       if (k < 0)
+                               return -1;
+                       dim = 1 + node->start + 1 + j;
+                       isl_seq_clr(graph->lp->ineq[k], 1 +  total);
+                       isl_int_set_si(graph->lp->ineq[k][dim], -1);
+                       isl_int_set_si(graph->lp->ineq[k][0], max_coefficient);
+               }
+       }
+
+       return 0;
+}
+
 /* Construct an ILP problem for finding schedule coefficients
  * that result in non-negative, but small dependence distances
  * over all dependences.
@@ -1140,8 +1177,10 @@ static int setup_lp(isl_ctx *ctx, struct isl_sched_graph *graph,
        int param_pos;
        int n_eq, n_ineq;
        int max_constant_term;
+       int max_coefficient;
 
        max_constant_term = ctx->opt->schedule_max_constant_term;
+       max_coefficient = ctx->opt->schedule_max_coefficient;
 
        parametric = ctx->opt->schedule_parametric;
        nparam = isl_space_dim(graph->node[0].dim, isl_dim_param);
@@ -1163,6 +1202,10 @@ static int setup_lp(isl_ctx *ctx, struct isl_sched_graph *graph,
        n_eq += 2 + parametric + force_zero;
        if (max_constant_term != -1)
                n_ineq += graph->n;
+       if (max_coefficient != -1)
+               for (i = 0; i < graph->n; ++i)
+                       n_ineq += 2 * graph->node[i].nparam +
+                                 2 * graph->node[i].nvar;
 
        graph->lp = isl_basic_set_alloc_space(dim, 0, n_eq, n_ineq);
 
@@ -1221,6 +1264,8 @@ static int setup_lp(isl_ctx *ctx, struct isl_sched_graph *graph,
                        isl_int_set_si(graph->lp->ineq[k][0], max_constant_term);
                }
 
+       if (add_bound_coefficient_constraints(ctx, graph) < 0)
+               return -1;
        if (add_all_validity_constraints(graph) < 0)
                return -1;
        if (add_all_proximity_constraints(graph) < 0)