dependence relationpingali/cs395t/2012sp/... · 2009. 10. 28. · lo op sk ewing a linear lo op...
TRANSCRIPT
![Page 1: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/1.jpg)
��
��
Transformations and Dependences
�
![Page 2: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/2.jpg)
��
��
Recall�
� Polyhedral algebra tools for
� determining emptiness of convex polyhedra
� enumerating integers in such a polyhedron�
� Central ideas�
� reduction of matrices to echelon form by unimodular
column operations�
� Fourier�Motzkin elimination
Let us use these tools to determine �i� legality of permutation and
�ii� generation of transformed code��
![Page 3: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/3.jpg)
Dependence relation
![Page 4: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/4.jpg)
Legal and impossible dependences
![Page 5: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/5.jpg)
Distance vectors
![Page 6: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/6.jpg)
Distance vectors
![Page 7: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/7.jpg)
Computing distance vectors
![Page 8: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/8.jpg)
Distance vectors: 2D loop nest
![Page 9: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/9.jpg)
Direction vectors
![Page 10: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/10.jpg)
Direction vectors for nested loops
![Page 11: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/11.jpg)
Example
![Page 12: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/12.jpg)
Example (contd.)
![Page 13: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/13.jpg)
Example (contd.)
![Page 14: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/14.jpg)
Dependence matrix
![Page 15: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/15.jpg)
��
��
Questions: (1) How do we generate new loop bounds? (2) How do we modify the loop body? (3) How do we know when loop interchange is legal?
DO I = 1, N
X(I,J) = 5
DO U = 1, N
X(V,U) = 5
0 11 0
IJ
= UV
DO J = I,N DO V = 1,U
Loop permutation can be modeled as a linear transformation on iteration space:
I
J
U
V
Permutation of loops in n-loop nest: nxn permutation matrix P
P I = U
�
![Page 16: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/16.jpg)
��
��
J2J1
Dependence distance = I2 - I1J2 - J1
Distance between iterations =
= I2 - I1J2 - J1
J2 - J1I2 - I1
I2J2
T T I1J1
T I1J1
I2J2
T
T- =
I
J
U
V
0 11 0
IJ
= UV
I2I1
Check for legality: interchange positions in distance/direction vector & check for lex +ve
DO I = 1, N
DO J = I,N
DO U = 1, N DO V = 1,U
.......... .........
If transformation P is legal and original dependence matrix is D, new dependence matrix is T*D.
��
![Page 17: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/17.jpg)
��
��
Correctness of general permutation
Transformation matrix� T
Dependence matrix� D
Matrix in which each column is a distancedirection vector
Legality� T�D � �
Dependence matrix of transformed program� T�D
��
![Page 18: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/18.jpg)
��
��
Examples�
DO I � ��N
DO J � ��N
X�I�J� � X�I��J��
Distance vector �� �� � permutation is legal
Dependence vector of transformed program �� ��
DO I � ��N
DO J � ��N
X�I�J� � X�I��J���
Distance vector �� ��� � permutation is not legal
�
![Page 19: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/19.jpg)
��
��
Code Generation for Transformed Loop Nest
Two problems� �� Loop bounds ��� Change of variables in body
�� New bounds�
Original bounds� A � I � b where A is in echelon form
Transformation� U � T � I
Note� for loop permutation� T is a permutation matrix
�� inverse is integer matrix
So bounds on U can be written as A � T��U � b
Perform Fourier�Motzkin elimination on this system of
inequalities to obtain bounds on U �
��� Change of variables�
I � T��U
Replace old variables by new using this formula
�
![Page 20: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/20.jpg)
��
��
Example�
-1 0
1 -1 0 1
1 00 11 0
< -1N 0N
UV
I
J
U
V
DO I = 1, N
X(I,J) = 5
DO U = 1, N
X(V,U) = 5
0 11 0
IJ
= UV
DO J = I,N DO V = 1,U
-1 0
1 -1 0 1
JI < -1
1 0 N 0N
elimination Fourier-Motzkin
�
![Page 21: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/21.jpg)
��
��
< -1N 0N
UV
<
< <
< <
-1 0
1 -1 0 1
1 00 11 0
-1N 0N
UV
-1 1 1 0
0 1 0 -1
Projecting out V from system gives
U 1 N
Bounds for V are
min(U,N) 1 V
These are loop bounds given by FM elimination.With a little extra work, we can simplify the upper bound of V to U.
�
![Page 22: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/22.jpg)
��
��
Key points�
� Loop bounds determination in transformed code is mechanical�
� Polyhedral algebra technology can handle very general bounds
with max s in lower bounds and min s in upper bounds�
� No need for pattern matching etc for triangular bounds and the
like�
�
![Page 23: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/23.jpg)
��
��
Theory for permutations applies to other loop transformations that
can be modeled as linear transformations� skewing� reversal�scaling�
Transformation matrix� T �a non�singular matrix�
Dependence matrix� D
Matrix in which each column is a distance�direction vector
Legality� T�D �
Dependence matrix of transformed program� T�D
Small complication with code generation if scaling is included�
�
![Page 24: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/24.jpg)
��
��
Motivating example� Wavefront code
���� �� �� ���� ��������
����
���� �� �� ���� ���� ��
���� �� �� ���� ���� ��
��������
����
����
��������
��������
����
���� �� �� ���� ��������
����
I
J
1 2 3 54
1
2
3
4
5
DO I = 1,N DO J = 1,N X(I,J) = X(I-1,J+1)......
Dependence matrix = -1
1
Dependence between two iterations
�� iterations touch the same location
�� potential for exploiting data reuse�
N iteration points between executions of dependent iterations�
Can we schedule dependent iterations closer together�
�
![Page 25: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/25.jpg)
��
��
For now� focus only on reuse opportunities between dependent
iterations�
This exploits only one kind of temporal locality�
There are other kinds of locality that are important�
� iterations that read from the same location� input dependences
� spatial locality
Both are easy to add to basic model as we will see later�
![Page 26: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/26.jpg)
��
��
Exploiting temporal locality in wavefront
����
��������
����
��������
�� ����
����
��������
����
��������
�� ����
����
��������
����
��������
�� ����
�� ���� �� ���� ����
��������
�� ���� �� ���� ����
��������
���� ���� �� �� �� ��
���� ���� �� �� ����
����
��������
��������
����
����
�� ��
��������
��������
����
����
�� ��
���� ���� �� �� ����
����
I
J
1 2 3 54
1
2
3
4
5
I
J
1 2 3 54
1
2
3
4
5
Tiling is illegal!Permutation is illegal!
We have studied two transformations� permutation and tiling�
Permutation and tiling are both illegal�
�
![Page 27: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/27.jpg)
��
��
Height Reduction
��
![Page 28: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/28.jpg)
��
��
One solution� schedule iterations along �� degree planes �
H
G
J
I
Note�� Transformation is legal�
� Dependent iterations are scheduled close together� so good for
locality�
Can we view this in terms of loop transformation�
Loop skewing followed by loop reversal�
��
![Page 29: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/29.jpg)
��
��
Loop Skewing� a linear loop transformation
I
J
U
V
IJ
= UV1 1
1 0
1-1
10
Skewing of inner loop by outer loop:
Skewing of inner loop by an outer loop: always legal
New dependence vectors: compute T*D
In this example, D = T*D =
This skewing has changed dependence vector but it has not brought dependent iterations
closer together....
1 0k 1
(k is some fixed integer)
��
![Page 30: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/30.jpg)
��
��
Skewing outer loop by inner loop
IJ
= UV
I
J
U
V
1 10 1
1 k0 1
Outer loop skewing:
Skewing of outer loop by inner loop: not necessarily legal
In this example, D = -1
T*D = 0-1
1 incorrect
Dependent iterations are closer together (good) but program is illegal (bad). How do we fix this??
��
![Page 31: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/31.jpg)
��
��
Loop Reversal�a linear loop transformation
0 0I U
U = [-1][I]
DO I = 1, N
X(I) = I+2 X(-U) = -U +2
DO U = -N,-1
Transformation matrix = [-1]
Another example: 2-D loop, reverse inner loop UV
IJ
1 00 -1
=
Legality of loop reversal: Apply transformation matrix to all dependences & verify lex +ve
5 -5
Code generation: easy
��
![Page 32: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/32.jpg)
��
��
Need for composite transformations
1 10 1
1 00 -1
I
J
U
V
IJ
= UV
UV
= GH
G
H
Composition of linear transformations= another linear transformation!
Composite transformation matrix is
* = 1 00 -1
1 10 1
1 10 -1
How do we synthesize this composite transformation??
close together! In final program, dependent iterations are
Transformation: skewing followed by reversal
��
![Page 33: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/33.jpg)
��
��
Some facts about permutation�reversal�skewing
� Transformation matrices for permutation�reversal�skewing are
unimodular�
� Any composition of these transformations can be represented
by a unimodular matrix�
� Any unimodular matrix can be decomposed into product of
permutation�reversal�skewing matrices�
� Legality of composite transformation T � check that T�D � �
�Proof� T� � �T� � �T� �D�� � �T� � T� � T�� �D��
� Code generation algorithm�
� Original bounds� A � I � b
� Transformation� U � T � I
� New bounds� compute from A � T��U � b
��
![Page 34: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/34.jpg)
��
��
Synthesizing composite transformations using matrix�based
approaches
� Rather than reason about sequences of transformations� we can
reason about the single matrix that represents the composite
transformation�
� Enabling abstraction� dependence matrix
��
![Page 35: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/35.jpg)
��
��
Height reduction� move reuse into inner loops
Dependence vector is�
���
��
Prefer not to have dependent iterations in di�erent outer loop iterations�
So dependence vector in transformed program should look like�
���
��
So T ��
���
��
��
���
This says rst row of T is orthogonal to�
���
��
So rst row of T can be chosen to be � ���
What about second row�
�
![Page 36: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/36.jpg)
��
��
Second row of T �call it s� should satisfy the following properties�
� s should be linearly independent of rst row of T non�singular
matrix��
� T �D should be a lexicographically positive vector�
� Determinant of matrix should be � or �� unimodularity��
One choice� � � ��� giving T ��
� �
� ���
�
�
![Page 37: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/37.jpg)
��
��
General questions
� How do we choose the �rst few rows of the transformation
matrix to push reuses down�
�� How do we �ll in the rest of the matrix to get unimodular
matrix�
��
![Page 38: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/38.jpg)
��
��
Linear loop transformations to enable tiling
�
![Page 39: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/39.jpg)
��
��
In general� tiling is not legal�
����
��������
��������
����
���� ��
����
��������
��������
����
��������
����
����
��������
��������
����
���� ��
����
��������
��������
����
��������
����
�� ���� ���� �� ���� ��
I
J
1 2 3 54
1
2
3
4
5
Tiling is illegal!
D = -1 1
Tiling is legal if loops are fully permutable �all permutations of
loops are legal��
Tiling is legal if all entries in dependence matrix are non�negative�
� Can we always convert a perfectly nested loop into a fully
permutable loop nest�
� When we can� how do we do it���
![Page 40: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/40.jpg)
��
��
Theorem� If all dependence vectors are distance vectors� we can
convert entire loop nest into a fully permutable loop nest�
Example� wavefront
Dependence matrix is�
� �
�A�
Dependence matrix of transformed program must have all positive
entries�
So �rst row of transformation can be � ��
Second row of transformation �m � �for any m � ��
General idea� skew inner loops by outer loops su�ciently to make
all negative entries non�negative���
![Page 41: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/41.jpg)
��
��
Transformation to make �rst row with negative entries into row
with non�negative entries
...
....
-k-n-m
...
...first rowwith negative entries...
....
row a
...
......p3p1 ...
...row b
(a) for each negative entry in the first row with negative entries, find the first positive number in the corresponding column
assume the rows for these positive entries are a,b etc as shown above
(b) skew the row with negative entries by appropriate multiples of rows a,b.... For our example, multiple of row a = ceiling(n/p2)
multiple of row b = ceiling(max(m/p1,k/p3))
Transformation: I0 0 ..0 ceiling(n/p2) 0 0 ceiling(max(m/p1,k/p3))0...0 I
p2
��
![Page 42: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/42.jpg)
��
��
General algorithm for making loop nest fully permutable�
If all entries in dependence matrix are non�negative� done�
Otherwise�
� Apply algorithm on previous slide to �rst row with
non�negative entries�
�� Generate new dependence matrix�
�� If no negative entries� done�
�� Otherwise� go step ���
��
![Page 43: Dependence relationpingali/CS395T/2012sp/... · 2009. 10. 28. · Lo op Sk ewing a linear lo op transformation I J U V I J = U 1 1 V 1 0 1-1 1 0 Skewing of inner loop by outer loop:](https://reader035.vdocuments.us/reader035/viewer/2022071412/6109dfe6cdc73d38106327e4/html5/thumbnails/43.jpg)
��
��
Result of tiling transformed wavefront
���� ���� �� ���� ��������
��������
���� ���� �� ���� ��������
��������
���� ���� �� ���� ���� ����
���� ���� �� ���� ��������
��������
��������
��������
����
��������
���� ����
��������
����
��������
��������
��������
��������
��������
����
��������
��������
���� ����
���� �� ���� ���� ��������
��������
��������
����
��������
��������
���� ����
��������
��������
��������
����
���� ��
���� �� ���� ���� ���� ����
I
J
1 2 3 54
1
2
3
4
5
I
J
1 2 3 54
1
2
3
4
5
1 11 0
Original loop Tiled fully permutable loop
Tiling generates a ��deep loop nest�
Not as nice as height reduction solution� but it will work �ne for
locality enhancement except at tile boundaries �but boundary
points small compared to number of interior points��
��