Modeladvanced
Polyhedral model
Also called polytope model, polyhedral compilation.
Represents a loop nest with affine bounds and accesses as integer points in polyhedra, with affine schedules and access functions.
The polyhedral model describes a loop nest by sets of integer points instead of by its text. Each execution of a statement, a statement instance, is an integer point in a polyhedron, the iteration domain. Each array reference is an affine function from the instance to the array cell it touches. The order of execution is an affine schedule that maps each instance to a date, a vector of integers compared in lexicographic order. Dependences become sets of pairs of points described by linear constraints. With this, questions about the program (which instance writes the value that this one reads, is this reordering legal, how should the code look after the change) become questions about linear inequalities over the integers. Its roots are the uniform recurrence equations of Karp, Miller and Winograd (1967) and the hyperplane method of Lamport (1974). Feautrier gave it its general form for array programs in 1988 to 1992. It is the basis of the Pluto compiler, of CLooG and isl, and of the polyhedral optimizers in GCC (Graphite) and LLVM (Polly).
The machine
Programs. The model covers a static control part (SCoP): a part of a program built from for loops, if statements and assignments, such that
- the bounds of each loop are maxima and minima of affine functions of the outer loop indices and of the parameters;
- each condition of an
ifis a conjunction of affine inequalities in the same quantities; - each array subscript is an affine function of the loop indices and the parameters;
- the parameters, such as the size , are integers that do not change inside the part.
Integer division and remainder by a constant are often allowed too (quasi-affine expressions), since they can be written with extra integer variables. Scalars are arrays with zero dimensions.
Iteration domains. A statement inside loops has the domain
the integer points of a polyhedron that depends on the parameters . Each point is one instance .
Accesses. Each reference of to an array is an affine function . The instance reads or writes the cell .
Schedules. A schedule gives each statement an affine map . The machine runs the instances in increasing lexicographic order of their dates. Instances with equal dates may run in any order, or at the same time. The original program has the 2d+1 schedule: interleave the loop indices with the textual position of each statement at each depth. For example, the schedule of a statement that is the second one inside the first loop of the program is .
Dependences. A pair of instances depends if both touch the same cell, at least one writes it, and the first comes first in the original schedule. For two references of and of , the dependent pairs are
The order is a disjunction (equal in the first entries and smaller in entry ), so is a union of polyhedra, one per level . These are dependence polyhedra.
Execution and equivalence. A new schedule is legal if for every dependent pair. Then every instance reads the same values as in the original order, by the reordering theorem on the legality page. Code generation turns the domains and the new schedule back into loops that visit each instance once, in schedule order; see polyhedral scanning.
What falls outside. Subscripts such as A[B[i]] or A[i*j], loops with while, bounds that depend on data, pointers with unknown targets, and calls with unknown side effects are not affine. A compiler either leaves such code out of the SCoP, or treats it with over-approximations, which lose the exactness of the analysis.
What it counts
The model is a representation, so it fixes what an analysis or a transformation can see and measure, not a single cost.
- Instances, not statements. Each dependence is known for each pair of instances, exactly, as a set of integer points. This is finer than a distance vector or a direction vector, which summarize the set.
- Size independent of the parameters. A domain or a dependence polyhedron has as many constraints as the program text gives, whatever the value of . The cost of the analysis depends on the number of statements, loops and references, not on the number of instances.
- Quality of a schedule. A schedule is judged by the number of sequential dimensions (each dimension that carries a dependence is a sequential loop), by which dimensions are parallel (no dependence carried there), by its latency (the number of distinct dates, which bounds the parallel time with unbounded processors), and by locality measures. Pluto, for example, bounds the dependence distance along each new dimension, which is a measure of reuse distance and of communication volume.
- Cost of the operations. The basic operations are tests of integer emptiness, projection, lexicographic minimum of integer points, and counting. Integer emptiness is integer linear programming, which is NP-complete in general but polynomial when the dimension is fixed. Fourier-Motzkin elimination can make the number of constraints grow doubly exponentially in the number of eliminated variables. In practice the dimensions are small (the depth of a loop nest), so these operations are fast enough.
A legal schedule is only a correct one. It can be slower than the original program, for example if it makes the inner loop jump through memory, or adds loops with large overhead. The objective functions of polyhedral schedulers are heuristics for speed, not proofs of it.
Relation to other models
- Dependence abstractions. Distance vectors, direction vectors and dependence levels are summaries of dependence polyhedra. The Allen-Kennedy algorithm uses levels only, and the unimodular transformations of a perfect nest use distance or direction vectors. A unimodular transformation is the special case of an affine schedule in which every statement gets the same square unimodular matrix , without the constant parts.
- Uniform recurrence equations. Karp, Miller and Winograd studied computations on the lattice points of a region in which each value depends on values at constant offsets. This is the case of the polyhedral model where every dependence has a constant distance. Their schedules, and the hyperplane method of Lamport for loops, are one-dimensional affine schedules of this case.
- Presburger arithmetic. Sets of integer points defined by affine constraints with existential quantifiers, unions and differences can all be written in Presburger arithmetic. Tools such as the Omega test and isl work with these Presburger sets. They are closed under projection, union and difference, while the integer points of a single polyhedron are not.
- Abstract interpretation. The polyhedra domain of abstract interpretation also uses convex polyhedra, but as over-approximations of the values of variables. The polyhedral model uses them to describe exactly the instances of a program whose control does not depend on data.
- Work and span. A schedule with one dimension and latency runs the program in parallel steps with unbounded processors. So is at least the length of the longest chain of dependences, which is the span of the computation in the work-span model.
Known results in the model
- Exact array dataflow. For a static control program, the source of each read (the last instance that wrote the cell before the read) is a piecewise affine function of the instance and the parameters, given by a quasi-affine selection tree. Feautrier computes it with parametric integer programming; see array dataflow analysis.
- Linear legality. The condition that for all points of a dependence polyhedron is an infinite set of constraints. The affine form of Farkas' lemma turns it into a finite set of linear equalities on the coefficients of the schedule and on new nonnegative multipliers. So the search for a one-dimensional affine schedule is a linear program; see the affine scheduling problem.
- Existence of schedules. A one-dimensional affine schedule may not exist. A loop nest whose instances form one chain of dependent steps, such as a running sum over a square array, has latency , and no affine function of the instance can give that latency with coefficients that do not depend on . A multidimensional affine schedule always exists for a static control program: the 2d+1 schedule of the original order is one. Feautrier's greedy method builds one in which each dimension satisfies as many dependences as it can; see Feautrier scheduling.
- Code generation. The integer points of a union of parameterized polyhedra can be scanned in lexicographic order by loops whose bounds come from Fourier-Motzkin elimination (Ancourt and Irigoin, 1991). Quilleré, Rajopadhye and Wilde (2000) and Bastoul's CLooG (2004) separate the domains of several statements to avoid guards in the loop bodies; see polyhedral scanning.
- Tiling for locality and parallelism. The tiling hyperplanes of the Pluto algorithm are found one at a time by a lexicographic minimum of an integer program that bounds the dependence distances, and they give tileable bands with outer parallel or pipelined loops.
- Counting. The number of instances of a statement, of distinct cells touched, or of cache misses in some models, is the number of integer points of a parametric polyhedron. Barvinok's algorithm counts the integer points of a polyhedron of fixed dimension in polynomial time, and its parametric form gives the count as a piecewise quasi-polynomial in the parameters; see the Barvinok algorithm.
Example. Take the triangular matrix-vector product
for i = 0 to N-1:
S1: y[i] = 0
for j = 0 to i:
S2: y[i] = y[i] + L[i][j] * x[j]
The domains are and , with and points. The original schedules, without the constant first entry of the 2d+1 form, are and . The write of by and its read by a later give the dependence polyhedron of all memory-based flow dependences. The value that reads comes only from for , and from for ; that is the exact dataflow. The schedule and is also legal: it initializes all of first, then runs the loop outside, and the inner loop over (from to ) is parallel.
References
- Richard M. Karp, Raymond E. Miller and Shmuel Winograd, The organization of computations for uniform recurrence equations, Journal of the ACM 14(3), 1967, 563-590, systems of uniform recurrence equations on the lattice points of a region, their computability and their schedules
- Paul Feautrier, Dataflow analysis of array and scalar references, International Journal of Parallel Programming 20(1), 1991, 23-53, static control programs, iteration domains, the sequencing predicate and the exact source of each read by parametric integer programming
- Paul Feautrier, Some efficient solutions to the affine scheduling problem, Part I, one-dimensional time, International Journal of Parallel Programming 21(5), 1992, 313-347, affine schedules, the affine form of Farkas' lemma, and the linear program for one-dimensional schedules
- Paul Feautrier, Some efficient solutions to the affine scheduling problem, Part II, multidimensional time, International Journal of Parallel Programming 21(6), 1992, 389-420, multidimensional affine schedules, their existence for every static control program, and the greedy construction
- Cédric Bastoul, Code generation in the polyhedral model is easier than you think, Proceedings of the 13th International Conference on Parallel Architectures and Compilation Techniques (PACT), 2004, 7-16, scattering functions, the scanning of unions of polyhedra and the CLooG code generator
- Uday Bondhugula, Albert Hartono, J. Ramanujam and P. Sadayappan, A practical automatic polyhedral parallelizer and locality optimizer, PLDI 2008, 101-113, the polyhedral representation used by Pluto (domains, dependence polyhedra, statement-wise affine transformations) and the tiling hyperplanes
- Alexander I. Barvinok, A polynomial time algorithm for counting integral points in polyhedra when the dimension is fixed, Mathematics of Operations Research 19(4), 1994, 769-779, the main theorem (counting the integer points of a rational polyhedron in fixed dimension in polynomial time)
Where this leads
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag 2D6R5Q Edit this page History Report an error Markdown