%in kempton park+277-882-255-28 abortion pills for sale in kempton park
Compiler Designing
1. Iteration spaces
and
Affine array indexes
By
Vijayapriya P
II-MSc (CS)
Department of CS & IT
Nadar saraswathi college of arts & science
2. Define iteration
Constructing iteration spaces from nest loops
Execution Order for Loop Nests
Matrix Formulation of Inequalities
Incorporating Symbolic Constants
Controlling the Order of Execution
Affine array indexes
Affine bounds and indices
Affine accesses
Affine and Nonaffine accesses in practice
Topic includes
3. The iteration space of a loop nest is defined to be all the
combinations of loop-index values in the nest.
there are three kinds of spaces in our transformation model
iteration space
data space
processor space
Each of the nested loops had a lower bound of 0 and an
upper bound of n — 1. loop nests, the upper and/or lower
bounds on one loop index can depend on the values of the
indexes of the outer loops.
Define iteration spaces
4. The sort of loop nests that can be handled by the
techniques to be developed.
Each loop has a single loop index, which we assume is
incremented by 1 at each iteration.
That assumption is without loss of generality, since if the
incrementation is by integer c > 1,
we can always replace uses of the index i by uses of ci +
a for some positive or negative constant a, and then
increment i by 1 in the loop.
Constructing iteration spaces
from loop nests
5. We can always replace uses of the index i by uses of ci+
a for some positive or negative constant a, and then
increment i by 1 in the loop. However, in more complicated, but
still quite realistic, loop nests, the upper and/or lower bounds on
one loop index can depend on the values of the indexes of the
outer loops.
For (i=2 ; i<=100; i=i+3)
Z[i]=0;
which increments i by 3 each time around the loop. The
effect is to set to 0 each of the elements Z[2], Z[5], Z [ 8 ] , . .
. , Z[98].
6. For (j=2; j<=32; j++)
Z [3*j+2]=0;
Substitute 3j + 2 for i. The lower limit i = 2 becomes j = 0
(just solve 3j + 2 = 2 for j ) , and the upper limit i < 100
becomes j < 32 (simplify 3j + 2 < 100 to get j < 32.67 and
round down because j has to be an integer).
For-loops in loop nests. A while-loop or repeat-loop can be
replaced by a for-loop if there is an index and upper and
lower bounds .
7. Model this two-deep loop nest by the 2-dimensional
polyhedron . The two axes represent the values of the loop
Indexes i and j
Index i can take on any integral value between 0 and 5;
index j can take on any integral value such that i < j < 7 .
8. A sequential execution of a loop nest sweeps through
iterations in its iteration space in an ascending
lexicographic order.
A vector i = I is lexicographically less
than another vector ,written , if and only if
there exists an m < min such that d
note that m=0 .
Execution order for loop nests
9. The iterations in a d-deep loop can be represented
mathematically as
fi in Zd j Bi + b 0g
Matrix formulation of inequalities
10. 1. Z, as is conventional in mathematics, represents the
set of integers - positive, negative, and zero,
2. B is a d*d integer matrix,
3. b is an integer vector of length d, and
4. 0 is a vector of d 0's.
Matrix formulation of inequalities
The iterations in a d-deep loop can be represented
mathematically as. fi in Zd j Bi + b 0g
11. To optimize a loop nest that involves certain variables
that are loop-invariant for all the loops in the nest. We call
such variables symbolic constants, but to describe the
boundaries of an iteration space we need to treat them as
variables and create an entry for them in the vector of loop
indexes.
i.e., The vector i in the general formulation of inequalities.
Incorporating symbolic constants
12. for(i=0;i<=n; i++)
{
…
}
This loop defines a one-dimensional iteration space,
with index i, bounded by i 0 and i ≤ n. Since n is a
symbolic constant.
13. Controlling the order of execution
The linear inequalities extracted from the lower and
upper bounds of a loop body define a set of iterations over
a convex polyhedron. the representation assumes no
execution ordering between iterations within the iteration
space.
The original program imposes one sequential order on
the iterations, which is the lexicographic order with respect
to the loop index variables ordered from the outermost to
the innermost.
14. projection
Find the loop bounds of the outer loop index in a two-
deep loop nest by projecting the convex polyhedron
representing the iteration space onto the outer dimension of
the space.
The projection of a polyhedron on a lower-dimensional
space is intuitively the shadow cast by the object onto that
space. The projection of the two-dimensional iteration space
15. The algorithm to generate the loop bounds to iterate over
a convex polyhedron is straightforward. We compute the
loop bounds in order, from the innermost to the outer loops.
Algorithm : Computing bounds for a given order of variables.
INPUT : A convex polyhedron S over variables v1,... ,vn.
OUTPUT : A set of lower bounds L{ and upper bounds Ui
for each vi, expressed only in terms of the fj's, for j < i.
METHOD : The algorithm is described
Loop- Bounds generation
16. Changing Axes
Sweeping the iteration space horizontally and vertically, as
discussed above, are just two of the most common ways of
visiting the iteration space. there are many other possibilities.
There are many other iteration-traversal orders not handled
by this technique. For example, we may wish to visit all the
odd rows in an iteration space before we visit the even rows.
18. Affine array indexes
The class of affine array accesses, where each array index is
Expressed as affine expression of loop indexes and symbolic
Constant. Affine function provide a succinct mapping from the
iteration. Space to the data space, making it easy to determine
which Iteration map to the same data or same cache line.
The affine upper and lower bounds of a loop can be
Represented as a matrix-vector calculation , we can do the
Same for affine access functions.
19. Affine bounds and indices
Assume loop bounds and array index expression are
Affine expression
A0+a1*i1+ …+ak * ik
Each loop bound for loop index ik is an affine expression
Over the previous loop indices i1 to i(k-1). Each loop
index expression is a affine expression over all loop
indices.
20. Affine accesses
The bounds of the loop are expressed as affine expressions
of the surrounding loop variables and symbolic constants.
The index for each dimension of the array is also an affine
expression of surrounding loop variables and symbolic
constants.
Example
Suppose i and j are loop index variables bounded by affine
expressions. Some examples of affine array accesses are Z[i],
Z[i + j + 1], Z[0], Z[i, i], and Z[2*i +1,3* j — 10].
21. If n is a symbolic constant for a loop nest, then Z[S * n, n — j]
is another example of an affine array access. However, Z[i * j]
and Z[n * j] are not affine accesses.
Each affine array access can be described by two matrices and
two vectors. The first matrix-vector pair is the B and b that
describe the iteration space for the access, as in the inequality of
Equation .
The second pair, which we usually refer to
as F and f, represent the function(s) of the loop-index variables
that produce the array index(es) used in the various dimensions
of the array access.
22. Formally, we represent an array access in a loop nest that
uses a vector of index variables i by the four-tuple T =
(F,f,B>b); it maps a vector i within the bounds
Bi+b>0
To the array element location
Fi+f
Also notice the third access, Y [j,j + 1], which, after matrix-
vector multiplication and addition, yields a pair of
functions, (J,j + 1). Finally, let us observe the fourth access
K[l,2] . This access is a constant, and unsurprisingly the
matrix F is all 0's. Thus, the vector of loop indexes, i, does
not appear in the access function.