isl and How to Solve Bart’s Parametric Integer Programming Problem Sven Verdoolaege

Transcription

isl and How to Solve Bart’s Parametric Integer Programming Problem Sven Verdoolaege
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
isl and How to Solve Bart’s Parametric Integer
Programming Problem
Sven Verdoolaege
October 30, 2009
1 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Outline
1
Motivation
2
isl and CLooG
3
Parametric Integer Programming
What?
Why?
How?
Observations
4
Improvements
piplib
barvinok
isl
5
Bart’s Problem
6
Conclusions
October 30, 2009
2 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Outline
1
Motivation
2
isl and CLooG
3
Parametric Integer Programming
What?
Why?
How?
Observations
4
Improvements
piplib
barvinok
isl
5
Bart’s Problem
6
Conclusions
October 30, 2009
3 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Integer Set Library
isl is an
LGPL
thread-safe
C
library for manipulating integer sets and relations
bounded by affine constraints
involving parameters and
existentially quantified variables
Supported operations include
basic operations such as intersection, union and set difference
integer projection
set coalescing
convex hull
integer affine hull
computing the lexicographic minimum of a relation,
4 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
5 / 37
Two Program Analysis and Transformation Tools
Why do we need an integer set library?
Equivalence checker
◮
◮
◮
Checks the equivalence of two programs represented in the polyhedral
model
Proves output is the same given that input is the same
Maintains maps between statement iterations of both programs that
should be proven to produce the same result
Requirements
◮
◮
manipulations on integer sets/maps
explicit support for existentially quantified variables
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
5 / 37
Two Program Analysis and Transformation Tools
Why do we need an integer set library?
Equivalence checker
◮
◮
◮
Checks the equivalence of two programs represented in the polyhedral
model
Proves output is the same given that input is the same
Maintains maps between statement iterations of both programs that
should be proven to produce the same result
Requirements
◮
◮
manipulations on integer sets/maps
explicit support for existentially quantified variables
CLooG
◮
Generates code for scanning integer points in polyhedra (iteration
domains)
Requirements
◮
◮
manipulations on integer sets
⇒ remove redundant constraints/code
explicit support for existentially quantified variables
⇒ replace some loops by guards
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Why not use a double description based library?
E.g., PolyLib, PPL, (polymake)
Who needs vertices anyway?
◮
◮
Very useful for LattE macchiato/barvinok style counting
(but neither equivalence checking or CLooG needs any counting)
Some operations can be performed more efficiently on explicit
representation
But:
⋆
⋆
Computing the dual can be costly
Double description requires more space
⇒ trade-off
(sets used in equivalence checking and CLooG usually have few
constraints)
6 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Why not use a double description based library?
E.g., PolyLib, PPL, (polymake)
Who needs vertices anyway?
◮
◮
Very useful for LattE macchiato/barvinok style counting
(but neither equivalence checking or CLooG needs any counting)
Some operations can be performed more efficiently on explicit
representation
But:
⋆
⋆
Computing the dual can be costly
Double description requires more space
⇒ trade-off
(sets used in equivalence checking and CLooG usually have few
constraints)
Usually focus on rational values
Little/no support for existentially quantified variables
6 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
7 / 37
Why do we need existentially quantified variables?
Modeling some problems
Which array elements are accessed in this loop?
for (j = 1; j <= s; ++j)
for (i = 1; i <= 8; ++i)
a[6i+9j-7] = a[6i+9j-7] + 5;
S(s) = {l ∈ Z | ∃i, j ∈ Z : l = 6i + 9j − 7 ∧ 1 ≤ j ≤ s ∧ 1 ≤ i ≤ 8}
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
7 / 37
Why do we need existentially quantified variables?
Modeling some problems
Which array elements are accessed in this loop?
for (j = 1; j <= s; ++j)
for (i = 1; i <= 8; ++i)
a[6i+9j-7] = a[6i+9j-7] + 5;
S(s) = {l ∈ Z | ∃i, j ∈ Z : l = 6i + 9j − 7 ∧ 1 ≤ j ≤ s ∧ 1 ≤ i ≤ 8}
Especially integer divisions/remainders
E.g., i % 10 <= 6
i
i − 10
≤6
10
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
7 / 37
Why do we need existentially quantified variables?
Modeling some problems
Which array elements are accessed in this loop?
for (j = 1; j <= s; ++j)
for (i = 1; i <= 8; ++i)
a[6i+9j-7] = a[6i+9j-7] + 5;
S(s) = {l ∈ Z | ∃i, j ∈ Z : l = 6i + 9j − 7 ∧ 1 ≤ j ≤ s ∧ 1 ≤ i ≤ 8}
Especially integer divisions/remainders
E.g., i % 10 <= 6
i
i − 10
≤6
10
i − 10α ≤ 6
with i − 9 ≤ 10α ≤ i
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
7 / 37
Why do we need existentially quantified variables?
Modeling some problems
Which array elements are accessed in this loop?
for (j = 1; j <= s; ++j)
for (i = 1; i <= 8; ++i)
a[6i+9j-7] = a[6i+9j-7] + 5;
S(s) = {l ∈ Z | ∃i, j ∈ Z : l = 6i + 9j − 7 ∧ 1 ≤ j ≤ s ∧ 1 ≤ i ≤ 8}
Especially integer divisions/remainders
E.g., i % 10 <= 6
i
i − 10
≤6
10
i − 10α ≤ 6
with i − 9 ≤ 10α ≤ i
◮
◮
May appear in original code
May be introduced by (PIP-based) dependence analysis
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Outline
1
Motivation
2
isl and CLooG
3
Parametric Integer Programming
What?
Why?
How?
Observations
4
Improvements
piplib
barvinok
isl
5
Bart’s Problem
6
Conclusions
October 30, 2009
8 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
CLooG Example
S1: {(i, j) | 1 ≤ i ≤ n ≤ m ∧ j = i}
S2: {(i, j) | 1 ≤ i ≤ n ≤ m ∧ i ≤ j ≤ n}
S3: {(i, j) | 1 ≤ i ≤ m ∧ j = n ≤ m}
j
i
October 30, 2009
9 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
CLooG Example
S1: {(i, j) | 1 ≤ i ≤ n ≤ m ∧ j = i}
S2: {(i, j) | 1 ≤ i ≤ n ≤ m ∧ i ≤ j ≤ n}
S3: {(i, j) | 1 ≤ i ≤ m ∧ j = n ≤ m}
j
i
October 30, 2009
9 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
CLooG Example
S1: {(i, j) | 1 ≤ i ≤ n ≤ m ∧ j = i}
S2: {(i, j) | 1 ≤ i ≤ n ≤ m ∧ i ≤ j ≤ n}
S3: {(i, j) | 1 ≤ i ≤ m ∧ j = n ≤ m}
j
i
October 30, 2009
9 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
CLooG Example
S1: {(i, j) | 1 ≤ i ≤ n ≤ m ∧ j = i}
S2: {(i, j) | 1 ≤ i ≤ n ≤ m ∧ i ≤ j ≤ n}
S3: {(i, j) | 1 ≤ i ≤ m ∧ j = n ≤ m}
j
for ( i =1; i <= m ; i ++) {
if ( i <= n ) {
S1 (i , i );
}
for ( j = i ;j <= n ; j ++) {
S2 ( i );
}
S3 (i , n );
}
i
October 30, 2009
9 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
CLooG Example
S1: {(i, j) | 1 ≤ i ≤ n ≤ m ∧ j = i}
S2: {(i, j) | 1 ≤ i ≤ n ≤ m ∧ i ≤ j ≤ n}
S3: {(i, j) | 1 ≤ i ≤ m ∧ j = n ≤ m}
j
for ( i =1; i <= m ; i ++) {
if ( i <= n ) {
S1 (i , i );
}
for ( j = i ;j <= n ; j ++) {
S2 ( i );
}
S3 (i , n );
}
i
October 30, 2009
9 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Improved Code Generation using CLooG
Using PolyLib as a backend:
for (p1=0;p1<=floord(8*N+63,32);p1++) {
for (p3=max(max(max(max(0,ceild(-32*p1-27,4)),
ceild(512*p1-128*N-975,16)),ceild(28*p1-7*N-20,36)),
ceild(60*p1-15*N-44,68));
p3<=min(min(floord(4*M+47,16),floord(24*p1+5*M+36,20)),
floord(136*p1+31*M+224,124));p3++) {
if ((p1 >= 0) && (p1 <= floord(N-1,4))) {
for (p5=max(0,4*p3);p5<=min(M-1,4*p3+3);p5++) {
for (p7=max(0,4*p1);p7<=min(N-1,4*p1+3);p7++) {
S9(p3,p5,p1,p7); /* ... */
10 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Improved Code Generation using CLooG
Using PolyLib as a backend:
for (p1=0;p1<=floord(8*N+63,32);p1++) {
for (p3=max(max(max(max(0,ceild(-32*p1-27,4)),
ceild(512*p1-128*N-975,16)),ceild(28*p1-7*N-20,36)),
ceild(60*p1-15*N-44,68));
p3<=min(min(floord(4*M+47,16),floord(24*p1+5*M+36,20)),
floord(136*p1+31*M+224,124));p3++) {
if ((p1 >= 0) && (p1 <= floord(N-1,4))) {
for (p5=max(0,4*p3);p5<=min(M-1,4*p3+3);p5++) {
for (p7=max(0,4*p1);p7<=min(N-1,4*p1+3);p7++) {
S9(p3,p5,p1,p7); /* ... */
Using isl as a backend:
for (p1=0;p1<=floord(N+7,4);p1++) {
for (p3=max(0,ceild(4*p1-N+1,4));
p3<=min(floord(M+11,4),floord(4*p1+M+3,4));p3++) {
if (p1 <= floord(N-1,4)) {
for (p5=4*p3;p5<=min(M-1,4*p3+3);p5++) {
for (p7=4*p1;p7<=min(N-1,4*p1+3);p7++) {
S9(p3,p5,p1,p7); /* ... */
10 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
CLooG Speed Comparison
Previous example (HD)
CLooG test suite
Simple tiling example (UKB)
Extreme tiling example (UKB)
LU example (UKB)
Sobel example (HD)
PolyLib-64
PolyLib-gmp
isl-gmp
0.052s
2.468s
0.292s
2.940s
0.228s
0.184s
0.128s
3.976s
0.744s
7.224s
0.492s
0.516s
0.112s
2.828s
0.328s
1.428s
0.140s
0.068s
On Intel Xeon W3520 @ 2.66GHz
HD: Harald Devos; UKB: Uday K Bondhugula
11 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Outline
1
Motivation
2
isl and CLooG
3
Parametric Integer Programming
What?
Why?
How?
Observations
4
Improvements
piplib
barvinok
isl
5
Bart’s Problem
6
Conclusions
October 30, 2009
12 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
13 / 37
Lexicographical Order
#define N 5
for (i = 1; i <= N; ++i)
for (j = 1; j <= i; ++j)
a[i][j]=
S = { (i, j) | i ≥ 1 ∧ i ≤ N ∧ j ≥ 1 ∧ j ≤ i }
Execution order: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3), (4,1), (4,2), (4,3),
(4,4) (5,1), (5,2), (5,3), (5,4), (5,5)
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
13 / 37
Lexicographical Order
#define N 5
for (i = 1; i <= N; ++i)
for (j = 1; j <= i; ++j)
a[i][j]=
S = { (i, j) | i ≥ 1 ∧ i ≤ N ∧ j ≥ 1 ∧ j ≤ i }
Execution order: (1,1), (2,1), (2,2), (3,1), (3,2), (3,3), (4,1), (4,2), (4,3),
(4,4) (5,1), (5,2), (5,3), (5,4), (5,5)
Lexicographical order:
a≺b≡
n
_
i=1

ai < bi ∧
i−1
^
j=1
⇒ smaller in first position where vectors differ

aj = bj 
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
14 / 37
Parametric Integer Programming
Given a relation R with parameters s
R(s) = { (x1 , x2 ) ∈ Zd1 × Zd2 | ∃z ∈ Ze : A1 x1 + A2 x2 + Bs + Dz ≥ c }
compute the lexicographic minimum of R:
lexmin R = { (x1 , x2 ) ∈ R | ∀x′2 ∈ R(s, x1 ) : x2 4 x′2 }
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
14 / 37
Parametric Integer Programming
Given a relation R with parameters s
R(s) = { (x1 , x2 ) ∈ Zd1 × Zd2 | ∃z ∈ Ze : A1 x1 + A2 x2 + Bs + Dz ≥ c }
compute the lexicographic minimum of R:
lexmin R = { (x1 , x2 ) ∈ R | ∀x′2 ∈ R(s, x1 ) : x2 4 x′2 }
Parametric integer programming is useful for
dependence analysis
(enumeration of) integer projections
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
14 / 37
Parametric Integer Programming
Given a relation R with parameters s
R(s) = { (x1 , x2 ) ∈ Zd1 × Zd2 | ∃z ∈ Ze : A1 x1 + A2 x2 + Bs + Dz ≥ c }
compute the lexicographic minimum of R:
lexmin R = { (x1 , x2 ) ∈ R | ∀x′2 ∈ R(s, x1 ) : x2 4 x′2 }
Parametric integer programming is useful for
dependence analysis
(enumeration of) integer projections
Technique: dual simplex + Gomory cuts
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Parametric Integer Programming: Why?
Data dependence analysis
Given a read from an array, where did the data come from?
That is, when was it last written?
15 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
15 / 37
Parametric Integer Programming: Why?
Data dependence analysis
Given a read from an array, where did the data come from?
That is, when was it last written?
Example:
for ( i = 0; i <= N ; ++ i )
for ( j = 0; j <= i ; ++ j )
a [ i +2* j ] = a [ i +2* j ] + f (i , j );
for ( k = 0; k <= 3* N ; ++ k )
b [ k ] = 2* a [ k ];
For any read through a[k] in iteration k of the second loop, what is
the last iteration (i, j) of the first loop writing to the same array
element?
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
16 / 37
Parametric Integer Programming: Why?
Data dependence analysis
for ( i = 0; i <= N ; ++ i )
for ( j = 0; j <= i ; ++ j )
a [ i +2* j ] = a [ i +2* j ] + f (i , j );
for ( k = 0; k <= 3* N ; ++ k )
b [ k ] = 2* a [ k ];
Relation between iterations reading/writing same array element:
R = { (k) → (i, j) ∈ Z×Z2 | 0 ≤ i ≤ N∧0 ≤ j ≤ i∧0 ≤ k ≤ 3N∧k = i+2j }
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
16 / 37
Parametric Integer Programming: Why?
Data dependence analysis
for ( i = 0; i <= N ; ++ i )
for ( j = 0; j <= i ; ++ j )
a [ i +2* j ] = a [ i +2* j ] + f (i , j );
for ( k = 0; k <= 3* N ; ++ k )
b [ k ] = 2* a [ k ];
Relation between iterations reading/writing same array element:
R = { (k) → (i, j) ∈ Z×Z2 | 0 ≤ i ≤ N∧0 ≤ j ≤ i∧0 ≤ k ≤ 3N∧k = i+2j }
Last (i, j) writing to an array element: R ′ = lexmax R =
{ (k) → (k, 0) | 0 ≤ k ≤ N − 1 } ⊔
{ (k) → (2q−k, k −q) | ∃q ∈ Z : N ≤ k ≤ 3N ∧ 2q ≤ k + N ≤ 2q + 1 }
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Parametric Integer Programming: How?
Assume:
we want to compute the lexicographic minimum
all unknown are non-negative
⇒ constraints xi ≥ 0 are (implicitly) imposed
October 30, 2009
17 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
17 / 37
Parametric Integer Programming: How?
Assume:
we want to compute the lexicographic minimum
all unknown are non-negative
⇒ constraints xi ≥ 0 are (implicitly) imposed
Dual simplex (operations performed on simplex tableau)
start from basic solution 0 (intersection of constraints xi ≥ 0)
as long as there is any violated constraint, move to lexico-larger
adjacent basic solution
(simple bookkeeping ensures lexico-positive move is always possible, if
there is a solution)
first feasible basic solution found is lexico-minimal solution
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
17 / 37
Parametric Integer Programming: How?
Assume:
we want to compute the lexicographic minimum
all unknown are non-negative
⇒ constraints xi ≥ 0 are (implicitly) imposed
Dual simplex (operations performed on simplex tableau)
start from basic solution 0 (intersection of constraints xi ≥ 0)
as long as there is any violated constraint, move to lexico-larger
adjacent basic solution
(simple bookkeeping ensures lexico-positive move is always possible, if
there is a solution)
first feasible basic solution found is lexico-minimal solution
Gomory cuts
extra constraints added to exclude rational solutions
may involve “new parameters” (extra integer divisions)
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Parametric Integer Programming: Example
a:
x ≥y +1
b:
2y ≥ p
c:
x ≥0
d:
y ≥0
October 30, 2009
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Parametric Integer Programming: Example
a:
x ≥y +1
b:
2y ≥ p
c:
x ≥0
d:
y ≥0
p=3
•
(0, 0)
October 30, 2009
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Parametric Integer Programming: Example
a:
x ≥y +1 0≥1
−
b:
2y ≥ p
0≥p
+/−
c:
x ≥0
0≥0
+
d:
y ≥0
0≥0
+
p=3
•
(0, 0)
October 30, 2009
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Parametric Integer Programming: Example
a:
x ≥y +1 0≥1
−
b:
2y ≥ p
0≥p
+/−
c:
x ≥0
0≥0
+
d:
y ≥0
0≥0
+
p=3
• •
(1, 0)
October 30, 2009
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Parametric Integer Programming: Example
a:
x ≥y +1
b:
2y ≥ p
c:
x ≥0
d:
y ≥0
p=3
•
(1, 0)
October 30, 2009
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Parametric Integer Programming: Example
a:
x ≥y +1 1≥1
+
b:
2y ≥ p
0≥p
+/−
c:
x ≥0
1≥0
+
d:
y ≥0
0≥0
+
p=3
•
(1, 0)
October 30, 2009
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Parametric Integer Programming: Example
a:
x ≥y +1 1≥1
+
b:
2y ≥ p
0≥p
+/−
c:
x ≥0
1≥0
+
d:
y ≥0
0≥0
+
p=3
•
p≤0
(1, 0)
p≥1
October 30, 2009
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Parametric Integer Programming: Example
a:
x ≥y +1 1≥1
+
b:
2y ≥ p
0≥p
+/−
c:
x ≥0
1≥0
+
d:
y ≥0
0≥0
+
p=3
•
p≤0
(1, 0)
•
p = −1
(1, 0)
p≥1
October 30, 2009
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Parametric Integer Programming: Example
a:
x ≥y +1 1≥1
+
b:
2y ≥ p
0≥p
+
c:
x ≥0
1≥0
+
d:
y ≥0
0≥0
+
p=3
•
p≤0
(1, 0)
•
p = −1
(1, 0)
p≥1
October 30, 2009
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Parametric Integer Programming: Example
a:
x ≥y +1 1≥1
+
b:
2y ≥ p
0≥p
+/−
c:
x ≥0
1≥0
+
d:
y ≥0
0≥0
+
p=3
•
p≤0
(1, 0)
(1, 0)
p≥1
(1, 0)
p=3
•
p = −1
•
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Parametric Integer Programming: Example
a:
x ≥y +1 1≥1
+
b:
2y ≥ p
0≥p
−
c:
x ≥0
1≥0
+
d:
y ≥0
0≥0
+
p=3
•
p≤0
(1, 0)
(1, 0)
p≥1
(1, 0)
p=3
•
p = −1
•
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Parametric Integer Programming: Example
a:
x ≥y +1 1≥1
+
b:
2y ≥ p
0≥p
−
c:
x ≥0
1≥0
+
d:
y ≥0
0≥0
+
p=3
•
p≤0
(1, 0)
(1, 0)
p≥1
(1 + p/2, p/2)
•
p=3
•
p = −1
•
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Parametric Integer Programming: Example
a:
x ≥y +1
b:
2y ≥ p
c:
x ≥0
d:
y ≥0
p=3
•
p≤0
(1, 0)
(1, 0)
p≥1
(1 + p/2, p/2)
p=3
•
p = −1
•
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Parametric Integer Programming: Example
a:
x ≥ y + 1 1 + p/2 ≥ p/2 + 1
b:
2y ≥ p
c:
d:
+
p≥p
+
x ≥0
1 + p/2 ≥ 0
+
y ≥0
p/2 ≥ 0
+
p=3
•
p≤0
(1, 0)
(1, 0)
p≥1
(1 + p/2, p/2)
p=3
•
p = −1
•
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Parametric Integer Programming: Example
a:
x ≥ y + 1 1 + p/2 ≥ p/2 + 1
b:
2y ≥ p
c:
d:
+
p≥p
+
x ≥0
1 + p/2 ≥ 0
+
y ≥0
p/2 ≥ 0
+
p=3
•
p≤0
(1, 0)
(1, 0)
p≥1
(1 + p/2, p/2)
p=3
•
p = −1
•
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Parametric Integer Programming: Example
a:
x ≥ y + 1 1 + p/2 ≥ p/2 + 1
b:
2y ≥ p
c:
+
p≥p
+
x ≥0
1 + p/2 ≥ 0
+
d:
y ≥0
p/2 ≥ 0
+
e:
y + ⌊p/2⌋ ≥ p
p/2 + ⌊p + 2⌋ ≥ p
−
p=3
•
p≤0
(1, 0)
(1, 0)
p≥1
(1 + p/2, p/2)
p=3
•
p = −1
•
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Parametric Integer Programming: Example
a:
x ≥ y + 1 1 + p/2 ≥ p/2 + 1
b:
2y ≥ p
c:
+
p≥p
+
x ≥0
1 + p/2 ≥ 0
+
d:
y ≥0
p/2 ≥ 0
+
e:
y + ⌊p/2⌋ ≥ p
p/2 + ⌊p + 2⌋ ≥ p
−
p=3
•
p≤0
(1, 0)
(1, 0)
p≥1
(1+p−⌊p/2⌋,p−⌊p/2⌋)
p=3
•
p = −1
•
•
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Parametric Integer Programming: Example
a:
x ≥y +1
b:
2y ≥ p
c:
x ≥0
d:
y ≥0
e:
y + ⌊p/2⌋ ≥ p
p=3
•
p≤0
(1, 0)
(1, 0)
p≥1
(1+p−⌊p/2⌋,p−⌊p/2⌋)
p=3
•
p = −1
•
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Parametric Integer Programming: Example
a:
x ≥ y + 1 1 + p − ⌊p/2⌋ ≥ p − ⌊p/2⌋ + 1
+
b:
2y ≥ p
2p − 2 ⌊p/2⌋ ≥ p
+
c:
x ≥0
1 + p − ⌊p/2⌋ ≥ 0
+
d:
y ≥0
p − ⌊p/2⌋ ≥ 0
+
e:
y + ⌊p/2⌋ ≥ p
p − ⌊p/2⌋ + ⌊p/2⌋ ≥ p
+
p=3
•
p≤0
(1, 0)
(1, 0)
p≥1
(1+p−⌊p/2⌋,p−⌊p/2⌋)
p=3
•
p = −1
•
18 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
19 / 37
Parametric Integer Programming: How?
Parameters are assumed to be integral
Set of parameter values is called the context
Determining the sign (+, −, +/−) of a constraint
+ there are no values of the parameters where constraint is violated
− there are no values of the parameters where constraint is not violated
+/− constraint is violated for only some values of the parameters
⇒ (non-parametric) integer feasibility problems
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
19 / 37
Parametric Integer Programming: How?
Parameters are assumed to be integral
Set of parameter values is called the context
Determining the sign (+, −, +/−) of a constraint
+ there are no values of the parameters where constraint is violated
− there are no values of the parameters where constraint is not violated
+/− constraint is violated for only some values of the parameters
⇒ (non-parametric) integer feasibility problems
piplib computes lexico-minimal value
found ⇒ problem feasible
not found ⇒ problem infeasible
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
20 / 37
Parametric Integer Programming: How?
Basic method starts from 0, assuming unknowns are non-negative
How to deal with unknowns/parameters of unrestricted sign?
⇒ “big parameter” trick
A special parameter M is assumed to be arbitrarily large (think ∞)
Problem is rewritten in terms of x′ = M1 + x
Initial value x′ = 0 corresponds to x = −M1 (think x = −∞)
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
20 / 37
Parametric Integer Programming: How?
Basic method starts from 0, assuming unknowns are non-negative
How to deal with unknowns/parameters of unrestricted sign?
⇒ “big parameter” trick
A special parameter M is assumed to be arbitrarily large (think ∞)
Problem is rewritten in terms of x′ = M1 + x
Initial value x′ = 0 corresponds to x = −M1 (think x = −∞)
Note: piplib uses different trick in context tableau
⇒ p is replaced by p + − p −
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Observations
Gomory cuts don’t cut it on infeasible problems
⇒ check feasibility of main tableau first (non-parametrically)
⇒ avoid Gomory cuts in context feasibility checks
21 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Observations
Gomory cuts don’t cut it on infeasible problems
⇒ check feasibility of main tableau first (non-parametrically)
⇒ avoid Gomory cuts in context feasibility checks
piplib doesn’t like (hidden) equalities among integer values
⇒ detect and exploit equalities
21 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Observations
Gomory cuts don’t cut it on infeasible problems
⇒ check feasibility of main tableau first (non-parametrically)
⇒ avoid Gomory cuts in context feasibility checks
piplib doesn’t like (hidden) equalities among integer values
⇒ detect and exploit equalities
much time is spent in context feasibility checks
⇒ use better algorithm for feasibility checks
⇒ try to perform checks incrementally
⇒ avoid checks as much as possible
21 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Observations
Gomory cuts don’t cut it on infeasible problems
⇒ check feasibility of main tableau first (non-parametrically)
⇒ avoid Gomory cuts in context feasibility checks
piplib doesn’t like (hidden) equalities among integer values
⇒ detect and exploit equalities
much time is spent in context feasibility checks
⇒ use better algorithm for feasibility checks
⇒ try to perform checks incrementally
⇒ avoid checks as much as possible
any “new parameter” increases the dimension of the problem
⇒ avoid needless introduction of new parameters
21 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Outline
1
Motivation
2
isl and CLooG
3
Parametric Integer Programming
What?
Why?
How?
Observations
4
Improvements
piplib
barvinok
isl
5
Bart’s Problem
6
Conclusions
October 30, 2009
22 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
23 / 37
Improvements in piplib
Some improvements in piplib compared to original implementation
perform tricks for handling unknowns and parameters of unrestricted
sign inside piplib [V., Dec. 2005, Feb. 2006]
big parameter considered divisible by any number [V., Aug. 2006]
avoid generation of duplicate new parameters [V., Apr. 2007]
simplify constraints [V., Apr. 2007]
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
24 / 37
Parametric Integer Programming in barvinok
barvinok’s lexmin performs parametric integer programming using a
completely different technique based on generating functions [V., 2006]
But, also maintains a “context” ⇒ feasibility checks
barvinok supports two kinds of feasibility checks
counting the integer points (0 ⇒ empty; not 0 ⇒ not empty)
⇒ Does not work very well in presence of many integer divisions
sampling domain using generalized basis reduction
⇒ some overhead, but fairly robust
barvinok keeps track of sample value in current context
⇒ when splitting the context, often only one case needs to be checked
⇒ reduces the number of feasibility checks by a factor of almost two
⇒ when extra integer division is added, new coordinate can be computed
easily
Context handling of lexmin can be seen as predecessor of isl
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
25 / 37
Parametric Integer Programming in isl
isl uses same algorithm as piplib in main tableau
(dual simplex + Gomory cuts)
isl supports two kinds of feasibility checks
recursive application (like piplib)
But,
◮
uses (separate) big parameter in context tableau as well
generalized basis reduction (like barvinok)
But,
◮
◮
generalized basis reduction is performed using incremental LP solver
equalities are detected in context tableau and, in some cases,
propagated to main tableau
In both cases,
context tableau is updated incrementally
a list of sample values is maintained
all equalities in initial main tableau are detected
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Updating Context Incrementally
Each split adds a new constraint to context tableau
Solution of context before split satisfies all previous inequalities
Working non-incrementally duplicates a lot of work
26 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Updating Context Incrementally
Each split adds a new constraint to context tableau
Solution of context before split satisfies all previous inequalities
Working non-incrementally duplicates a lot of work
Gomory cuts context: continue working before or after cuts?
+
+
−
−
◮
◮
always maintain integer sample
integer sample may also satisfy new constraint
if not, then previous cuts may be redundant
accumulation of a large number of cuts
initial implementation (never made public) kept cuts
current implementation drops cuts
26 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
26 / 37
Updating Context Incrementally
Each split adds a new constraint to context tableau
Solution of context before split satisfies all previous inequalities
Working non-incrementally duplicates a lot of work
Gomory cuts context: continue working before or after cuts?
+
+
−
−
◮
◮
always maintain integer sample
integer sample may also satisfy new constraint
if not, then previous cuts may be redundant
accumulation of a large number of cuts
initial implementation (never made public) kept cuts
current implementation drops cuts
Generalized basis reduction context
◮
◮
◮
incrementally maintain set of points with unit boxes in original set
non-empty ⇒ simply round up rational sample
incrementally maintain recession cone (gbr requires bounded sets)
current implementation does not compute reduced basis incrementally
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Maintaining a List of Sample Values
Checking the sign of a constraint
(evaluated in sample point of main tableau)
⇒ check at sample values (of context) first
◮
◮
◮
◮
both > 0 and < 0 ⇒ +/− (no check needed)
all ≥ 0 ⇒ check feasibility of < 0
all ≤ 0 ⇒ check feasibility of > 0
all = 0 (rare) ⇒ one or two checks needed
October 30, 2009
27 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Maintaining a List of Sample Values
Checking the sign of a constraint
(evaluated in sample point of main tableau)
⇒ check at sample values (of context) first
◮
◮
◮
◮
both > 0 and < 0 ⇒ +/− (no check needed)
all ≥ 0 ⇒ check feasibility of < 0
all ≤ 0 ⇒ check feasibility of > 0
all = 0 (rare) ⇒ one or two checks needed
Feasibility check
⇒ add sample value found, if any
October 30, 2009
27 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Maintaining a List of Sample Values
Checking the sign of a constraint
(evaluated in sample point of main tableau)
⇒ check at sample values (of context) first
◮
◮
◮
◮
both > 0 and < 0 ⇒ +/− (no check needed)
all ≥ 0 ⇒ check feasibility of < 0
all ≤ 0 ⇒ check feasibility of > 0
all = 0 (rare) ⇒ one or two checks needed
Feasibility check
⇒ add sample value found, if any
Adding a constraint to the context
⇒ (temporarily) remove samples violating constraint
October 30, 2009
27 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Detecting and Exploiting Equalities
Exploiting equalities
pip models equality as pair of inequalities
isl uses equality to reduce number of columns in tableau
28 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Detecting and Exploiting Equalities
Exploiting equalities
pip models equality as pair of inequalities
isl uses equality to reduce number of columns in tableau
Detecting equalities
Main tableau
⇒ compute integer affine hull of input set
⇒ using generalized basis reduction
28 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Detecting and Exploiting Equalities
Exploiting equalities
pip models equality as pair of inequalities
isl uses equality to reduce number of columns in tableau
Detecting equalities
Main tableau
⇒ compute integer affine hull of input set
⇒ using generalized basis reduction
Context tableau (only in gbr case)
◮
check for equalities after each cut introducing new integer division
⇒ compute integer affine hull (incrementally)
⇒ exploit list of sample values in computing affine hull
⇒ update list of sample values
28 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
28 / 37
Detecting and Exploiting Equalities
Exploiting equalities
pip models equality as pair of inequalities
isl uses equality to reduce number of columns in tableau
Detecting equalities
Main tableau
⇒ compute integer affine hull of input set
⇒ using generalized basis reduction
Context tableau (only in gbr case)
◮
◮
check for equalities after each cut introducing new integer division
⇒ compute integer affine hull (incrementally)
⇒ exploit list of sample values in computing affine hull
⇒ update list of sample values
propagate equalities to main tableau that express new integer division
as integer linear combination of parameters and previous integer
divisions
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Detecting equalities in main tableau
For example: fimmel.pip
pip returns
(if #[ -1 0 1]
(if #[ 0 -1 0]
()
(if #[ 0 -1 5]
(if #[ -3 -1 5]
(if #[ 0 -1 1]
(newparm 2 (div #[ 0 1 1] 3))
(newparm 3 (div #[ 0 1 5 3] 6))
(newparm 4 (div #[ 0 2 0 1 0] 3))
()
(if #[ 0 -1 3]
(newparm 2 (div #[ 0 2 1] 3))
()
()
)
)
(if #[ 0 -1 3]
(newparm 2 (div #[ 0 2 1] 3))
()
()
)
)
()
)
)
()
)
isl detects absence of solution before starting dual simplex method
29 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
30 / 37
Which Split First?
The main tableau may have many constraints with sign +/−
Which constraint should be used first?
pip: take constraint with smallest biggest coefficient
isl: take constraint that makes most other splitting constraints
redundant
⇒ on positive side of split, all of these redundant constraints will also
have a positive sign
⇒ on negative side of split, we have to move to a different sample point
⇒ unpredictable effect on signs of constraints
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Why not Use Omega to Check Feasibility?
problem
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
dim
6
6
5
5
5
3
8
7
7
8
4
6
12
11
10
9
7
4
3
3
4
4
4
4
2
5
solution
yes
yes
yes
yes
yes
no
no
no
no
yes
yes
no
yes
yes
yes
yes
yes
yes
no
yes
yes
no
no
no
no
yes
isl
0.004s
0.000s
0.012s
0.004s
0.032s
0.012s
0.008s
0.008s
0.008s
0.000s
0.008s
0.000s
0.012s
0.008s
0.012s
0.008s
0.008s
0.004s
0.000s
0.000s
0.012s
0.008s
0.008s
0.008s
0.004s
0.004s
Omega
error?
error?
error?
error?
error?
0.016s
0.012s
0.016s
0.020s
0.016s
0.012s
0.012s
max # constr (512)
parse error?
0.016s
0.020s
0.024s
parse error?
0.016s
0.012s
“no suitable constraint”
parse error?
overflow?
overflow?
0.008s
parse error?
parse
parse
parse
parse
parse
Omega+
segmentation fault
segmentation fault
segmentation fault
segmentation fault
segmentation fault
0.000s
0.000s
0.004s
0.000s
0.000s
0.004s
0.000s
max # constr (2048)
0.240s
0.004s
0.004s
0.004s
0.004s
0.000s
0.000s
> 5m
> 5m
overflow
> 5m
0.000s
segmentation fault
October 30, 2009
31 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Outline
1
Motivation
2
isl and CLooG
3
Parametric Integer Programming
What?
Why?
How?
Observations
4
Improvements
piplib
barvinok
isl
5
Bart’s Problem
6
Conclusions
October 30, 2009
32 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Bart’s Dependence Analysis Problem
for i1 = 1 : 1 : 8 ,
for i2 = 1 : 1 : 2 ,
for i3 = 1 : 1 : 2 ,
for i4 = 1 : 1 : 2 ,
for i5 = 1 : 1 : 2 ,
for i6 = 1 : 1 : 2 ,
for i7 = 1 : 1 : 2 ,
for i8 = 1 : 1 : 2 ,
for i9 = 1 : 1 : 2 ,
for i10 = 1 : 1 : 2 ,
[ x ( i1 -1 , i2 -1+2* i3 -2+4* i4 -4+8* i5 -8+16* i6 -16+32* i7 -32+
64* i8 -64+128* i9 -128+256* i10 -256) ] = d ( u ( i0 ) );
end
end
end
end
end
end
end
end
end
end
for j1 = 1 : 1 : 8 ,
for j2 = 1 : 1 : 128 ,
[ y ( i0 ) ] = f ( x ( j1 -1 ,3* j2 -3+66));
end
end
33 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
34 / 37
A Corresponding Parametric Integer Programming Problem
4
1
1
1
1
4
-1 0 8
1 0 -1
0 -1 128
0 1 -1
-1
24 14
1 0 1 2 4 8 16 32 64 128 256 0 3 574
1 0 -1 -2 -4 -8 -16 -32 -64 -128 -256 0 -3 -574
1 1 0 0 0 0 0 0 0 0 0 1 0 0
1 -1 0 0 0 0 0 0 0 0 0 -1 0 0
1 1 0 0 0 0 0 0 0 0 0 0 0 8
1 -1 0 0 0 0 0 0 0 0 0 0 0 -1
1 0 1 0 0 0 0 0 0 0 0 0 0 2
1 0 -1 0 0 0 0 0 0 0 0 0 0 -1
1 0 0 1 0 0 0 0 0 0 0 0 0 2
1 0 0 -1 0 0 0 0 0 0 0 0 0 -1
1 0 0 0 1 0 0 0 0 0 0 0 0 2
1 0 0 0 -1 0 0 0 0 0 0 0 0 -1
1 0 0 0 0 1 0 0 0 0 0 0 0 2
1 0 0 0 0 -1 0 0 0 0 0 0 0 -1
1 0 0 0 0 0 1 0 0 0 0 0 0 2
1 0 0 0 0 0 -1 0 0 0 0 0 0 -1
1 0 0 0 0 0 0 1 0 0 0 0 0 2
1 0 0 0 0 0 0 -1 0 0 0 0 0 -1
1 0 0 0 0 0 0 0 1 0 0 0 0 2
1 0 0 0 0 0 0 0 -1 0 0 0 0 -1
1 0 0 0 0 0 0 0 0 1 0 0 0 2
1 0 0 0 0 0 0 0 0 -1 0 0 0 -1
1 0 0 0 0 0 0 0 0 0 1 0 0 2
1 0 0 0 0 0 0 0 0 0 -1 0 0 -1
Urs_unknowns
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
35 / 37
Solving Bart’s Parametric Integer Programming Problem
Computation times
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
35 / 37
Solving Bart’s Parametric Integer Programming Problem
Computation times
pip: 47.5s
Answer: The solution is too complex! : sol
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
35 / 37
Solving Bart’s Parametric Integer Programming Problem
Computation times
pip: 47.5s
Answer: The solution is too complex! : sol
lexmin: 275m
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
35 / 37
Solving Bart’s Parametric Integer Programming Problem
Computation times
pip: 47.5s
Answer: The solution is too complex! : sol
lexmin: 275m
isl pip with Gomory cuts context: ∞
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
35 / 37
Solving Bart’s Parametric Integer Programming Problem
Computation times
pip: 47.5s
Answer: The solution is too complex! : sol
lexmin: 275m
isl pip with Gomory cuts context: ∞
isl pip with gbr context: 3s
◮
◮
without detection of equalities: ∞
without propagation of equalities: 8m
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
35 / 37
Solving Bart’s Parametric Integer Programming Problem
Computation times
pip: 47.5s
Answer: The solution is too complex! : sol
lexmin: 275m
isl pip with Gomory cuts context: ∞
isl pip with gbr context: 3s
◮
◮
without detection of equalities: ∞
without propagation of equalities: 8m
Explanation:
many integer divisions are generated, each depending on previous
one(s)
after several splits of context, most integer divisions have fixed value
propagating fixed values to main tableau stops generation of new
integer divisions
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
Outline
1
Motivation
2
isl and CLooG
3
Parametric Integer Programming
What?
Why?
How?
Observations
4
Improvements
piplib
barvinok
isl
5
Bart’s Problem
6
Conclusions
October 30, 2009
36 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Conclusions
isl: a new integer set library
currently used in equivalence checking tool and CLooG:
◮
Produces better code than PolyLib backend, without speed penalty
explicit support for existentially quantified variables
all computations in exact integer arithmetic using GMP
built-in (P)ILP solver and incremental LP solver
◮
PILP solver can handle Bart’s problem
released under LGPL license
37 / 37
Sven Verdoolaege
isl and How to Solve Bart’s PIP Problem
October 30, 2009
Conclusions
isl: a new integer set library
currently used in equivalence checking tool and CLooG:
◮
Produces better code than PolyLib backend, without speed penalty
explicit support for existentially quantified variables
all computations in exact integer arithmetic using GMP
built-in (P)ILP solver and incremental LP solver
◮
PILP solver can handle Bart’s problem
released under LGPL license
Future Work
further optimizations
isl calculator (similar to Omega calculator)
port barvinok to isl
barvinok currently uses
◮
◮
PolyLib: GPLv2 only, . . .
⇒ isl needs chamber decomposition and parametric vertices
NTL: not thread-safe, C++
⇒ isl needs LLL
37 / 37