Polytope modelThe 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 program optimization. The polyhedral method treats each loop iteration within nested loops as lattice points inside mathematical objects called polyhedra, performs affine transformations or more general non-affine transformations such as tiling on the polytopes, and then converts the transformed polytopes into equivalent, but optimized (depending on targeted optimization goal), loop nests through polyhedra scanning. Simple exampleConsider the following example written in C: const int n = 100;
int i, j;
int a[n][n] = {{0,1}};
for (i = 1; i < n; i++) {
for (j = 1; j < (i + 2) && j < n; j++) {
a[i][j] = a[i - 1][j] + a[i][j - 1];
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; ++j) {
printf("%4d ", a[i][j]);
}
puts("");
}
The essential problem with this code is that each iteration of the inner loop on An application of the polytope model, with the affine transformation and the appropriate change in the boundaries, will transform the nested loops above into: a[i - j][j] = a[i - j - 1][j] + a[i - j][j - 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. Indeed, given Detailed example![]() src , before loop skewing. The red dot corresponds to src[1][0] ; the pink dot corresponds to src[2][2] .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 Each iteration of the inner loop modifies the values in
![]() src , after loop skewing. The array elements will be processed in the order gray, red, green, blue, yellow...Performing the affine transformation 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
See also
External links and references
|
Portal di Ensiklopedia Dunia