POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension...
Transcript of POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension...
![Page 1: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/1.jpg)
POLYTOPE MODELSeminar “Sprachen für Parallelprogrammierung”
Tim Habermaas
1
![Page 2: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/2.jpg)
POLYTOPE MODEL
• Ist ein mathematisches Modell zur automatischen Parallelisierung von Schleifen.
•Dabei wird das Quellprogramm als Polytop beschrieben und dieses Polytop so transformiert, dass das resultierende Zielprogramm parallelisierbar ist.
2
![Page 3: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/3.jpg)
POLYTOP
• Verallgemeinertes Polygon in beliebiger Dimension
• Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen
Polygonn = 2
Polyedern = 3
A ∗ x ≥ b
3
![Page 4: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/4.jpg)
POLYTOP-BEISPIEL
4
![Page 5: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/5.jpg)
QUELLPROGRAMM
•Der einzige erlaubte Datentyp ist Array.
• Array-Indizes müssen affine Funktionen in den Schleifenvariablen sein.
•Die einzigen erlaubten Statements sind Schleifen (mit Schrittweite ±1) und Array-Zuweisungen.
for i1 = l1 to u1 for i2 = l2 to u2 ... a[i1, i2] = a[i1, 0] * 4 + b[i10 + 10 * i1] end S2end
5
![Page 6: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/6.jpg)
INDEXRAUM
• Jedes Statement S besitzt einen Indexraum IS.
•Dieser Indexraum lässt sich als Ungleichungssystem darstellen, welches ein Polytop beschreibt.
for i = 0 to n for j = 0 to m S1 end S2end
i ≥ 0
j ≥ 0i ≤ n
j ≤ m
S1: S2: i ≥ 0
i ≤ n
6
![Page 7: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/7.jpg)
INDEXVEKTOR
• Ein Element eines Indexraumes heißt Indexvektor.
for i = 0 to 3 for j = 0 to 4 a[i, j] = 10 endend
x =
12
7
![Page 8: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/8.jpg)
BEISPIELfor i = 0 to 5 for j = 0 to 4 a[i, j] = a[i - 1, j] + a[i, j - 1] * 10 endend
A ∗ x =
1 0−1 00 10 −1
∗ij
≥
0−50−4
Als Polytop:
8
![Page 9: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/9.jpg)
BEISPIELfor i = 0 to 5 for j = 0 to 4 a[i, j] = a[i - 1, j] + a[i, j - 1] * 10 endend
j
i9
![Page 10: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/10.jpg)
ABHÄNGIGKEITEN
j
i10
for i = 0 to 5 for j = 0 to 4 a[i, j] = a[i - 1, j] + a[i, j - 1] * 10 endend
d1 =
10
d2 =
01
![Page 11: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/11.jpg)
SCHEDULE
•Ist gültig, wenn er alle Abhängigkeiten erhält:
•Muss eine affine Funktion sein.
•Beschreibt welche Operationen zum Zeitpunkt t ausgeführt werden.
∀x, x : x, x ∈ Ω ∧ (x, x) ∈ E : t(x) <lex t(x)
11
t : Statement× Indexvektor → Z
![Page 12: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/12.jpg)
ALLOKATION
•Weist einer Operation (Statement x Indexvektor) einen Prozessor zu.
•Muss ebenfalls eine affine Funktion sein.
12
a : Statement× Indexvektor → Zr
![Page 13: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/13.jpg)
SCHEDULE
j
i
t(
ij
) = i+ j
13
for i = 0 to 5 for j = 0 to 4 a[i, j] = a[i - 1, j] + a[i, j - 1] * 10 endend
![Page 14: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/14.jpg)
ALLOCATION
j
i
t(
ij
) = i+ j
a(
ij
) = i
14
for i = 0 to 5 for j = 0 to 4 a[i, j] = a[i - 1, j] + a[i, j - 1] * 10 endend
![Page 15: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/15.jpg)
l
k
ZIEL
t(
ij
) = i+ j
a(
ij
) = i
15
for i = 0 to 5 for j = 0 to 4 a[i, j] = a[i - 1, j] + a[i, j - 1] * 10 endend
![Page 16: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/16.jpg)
TRANSFORMATIONSMATRIX
t(
ij
) = i+ j
a(
ij
) = i
T =
1 11 0
16
for i = 0 to 5 for j = 0 to 4 a[i, j] = a[i - 1, j] + a[i, j - 1] * 10 endend
![Page 17: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/17.jpg)
NEUE INDIZES
T =
1 11 0
T ∗ x = T ∗ij
= y =
kl
=
i+ ji
17
for i = 0 to 5 for j = 0 to 4 a[i, j] = a[i - 1, j] + a[i, j - 1] * 10 endend
![Page 18: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/18.jpg)
TRANSFORMIERTES POLYTOP
A ∗ x = A ∗ (T−1 ∗ y) ≥ b
T−1 =
0 11 −1
1 0−1 00 10 −1
∗ (0 11 −1
∗ y) =
l−lk − ll − k
≥
0−50−4
18
![Page 19: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/19.jpg)
TRANSFORMIERTES POLYTOP
l−lk − ll − k
≥
0−50−4
Problem:Das transformierte Polytope lässt sich nicht ohne weiteres in eine Schleife verwandeln, da l von k und k von l abhängt.
Lösung:Fourier-Motzkin-Elimination
19
![Page 20: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/20.jpg)
FOURIER-MOTZKIN-ELIMINATION
• Eliminiert Variablen aus einem Ungleichungssystem.
20
![Page 21: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/21.jpg)
FOURIER-MOTZKIN-ELIMINATION
max(0, k − 4) ≤ l ≤ min(k, 5) ⇒max(0, k − 4) ≤ min(k, 5)
⇒ 0 ≤ k
k ≤ 921
l ≥ 0
l ≥ k − 4
l ≤ 5
l ≤ k
![Page 22: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/22.jpg)
l
k
for k = 0 to 9 parfor l = max(0, k - 4) to min(5, k) i = l j = k - l a[i, j] = a[i - 1, j] + a[i, j - 1] * 10 endend
ZIELPROGRAMM
22
![Page 23: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/23.jpg)
FINDEN EINES SCHEDULES
• Hyperebenen-Methode von Lampert
•Methode von Feautrier
23
![Page 24: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/24.jpg)
HYPEREBENEN-METHODE
• benötigt perfekt verschachtelte Schleifen
• schleifenbasiert, dies heißt für jede Schleife wird eine Transformationsmatrix berechnet
• nicht immer optimal
24
for i1 = l1 to u1 for i2 = l2 to u2 S1 S2 ...
endend
![Page 25: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/25.jpg)
METHODE VON FEAUTRIER
• statementbasiert, das heißt für jedes Statement gewinnt man eine eigene Transformationsmatrix
• optimal
• löst LIP (Linear Integer Program)
• hoher Rechenaufwand
25
![Page 26: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/26.jpg)
ZUSAMMENFÜGEN VON SCHLEIFEN
• Runtime
• Compile time
26
![Page 27: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/27.jpg)
RUNTIME
27
for i = 0 to 8 for j = 0 to m S1 end S2end
for i = 0 to 5 S3end
for i = 0 to 8 for j = 0 to m S1 end S2 if i <= 5 S3 endend
![Page 28: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/28.jpg)
COMPILE TIME
28
for i = 0 to n for j = 0 to m S1 end S2 S3end
for i = n + 1 to 8 for j = 0 to m S1 end S2end
for i = 0 to 8 for j = 0 to m S1 end S2end
for i = 0 to n S3end
0 <= n <= 8
![Page 29: POLYTOPE MODEL - pp.ipd.kit.edu · POLYTOP • Verallgemeinertes Polygon in beliebiger Dimension • Konvexe Polytope lassen sich als lineares Ungleichungssystem darstellen Polygon](https://reader031.fdocument.pub/reader031/viewer/2022040701/5d6200c588c993197b8b8634/html5/thumbnails/29.jpg)
LITERATUR
• Loop Parallelization in the Polytope Model (Christian Lengauer)
•Code Generation in the Polytope Model (Martin Griebl, Christian Lengauer, Sabine Wetzel)
•Automatische Methoden zur Parallelisierung im Polyedermodell (Christian Wieninger)
29