well-behaved dataflow graphs arvind computer science & artificial intelligence lab

28
March 4, 2008 http://csg.csail.mit.edu/ arvind/ DF2-1 Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology

Upload: bart

Post on 29-Jan-2016

30 views

Category:

Documents


0 download

DESCRIPTION

Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab Massachusetts Institute of Technology. Outline. Kahnian networks and dataflow Streams with holes & Tagged interpretation Well behaved graphs. Q. P. Kahnian Networks. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 http://csg.csail.mit.edu/arvind/ DF2-1

Well-behaved Dataflow Graphs

ArvindComputer Science & Artificial Intelligence LabMassachusetts Institute of Technology

Page 2: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-2http://csg.csail.mit.edu/arvind/

Outline

• Kahnian networks and dataflow

• Streams with holes & Tagged interpretation

• Well behaved graphs

Page 3: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-3http://csg.csail.mit.edu/arvind/

Kahnian Networks

Computing stations connected by unbounded, FIFO channels

Each station executes a sequential programwait(ch): blocking read from a channelsend(x,ch): non blocking

a station either blocks for an input on a specific channel or computes

P Q

Page 4: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-4http://csg.csail.mit.edu/arvind/

An Example

X

Y Z

T0 T1

f

g

h1h0

Process f(U,V; W) { b= true; While true do

{ i := if b then wait(U) else wait(V); print(i); send(i,W); b := not b} }

Process g(U ; V,W) { b= true; While true do

{ i := wait(U); if b then send(i,V) else send(i,W) b := not b } }

Process hC (U ; V) { send(c,V); While true do

{ i := wait(U); send(i,V) } }

X = f(Y,Z) || T0 , T1 = g(X) || Y = h0(T0) || Z = h1(T1)

Page 5: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-5http://csg.csail.mit.edu/arvind/

Kahnian Networks & Dataflow

Dataflow Graphs can Express any Kahnian Network and vice versa

X

Y Z

T0 T1

f

gh1

h0

T F not

T F not

Page 6: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-6http://csg.csail.mit.edu/arvind/

Determinacy

A computing station in Kahnian network can be viewed as a monotonic and continuous function from sequences to sequences

The least fixed point solutions characterize the I/O behavior of such stations

Dataflow operators can have any granularity and can be expressed in any sequential language

Page 7: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-7http://csg.csail.mit.edu/arvind/

Missing Tokens

T F T F

F T T

x

x

x cannot be moved to the output because the token corresponding to T is missing.

How to model stream with “holes” ?

Page 8: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-8http://csg.csail.mit.edu/arvind/

Another Interpretation of DFGsStreams with “holes”

Streams with missing tokens

{v1, v2, v4, , v6, ....}

can be modeled by a set of tokens where tokens carry a tag designating their position in the stream

{ <1, v1>, <2, v2>, <4, v4>, <6, v6> }

Page 9: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-9http://csg.csail.mit.edu/arvind/

Tagged Semantics of Operatorsadd(xs,ys) =

{<i,x+y> <i,x> xs, <i,y>ys}

T-gatebs,xs) = {<k,x> | <i,T>bs, <i,x> xs,

j i . <j,bj> bs , k = T-Cnt(bs,i)}

mergebs,xs,ys) = {<i,x> | <i,T>bs, <k,x> xs,

j i . <j,bj> bs, k = T-Cnt(bs,i)} {<i,y> | <i,F>bs, <k,y> ys,

j i . <j,bj> bs, k = F-Cnt(bs,i)}

Da(xs) = {<i+1,x> | <i,x> xs} {<1,a>}

Page 10: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-10http://csg.csail.mit.edu/arvind/

Ordering on Streams with HolesStream with holes: { <i, vi>, <j, vj>, <k, vk> }

The least element: { } (aka )

The partial order (): subset order

It is easy to show that all the operators under the tagged semantics are monotonic and continuous

tagged semantics are also deterministic

Page 11: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-11http://csg.csail.mit.edu/arvind/

Tagged versus FIFO InterpretationTheorem:

Suppose the least fixed point of a dataflow program

X = { X1, ..., Xn } in the FIFO interpretation

and Y = { Y1, ..., Yn } in the tagged

interpretation then

X Y .

Proof: Based on structural induction1. Show it holds for each operator2. Show it holds under juxtaposition and

iteration

Tagged interpretation gives more defined answers and has more parallelism

Page 12: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-12http://csg.csail.mit.edu/arvind/

Tagged versus FIFO Interpretation

