Skip to content

Commit

Permalink
scheduler: simplify schedule constraints with respect to context
Browse files Browse the repository at this point in the history
Before this commit, computing a schedule for the constraints

    [N] -> { A[] -> C[] : N <= 0;
	     A[] -> B[0] : N >= 1; B[N-1] -> C[] : N >= 1 }

would not combine the three statements into a single band,
even if N is known to be non-negative (as specified by the context),
while specializing the constraints to a specific value of N
would result in such a single band.
The reason is that the context was essentially being ignored and
it is then impossible to shift C with respect to B because
N is not known to be non-negative at the point where
the shift is needed.

This commit also does not use the context at that point,
but it does do so at the point where the schedule constraints
are extracted.  In particular, every schedule constraint
is simplified with respect to the context.
This turns the constraint { A[] -> C[] : N <= 0 }
into { A[] -> C[] : N == 0 } and then a shift that is valid
across all constraints can be computed.

For other cases, it may be required to also take into account
the context elsewhere.

Reported-by: le yin <[email protected]>
Signed-off-by: Sven Verdoolaege <[email protected]>
  • Loading branch information
Sven Verdoolaege committed Feb 12, 2023
1 parent d219a7d commit 5d5b77e
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 1 deletion.
13 changes: 12 additions & 1 deletion isl_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@ static isl_stat extract_node(__isl_take isl_set *set, void *user)
}

struct isl_extract_edge_data {
isl_schedule_constraints *sc;
enum isl_edge_type type;
struct isl_sched_graph *graph;
};
Expand Down Expand Up @@ -1249,6 +1250,11 @@ static isl_stat skip_edge(__isl_take isl_map *map, __isl_take isl_map *tagged)
* the union of all the "map" relations
* for which extract_edge is called that result in the same edge->map.
*
* Compute the gist with respect to the context.
* This may remove some constraints on the parameters or
* eliminate some parts of the dependence relation
* that are not relevant on the context.
*
* If the source or the destination node is compressed, then
* intersect both "map" and "tagged" with the constraints that
* were used to construct the compression.
Expand All @@ -1264,7 +1270,9 @@ static isl_stat extract_edge(__isl_take isl_map *map, void *user)
struct isl_sched_graph *graph = data->graph;
struct isl_sched_node *src, *dst;
struct isl_sched_edge *edge;
isl_set *context;
isl_map *tagged = NULL;
isl_schedule_constraints *sc = data->sc;

if (data->type == isl_edge_condition ||
data->type == isl_edge_conditional_validity) {
Expand All @@ -1285,6 +1293,9 @@ static isl_stat extract_edge(__isl_take isl_map *map, void *user)
!isl_sched_graph_is_node(graph, dst))
return skip_edge(map, tagged);

context = isl_schedule_constraints_get_context(sc);
map = isl_map_gist_params(map, context);

if (src->compressed || dst->compressed) {
isl_map *hull;
hull = extract_hull(src, dst);
Expand Down Expand Up @@ -1345,7 +1356,7 @@ isl_stat isl_sched_graph_init(struct isl_sched_graph *graph,
isl_ctx *ctx;
isl_union_set *domain;
isl_union_map *c;
struct isl_extract_edge_data data;
struct isl_extract_edge_data data = { sc };
enum isl_edge_type i;
isl_stat r;
isl_size n;
Expand Down
5 changes: 5 additions & 0 deletions test_inputs/schedule/leyin1.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This is a specialized version of leyin2?.sc (for N = 32),
# showing that a single band is computed.
domain: { A[]; B[0:31]; C[] }
validity: { A[] -> B[0]; B[31] -> C[] }
proximity: { A[] -> B[0]; B[31] -> C[] }
10 changes: 10 additions & 0 deletions test_inputs/schedule/leyin1.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
domain: "{ B[i0] : 0 <= i0 <= 31; C[]; A[] }"
child:
schedule: "[{ B[i0] -> [(i0)]; C[] -> [(31)]; A[] -> [(0)] }]"
permutable: 1
coincident: [ 1 ]
child:
sequence:
- filter: "{ A[] }"
- filter: "{ B[i0] }"
- filter: "{ C[] }"
14 changes: 14 additions & 0 deletions test_inputs/schedule/leyin2a.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This is a generalized version of leyin1.sc,
# with an extra dependence that simplifies away when N = 32.
# However, since N is known to be non-negative, this should still
# produce a similar schedule (with a single band).
# The exact form of the schedule depends on whether the whole-component or
# the incremental scheduler is used.
# This is the incremental scheduler version.
# OPTIONS: --no-schedule-whole-component
domain: [N] -> { A[]; B[0:N-1]; C[] }
context: [N] -> { : N >= 0 }
validity: [N] -> { A[] -> C[] : N <= 0;
A[] -> B[0] : N >= 1; B[N-1] -> C[] : N >= 1 }
proximity: [N] -> { A[] -> C[] : N <= 0;
A[] -> B[0] : N >= 1; B[N-1] -> C[] : N >= 1 }
13 changes: 13 additions & 0 deletions test_inputs/schedule/leyin2a.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
domain: "[N] -> { B[i0] : 0 <= i0 < N; C[]; A[] }"
child:
schedule: "[N] -> [{ B[i0] -> [(1 + i0)]; C[] -> [(N)]; A[] -> [(0)] }]"
permutable: 1
coincident: [ 1 ]
child:
sequence:
- filter: "[N] -> { A[]; B[i0] }"
child:
set:
- filter: "[N] -> { A[] }"
- filter: "[N] -> { B[i0] }"
- filter: "[N] -> { C[] }"
14 changes: 14 additions & 0 deletions test_inputs/schedule/leyin2b.sc
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This is a generalized version of leyin1.sc,
# with an extra dependence that simplifies away when N = 32.
# However, since N is known to be non-negative, this should still
# produce a similar schedule (with a single band).
# The exact form of the schedule depends on whether the whole-component or
# the incremental scheduler is used.
# This is the whole-component scheduler version.
# OPTIONS: --schedule-whole-component
domain: [N] -> { A[]; B[0:N-1]; C[] }
context: [N] -> { : N >= 0 }
validity: [N] -> { A[] -> C[] : N <= 0;
A[] -> B[0] : N >= 1; B[N-1] -> C[] : N >= 1 }
proximity: [N] -> { A[] -> C[] : N <= 0;
A[] -> B[0] : N >= 1; B[N-1] -> C[] : N >= 1 }
10 changes: 10 additions & 0 deletions test_inputs/schedule/leyin2b.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
domain: "[N] -> { B[i0] : 0 <= i0 < N; C[]; A[] }"
child:
schedule: "[N] -> [{ B[i0] -> [(i0)]; C[] -> [(N)]; A[] -> [(0)] }]"
permutable: 1
coincident: [ 1 ]
child:
sequence:
- filter: "[N] -> { A[] }"
- filter: "[N] -> { C[] }"
- filter: "[N] -> { B[i0] }"

0 comments on commit 5d5b77e

Please sign in to comment.