Algorithm Search⌘K

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 S(i⃗)S(\vec{i}) 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 if is 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 NN, 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 SS inside dSd_S loops has the domain

DS(N⃗)={ i⃗∈ZdS:ASi⃗+BSN⃗+c⃗S≥0⃗ },\mathcal{D}_S(\vec{N}) = \{\, \vec{i} \in \mathbb{Z}^{d_S} : A_S \vec{i} + B_S \vec{N} + \vec{c}_S \ge \vec{0} \,\},

the integer points of a polyhedron that depends on the parameters N⃗\vec{N}. Each point is one instance S(i⃗)S(\vec{i}).

Accesses. Each reference of SS to an array XX is an affine function f(i⃗)=Fi⃗+GN⃗+h⃗f(\vec{i}) = F \vec{i} + G \vec{N} + \vec{h}. The instance S(i⃗)S(\vec{i}) reads or writes the cell X[f(i⃗)]X[f(\vec{i})].

Schedules. A schedule gives each statement an affine map θS(i⃗)=ΘSi⃗+ΓSN⃗+γ⃗S∈Zm\theta_S(\vec{i}) = \Theta_S \vec{i} + \Gamma_S \vec{N} + \vec{\gamma}_S \in \mathbb{Z}^m. 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 (0,i,1)(0, i, 1).

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 ff of SS and gg of TT, the dependent pairs are

PS,T={ (s⃗,t⃗):s⃗∈DS, t⃗∈DT, f(s⃗)=g(t⃗), θS0(s⃗)≺θT0(t⃗) }.\mathcal{P}_{S,T} = \{\, (\vec{s}, \vec{t}) : \vec{s} \in \mathcal{D}_S,\ \vec{t} \in \mathcal{D}_T,\ f(\vec{s}) = g(\vec{t}),\ \theta^0_S(\vec{s}) \prec \theta^0_T(\vec{t}) \,\}.

The order ≺\prec is a disjunction (equal in the first l−1l - 1 entries and smaller in entry ll), so PS,T\mathcal{P}_{S,T} is a union of polyhedra, one per level ll. These are dependence polyhedra.

Execution and equivalence. A new schedule θ\theta is legal if θS(s⃗)≺θT(t⃗)\theta_S(\vec{s}) \prec \theta_T(\vec{t}) 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 NN. 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 Θ\Theta, 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 LL runs the program in LL parallel steps with unbounded processors. So LL 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 θT(t⃗)−θS(s⃗)≥1\theta_T(\vec{t}) - \theta_S(\vec{s}) \ge 1 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 N2N^2 dependent steps, such as a running sum over a square array, has latency N2N^2, and no affine function of the instance can give that latency with coefficients that do not depend on NN. 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 DS1={S1[i]:0≤i≤N−1}\mathcal{D}_{S1} = \{ S1[i] : 0 \le i \le N - 1 \} and DS2={S2[i,j]:0≤i≤N−1, 0≤j≤i}\mathcal{D}_{S2} = \{ S2[i, j] : 0 \le i \le N - 1,\ 0 \le j \le i \}, with NN and N(N+1)/2N(N + 1)/2 points. The original schedules, without the constant first entry of the 2d+1 form, are θS10(i)=(i,0,0)\theta^0_{S1}(i) = (i, 0, 0) and θS20(i,j)=(i,1,j)\theta^0_{S2}(i, j) = (i, 1, j). The write of y[i]y[i] by S2S_2 and its read by a later S2S_2 give the dependence polyhedron {(S2[i,j],S2[i′,j′]):i′=i, 0≤j<j′≤i≤N−1}\{ (S2[i, j], S2[i', j']) : i' = i,\ 0 \le j < j' \le i \le N - 1 \} of all memory-based flow dependences. The value that S2[i,j′]S2[i, j'] reads comes only from S2[i,j′−1]S2[i, j' - 1] for j′≥1j' \ge 1, and from S1[i]S1[i] for j′=0j' = 0; that is the exact dataflow. The schedule θS1(i)=(0,i)\theta_{S1}(i) = (0, i) and θS2(i,j)=(j+1,i)\theta_{S2}(i, j) = (j + 1, i) is also legal: it initializes all of yy first, then runs the jj loop outside, and the inner loop over ii (from jj to N−1N - 1) is parallel.

References

  1. 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
  2. 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
  3. 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
  4. 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
  5. 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
  6. 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
  7. 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.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/2D6R5Q/text.yaml