Theorem: Suppose the least fixed point of a dataflow program isX = { X1, ..., Xn } in the FIFO interpretation where Xi is the stream associated with a particular arc in the program.

Let Y = { Y1, ..., Yn } represent the fixed point of the same program in the tagged interpretation, then

X Y .

Proof: Based on structural induction1. Show it holds for each operator2. Show it holds under juxtaposition and iteration

Tagged interpretation gives more defined answers and has more parallelism

Page 13: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-13http://csg.csail.mit.edu/arvind/

Well Behaved Dataflow Graphs

• • •

• • •

P

Before After

• • •

• • •

P

1. One token on each input arc produces exactly one token on each output arc.

2. The initial distribution of tokens on the arcs is restored.

Page 14: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-14http://csg.csail.mit.edu/arvind/

Control Operators are not well-behaved

Fork Primitive Ops

+

Switch Merge

T FT F

T T

+ T FT F

T T

Not well-behaved

Page 15: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-15http://csg.csail.mit.edu/arvind/

The Block Schema a b

+ *7

- +

*

yx

1 2

3 4

5

{x = a + b; y = b * 7in (x-y) * (x+y)}

Any acyclic interconnection of WBGs is a WBG

Page 16: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-16http://csg.csail.mit.edu/arvind/

The Conditional Schema

If p then a + b else a * a

a b

+ *

T FT F

T F

p ..

Page 17: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-17http://csg.csail.mit.edu/arvind/

Another Conditional Schema

If p then a + b else a * a

What is wrong with this schema?

+ *

T Fp

a b

Page 18: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-18http://csg.csail.mit.edu/arvind/

Merge Operator is Essential for Determinacy

Suppose g(X2)computes muchfaster than f(X1).

Tokens will come out in the wrong order without the merge operator.

T F T F

T F

f g f g

X2

X1

F T F T

X

X2

X1

Page 19: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-19http://csg.csail.mit.edu/arvind/

The Loop Schema

initial x = awhile p(x) do next x = f(x) ;finally x

F

p

f

x

next x

T F

T F

a

Page 20: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-20http://csg.csail.mit.edu/arvind/

Well Behaved Dataflow Graphs (WBGs): Rules to form WBGs

1. Primitive operators like + and fork are WBGs (T-gate, F-gate and merge are not WBGs).

2. The block schema, i.e., an acyclic interconnection of graphs, is a WBG, if all its component graphs are WGBs.

3. The conditional schema is a WBG, if the graphs for the True side and False side are WBGs.

4. The loop schema is a WBG, if the graphs for the predicate and the body are WBGs.

Page 21: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-21http://csg.csail.mit.edu/arvind/

Unbounded Cyclic Graphs

Unbounded number of tokens on an arc can only arise due to cycles.

<n

+1

F T F

f

+

0 1F

T F T F

T F

Page 22: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-22http://csg.csail.mit.edu/arvind/

Bounded Cyclic Graphs

<n

+1

F T F

f

+

0 1F

T F T F

T F

synck-bound

Page 23: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-23http://csg.csail.mit.edu/arvind/

Bounded Cyclic Graphs

+ 1

T F

T F

F T F

T F

f

+

0 1

Sync

k-bound

< n

F

Page 24: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-24http://csg.csail.mit.edu/arvind/

Well Behaved Schemas

f

p

T F

T F F

LoopBounded Loop

Needed for resource management

Page 25: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-25http://csg.csail.mit.edu/arvind/

New Definition of Well Behavedness

1. One token on each input arc produces exactly one token on each output arc.

2. The initial distribution of tokens on the arcs is restored.

3. No arc can have an unbounded buildup of tokens.

Before After

• • •

P

• • •

• • •

P

• • •

Page 26: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-26http://csg.csail.mit.edu/arvind/

Bounded Cyclic Graphsare Well Behaved

Initial number of tokens at the gate input determines the maximum number of tokens on any arc.

However, loop bounding can alter the "meaning" of a graph, i.e., can cause deadlock.

In general, restricting the number of tokens on an arc causes deadlock.

Page 27: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-27http://csg.csail.mit.edu/arvind/

Can this program deadlock if the number of tokens per arc is restricted?

+1

T F

T F

F T F

T F

+10

0F

<4

Page 28: Well-behaved Dataflow Graphs Arvind Computer Science & Artificial Intelligence Lab

March 4, 2008 DF2-28http://csg.csail.mit.edu/arvind/

Static DFGs as a Base Language

Static DFGs can express all recursively enumerable functions

Static DFGs are not sufficient as a target for compiling high level languages. Support is lacking for:

procedure calls data structures

Dynamic Dataflow Graphs