march 4, 2008 df4-1 from id/ph to dataflow graphs arvind computer science & artificial...
TRANSCRIPT
March 4, 2008 DF4-1http://csg.csail.mit.edu/arvind/
From Id/pH to Dataflow Graphs
ArvindComputer Science & Artificial Intelligence LabMassachusetts Institute of Technology
March 4, 2008 DF4-2http://csg.csail.mit.edu/arvind/
Parallel Language Model Global Heap ofShared Objects
Tree ofActivationFrames
h:g:
f:
loop
activethreads
asynchronous and parallelat all levels
March 4, 2008 DF4-3http://csg.csail.mit.edu/arvind/
Dataflow Graphs + I-Structures + . . .
TTDA Monsoon *T
*T-Voyager
Id Worldimplicit parallelism
Id
March 4, 2008 DF4-4http://csg.csail.mit.edu/arvind/
Id Compiler PhasesId
Kernel Id
Parallel Three Address Code, P-TAC
Dataflow Graphs/Threads
Machine Graphs von Neumann
code
R
educ
tion
desugar
select representations
F
ixed
Pro
gram
Semantics of each intermediate language is important to show the correctness of each module
March 4, 2008 DF4-5http://csg.csail.mit.edu/arvind/
Choosing Representations: Arrays
lower upper
lowerupper
bounds lower upper
lowerupper
bounds 1.
2.
3.
bounds array4.
March 4, 2008 DF4-6http://csg.csail.mit.edu/arvind/
type list *0 = nil | cons *0 (list *0)
1. nil tag=0
tag=1cons
2. nil
cons
tag
Boxed
Boxed
Unboxed
Implicit
Assumption: Pointers can be distinguished from small integers
Similar issues arise for all Algebraic Types
Choosing Representations: Lists
March 4, 2008 DF4-7http://csg.csail.mit.edu/arvind/
Case Expression and Tags
type foo .. = C1 ... | C2 ... | ... | Cn ...
The case expression for type foo
foo-case(d,e1,...,en)
is implemented using the case construct:
casek(i ,e1,...,ek)ei
where i = ifetch(d);
March 4, 2008 DF4-8http://csg.csail.mit.edu/arvind/
Top Level Functionsf = k(x1,...,xk).eDo not contain any free variables except the names of other top level functions.
In general, its arguments can be supplied in one of two ways: 1. As a data structure which is built incrementally
F = xs.{ (x1,...,xk) = destruct(xs); in e }
2. All at once - fast call Ffc = k(x1,...,xk).e
March 4, 2008 DF4-9http://csg.csail.mit.edu/arvind/
Multi-arity Functionsdef f x1 ... xk = e
can be translated as f = x1.x2. ... xk.e
However, most implementation use k-arity sf = k(x1,...,xk).e
with the rules:(k(x1,...,xk).e) a
{ x’1 = a in ((k(x1,...,xk).e) x’1)} if k > 1
((k(x1,...,xk).e) x’1 ... x’n ) a { x’n+1 = a in ((k(x1,...,xk).e) x’1 ... x’n+1)} if n < k-1
((k(x1,...,xk).e) x’1 ... x’n ) a { x’n+1 = a in e[x’1/x1]... [x’k/xk]} if n = k-1
Partial applications are values and thus substitutable
March 4, 2008 DF4-10http://csg.csail.mit.edu/arvind/
Loop Translation
TE[{while ep do S finally ef } =
{ p = k(x1,...,xk).TE[ep] ; b = k(x1,...,xk). { TS[S]
in nextx1,...,nextxk};
tp = p x ; t = Wloopk(p,b,x,tp) ; tf = TE[ef][t/x] ;in
tf }where
x = (x1,...,xk) and xi’s are the “nextified” variables of S and “next x” is replaced by “nextx” everywhere
March 4, 2008 DF4-11http://csg.csail.mit.edu/arvind/
Loop RulesWloopk(p, b, x, true)
{ t = b x; tp = p t;
t’ = Wloopk(p, b, t, tp) in t’ }
Wloopk(p, b, x, false) x
March 4, 2008 DF4-12http://csg.csail.mit.edu/arvind/
KId - The Kernel Id LanguageAn extended S-calculus
E ::= x | k(x1,...,xk).E | SE SE | { S in SE } | Casek(SE, E1,...,Ek)
| PFk(SE1,...,SEk) | CN0 | CNk(SE1,...,SEk)| allocate()| Wloop(Ep,Eb,x,bool)
S ::= x = E | S; S | S --- S| store(SE,SE,SE)
PF2 ::= ...| i-fetch | m-fetch Simple Expressions
SE ::= x | CN0 | CNk(SE1,...,SEk) | k(x1,...,xk).E | ((k(x1,...,xk).E) SE1...SEn) n < k
March 4, 2008 DF4-13http://csg.csail.mit.edu/arvind/
KId Optimizations
“Totally correct” optimizations (S rewrite rules)• Constant Propagation/Folding• Fetch Elimination• Barrier discharge• Inline Substitution/Specialization• Dead-code Elimination /Garbage collection ...
Additional transformations or rewrite rules• Algebraic Identities• Common Subexpression Elimination• Code Hoisting out of Conditionals• Loop Optimizations
• Peeling/Unrolling• Lifting loop invariants• Eliminating circulating variables and constants• Induction variable analysis
March 4, 2008 DF4-14http://csg.csail.mit.edu/arvind/
P-TAC: Three Address CodeA lower level language than KId
1. Exposes all address calculations. Requires choosing representations for all data structures
2. No nested function definitions - -abstractions exist only at the top level
3. Partial applications are represented as data structures (Closures)
March 4, 2008 DF4-15http://csg.csail.mit.edu/arvind/
Generating Dataflow Graphs
GE :: P-TAC Expression --> DFG
. . .
. . .
tg x1 xn
sg
G
March 4, 2008 DF4-16http://csg.csail.mit.edu/arvind/
P-TAC to Dataflow GraphsExpressions
apply
x1 x2
GE[c] = c
GE[x1 x2] =
GE[PFk(x1,...,xk)] = PFk
x1 ... xk
GE[x] = x
March 4, 2008 DF4-17http://csg.csail.mit.edu/arvind/
Case Schema
GE[Casek(i, e1,...,ek)] 1 k
GE[e1] GE[ek]
Switch
i x1 ... xn
...
x1 ... xn x1 ... xn
• { x1,...,xn } = FV(e1)U...U FV(ek)
• All ei’s must have the same number of outputs
• Unused xi’s in each branch have to be collected for signal generation
March 4, 2008 DF4-18http://csg.csail.mit.edu/arvind/
Graph for Function ApplicationThe Full Application case
t
((k(x1,...,xk).e) x’1 ... x’k-1 ) a { x’k = a in e[x’1/x1]... [x’k/xk]
a new copy of echange tag
a
apply
f
xt:
f
get context extract tag
change Tag0 change Tag1
a
change Tag
1:
0:
GE[e]
Apply is a conditional schema;make-closure part is not shown
March 4, 2008 DF4-19http://csg.csail.mit.edu/arvind/
Loop Schema
GE[Wloopk(p,b,(x1,...,xk),tp] =
next nextGS[Sb]
GE[ep]
x1 ... xk tp
next• {x1,...,xn} are the nextified variables
• p = k(x1...xk).ep
• b = k(x1...xk).{Sb in next x1,...,next xk }
...
...
March 4, 2008 DF4-20http://csg.csail.mit.edu/arvind/
P-TAC to Dataflow GraphsThe Block Expression
GE[{S in x}] =where{x1,...,xn} = FV(S)
GS[x = e] =where{x1,...,xn} = FV(e)
. . .tg x1 xn
sg
GE(e)
x
GS[store(x1,x2)] =
x1 x2
sg
istore
. . .
. . .
tg x1 xn
y1 ym
GS(S)
x sg
March 4, 2008 DF4-21http://csg.csail.mit.edu/arvind/
Parallel Composition''Wiring Diagrams''
{y1,...,yn} = BV(S1) U BV(S2){x1,...,xn} = FV(S1) U FV(S2) - {y1,...,yn}
GS[S1;S2] =
. . .
. . .
tg x11 x1n
y11 y1m sg
GS(S1)
. . .
. . .
tg x21 x2n
y21 y2m sg
GS(S2)
x1 ... xn
y1 ... yn
Id
Each xij is to be connected to the yij with the same name
March 4, 2008 DF4-22http://csg.csail.mit.edu/arvind/
Sequential Composition
{x1,...,xn} = FV(S1) U FV(S2){y1,...,yn} = BV(S1) U BV(S2)
. . .
. . .
tg x11 x1n
y11 y1m sg
GS(S1)
GS[S1---S2] =
. . .
. . .
tg x21 x2n
y21 y2m sg
GS(S2)
x1 ... xn
y1 ... yn
Each x2j is to be connected to the y1j with the same name