Polytope model

Polytope model

The polyhedral model (also called the polytope method) is a mathematical framework for loop nest optimization in compiler theory. The polytope method models operations within nested manifest loops as mathematical objects called polytopes, performs affine transformations on the polytopes, and then converts the transformed polytopes into equivalent, but more efficient, loop nests.

Consider the following example in pseudocode:

for i := 0 to n do for j := 0 to i+2 do A(i, j) := A(i-1, j) + A(i, j-1) end end

The essential problem with this code is that each iteration of the inner loop on A(i, j) requires that the previous iteration's result A(i, j-1) be available already. Therefore, this code cannot be parallelized or pipelined as it is currently written.

An application of the polytope model will transform the nested loops above into

for t := 0 to 2n+2 do for p := max(0, t-n) to min(t, floor(t/2)+1) do A(t-p, p) := A(t-p-1, p) + A(t-p, p-1) end end

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, over t, does depend on previous iterations.)

Detailed example

The following C code implements a form of error-distribution dithering similar to Floyd-Steinberg dithering, but modified for pedagogical reasons. The two-dimensional array src contains h rows of w pixels, each pixel having a grayscale 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 modifies the values in src [i] [j] based on the values of src [i-1] [j] , src [i] [j-1] , and src [i+1] [j-1] . (The same dependencies apply to dst [i] [j] . For the purposes of loop skewing, we can think of src [i] [j] and dst [i] [j] as the same element.) We can illustrate the dependencies of src [i] [j] graphically, as in the diagram on the right.

#define ERR(x,y) (dst [x] [y] - src [x] [y] ) void dither(unsigned char **src, unsigned char **dst, int w, int h) { int i, j; for (j=0; j < h; ++j) { for (i=0; i < w; ++i) { int v = src [i] [j] ; if (i > 0) v -= ERR(i-1, j)/2; if (j > 0) v -= ERR(i, j-1)/4; if (j > 0 && i < w-1) v -= ERR(i+1, j-1)/4; dst [i] [j] = (v < 128)? 0: 255; src [i] [j] = (v < 0)? 0: (v < 255)? v: 255; } } }

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.

void dither_skewed(unsigned char **src, unsigned char **dst, int w, int h) { int t, p; for (t=0; t < w + 2*h; ++t) { int pmin = max(t%2, t - 2*h + 2); int pmax = min(t, w-1); for (p=pmin; p <= pmax; p += 2) { int i = p; int j = (t-p)/2; int v = src [i] [j] ; if (i > 0) v -= ERR(i-1, j)/2; if (j > 0) v -= ERR(i, j-1)/4; if (j > 0 && i < w-1) v -= ERR(i+1, j-1)/4; dst [i] [j] = (v < 128)? 0: 255; src [i] [j] = (v < 0)? 0: (v < 255)? v: 255; } } }

ee also

*Frameworks supporting the polyhedral model
*Loop nest optimization
*Loop unrolling
*Loop reversal
*Loop tiling

External links and references

* [http://www.infosun.fmi.uni-passau.de/cl/loopo/doc/loopo_doc/node3.html "The basic polytope method"] , tutorial by Martin Griebl containing diagrams of the pseudocode example above
* [http://www.cloog.org/ "The CLooG Polyhedral Code Generator"]
* [http://citeseer.ist.psu.edu/griebl98code.html "Code Generation in the Polytope Model"] (1998). Martin Griebl, Christian Lengauer, and Sabine Wetzel


Wikimedia Foundation. 2010.

Игры ⚽ Нужно сделать НИР?

Look at other dictionaries:

  • Regular polytope — In mathematics, a regular polytope is a polytope whose symmetry is transitive on its flags, thus giving it the highest degree of symmetry. All its elements or j faces (for all 0≤ j ≤ n , where n is the dimension of the polytope) cells, faces and… …   Wikipedia

  • Frameworks supporting the polyhedral model — Use of the polyhedral model within a compiler requires software to represent the objects of this framework (sets of integer valued points in regions of various spaces) and perform operations upon them (e.g., testing whether the set is empty). Two …   Wikipedia

  • Littelmann path model — In mathematics, the Littelmann path model is a combinatorial device due to Peter Littelmann for computing multiplicities without overcounting in the representation theory of symmetrisable Kac Moody algebras. Its most important application is to… …   Wikipedia

  • Автоматическое распараллеливание — Автоматическое распараллеливание  оптимизация программы компилятором, состоящая в автоматическом ее преобразовании в форму, работающую на параллельном компьютере, например, на SMP или NUMA машине. Целью автоматизации распараллеливания… …   Википедия

  • Loop optimization — In compiler theory, loop optimization plays an important role in improving cache performance, making effective use of parallel processing capabilities, and reducing overheads associated with executing loops. Most execution time of a scientific… …   Wikipedia

  • Automatic parallelization — Automatic parallelization, also auto parallelization, autoparallelization, parallelization, or //ization (shorthand), the last two of which imply automation when used in context, refers to converting sequential code into multi threaded or… …   Wikipedia

  • Manifest expression — A manifest expression is a programming language construct that a compiler can analyse to deduce which values it can take without having to execute the program. This information can enable compiler optimizations, in particular loop nest… …   Wikipedia

  • 120-cell — Schlegel diagram (vertices and edges) Type Convex regular 4 polytope Schläfli symbol {5,3,3} …   Wikipedia

  • Linear programming — (LP, or linear optimization) is a mathematical method for determining a way to achieve the best outcome (such as maximum profit or lowest cost) in a given mathematical model for some list of requirements represented as linear relationships.… …   Wikipedia

  • List of mathematics articles (G) — NOTOC G G₂ G delta space G networks Gδ set G structure G test G127 G2 manifold G2 structure Gabor atom Gabor filter Gabor transform Gabor Wigner transform Gabow s algorithm Gabriel graph Gabriel s Horn Gain graph Gain group Galerkin method… …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”