HOME

TheInfoList



OR:

The polyhedral model (also called the polytope method) is a mathematical framework for programs that perform large numbers of operations -- too large to be explicitly enumerated -- thereby requiring a ''compact'' representation. Nested loop programs are the typical, but not the only example, and the most common use of the model is for
loop nest optimization In computer science and particularly in compiler design, loop nest optimization (LNO) is an optimization technique that applies a set of loop transformations for the purpose of locality optimization or parallelization or another loop overhead re ...
in
program optimization In computer science, program optimization, code optimization, or software optimization, is the process of modifying a software system to make some aspect of it work more efficiently or use fewer resources. In general, a computer program may be o ...
. The polyhedral method treats each loop iteration within nested loops as
lattice points In geometry and group theory, a lattice in the real coordinate space \mathbb^n is an infinite set of points in this space with the properties that coordinate wise addition or subtraction of two points in the lattice produces another lattice poin ...
inside mathematical objects called
polyhedra In geometry, a polyhedron (plural polyhedra or polyhedrons; ) is a three-dimensional shape with flat polygonal faces, straight edges and sharp corners or vertices. A convex polyhedron is the convex hull of finitely many points, not all on ...
, performs affine transformations or more general non-affine transformations such as
tiling Tiling may refer to: *The physical act of laying tiles * Tessellations Computing *The compiler optimization of loop tiling *Tiled rendering, the process of subdividing an image by regular grid *Tiling window manager People *Heinrich Sylvester T ...
on the polytopes, and then converts the transformed polytopes into equivalent, but optimized (depending on targeted optimization goal), loop nests through polyhedra scanning.


Simple example

Consider the following example written in C: const int n = 100; int i, j, a n]; for (i = 1; i < n; i++) The essential problem with this code is that each iteration of the inner loop on a j] requires that the previous iteration's result, a j - 1], be available already. Therefore, this code cannot be parallelized or Pipeline (computing), pipelined as it is currently written. An application of the polytope model, with the affine transformation (i',\, j') = (i+j,\, j) and the appropriate change in the boundaries, will transform the nested loops above into: a - jj] = a - j - 1j] + a - jj - 1]; In this case, no iteration of the inner loop depends on the previous iteration's results; the entire inner loop can be executed in parallel. (However, each iteration of the outer loop does depend on previous iterations.)


Detailed example

The following C code implements a form of error-distribution
dither Dither is an intentionally applied form of noise used to randomize quantization error, preventing large-scale patterns such as color banding in images. Dither is routinely used in processing of both digital audio and video data, and is often ...
ing similar to
Floyd–Steinberg dithering Floyd–Steinberg dithering is an image dithering algorithm first published in 1976 by Robert W. Floyd and Louis Steinberg. It is commonly used by image manipulation software, for example when an image is converted into GIF format that is restr ...
, but modified for pedagogical reasons. The two-dimensional array src contains h rows of w pixels, each pixel having a
grayscale In digital photography, computer-generated imagery, and colorimetry, a grayscale image is one in which the value of each pixel is a single sample representing only an ''amount'' of light; that is, it carries only intensity information. Graysc ...
value between 0 and 255 inclusive. After the routine has finished, the output array dst will contain only pixels with value 0 or value 255. During the computation, each pixel's dithering error is collected by adding it back into the src array. (Notice that src and dst are both read and written during the computation; src is not read-only, and dst is not write-only.) Each iteration of the
inner loop Inner loop may refer to: * Inner loop in computer programs * Inner Loop (Phoenix), a section of Interstate 10 in downtown Phoenix, Arizona, United States * Inner Loop (Rochester), an expressway around downtown Rochester, New York, United States * I ...
modifies the values in src j] based on the values of src -1j], src j-1], and src +1j-1]. (The same dependencies apply to dst j]. For the purposes of Loop optimization#Common loop transformations, loop skewing, we can think of src j] and dst j] as the same element.) We can illustrate the dependencies of src j] graphically, as in the diagram on the right. Performing the affine transformation (p,\, t) = (i,\, 2j+i) on the original dependency diagram gives us a new diagram, which is shown in the next image. We can then rewrite the code to loop on p and t instead of i and j, obtaining the following "skewed" routine.


See also

* Frameworks supporting the polyhedral model *
Loop nest optimization In computer science and particularly in compiler design, loop nest optimization (LNO) is an optimization technique that applies a set of loop transformations for the purpose of locality optimization or parallelization or another loop overhead re ...
*
Loop optimization In compiler theory, loop optimization is the process of increasing execution speed and reducing the overheads associated with loops. It plays an important role in improving cache performance and making effective use of parallel processing capabi ...
*
Loop unrolling Loop unrolling, also known as loop unwinding, is a loop transformation technique that attempts to optimize a program's execution speed at the expense of its binary size, which is an approach known as space–time tradeoff. The transformation ...
*
Loop tiling In computer science and particularly in compiler design, loop nest optimization (LNO) is an optimization technique that applies a set of loop transformations for the purpose of locality optimization or parallelization or another loop overhead redu ...


External links and references


"The basic polytope method"
tutorial by Martin Griebl containing diagrams of the pseudocode example above
"Code Generation in the Polytope Model"
(1998). Martin Griebl, Christian Lengauer, and Sabine Wetzel
"The CLooG Polyhedral Code Generator""CodeGen+: Z-polyhedra scanning"PoCC: the Polyhedral Compiler CollectionPLUTO - An automatic parallelizer and locality optimizer for affine loop nests
**{{Cite book, last1=Bondhugula, first1=Uday, last2=Hartono, first2=Albert, last3=Ramanujam, first3=J., last4=Sadayappan, first4=P., date=2008-01-01, title=A Practical Automatic Polyhedral Parallelizer and Locality Optimizer, journal=Proceedings of the 29th ACM SIGPLAN Conference on Programming Language Design and Implementation, series=PLDI '08, location=New York, NY, USA, publisher=ACM, pages=101–113, doi=10.1145/1375581.1375595, isbn=9781595938602, s2cid=7086982
polyhedral.info
- A website that collect information about polyhedral compilation
Polly - LLVM Framework for High-Level Loop and Data-Locality Optimizations
*The MI
Tiramisu Polyhedral
Framework. Compiler optimizations Articles with example pseudocode Articles with example C code