Tools for the Polyhedral Model
Transcript of Tools for the Polyhedral Model
![Page 1: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/1.jpg)
December 15, 2009 1 / 35
Tools for the Polyhedral Model
Sven Verdoolaege
Katholieke Universiteit Leuven, Belgium
December 15, 2009
![Page 2: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/2.jpg)
December 15, 2009 2 / 35
Outline
1 Polyhedral Model
2 isl
Introduction and RepresentationParametric Integer Programming
3 CLooG
4 barvinok
5 bernstein
6 Conclusions
![Page 3: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/3.jpg)
Polyhedral Model December 15, 2009 3 / 35
Outline
1 Polyhedral Model
2 isl
Introduction and RepresentationParametric Integer Programming
3 CLooG
4 barvinok
5 bernstein
6 Conclusions
![Page 4: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/4.jpg)
Polyhedral Model December 15, 2009 4 / 35
Polyhedral Program Analysis and Transformation
Observation:
Most expensive part of a multimedia or signal processing program:manipulation of arrays inside loops
⇒ most interesting part to optimize
![Page 5: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/5.jpg)
Polyhedral Model December 15, 2009 4 / 35
Polyhedral Program Analysis and Transformation
Observation:
Most expensive part of a multimedia or signal processing program:manipulation of arrays inside loops
⇒ most interesting part to optimize
⇒ need for compact representation ofiterations of a loop/elements of an array
⇒ + efficient to manipulate
![Page 6: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/6.jpg)
Polyhedral Model December 15, 2009 4 / 35
Polyhedral Program Analysis and Transformation
Observation:
Most expensive part of a multimedia or signal processing program:manipulation of arrays inside loops
⇒ most interesting part to optimize
⇒ need for compact representation ofiterations of a loop/elements of an array
⇒ + efficient to manipulate
⇒ Integer points in polyhedra (“polyhedral model”)⇒ More generally: sets of integers bounded by affine inequalities
![Page 7: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/7.jpg)
Polyhedral Model December 15, 2009 5 / 35
Polyhedral Representation Example: Iteration Domain
#define N 5
for (i = 1; i <= N; ++i)
for (j = 1; j <= i; ++j)
a[i][j]=
Assumptions on sequential code:
iterators are integers
loops with affine bounds
affine conditions
affine index expressions
![Page 8: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/8.jpg)
Polyhedral Model December 15, 2009 5 / 35
Polyhedral Representation Example: Iteration Domain
#define N 5
for (i = 1; i <= N; ++i)
for (j = 1; j <= i; ++j)
a[i][j]=
j
iIteration domain: P = { [i , j ] | i ≥ 1 }
Assumptions on sequential code:
iterators are integers
loops with affine bounds
affine conditions
affine index expressions
![Page 9: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/9.jpg)
Polyhedral Model December 15, 2009 5 / 35
Polyhedral Representation Example: Iteration Domain
#define N 5
for (i = 1; i <= N; ++i)
for (j = 1; j <= i; ++j)
a[i][j]=
j
iIteration domain: P = { [i , j ] | i ≥ 1 ∧ i ≤ N }
Assumptions on sequential code:
iterators are integers
loops with affine bounds
affine conditions
affine index expressions
![Page 10: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/10.jpg)
Polyhedral Model December 15, 2009 5 / 35
Polyhedral Representation Example: Iteration Domain
#define N 5
for (i = 1; i <= N; ++i)
for (j = 1; j <= i; ++j)
a[i][j]=
j
iIteration domain: P = { [i , j ] | i ≥ 1 ∧ i ≤ N ∧ j ≥ 1 }
Assumptions on sequential code:
iterators are integers
loops with affine bounds
affine conditions
affine index expressions
![Page 11: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/11.jpg)
Polyhedral Model December 15, 2009 5 / 35
Polyhedral Representation Example: Iteration Domain
#define N 5
for (i = 1; i <= N; ++i)
for (j = 1; j <= i; ++j)
a[i][j]=
j
iIteration domain: P = { [i , j ] | i ≥ 1 ∧ i ≤ N ∧ j ≥ 1 ∧ j ≤ i }
Assumptions on sequential code:
iterators are integers
loops with affine bounds
affine conditions
affine index expressions
![Page 12: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/12.jpg)
Polyhedral Model December 15, 2009 5 / 35
Polyhedral Representation Example: Iteration Domain
#define N 5
for (i = 1; i <= N; ++i)
for (j = 1; j <= i; ++j)
a[i][j]=
j
i
•
• •
• • •
• • • •
• • • • •
Iteration domain: P = { [i , j ] | i ≥ 1 ∧ i ≤ N ∧ j ≥ 1 ∧ j ≤ i }
Assumptions on sequential code:
iterators are integers
loops with affine bounds
affine conditions
affine index expressions
![Page 13: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/13.jpg)
Polyhedral Model December 15, 2009 5 / 35
Polyhedral Representation Example: Iteration Domain
#define N 5
for (i = 1; i <= N; ++i)
for (j = 1; j <= i; ++j)
a[i][j]=
j
i
•
• •
• • •
• • • •
• • • • •
•
• •
Iteration domain: P = { [i , j ] | i ≥ 1 ∧ i ≤ N ∧ j ≥ 1 ∧ j ≤ i }
Alternative representation: P = conv.hull { (1, 1), (N, 1), (N, N) }
Assumptions on sequential code:
iterators are integers
loops with affine bounds
affine conditions
affine index expressions
![Page 14: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/14.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
Execution order: top-down, left-right
•, ◦ Statement iterationData flow dependence
• Executed statementData in memory
![Page 15: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/15.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
Execution order: top-down, left-right
•, ◦ Statement iterationData flow dependence
• Executed statementData in memory
![Page 16: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/16.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
•
Execution order: top-down, left-right
•, ◦ Statement iterationData flow dependence
• Executed statementData in memory
![Page 17: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/17.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
• •
Execution order: top-down, left-right
•, ◦ Statement iterationData flow dependence
• Executed statementData in memory
![Page 18: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/18.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
• • •
Execution order: top-down, left-right
•, ◦ Statement iterationData flow dependence
• Executed statementData in memory
![Page 19: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/19.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
• • • •
Execution order: top-down, left-right
•, ◦ Statement iterationData flow dependence
• Executed statementData in memory
![Page 20: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/20.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
• • • • •
Execution order: top-down, left-right
•, ◦ Statement iterationData flow dependence
• Executed statementData in memory
![Page 21: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/21.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
• • • • •
•
Execution order: top-down, left-right
•, ◦ Statement iterationData flow dependence
• Executed statementData in memory
![Page 22: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/22.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
• • • • •
• •
Execution order: top-down, left-right
•, ◦ Statement iterationData flow dependence
• Executed statementData in memory
![Page 23: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/23.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
• • • • •
• • •
Execution order: top-down, left-right
•, ◦ Statement iterationData flow dependence
• Executed statementData in memory
![Page 24: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/24.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
• • • • •
• • • •
Execution order: top-down, left-right
•, ◦ Statement iterationData flow dependence
• Executed statementData in memory
![Page 25: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/25.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
• • • • •
• • • • •
Execution order: top-down, left-right
•, ◦ Statement iterationData flow dependence
• Executed statementData in memory
![Page 26: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/26.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
Execution order: top-down, left-right
•, ◦ Statement iterationData flow dependence
• Executed statementData in memory
• • • • •
◦ ◦ ◦ ◦ ◦
![Page 27: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/27.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[N-i] = f(a[i])
• • • • •
◦ ◦ ◦ ◦ ◦
![Page 28: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/28.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[N-i] = f(a[i])
• • • • •
◦ ◦ ◦ ◦ ◦
•
•
•
•
•
◦
◦
◦
◦
◦
![Page 29: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/29.jpg)
Polyhedral Model December 15, 2009 6 / 35
Polyhedral Program Transformation Example
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[N-i] = f(a[i])
• • • • •
◦ ◦ ◦ ◦ ◦
for (i = 0; i <= N; ++i) {
a[i] = ...
b[N-i] = f(a[i])
}
•
•
•
•
•
◦
◦
◦
◦
◦
![Page 30: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/30.jpg)
Polyhedral Model December 15, 2009 7 / 35
Polyhedral Program Analysis and Transformation Overview
program code
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
![Page 31: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/31.jpg)
Polyhedral Model December 15, 2009 7 / 35
Polyhedral Program Analysis and Transformation Overview
program code
parser
polyhedral model
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
![Page 32: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/32.jpg)
Polyhedral Model December 15, 2009 7 / 35
Polyhedral Program Analysis and Transformation Overview
program code
parser
polyhedral model analysis andtransformation
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
• • • • •
◦◦◦◦◦
•
•
•
•
•
◦
◦
◦
◦
◦
![Page 33: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/33.jpg)
Polyhedral Model December 15, 2009 7 / 35
Polyhedral Program Analysis and Transformation Overview
program code
parser
polyhedral model
polyhedralscanner
analysis andtransformation
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
for (i = 0; i <= N; ++i) {
a[i] = ...
b[N-i] = f(a[i])
}
• • • • •
◦◦◦◦◦
•
•
•
•
•
◦
◦
◦
◦
◦
![Page 34: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/34.jpg)
isl December 15, 2009 8 / 35
Outline
1 Polyhedral Model
2 isl
Introduction and RepresentationParametric Integer Programming
3 CLooG
4 barvinok
5 bernstein
6 Conclusions
![Page 35: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/35.jpg)
isl Introduction and Representation December 15, 2009 9 / 35
Polyhedral Program Analysis and Transformation Overview
program code
parser
polyhedral model
polyhedralscanner
analysis andtransformation
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
for (i = 0; i <= N; ++i) {
a[i] = ...
b[N-i] = f(a[i])
}
• • • • •
◦◦◦◦◦
•
•
•
•
•
◦
◦
◦
◦
◦
![Page 36: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/36.jpg)
isl Introduction and Representation December 15, 2009 10 / 35
Representation and Manipulation of Sets of IntegersPossible representations:
double description based◮ PolyLib◮ PPL◮ polymake◮ . . .
Some operations can be performed more efficiently on explicitrepresentation, but
◮ Computing the dual can be costly◮ Double description requires more space
⇒ trade-off
![Page 37: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/37.jpg)
isl Introduction and Representation December 15, 2009 10 / 35
Representation and Manipulation of Sets of IntegersPossible representations:
double description based◮ PolyLib◮ PPL◮ polymake◮ . . .
Some operations can be performed more efficiently on explicitrepresentation, but
◮ Computing the dual can be costly◮ Double description requires more space
⇒ trade-offconstraints based
◮ Omega◮ isl
![Page 38: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/38.jpg)
isl Introduction and Representation December 15, 2009 10 / 35
Representation and Manipulation of Sets of IntegersPossible representations:
double description based◮ PolyLib◮ PPL◮ polymake◮ . . .
Some operations can be performed more efficiently on explicitrepresentation, but
◮ Computing the dual can be costly◮ Double description requires more space
⇒ trade-offconstraints based
◮ Omega◮ isl
number decision diagrams◮ LASH◮ . . .
generating functions
![Page 39: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/39.jpg)
isl Introduction and Representation December 15, 2009 10 / 35
Representation and Manipulation of Sets of IntegersPossible representations:
double description based◮ PolyLib◮ PPL◮ polymake◮ . . .
Some operations can be performed more efficiently on explicitrepresentation, but
◮ Computing the dual can be costly◮ Double description requires more space
⇒ trade-offconstraints based
◮ Omega◮ isl
number decision diagrams◮ LASH◮ . . .
generating functions
![Page 40: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/40.jpg)
isl Introduction and Representation December 15, 2009 11 / 35
isl Overviewisl 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
sampling and scanning using generalized basis reduction
computing the lexicographic minimum of a relation,
![Page 41: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/41.jpg)
isl Introduction and Representation December 15, 2009 12 / 35
Why do we need existentially quantified variables?
Modeling some problemsWhich 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}
![Page 42: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/42.jpg)
isl Introduction and Representation December 15, 2009 12 / 35
Why do we need existentially quantified variables?
Modeling some problemsWhich 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/remaindersE.g., i % 10 <= 6
i − 10
⌊
i
10
⌋
≤ 6
![Page 43: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/43.jpg)
isl Introduction and Representation December 15, 2009 12 / 35
Why do we need existentially quantified variables?
Modeling some problemsWhich 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/remaindersE.g., i % 10 <= 6
i − 10
⌊
i
10
⌋
≤ 6
i − 10α ≤ 6
with i − 9 ≤ 10α ≤ i
![Page 44: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/44.jpg)
isl Introduction and Representation December 15, 2009 12 / 35
Why do we need existentially quantified variables?
Modeling some problemsWhich 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/remaindersE.g., i % 10 <= 6
i − 10
⌊
i
10
⌋
≤ 6
i − 10α ≤ 6
with i − 9 ≤ 10α ≤ i
◮ May appear in original code◮ May be introduced by (PIP-based) dependence analysis
![Page 45: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/45.jpg)
isl Introduction and Representation December 15, 2009 13 / 35
Internal Representation
Polyhedral sets and relations
S(s) = { x ∈ Zd | ∃z ∈ Ze : Ax + Bs + Dz ≥ c }
R(s) = { (x1, x2) ∈ Zd1 × Zd2 | ∃z ∈ Ze : A1x1 + A2x2 + Bs + Dz ≥ c }
“basic” types: “convex” sets and maps (relations)
◮ equality + inequality constraints◮ parameters s◮ (optional) explicit representation of existentially quantified variables as
integer divisions
⇒ useful for aligning dimensions when performing set operations (e.g., setdifference)
⇒ can be computed using PIP⇒ already available if obtained from PIP-based dependence analysis
union types: sets and maps
⇒ (disjoint) unions of basic sets/maps
![Page 46: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/46.jpg)
isl Parametric Integer Programming December 15, 2009 14 / 35
Polyhedral Program Analysis and Transformation Overview
program code
parser
polyhedral model
polyhedralscanner
analysis andtransformation
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
for (i = 0; i <= N; ++i) {
a[i] = ...
b[N-i] = f(a[i])
}
• • • • •
◦◦◦◦◦
•
•
•
•
•
◦
◦
◦
◦
◦
![Page 47: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/47.jpg)
isl Parametric Integer Programming December 15, 2009 15 / 35
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)
![Page 48: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/48.jpg)
isl Parametric Integer Programming December 15, 2009 15 / 35
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
aj = bj
⇒ smaller in first position where vectors differ
![Page 49: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/49.jpg)
isl Parametric Integer Programming December 15, 2009 16 / 35
Parametric Integer Programming
Given a relation R with parameters s
R(s) = { (x1, x2) ∈ Zd1 × Zd2 | ∃z ∈ Ze : A1x1 + A2x2 + Bs + Dz ≥ c }
compute the lexicographic minimum of R:
lexminR = { (x1, x2) ∈ R | ∀x′2 ∈ R(s, x1) : x2 4 x′2 }
![Page 50: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/50.jpg)
isl Parametric Integer Programming December 15, 2009 16 / 35
Parametric Integer Programming
Given a relation R with parameters s
R(s) = { (x1, x2) ∈ Zd1 × Zd2 | ∃z ∈ Ze : A1x1 + A2x2 + Bs + Dz ≥ c }
compute the lexicographic minimum of R:
lexminR = { (x1, x2) ∈ R | ∀x′2 ∈ R(s, x1) : x2 4 x′2 }
Parametric integer programming is useful for
dependence analysis
(enumeration of) integer projections
![Page 51: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/51.jpg)
isl Parametric Integer Programming December 15, 2009 16 / 35
Parametric Integer Programming
Given a relation R with parameters s
R(s) = { (x1, x2) ∈ Zd1 × Zd2 | ∃z ∈ Ze : A1x1 + A2x2 + Bs + Dz ≥ c }
compute the lexicographic minimum of R:
lexminR = { (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
![Page 52: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/52.jpg)
isl Parametric Integer Programming December 15, 2009 17 / 35
Dataflow Analysis
Given a read from an array element, what was the last write to
the same array element before the read?
Simple case: array written through a single access
for (i = 0; i < N; ++i)
for (j = 0; j < N - i; ++j)
a[i+j] = f(a[i+j]);
for (i = 0; i < N; ++i)
Write(a[i]);
![Page 53: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/53.jpg)
isl Parametric Integer Programming December 15, 2009 17 / 35
Dataflow Analysis
Given a read from an array element, what was the last write to
the same array element before the read?
Simple case: array written through a single access
for (i = 0; i < N; ++i)
for (j = 0; j < N - i; ++j)
a[i+j] = f(a[i+j]);
for (i = 0; i < N; ++i)
Write(a[i]);
![Page 54: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/54.jpg)
isl Parametric Integer Programming December 15, 2009 17 / 35
Dataflow Analysis
Given a read from an array element, what was the last write to
the same array element before the read?
Simple case: array written through a single access
for (i = 0; i < N; ++i)
for (j = 0; j < N - i; ++j)
a[i+j] = f(a[i+j]);
for (i = 0; i < N; ++i)
Write(a[i]);
Access relations:A1 = {(i , j) → (i + j) | 0 ≤ i < N ∧ 0 ≤ j < N − i}A2 = {(i) → (i) | 0 ≤ i < N}
![Page 55: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/55.jpg)
isl Parametric Integer Programming December 15, 2009 17 / 35
Dataflow Analysis
Given a read from an array element, what was the last write to
the same array element before the read?
Simple case: array written through a single access
for (i = 0; i < N; ++i)
for (j = 0; j < N - i; ++j)
a[i+j] = f(a[i+j]);
for (i = 0; i < N; ++i)
Write(a[i]);
Access relations:A1 = {(i , j) → (i + j) | 0 ≤ i < N ∧ 0 ≤ j < N − i}A2 = {(i) → (i) | 0 ≤ i < N}
Map to all writes: R ′ = A1−1 ◦ A2 = {(i) → (i ′, i − i ′) | 0 ≤ i ′ ≤ i < N}
![Page 56: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/56.jpg)
isl Parametric Integer Programming December 15, 2009 17 / 35
Dataflow Analysis
Given a read from an array element, what was the last write to
the same array element before the read?
Simple case: array written through a single access
for (i = 0; i < N; ++i)
for (j = 0; j < N - i; ++j)
a[i+j] = f(a[i+j]);
for (i = 0; i < N; ++i)
Write(a[i]);
Access relations:A1 = {(i , j) → (i + j) | 0 ≤ i < N ∧ 0 ≤ j < N − i}A2 = {(i) → (i) | 0 ≤ i < N}
Map to all writes: R ′ = A1−1 ◦ A2 = {(i) → (i ′, i − i ′) | 0 ≤ i ′ ≤ i < N}
Last write: R = lexmaxR ′ = {(i) → (i , 0) | 0 ≤ i < N}
![Page 57: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/57.jpg)
isl Parametric Integer Programming December 15, 2009 17 / 35
Dataflow Analysis
Given a read from an array element, what was the last write to
the same array element before the read?
Simple case: array written through a single access
for (i = 0; i < N; ++i)
for (j = 0; j < N - i; ++j)
a[i+j] = f(a[i+j]);
for (i = 0; i < N; ++i)
Write(a[i]);
Access relations:A1 = {(i , j) → (i + j) | 0 ≤ i < N ∧ 0 ≤ j < N − i}A2 = {(i) → (i) | 0 ≤ i < N}
Map to all writes: R ′ = A1−1 ◦ A2 = {(i) → (i ′, i − i ′) | 0 ≤ i ′ ≤ i < N}
Last write: R = lexmaxR ′ = {(i) → (i , 0) | 0 ≤ i < N}
In general: impose lexicographical order on shared iterators
![Page 58: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/58.jpg)
CLooG December 15, 2009 18 / 35
Outline
1 Polyhedral Model
2 isl
Introduction and RepresentationParametric Integer Programming
3 CLooG
4 barvinok
5 bernstein
6 Conclusions
![Page 59: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/59.jpg)
CLooG December 15, 2009 19 / 35
Polyhedral Program Analysis and Transformation Overview
program code
parser
polyhedral model
polyhedralscanner
analysis andtransformation
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
for (i = 0; i <= N; ++i) {
a[i] = ...
b[N-i] = f(a[i])
}
• • • • •
◦◦◦◦◦
•
•
•
•
•
◦
◦
◦
◦
◦
![Page 60: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/60.jpg)
CLooG December 15, 2009 20 / 35
CLooG ExampleCLooG generates code for scanning integer points in polyhedra (iterationdomains)
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}
i
j
![Page 61: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/61.jpg)
CLooG December 15, 2009 20 / 35
CLooG ExampleCLooG generates code for scanning integer points in polyhedra (iterationdomains)
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}
i
j
![Page 62: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/62.jpg)
CLooG December 15, 2009 20 / 35
CLooG ExampleCLooG generates code for scanning integer points in polyhedra (iterationdomains)
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}
i
j
![Page 63: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/63.jpg)
CLooG December 15, 2009 20 / 35
CLooG ExampleCLooG generates code for scanning integer points in polyhedra (iterationdomains)
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}
i
jfor (i=1;i<=m;i++) {
if (i <= n) {
S1(i,i);
}
for (j=i;j<=n;j++) {
S2(i);
}
S3(i,n);
}
![Page 64: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/64.jpg)
CLooG December 15, 2009 20 / 35
CLooG ExampleCLooG generates code for scanning integer points in polyhedra (iterationdomains)
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}
i
jfor (i=1;i<=m;i++) {
if (i <= n) {
S1(i,i);
}
for (j=i;j<=n;j++) {
S2(i);
}
S3(i,n);
}
![Page 65: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/65.jpg)
barvinok December 15, 2009 21 / 35
Outline
1 Polyhedral Model
2 isl
Introduction and RepresentationParametric Integer Programming
3 CLooG
4 barvinok
5 bernstein
6 Conclusions
![Page 66: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/66.jpg)
barvinok December 15, 2009 22 / 35
Polyhedral Program Analysis and Transformation Overview
program code
parser
polyhedral model
polyhedralscanner
analysis andtransformation
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
for (i = 0; i <= N; ++i) {
a[i] = ...
b[N-i] = f(a[i])
}
• • • • •
◦◦◦◦◦
•
•
•
•
•
◦
◦
◦
◦
◦
![Page 67: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/67.jpg)
barvinok December 15, 2009 23 / 35
Counting Example 1
How many times is S1 executed ?
for (i=1; i<=N; i++)
for (j=1; j<=i; j++)
S1;
![Page 68: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/68.jpg)
barvinok December 15, 2009 23 / 35
Counting Example 1
How many times is S1 executed ?
for (i=1; i<=N; i++)
for (j=1; j<=i; j++)
S1;
N = 4
i
j(0, 0)
••••
•••
•• •
#{ (i , j) ∈ Z2 | 1 ≤ i ≤ N ∧ 1 ≤ j ≤ i } =N(N + 1)
2
![Page 69: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/69.jpg)
barvinok December 15, 2009 23 / 35
Counting Example 1
How many times is S1 executed ?
for (i=1; i<=N; i++)
for (j=1; j<=i; j++)
S1;
N = 4
i
j(0, 0)
••••
•••
•• •
#{ (i , j) ∈ Z2 | 1 ≤ i ≤ N ∧ 1 ≤ j ≤ i } =N(N + 1)
2
= #
[
i
j
]
∈ Z2 |
1 0−1 00 11 −1
[
i
j
]
≥
0−100
[
N]
+
1010
![Page 70: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/70.jpg)
barvinok December 15, 2009 24 / 35
Counting Example 2
How many times is S1 executed ?
for (i=max(0,N-M); i<=N-M+3; i++)
for (j=0; j<=N-2*i; j++)
S1;
![Page 71: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/71.jpg)
barvinok December 15, 2009 24 / 35
Counting Example 2
How many times is S1 executed ?
for (i=max(0,N-M); i<=N-M+3; i++)
for (j=0; j<=N-2*i; j++)
S1;
Equal to the number of elements in
P( NM ) =
[
i
j
]
∈ Z2 |
1 01 0−1 00 1−2 −1
[
i
j
]
≥
0 01 −1−1 10 0−1 0
[
N
M
]
+
00−300
![Page 72: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/72.jpg)
barvinok December 15, 2009 25 / 35
Counting Example 2
#P( NM ) =
−4N + 8M − 8 if M ≤ N ≤ 2M − 6
MN − 2N − M2 + 6M − 8
if N ≤ M ≤ N + 3 ∧ N ≤ 2M − 6
N2
4 + 34N + 1
2
⌊
N2
⌋
+ 1 if 0 ≤ N ≤ M ∧ 2M ≤ N + 6
N2
4 − MN − 54N + M2 + 2M + 1
2
⌊
N2
⌋
+ 1
if M ≤ N ≤ 2M ≤ N + 6
![Page 73: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/73.jpg)
barvinok December 15, 2009 25 / 35
Counting Example 2
#P( NM ) =
−4N + 8M − 8 if M ≤ N ≤ 2M − 6
MN − 2N − M2 + 6M − 8
if N ≤ M ≤ N + 3 ∧ N ≤ 2M − 6
N2
4 + 34N + 1
2
⌊
N2
⌋
+ 1 if 0 ≤ N ≤ M ∧ 2M ≤ N + 6
N2
4 − MN − 54N + M2 + 2M + 1
2
⌊
N2
⌋
+ 1
if M ≤ N ≤ 2M ≤ N + 6
Chambers:
N
M
![Page 74: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/74.jpg)
barvinok December 15, 2009 26 / 35
Counting Example 3
How many elements of array a are accessed ?
for (j = 1; j <= p; ++j)
for (i = 1; i <= 8; ++i)
a[6i+9j-7] = a[6i+9j-7] + 5;
![Page 75: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/75.jpg)
barvinok December 15, 2009 26 / 35
Counting Example 3
How many elements of array a are accessed ?
for (j = 1; j <= p; ++j)
for (i = 1; i <= 8; ++i)
a[6i+9j-7] = a[6i+9j-7] + 5;
Equal to the number of elements in
Sp = { l ∈ Z | ∃i , j ∈ Z : l = 6i + 9j − 7 ∧ 1 ≤ j ≤ p ∧ 1 ≤ i ≤ 8 }
![Page 76: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/76.jpg)
barvinok December 15, 2009 26 / 35
Counting Example 3
How many elements of array a are accessed ?
for (j = 1; j <= p; ++j)
for (i = 1; i <= 8; ++i)
a[6i+9j-7] = a[6i+9j-7] + 5;
Equal to the number of elements in
Sp = { l ∈ Z | ∃i , j ∈ Z : l = 6i + 9j − 7 ∧ 1 ≤ j ≤ p ∧ 1 ≤ i ≤ 8 }
#Sp =
{
8 if p = 1
3p + 10 if p ≥ 2
![Page 77: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/77.jpg)
barvinok December 15, 2009 27 / 35
Weighted Counting Example
p = a;
for (i = 0; i < N; ++i)
for (j = i; j < N; ++j) {
p += j * ((j-i)/4);
*p = 0;
}
Can we parallelize this code?
![Page 78: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/78.jpg)
barvinok December 15, 2009 27 / 35
Weighted Counting Example
p = a;
for (i = 0; i < N; ++i)
for (j = i; j < N; ++j) {
p += j * ((j-i)/4);
*p = 0;
}
Can we parallelize this code?
⇒ No, (false) dependency through p
⇒ Compute closed formula for p
p = a+∑
(i ′,j ′)∈S
(i ′,j ′)4(i ,j)
j ′⌊
j ′ − i ′
4
⌋
with S = { (i ′, j ′) ∈ Z2 | 0 ≤ i ′ < N ∧ i ′ ≤ j ′ < N }
![Page 79: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/79.jpg)
barvinok December 15, 2009 27 / 35
Weighted Counting Example
p = a;
for (i = 0; i < N; ++i)
for (j = i; j < N; ++j) {
p += j * ((j-i)/4);
*p = 0;
}
Can we parallelize this code?
⇒ No, (false) dependency through p
⇒ Compute closed formula for p
p = a+∑
(i ′,j ′)∈S
(i ′,j ′)4(i ,j)
j ′⌊
j ′ − i ′
4
⌋
= a+∑
(i ′,j ′)∈S
i ′<i
j ′⌊
j ′ − i ′
4
⌋
+∑
(i ′,j ′)∈S
i ′=i ,j ′≤j
j ′⌊
j ′ − i ′
4
⌋
with S = { (i ′, j ′) ∈ Z2 | 0 ≤ i ′ < N ∧ i ′ ≤ j ′ < N }
![Page 80: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/80.jpg)
barvinok December 15, 2009 27 / 35
Weighted Counting Example
p = a;
for (i = 0; i < N; ++i)
for (j = i; j < N; ++j) {
p += j * ((j-i)/4);
*p = 0;
}
Can we parallelize this code?
⇒ No, (false) dependency through p
⇒ Compute closed formula for p
p = a+∑
(i ′,j ′)∈S
(i ′,j ′)4(i ,j)
j ′⌊
j ′ − i ′
4
⌋
= a+∑
(i ′,j ′)∈S
i ′<i
j ′⌊
j ′ − i ′
4
⌋
+∑
(i ′,j ′)∈S
i ′=i ,j ′≤j
j ′⌊
j ′ − i ′
4
⌋
with S = { (i ′, j ′) ∈ Z2 | 0 ≤ i ′ < N ∧ i ′ ≤ j ′ < N }
⇒ weighted counting
![Page 81: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/81.jpg)
barvinok December 15, 2009 27 / 35
Weighted Counting Example
p = a;
for (i = 0; i < N; ++i)
for (j = i; j < N; ++j) {
p += j * ((j-i)/4);
*p = 0;
}
N − 1
i − 1
j ′
i ′
•••
••••
•••••
••••••
Can we parallelize this code?
⇒ No, (false) dependency through p
⇒ Compute closed formula for p
p = a+∑
(i ′,j ′)∈S
(i ′,j ′)4(i ,j)
j ′⌊
j ′ − i ′
4
⌋
= a+∑
(i ′,j ′)∈S
i ′<i
j ′⌊
j ′ − i ′
4
⌋
+∑
(i ′,j ′)∈S
i ′=i ,j ′≤j
j ′⌊
j ′ − i ′
4
⌋
with S = { (i ′, j ′) ∈ Z2 | 0 ≤ i ′ < N ∧ i ′ ≤ j ′ < N }
⇒ weighted counting
![Page 82: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/82.jpg)
barvinok December 15, 2009 28 / 35
Parametric Polytopes and Piecewise Step-polynomials
Parametric polytope:
P(s) : s 7→ {t ∈ Qd | As + Bt + c ≥ 0}
(N, i , j) → { (i ′, j ′) | 0 ≤ i ′ < i∧i ′ ≤ j ′ < N }
N − 1
i − 1
j ′
i ′
•••
••••
•••••
••••••
![Page 83: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/83.jpg)
barvinok December 15, 2009 28 / 35
Parametric Polytopes and Piecewise Step-polynomials
Parametric polytope:
P(s) : s 7→ {t ∈ Qd | As + Bt + c ≥ 0}
(N, i , j) → { (i ′, j ′) | 0 ≤ i ′ < i∧i ′ ≤ j ′ < N }
N − 1
i − 1
j ′
i ′
•••
••••
•••••
••••••
Step-polynomial: q(s, t) ∈ Q [⌊Q[s, t]≤1⌋] j ′⌊
j ′−i ′
4
⌋
Piecewise step-polynomial: (s, t) 7→
q1(s, t) if t ∈ P1(s)
. . .
qk(s, t) if t ∈ Pk(s)
![Page 84: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/84.jpg)
barvinok December 15, 2009 28 / 35
Parametric Polytopes and Piecewise Step-polynomials
Parametric polytope:
P(s) : s 7→ {t ∈ Qd | As + Bt + c ≥ 0}
(N, i , j) → { (i ′, j ′) | 0 ≤ i ′ < i∧i ′ ≤ j ′ < N }
N − 1
i − 1
j ′
i ′
•••
••••
•••••
••••••
Step-polynomial: q(s, t) ∈ Q [⌊Q[s, t]≤1⌋] j ′⌊
j ′−i ′
4
⌋
Piecewise step-polynomial: (s, t) 7→
q1(s, t) if t ∈ P1(s)
. . .
qk(s, t) if t ∈ Pk(s)
Weighted counting:
Zn → Q : s 7→∑
i
∑
t∈Zd
[t ∈ Pi (s)] qi (s, t)
![Page 85: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/85.jpg)
barvinok December 15, 2009 29 / 35
barvinok Overview
Main functionality: (weighted) counting of elements in polyhedral set
Input:
polyhedral set, or
piecewise step-polynomial
Output:
piecewise step-polynomial c(s)
⇒ number of elements in set⇒ weighted number of elements in each cell
or
generating function C (x) =∑
s c(s) xs
![Page 86: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/86.jpg)
bernstein December 15, 2009 30 / 35
Outline
1 Polyhedral Model
2 isl
Introduction and RepresentationParametric Integer Programming
3 CLooG
4 barvinok
5 bernstein
6 Conclusions
![Page 87: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/87.jpg)
bernstein December 15, 2009 31 / 35
Polyhedral Program Analysis and Transformation Overview
program code
parser
polyhedral model
polyhedralscanner
analysis andtransformation
for (i = 0; i <= N; ++i)
a[i] = ...
for (i = 0; i <= N; ++i)
b[i] = f(a[N-i])
for (i = 0; i <= N; ++i) {
a[i] = ...
b[N-i] = f(a[i])
}
• • • • •
◦◦◦◦◦
•
•
•
•
•
◦
◦
◦
◦
◦
![Page 88: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/88.jpg)
bernstein December 15, 2009 32 / 35
bernstein example
for (i = 0; i < N; ++i)
for (j = i; j < N; ++j) {
p = malloc(i * j + i - N + 1);
/* ... */
free(p);
}
How much memory is needed?
![Page 89: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/89.jpg)
bernstein December 15, 2009 32 / 35
bernstein example
for (i = 0; i < N; ++i)
for (j = i; j < N; ++j) {
p = malloc(i * j + i - N + 1);
/* ... */
free(p);
}
How much memory is needed?
m(N) = max(i ,j)∈S
(ij + i − N + 1)
with S = { (i , j) ∈ Z2 | 0 ≤ i < N ∧ i ≤ j < N }
![Page 90: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/90.jpg)
bernstein December 15, 2009 32 / 35
bernstein example
for (i = 0; i < N; ++i)
for (j = i; j < N; ++j) {
p = malloc(i * j + i - N + 1);
/* ... */
free(p);
}
How much memory is needed?
m(N) = max(i ,j)∈S
(ij + i − N + 1)
with S = { (i , j) ∈ Z2 | 0 ≤ i < N ∧ i ≤ j < N }
Typical application: maximal number of live elements
⇒ count the number of live elements at each execution point
⇒ compute upper bound over all execution points
![Page 91: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/91.jpg)
bernstein December 15, 2009 33 / 35
Computing Parametric Upper Bounds
Maximal memory requirements:
u(N) ≥ m(N) = max0≤i<N∧i≤j<N
(ij + i − N + 1)
m(N) can be approximated using Bernstein expansion ⇒ u(N)
Ideally:◮ maximum over◮ integer points
Bernstein expansion gives◮ upper bound over◮ rational points
In practice very accurate
![Page 92: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/92.jpg)
Conclusions December 15, 2009 34 / 35
Outline
1 Polyhedral Model
2 isl
Introduction and RepresentationParametric Integer Programming
3 CLooG
4 barvinok
5 bernstein
6 Conclusions
![Page 93: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/93.jpg)
Conclusions December 15, 2009 35 / 35
ConclusionSeveral tools have been developed within the context of the polyhedralmodel, including,
isl (http://freshmeat.net/projects/isl/)Represents and manipulates sets and relations of integersSupports several operations including parametric integer programmingCLooG (http://www.cloog.org/)Generates code for scanning the elements of polytopesbarvinok (http://freshmeat.net/projects/barvinok/)Counts the number of elements in a polyhedral set, possibly weightedby a step-polynomialbernstein (included in barvinok)Computes bounds on polynomials over parametric polytopes
![Page 94: Tools for the Polyhedral Model](https://reader030.fdocuments.us/reader030/viewer/2022020703/61fb357a2e268c58cd5b72fb/html5/thumbnails/94.jpg)
Conclusions December 15, 2009 35 / 35
ConclusionSeveral tools have been developed within the context of the polyhedralmodel, including,
isl (http://freshmeat.net/projects/isl/)Represents and manipulates sets and relations of integersSupports several operations including parametric integer programmingCLooG (http://www.cloog.org/)Generates code for scanning the elements of polytopesbarvinok (http://freshmeat.net/projects/barvinok/)Counts the number of elements in a polyhedral set, possibly weightedby a step-polynomialbernstein (included in barvinok)Computes bounds on polynomials over parametric polytopes
Future Work: port barvinok to isl; now uses
PolyLib: GPLv2 only, . . .⇒ isl needs chamber decomposition and parametric verticesNTL: not thread-safe, C++⇒ isl needs LLL