125
Fundamental Algorithms for System Modeling, Analysis, and Optimization Stavros Tripakis, Edward A. Lee UC Berkeley EECS 144/244 Fall 2014 Copyright © 2014, E. A. Lee, J. Roydhowdhury, S. A. Seshia, S. Tripakis All rights reserved Scheduling dataflow systems Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 1 / 64

Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

  • Upload
    others

  • View
    1

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Fundamental Algorithms for System Modeling, Analysis, and Optimization

Stavros Tripakis, Edward A. LeeUC BerkeleyEECS 144/244Fall 2014

Copyright © 2014, E. A. Lee, J. Roydhowdhury, S. A. Seshia, S. TripakisAll rights reserved

Scheduling dataflow systems

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 1 / 64

Page 2: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Dataflow

Generic term in CS, multiple meanings.Common theme: data flowing through some computing network.

These lectures: asynchronous processes communicating via FIFO queues.

Applications:- Computer architecture: dataflow vs. von Neumann - Signal processing (e.g., SDF)- Distributed systems (e.g., Kahn process networks)- …

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 1 / 64

Page 3: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

A zoo of dataflow models Computation graphs [Karp & Miller - 1966] Process networks [Kahn - 1974] Static dataflow [Dennis - 1974] Dynamic dataflow [Arvind, 1981] K-bounded loops [Culler, 1986] Synchronous dataflow [Lee & Messerschmitt, 1986] Structured dataflow [Kodosky, 1986] PGM: Processing Graph Method [Kaplan, 1987] Synchronous languages [Lustre, Signal, 1980’s] Well-behaved dataflow [Gao, 1992] Boolean dataflow [Buck and Lee, 1993] Multidimensional SDF [Lee, 1993] Cyclo-static dataflow [Lauwereins, 1994] Integer dataflow [Buck, 1994] Bounded dynamic dataflow [Lee and Parks, 1995] Heterochronous dataflow [Girault, Lee, & Lee, 1997] Parameterized dataflow [Bhattacharya and Bhattacharyya 2001] Scenarios [Geilen, 2010] …

We will look at untimed,then timed SDF

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 1 / 64

Page 4: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Synchronous Data Flow –a better (and sometimes used) term is Static Data Flow (SDF)

One of the most basic dataflow models

Proposed in 1987 [Lee and Messerschmitt, 1987]

Widely used: mainly in signal-processing applications

Many many variants: SDF, CSDF, HSDF, SADF, ...

Semantics: untimed, timed, probabilisticI untimed variants can be used for checking correctness of the system

(e.g., consistency, deadlocks), and for design-space exploration (e.g.,buffer sizing)

I timed variants can be used for performance analysis:F worst-caseF or, in the case of probabilistic models, average-case

We look first at untimed, then at timed SDF

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 4 / 64

Page 5: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

UNTIMED SDF

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 5 / 64

Page 6: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

(Untimed) SDF: Synchronous (Static) Data Flow

A B Cα β1 2 3 1

•2

An SDFG (SDF Graph)

A,B,C: dataflow actors

1, 2, 3, ...: token production/consumption rates

α, β: (a-priori unbounded) FIFO queues (channels)I each channel has unique producer/consumerI abstract from token values ⇒ FIFO property ignored

Channels can have initial tokens

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 6 / 64

Page 7: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

(Untimed) SDF: Synchronous (Static) Data Flow

A B Cα β1 2 3 1•2

An SDFG (SDF Graph)

A,B,C: dataflow actors

1, 2, 3, ...: token production/consumption rates

α, β: (a-priori unbounded) FIFO queues (channels)I each channel has unique producer/consumerI abstract from token values ⇒ FIFO property ignored

Channels can have initial tokens

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 6 / 64

Page 8: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

(Untimed) SDF

A B Cα β1 2 3 1•2

An SDFG (SDF Graph)

Behavior (intuition):I Asynchronous interleaving: any actor that has enough input tokens

available can fire.

I A: can fire at any time; it produces 1 token every time it firesI B: needs 2 tokens in order to fire; it consumes 2 tokens and produces 3

tokens every time it fires;I C: needs 1 token in order to fire; it consumes 1 token each time it fires.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 7 / 64

Page 9: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

(Untimed) SDF

A B Cα β1 2 3 1•2

An SDFG (SDF Graph)

Behavior (more formally):I An SDFG semantics = labeled transition system (LTS):

states + labeled transitions.

I state: # tokens in every channel

I transition labeled A: actor A fires.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 8 / 64

Page 10: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Example

A B Cα β1 2 3 1

This SDFG defines the following LTS:

(0, 0)

A−→ (1, 0)A−→ (2, 0)

A−→ (3, 0)A−→ (4, 0) · · ·

(0, 3)B A−→ (1, 3)

A−→ (2, 3) · · ·

(0, 2)C

· · ·

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 9 / 64

Page 11: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Example

A B Cα β1 2 3 1

This SDFG defines the following LTS:

(0, 0) A−→ (1, 0)

A−→ (2, 0)A−→ (3, 0)

A−→ (4, 0) · · ·

(0, 3)B A−→ (1, 3)

A−→ (2, 3) · · ·

(0, 2)C

· · ·

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 9 / 64

Page 12: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Example

A B Cα β1 2 3 1

This SDFG defines the following LTS:

(0, 0) A−→ (1, 0)A−→ (2, 0)

A−→ (3, 0)A−→ (4, 0) · · ·

(0, 3)B A−→ (1, 3)

A−→ (2, 3) · · ·

(0, 2)C

· · ·

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 9 / 64

Page 13: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Example

A B Cα β1 2 3 1

This SDFG defines the following LTS:

(0, 0) A−→ (1, 0)A−→ (2, 0)

A−→ (3, 0)A−→ (4, 0) · · ·

(0, 3)B A−→ (1, 3)

A−→ (2, 3) · · ·

(0, 2)C

· · ·

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 9 / 64

Page 14: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Example

A B Cα β1 2 3 1

This SDFG defines the following LTS:

(0, 0) A−→ (1, 0)A−→ (2, 0)

A−→ (3, 0)A−→ (4, 0) · · ·

(0, 3)B

A−→ (1, 3)A−→ (2, 3) · · ·

(0, 2)C

· · ·

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 9 / 64

Page 15: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Example

A B Cα β1 2 3 1

This SDFG defines the following LTS:

(0, 0) A−→ (1, 0)A−→ (2, 0)

A−→ (3, 0)A−→ (4, 0) · · ·

(0, 3)B A−→ (1, 3)

A−→ (2, 3) · · ·

(0, 2)C

· · ·

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 9 / 64

Page 16: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Observations

A B Cα β1 2 3 1

There exist behaviors where queues grow unbounded

But there are also behaviors where this doesn’t happenI and all actors keep firing

These are the behaviors we want.

Represented by periodic schedules:

(AABCCC)ω

Can we always find such schedules?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 10 / 64

Page 17: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Observations

A B Cα β1 2 3 1

There exist behaviors where queues grow unbounded

But there are also behaviors where this doesn’t happenI and all actors keep firing

These are the behaviors we want.

Represented by periodic schedules:

(AABCCC)ω

Can we always find such schedules?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 10 / 64

Page 18: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Observations

A B Cα β1 2 3 1

There exist behaviors where queues grow unbounded

But there are also behaviors where this doesn’t happenI and all actors keep firing

These are the behaviors we want.

Represented by periodic schedules:

(AABCCC)ω

Can we always find such schedules?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 10 / 64

Page 19: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Observations

A B Cα β1 2 3 1

There exist behaviors where queues grow unbounded

But there are also behaviors where this doesn’t happenI and all actors keep firing

These are the behaviors we want.

Represented by periodic schedules:

(AABCCC)ω

Can we always find such schedules?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 10 / 64

Page 20: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Observations

A B Cα β1 2 3 1

There exist behaviors where queues grow unbounded

But there are also behaviors where this doesn’t happenI and all actors keep firing

These are the behaviors we want.

Represented by periodic schedules:

(AABCCC)ω

Can we always find such schedules?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 10 / 64

Page 21: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Deadlock

A B

1 1

2 1•2

Behavior deadlocks!(0, 2)

A−→ (1, 0)B−→ (0, 1)

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 11 / 64

Page 22: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Deadlock

A B

1 1

2 1•2

Behavior deadlocks!(0, 2)

A−→ (1, 0)B−→ (0, 1)

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 11 / 64

Page 23: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Unbounded behavior

A B

2 1

1 1•

Queues keep growing!

(0, 1)A−→ (2, 0)

B−→ (1, 1)B−→ (0, 2)

A−→ (2, 1)B−→ (1, 2)

B−→ (0, 3) · · ·

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 12 / 64

Page 24: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Unbounded behavior

A B

2 1

1 1•

Queues keep growing!

(0, 1)A−→ (2, 0)

B−→ (1, 1)B−→ (0, 2)

A−→ (2, 1)B−→ (1, 2)

B−→ (0, 3) · · ·

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 12 / 64

Page 25: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

ANALYZING UNTIMED SDF GRAPHS

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 13 / 64

Page 26: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Balance equations and repetition vectors

A B

2 1

1 1•

Balance equations:

For each channel: tokens produced = tokens consumed

I initial tokens don’t matter for balance equations

qA · 2 = qB · 1 // equation for channel A→ B

qB · 1 = qA · 1 // equation for channel B → A

qA: number of times actor A fires

Solution to balance equations is called repetition vector

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 14 / 64

Page 27: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Balance equations and repetition vectors

A B

2 1

1 1•

2qA = qB

qB = qA

Only trivial solution (always exists): qA = qB = 0

SDF graph is inconsistent

Inconsistency ⇒ cannot hope to find periodic schedule that keepsqueues bounded and fires all actors infinitely often.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 15 / 64

Page 28: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Balance equations and repetition vectors

A B

2 1

1 1•

2qA = qB

qB = qA

Only trivial solution (always exists): qA = qB = 0

SDF graph is inconsistent

Inconsistency ⇒ cannot hope to find periodic schedule that keepsqueues bounded and fires all actors infinitely often.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 15 / 64

Page 29: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Balance equations and repetition vectorsAnother example:

A B

3 6

2 4•5

3qA = 6qB // equation for channel A→ B

2qA = 4qB // equation for channel B → A

Non-zero solution: qB = 1, qA = 2qB = 2I Any multiple is also a solution

SDF graph is consistent

In this case we also have a periodic schedule: (AAB)ω.

Does consistency imply existence of valid periodic schedule?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 16 / 64

Page 30: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Balance equations and repetition vectorsAnother example:

A B

3 6

2 4•5

3qA = 6qB // equation for channel A→ B

2qA = 4qB // equation for channel B → A

Non-zero solution: qB = 1, qA = 2qB = 2I Any multiple is also a solution

SDF graph is consistent

In this case we also have a periodic schedule: (AAB)ω.

Does consistency imply existence of valid periodic schedule?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 16 / 64

Page 31: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Balance equations and repetition vectorsAnother example:

A B

3 6

2 4•5

3qA = 6qB // equation for channel A→ B

2qA = 4qB // equation for channel B → A

Non-zero solution: qB = 1, qA = 2qB = 2I Any multiple is also a solution

SDF graph is consistent

In this case we also have a periodic schedule: (AAB)ω.

Does consistency imply existence of valid periodic schedule?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 16 / 64

Page 32: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Consistency vs. deadlock

Consistency 6⇒ absence of deadlock:

A B

1 1

1 1

Absence of deadlock 6⇒ consistency:

A B

2 1

1 1•

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 17 / 64

Page 33: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Consistency vs. deadlock

Consistency 6⇒ absence of deadlock:

A B

1 1

1 1

Absence of deadlock 6⇒ consistency:

A B

2 1

1 1•

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 17 / 64

Page 34: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Consistency

Can “chain SDFGs” be inconsistent?

No. Can obtain rate of down-stream actor relative to that ofup-stream actor ⇒ then use LCM (least common multiple) tonormalize.

Can “tree SDFGs” be inconsistent?No. Idem.

Can arbitrary DAGs (directed acyclic graphs) be inconsistent?Yes:

A B

2 1

1 1

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 18 / 64

Page 35: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Consistency

Can “chain SDFGs” be inconsistent?No. Can obtain rate of down-stream actor relative to that ofup-stream actor ⇒ then use LCM (least common multiple) tonormalize.

Can “tree SDFGs” be inconsistent?No. Idem.

Can arbitrary DAGs (directed acyclic graphs) be inconsistent?Yes:

A B

2 1

1 1

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 18 / 64

Page 36: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Consistency

Can “chain SDFGs” be inconsistent?No. Can obtain rate of down-stream actor relative to that ofup-stream actor ⇒ then use LCM (least common multiple) tonormalize.

Can “tree SDFGs” be inconsistent?

No. Idem.

Can arbitrary DAGs (directed acyclic graphs) be inconsistent?Yes:

A B

2 1

1 1

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 18 / 64

Page 37: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Consistency

Can “chain SDFGs” be inconsistent?No. Can obtain rate of down-stream actor relative to that ofup-stream actor ⇒ then use LCM (least common multiple) tonormalize.

Can “tree SDFGs” be inconsistent?No. Idem.

Can arbitrary DAGs (directed acyclic graphs) be inconsistent?Yes:

A B

2 1

1 1

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 18 / 64

Page 38: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Consistency

Can “chain SDFGs” be inconsistent?No. Can obtain rate of down-stream actor relative to that ofup-stream actor ⇒ then use LCM (least common multiple) tonormalize.

Can “tree SDFGs” be inconsistent?No. Idem.

Can arbitrary DAGs (directed acyclic graphs) be inconsistent?

Yes:

A B

2 1

1 1

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 18 / 64

Page 39: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Consistency

Can “chain SDFGs” be inconsistent?No. Can obtain rate of down-stream actor relative to that ofup-stream actor ⇒ then use LCM (least common multiple) tonormalize.

Can “tree SDFGs” be inconsistent?No. Idem.

Can arbitrary DAGs (directed acyclic graphs) be inconsistent?Yes:

A B

2 1

1 1

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 18 / 64

Page 40: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

CHECKING FOR DEADLOCKS

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 19 / 64

Page 41: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

What about deadlock?

Consistency 6⇒ absence of deadlocks:

A B

1 1

1 1

How to check whether a given SDF graph deadlocks?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 20 / 64

Page 42: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Checking for deadlocks

1 Check consistency: if consistent, compute non-zero repetition vector q

2 Simulate execution of SDFG, firing actors no more times than whatq specifies (⇒ termination)

I if we manage to complete execution then no deadlock: periodicschedule has been found

I otherwise: SDFG deadlocks

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 21 / 64

Page 43: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Checking for deadlocks: example

A B

1 1

1 1

1 Graph consistent: qA = qB = 1

2 Simulate execution:

from initial channel state (0, 0) no firing possible

⇒ SDFG deadlocks

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 22 / 64

Page 44: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Checking for deadlocks: another example

A B

2 1

2 1

•2

1 Graph consistent: qA = 1, qB = 2

2 Simulate execution (firing A at most once, B twice):

(2, 0)B−→ (1, 1)

B−→ (0, 2)A−→ (2, 0)

⇒ SDFG is deadlock-free

⇒ schedule: (BBA)ω

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 23 / 64

Page 45: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Interesting questions on deadlock-checking algorithm

Why is it enough to stop after one repetition vector?

I channel state after one repetition = initial channel state⇒ schedule can be repeated forever⇒ found periodic schedule !

Does the order in which actors are fired during simulation matter?I No.I Intuition:

1 each channel has unique reader ⇒ firing an actor cannot disableanother actor

2 each channel has unique writer ⇒ firing A;B has same effect as B;A

I Deeper theory: Kahn Process Networks

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 24 / 64

Page 46: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Interesting questions on deadlock-checking algorithm

Why is it enough to stop after one repetition vector?I channel state after one repetition = initial channel state

⇒ schedule can be repeated forever⇒ found periodic schedule !

Does the order in which actors are fired during simulation matter?I No.I Intuition:

1 each channel has unique reader ⇒ firing an actor cannot disableanother actor

2 each channel has unique writer ⇒ firing A;B has same effect as B;A

I Deeper theory: Kahn Process Networks

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 24 / 64

Page 47: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Interesting questions on deadlock-checking algorithm

Why is it enough to stop after one repetition vector?I channel state after one repetition = initial channel state

⇒ schedule can be repeated forever⇒ found periodic schedule !

Does the order in which actors are fired during simulation matter?

I No.I Intuition:

1 each channel has unique reader ⇒ firing an actor cannot disableanother actor

2 each channel has unique writer ⇒ firing A;B has same effect as B;A

I Deeper theory: Kahn Process Networks

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 24 / 64

Page 48: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Interesting questions on deadlock-checking algorithm

Why is it enough to stop after one repetition vector?I channel state after one repetition = initial channel state

⇒ schedule can be repeated forever⇒ found periodic schedule !

Does the order in which actors are fired during simulation matter?I No.I Intuition:

1 each channel has unique reader ⇒ firing an actor cannot disableanother actor

2 each channel has unique writer ⇒ firing A;B has same effect as B;A

I Deeper theory: Kahn Process Networks

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 24 / 64

Page 49: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

BUFFER SIZE ANALYSIS

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 25 / 64

Page 50: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Buffer size analysis

Consistency and no deadlocks ⇒ periodic schedule ⇒ queues remainbounded.

Can we compute the size of buffers we need for each queue?

What if we want to limit some queue to a pre-determined size?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 26 / 64

Page 51: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Computing buffer sizes

A B

2 1

2 1

•2

Graph consistent: qA = 1, qB = 2

Keep track of queue size during simulation:

(2, 0)B−→ (1, 1)

B−→ (0, 2)A−→ (2, 0)

Max queue size over all simulation steps needed for each queue.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 27 / 64

Page 52: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Does buffer size depend on schedule?

A B2 3

Compare schedules: (AAABB)ω vs. (AABAB)ω.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 28 / 64

Page 53: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Does buffer size depend on schedule?

A B2 3

Compare schedules: (AAABB)ω vs. (AABAB)ω.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 28 / 64

Page 54: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Does buffer size depend on schedule?

A B2 3

Compare schedules: (AAABB)ω vs. (AABAB)ω.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 28 / 64

Page 55: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Modeling Finite Queues with Backward Channels

P1

queue of size kP2

1 1= P1 P2

•k1 1

1 1

Each time P1 needs to write, it must first remove a token from thebackward channel.

I If there are no tokens left then it means that the (forward) queue is full.

Each time P2 reads, it puts a token into the backward channel.

Can be easily generalized to m,n tokens produced / consumed. How?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 29 / 64

Page 56: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Modeling Finite Queues with Backward Channels

P1

queue of size kP2

1 1= P1 P2

•k1 1

1 1

Each time P1 needs to write, it must first remove a token from thebackward channel.

I If there are no tokens left then it means that the (forward) queue is full.

Each time P2 reads, it puts a token into the backward channel.

Can be easily generalized to m,n tokens produced / consumed. How?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 29 / 64

Page 57: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Modeling Finite Queues with Backward Channels

P1

queue of size kP2

1 1= P1 P2

•k1 1

1 1

Each time P1 needs to write, it must first remove a token from thebackward channel.

I If there are no tokens left then it means that the (forward) queue is full.

Each time P2 reads, it puts a token into the backward channel.

Can be easily generalized to m,n tokens produced / consumed. How?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 29 / 64

Page 58: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

KAHN PROCESS NETWORKS

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 30 / 64

Page 59: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Kahn Process Networks

Can be seen as generalization of SDFI although Kahn’s work [Kahn, 1974] pre-dates

SDF [Lee and Messerschmitt, 1987] by more than 10 yearsI Kahn’s motivation: distributed systems / parallel programming

Main idea:I generalize dataflow actors to Kahn processesI Kahn process: an arbitrary sequential program reading from and

writing to queuesF read is blocking (Kahn called it wait): if queue is empty, process

blocks until queue becomes non-emptyF write is non-blocking (Kahn called it send): queues are a-priori

unbounded as in SDF

Highly recommended reading: [Kahn, 1974] (on bcourses).

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 31 / 64

Page 60: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Kahn Process Networks

Can be seen as generalization of SDFI although Kahn’s work [Kahn, 1974] pre-dates

SDF [Lee and Messerschmitt, 1987] by more than 10 yearsI Kahn’s motivation: distributed systems / parallel programming

Main idea:I generalize dataflow actors to Kahn processesI Kahn process: an arbitrary sequential program reading from and

writing to queuesF read is blocking (Kahn called it wait): if queue is empty, process

blocks until queue becomes non-emptyF write is non-blocking (Kahn called it send): queues are a-priori

unbounded as in SDF

Highly recommended reading: [Kahn, 1974] (on bcourses).

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 31 / 64

Page 61: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Kahn Process Networks

Can be seen as generalization of SDFI although Kahn’s work [Kahn, 1974] pre-dates

SDF [Lee and Messerschmitt, 1987] by more than 10 yearsI Kahn’s motivation: distributed systems / parallel programming

Main idea:I generalize dataflow actors to Kahn processesI Kahn process: an arbitrary sequential program reading from and

writing to queuesF read is blocking (Kahn called it wait): if queue is empty, process

blocks until queue becomes non-emptyF write is non-blocking (Kahn called it send): queues are a-priori

unbounded as in SDF

Highly recommended reading: [Kahn, 1974] (on bcourses).

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 31 / 64

Page 62: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Kahn Process Network: Example

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 32 / 64

Page 63: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

SDF actors are a special case of Kahn processes

SDF actor:

A32

Corresponding Kahn process:

Process A(integer in U; integer out V);

Begin integer I1, I2, R1, R2, R3;

Repeat Begin

I1 := wait(U);

I2 := wait(U);

... compute R1, R2, R3 ...

send R1 on V;

send R2 on V;

send R3 on V;

end;

End;

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 33 / 64

Page 64: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Kahn processes are more general than SDF actorsIn SDF, token production/consumption rates are static:

A32

In Kahn processes, they are dynamic:

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 34 / 64

Page 65: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

SDF graphs are a special case of Kahn process networks

SDFG:

A B1 1•

2

Kahn process network:

Begin

Integer channel X;

Process A(integer out V);

Begin integer R1, R2, R;

... compute initial tokens R1,

R2 ...

send R1 on V;

send R2 on V;

Repeat Begin

... compute R ...

send R on V;

end;

End;

Process B(integer in U);

...

End;

/* main: */

A(X) par B(X)

End;Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 35 / 64

Page 66: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Semantics of Kahn Process Networks

We can give both operational and denotational semantics.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 36 / 64

Page 67: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Operational vs. Denotational Semantics

What is the meaning of a (say, C) program?

Operational semantics answer: the sequence of steps that theprogram takes to compute its output from its input

Denotational semantics answer: a function f that returns the rightoutput for a given input

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 37 / 64

Page 68: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Semantics of Kahn Process Networks

Operational semantics:

KPN defines a transition system (similar to the SDF semantics wedefined above)

global state = local states (local vars, program counters, ...) of eachprocess + contents of all queues

transition: one process makes a moveI must define some kind of “atomic” moves for processes: for instance,

one statement in the sequential programI asynchronous (interleaving) semantics.

Denotational semantics: this is what we will focus on next.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 38 / 64

Page 69: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Semantics of Kahn Process Networks

Operational semantics:

KPN defines a transition system (similar to the SDF semantics wedefined above)

global state = local states (local vars, program counters, ...) of eachprocess + contents of all queues

transition: one process makes a moveI must define some kind of “atomic” moves for processes: for instance,

one statement in the sequential programI asynchronous (interleaving) semantics.

Denotational semantics: this is what we will focus on next.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 38 / 64

Page 70: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Denotational Semantics of Kahn Process Networks

General idea:

Each process = a function on streams

An entire (closed) network = a (big) functionon (vectors of) streams

Semantics = the stream computed by thenetwork at every queue

Major benefits:

Can handle feedback loops in an elegant manner: fixpoint theory

Determinacy: network has a unique solutionI In terms of operational semantics: order of interleaving does not

matter (as long as it is fair)I Example: if one execution deadlocks, all executions deadlock

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 39 / 64

Page 71: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Denotational Semantics of Kahn Process Networks

General idea:

Each process = a function on streams

An entire (closed) network = a (big) functionon (vectors of) streams

Semantics = the stream computed by thenetwork at every queue

Major benefits:

Can handle feedback loops in an elegant manner: fixpoint theory

Determinacy: network has a unique solutionI In terms of operational semantics: order of interleaving does not

matter (as long as it is fair)I Example: if one execution deadlocks, all executions deadlock

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 39 / 64

Page 72: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Denotational Semantics of Kahn Process Networks

General idea:

Each process = a function on streams

An entire (closed) network = a (big) functionon (vectors of) streams

Semantics = the stream computed by thenetwork at every queue

Major benefits:

Can handle feedback loops in an elegant manner: fixpoint theory

Determinacy: network has a unique solutionI In terms of operational semantics: order of interleaving does not

matter (as long as it is fair)I Example: if one execution deadlocks, all executions deadlock

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 39 / 64

Page 73: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Kahn processes as functions on streams: example

What is the stream function associated with this process?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 40 / 64

Page 74: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Kahn processes as functions on streams: example

What is the stream function associated with this process?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 41 / 64

Page 75: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Kahn processes as functions on streams: example

What is the stream function associated with this process?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 42 / 64

Page 76: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Summary of the rest

Kahn processes are monotonic and continuous functions on streams:

Prefix order on streams: s ≤ s′ if s is a prefix of s′.

ε: the empty stream (empty sequence).

Kahn processes: monotonic functions on streams.

The more tokens added to the input, the more added to the output.

Kahn processes: continuous functions on streams.

A process cannot “wait forever” to produce an output.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 43 / 64

Page 77: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Summary of the rest

Kahn processes are monotonic and continuous functions on streams:

Prefix order on streams: s ≤ s′ if s is a prefix of s′.

ε: the empty stream (empty sequence).

Kahn processes: monotonic functions on streams.

The more tokens added to the input, the more added to the output.

Kahn processes: continuous functions on streams.

A process cannot “wait forever” to produce an output.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 43 / 64

Page 78: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Summary of the rest

Kahn processes are monotonic and continuous functions on streams:

Prefix order on streams: s ≤ s′ if s is a prefix of s′.

ε: the empty stream (empty sequence).

Kahn processes: monotonic functions on streams.

The more tokens added to the input, the more added to the output.

Kahn processes: continuous functions on streams.

A process cannot “wait forever” to produce an output.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 43 / 64

Page 79: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Summary of the rest

Kahn processes are monotonic and continuous functions on streams:

Prefix order on streams: s ≤ s′ if s is a prefix of s′.

ε: the empty stream (empty sequence).

Kahn processes: monotonic functions on streams.

The more tokens added to the input, the more added to the output.

Kahn processes: continuous functions on streams.

A process cannot “wait forever” to produce an output.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 43 / 64

Page 80: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Summary of the rest

Theorem

A continuous function f : (D∗∗)n → (D∗∗)n has a least fixpoint s.Moreover, s = limn→∞ f

n(ε, ε, ..., ε).

The denotational semantics of a Kahn process network K is the leastfixpoint of the corresponding function fK .

Note: the least fixpoint may contain ε or infinite streams.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 44 / 64

Page 81: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Streams

Stream = a finite or infinite sequence of values.

D: set of values

D∗: set of all finite sequences of values from D

I This includes the empty sequence ε

Dω: set of all infinite sequences of values from D

I Note: Dω = DN = set of all total functions from N to D

D∗∗ = D∗ ∪Dω

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 45 / 64

Page 82: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Streams

Stream = a finite or infinite sequence of values.

D: set of values

D∗: set of all finite sequences of values from DI This includes the empty sequence ε

Dω: set of all infinite sequences of values from D

I Note: Dω = DN = set of all total functions from N to D

D∗∗ = D∗ ∪Dω

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 45 / 64

Page 83: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Streams

Stream = a finite or infinite sequence of values.

D: set of values

D∗: set of all finite sequences of values from DI This includes the empty sequence ε

Dω: set of all infinite sequences of values from DI Note: Dω = DN = set of all total functions from N to D

D∗∗ = D∗ ∪Dω

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 45 / 64

Page 84: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Streams: Examples

Let D = {0, 1}.Consider the streams:

0 ∈ D∗

00000 = 05 ∈ D∗

010101 · · · = (01)ω ∈ Dω

010010001041051 · · · ∈ Dω

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 46 / 64

Page 85: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Streams: Examples

Let D = {0, 1}.Consider the streams:

0 ∈ D∗

00000 = 05 ∈ D∗

010101 · · · = (01)ω ∈ Dω

010010001041051 · · · ∈ Dω

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 46 / 64

Page 86: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Streams: Examples

Let D = {0, 1}.Consider the streams:

0 ∈ D∗

00000 = 05 ∈ D∗

010101 · · · = (01)ω ∈ Dω

010010001041051 · · · ∈ Dω

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 46 / 64

Page 87: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Streams: Examples

Let D = {0, 1}.Consider the streams:

0 ∈ D∗

00000 = 05 ∈ D∗

010101 · · · = (01)ω ∈ Dω

010010001041051 · · · ∈ Dω

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 46 / 64

Page 88: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Prefix Order on StreamsLet s · s′ denote stream concatenation:

if s′ = ε, then s · s′ = s (s could be infinite in this case)

if s′ 6= ε, then s must be finite (s′ could be finite or infinite)

s1 is a prefix of s2, denoted s1 ≤ s2, iff

∃s3 : s2 = s1 · s3

Note that s3 may be the empty string, in which case s1 = s2

so s ≤ s for any stream s

Examples:

000 ≤ 0001

000 ≤ 0001ω

000 6≤ 0010

000 · · · = 0ω 6≤ 10ω = 1000 · · ·

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 47 / 64

Page 89: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Prefix Order on StreamsLet s · s′ denote stream concatenation:

if s′ = ε, then s · s′ = s (s could be infinite in this case)

if s′ 6= ε, then s must be finite (s′ could be finite or infinite)

s1 is a prefix of s2, denoted s1 ≤ s2, iff

∃s3 : s2 = s1 · s3

Note that s3 may be the empty string, in which case s1 = s2

so s ≤ s for any stream s

Examples:

000 ≤ 0001

000 ≤ 0001ω

000 6≤ 0010

000 · · · = 0ω 6≤ 10ω = 1000 · · ·

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 47 / 64

Page 90: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Prefix Order on StreamsLet s · s′ denote stream concatenation:

if s′ = ε, then s · s′ = s (s could be infinite in this case)

if s′ 6= ε, then s must be finite (s′ could be finite or infinite)

s1 is a prefix of s2, denoted s1 ≤ s2, iff

∃s3 : s2 = s1 · s3

Note that s3 may be the empty string, in which case s1 = s2

so s ≤ s for any stream s

Examples:

000 ≤ 0001

000 ≤ 0001ω

000 6≤ 0010

000 · · · = 0ω 6≤ 10ω = 1000 · · ·

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 47 / 64

Page 91: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Prefix Order on StreamsLet s · s′ denote stream concatenation:

if s′ = ε, then s · s′ = s (s could be infinite in this case)

if s′ 6= ε, then s must be finite (s′ could be finite or infinite)

s1 is a prefix of s2, denoted s1 ≤ s2, iff

∃s3 : s2 = s1 · s3

Note that s3 may be the empty string, in which case s1 = s2

so s ≤ s for any stream s

Examples:

000 ≤ 0001

000 ≤ 0001ω

000 6≤ 0010

000 · · · = 0ω 6≤ 10ω = 1000 · · ·

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 47 / 64

Page 92: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Prefix Order on StreamsLet s · s′ denote stream concatenation:

if s′ = ε, then s · s′ = s (s could be infinite in this case)

if s′ 6= ε, then s must be finite (s′ could be finite or infinite)

s1 is a prefix of s2, denoted s1 ≤ s2, iff

∃s3 : s2 = s1 · s3

Note that s3 may be the empty string, in which case s1 = s2

so s ≤ s for any stream s

Examples:

000 ≤ 0001

000 ≤ 0001ω

000 6≤ 0010

000 · · · = 0ω 6≤ 10ω = 1000 · · ·

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 47 / 64

Page 93: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Prefix order is a partial order

≤ is a partial order on D∗∗, i.e., it is

reflexive : ∀s : s ≤ s

antisymmetric : ∀s, s′ : s ≤ s′ ∧ s′ ≤ s⇒ s = s′

transitive : ∀s, s′, s′′ : s ≤ s′ ∧ s′ ≤ s′′ ⇒ s ≤ s′′

The pair (D∗∗,≤) is a poset (partially-ordered set).

In fact, it is a CPO (a complete poset) because it also satisfies

for any increasing chain s0 ≤ s1 ≤ s2 ≤ · · · : limn→∞

sn is in D∗∗

It has a least element ⊥ (which one is it?) such that ∀s : ⊥ ≤ s.

⊥ = ε (the empty sequence)

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 48 / 64

Page 94: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Prefix order is a partial order

≤ is a partial order on D∗∗, i.e., it is

reflexive : ∀s : s ≤ s

antisymmetric : ∀s, s′ : s ≤ s′ ∧ s′ ≤ s⇒ s = s′

transitive : ∀s, s′, s′′ : s ≤ s′ ∧ s′ ≤ s′′ ⇒ s ≤ s′′

The pair (D∗∗,≤) is a poset (partially-ordered set).

In fact, it is a CPO (a complete poset) because it also satisfies

for any increasing chain s0 ≤ s1 ≤ s2 ≤ · · · : limn→∞

sn is in D∗∗

It has a least element ⊥ (which one is it?) such that ∀s : ⊥ ≤ s.

⊥ = ε (the empty sequence)

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 48 / 64

Page 95: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Prefix order is a partial order

≤ is a partial order on D∗∗, i.e., it is

reflexive : ∀s : s ≤ s

antisymmetric : ∀s, s′ : s ≤ s′ ∧ s′ ≤ s⇒ s = s′

transitive : ∀s, s′, s′′ : s ≤ s′ ∧ s′ ≤ s′′ ⇒ s ≤ s′′

The pair (D∗∗,≤) is a poset (partially-ordered set).

In fact, it is a CPO (a complete poset) because it also satisfies

for any increasing chain s0 ≤ s1 ≤ s2 ≤ · · · : limn→∞

sn is in D∗∗

It has a least element ⊥ (which one is it?) such that ∀s : ⊥ ≤ s.

⊥ = ε (the empty sequence)

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 48 / 64

Page 96: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Prefix order is a partial order

≤ is a partial order on D∗∗, i.e., it is

reflexive : ∀s : s ≤ s

antisymmetric : ∀s, s′ : s ≤ s′ ∧ s′ ≤ s⇒ s = s′

transitive : ∀s, s′, s′′ : s ≤ s′ ∧ s′ ≤ s′′ ⇒ s ≤ s′′

The pair (D∗∗,≤) is a poset (partially-ordered set).

In fact, it is a CPO (a complete poset) because it also satisfies

for any increasing chain s0 ≤ s1 ≤ s2 ≤ · · · : limn→∞

sn is in D∗∗

It has a least element ⊥ (which one is it?) such that ∀s : ⊥ ≤ s.

⊥ = ε (the empty sequence)

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 48 / 64

Page 97: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Functions on Streams

Function on streams (single-input / single-output):

f : D∗∗ → D∗∗

Function on streams (general):

f : (D∗∗)n → (D∗∗)m

f......

s1

sn

s′1

s′m

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 49 / 64

Page 98: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Functions on Streams

Function on streams (single-input / single-output):

f : D∗∗ → D∗∗

Function on streams (general):

f : (D∗∗)n → (D∗∗)m

f......

s1

sn

s′1

s′m

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 49 / 64

Page 99: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Kahn Processes = Functions on Streams

P......

s1

sn

s′1

s′m

= fP......

s1

sn

s′1

s′m

Basic idea:

Fix the contents of input queues to s1, ..., sn.

Let the process P run.

Observe the contents of output queues: s′1, ..., s′m.

Notice that Kahn processes are deterministic programs.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 50 / 64

Page 100: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Kahn Processes = Functions on Streams

P......

s1

sn

s′1

s′m

= fP......

s1

sn

s′1

s′m

Basic idea:

Fix the contents of input queues to s1, ..., sn.

Let the process P run.

Observe the contents of output queues: s′1, ..., s′m.

Notice that Kahn processes are deterministic programs.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 50 / 64

Page 101: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Monotonic Functions on Streams

A stream function f : D∗∗ → D∗∗ is monotonic (w.r.t. ≤) iff

∀s, s′ ∈ D∗∗ : s ≤ s′ ⇒ f(s) ≤ f(s′)

Stream functions defined by Kahn processes are monotonic. Why?

Once something is written to an output queue, it cannot be takenback.

More inputs ⇒ more outputs.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 51 / 64

Page 102: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Monotonic Functions on Streams

A stream function f : D∗∗ → D∗∗ is monotonic (w.r.t. ≤) iff

∀s, s′ ∈ D∗∗ : s ≤ s′ ⇒ f(s) ≤ f(s′)

Stream functions defined by Kahn processes are monotonic. Why?

Once something is written to an output queue, it cannot be takenback.

More inputs ⇒ more outputs.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 51 / 64

Page 103: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Monotonic Functions on Streams

A stream function f : D∗∗ → D∗∗ is monotonic (w.r.t. ≤) iff

∀s, s′ ∈ D∗∗ : s ≤ s′ ⇒ f(s) ≤ f(s′)

Stream functions defined by Kahn processes are monotonic. Why?

Once something is written to an output queue, it cannot be takenback.

More inputs ⇒ more outputs.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 51 / 64

Page 104: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Continuous Functions on Streams

A stream function f : D∗∗ → D∗∗ is continuous (w.r.t. ≤) if f ismonotonic and for any increasing chain s0 ≤ s1 ≤ s2 ≤ · · ·

f( limn→∞

sn) = limn→∞

f(sn)

Note: by monotonicity of f , and the fact that s0 ≤ s1 ≤ s2 ≤ · · · is achain, f(s0) ≤ f(s1) ≤ f(s2) ≤ · · · is also a chain, so

limn→∞

f(sn)

is well-defined.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 52 / 64

Page 105: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Continuous Functions on Streams

By definition continuity implies monotonicity.1

But: monotonicity does not generally imply continuity.

Quiz: Can you think of

a non-monotonic stream function?

a non-continuous stream function?

a monotonic but non-continuous stream function?

1Alternative definitions of continuity exist that imply monotonicity. See goodtextbook on order theory: [Davey and Priestley, 2002].

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 53 / 64

Page 106: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Continuous Functions on Streams

Stream functions defined by Kahn processes are continuous.

Quiz: Why?

Kahn processes cannot “take forever” to produce an output. Every output theyproduce must be produced because of the finite sequence of inputs the processhas read so far. If for all finite sequences the process produces no outputs, thenthe process produces no outputs at all, even for the infinite sequence.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 54 / 64

Page 107: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Continuous Functions on Streams

Stream functions defined by Kahn processes are continuous.

Quiz: Why?

Kahn processes cannot “take forever” to produce an output. Every output theyproduce must be produced because of the finite sequence of inputs the processhas read so far. If for all finite sequences the process produces no outputs, thenthe process produces no outputs at all, even for the infinite sequence.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 54 / 64

Page 108: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Monotonic and Continuous Functions on Streams

The notions of monotonicity and continuity extend to functions ofarbitrary arity:

f : (D∗∗)n → (D∗∗)m

Basic idea:

“Lift” ≤ to vectors element-wise

(s1, s2, ..., sn) ≤ (s′1, s′2, ..., s

′n)

iffs1 ≤ s′1 ∧ s2 ≤ s′2 ∧ · · · ∧ sn ≤ s′n

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 55 / 64

Page 109: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Fixpoint Theorem

Theorem

A continuous function f : (D∗∗)n → (D∗∗)n has a least fixpoint s.Moreover, s = limn→∞ f

n(ε, ε, ..., ε).

Least fixpoint s means:

s is a fixpoint: f(s) = s.

s is a least fixpoint: for any other fixpoint s′ = f(s′), s ≤ s′.Note: least implies s is unique.

How is s related to the semantics of Kahn process networks?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 56 / 64

Page 110: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Fixpoint Theorem

Theorem

A continuous function f : (D∗∗)n → (D∗∗)n has a least fixpoint s.Moreover, s = limn→∞ f

n(ε, ε, ..., ε).

Least fixpoint s means:

s is a fixpoint: f(s) = s.

s is a least fixpoint: for any other fixpoint s′ = f(s′), s ≤ s′.Note: least implies s is unique.

How is s related to the semantics of Kahn process networks?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 56 / 64

Page 111: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

From Process Network to Fixpoint Equations

P1 P2

process network

=

f1 f2

s1

s2

fixpoint equations

s1 = f1(s2)

s2 = f2(s1)

Can be rewritten as:

(s1, s2) = f(s1, s2)

where f : (D∗∗)2 → (D∗∗)2 is defined as:

f(s1, s2) =̂(f1(s2), f2(s1)

)

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 57 / 64

Page 112: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

From Process Network to Fixpoint Equations

P1 P2

process network

=

f1 f2

s1

s2

fixpoint equations

s1 = f1(s2)

s2 = f2(s1)

Can be rewritten as:

(s1, s2) = f(s1, s2)

where f : (D∗∗)2 → (D∗∗)2 is defined as:

f(s1, s2) =̂(f1(s2), f2(s1)

)Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 57 / 64

Page 113: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Putting it all together

The denotational semantics of the Kahn process network

P1 P2 = f1 f2

s1

s2

is the unique least fixpoint (s1, s2) of the set of equations:

s1 = f1(s2)

s2 = f2(s1)

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 58 / 64

Page 114: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Example: denotational semantics of SDF graphs

A B

1 1

1 1

Viewing A and B as functions on streams of tokens:

A(ε) = B(ε) = ε

A(•) = B(•) = •A(••) = B(••) = • •A(• • •) = B(• • •) = • • •· · ·

Computing the fixpoint:

f(ε, ε) = (A(ε), B(ε)) = (ε, ε)

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 59 / 64

Page 115: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Example: denotational semantics of SDF graphs

A B

1 1

1 1

Viewing A and B as functions on streams of tokens:

A(ε) = B(ε) = ε

A(•) = B(•) = •A(••) = B(••) = • •A(• • •) = B(• • •) = • • •· · ·

Computing the fixpoint:

f(ε, ε) = (A(ε), B(ε)) = (ε, ε)

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 59 / 64

Page 116: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Example: denotational semantics of SDF graphs

A B

2 1

2 1

•2

Viewing A as a function on streams of tokens (B is as before):

A(ε) = • • // this captures initial tokens

A(•) = • •A(••) = • • • •

A(• • •) = • • • •A(• • ••) = • • • • • •

· · ·

Computing the fixpoint:

f(ε, ε) = (A(ε), B(ε)) = (••, ε)f(••, ε) = (A(ε), B(••)) = (••, ••)

f(••, ••) = (A(••), B(••)) = (• • ••, ••)... fixpoint is (•ω , •ω).

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 60 / 64

Page 117: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Example: denotational semantics of SDF graphs

A B

2 1

2 1

•2

Viewing A as a function on streams of tokens (B is as before):

A(ε) = • • // this captures initial tokens

A(•) = • •A(••) = • • • •

A(• • •) = • • • •A(• • ••) = • • • • • •

· · ·

Computing the fixpoint:

f(ε, ε) = (A(ε), B(ε)) = (••, ε)f(••, ε) = (A(ε), B(••)) = (••, ••)

f(••, ••) = (A(••), B(••)) = (• • ••, ••)... fixpoint is (•ω , •ω).

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 60 / 64

Page 118: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Assessment

Why get excited about Kahn process networks?

Elegant mathematics

I (to compare, try to define formal operational semantics, or see papersthat do that, e.g., [Lynch and Stark, 1989, Jonsson, 1994])

Caveats:

I Still need to relate denotational to some operational semantics, toconvince ourselves that they areequivalent [Lynch and Stark, 1989, Jonsson, 1994].

I Framework difficult to extend to non-deterministic processes – c.f.famous “Brock-Ackerman anomaly” and relatedliterature [Brock and Ackerman, 1981, Jonsson, 1994]

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 61 / 64

Page 119: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Assessment

Why get excited about Kahn process networks?

Elegant mathematics

I (to compare, try to define formal operational semantics, or see papersthat do that, e.g., [Lynch and Stark, 1989, Jonsson, 1994])

Caveats:

I Still need to relate denotational to some operational semantics, toconvince ourselves that they areequivalent [Lynch and Stark, 1989, Jonsson, 1994].

I Framework difficult to extend to non-deterministic processes – c.f.famous “Brock-Ackerman anomaly” and relatedliterature [Brock and Ackerman, 1981, Jonsson, 1994]

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 61 / 64

Page 120: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Assessment

Why get excited about Kahn process networks?

Foundations of asynchronous message-passing paradigm.

Deterministic concurrency.

I Writing/debugging concurrent programs made easier.I Contrast this to threads [Lee, 2006].

I How is determinism achieved in Kahn Process Networks?I No shared memory! Channels have unique writer/reader processes.I Blocking read.I No “peeking” into input queues allowed, no removing data already

written into output queues, etc.

Criticism: KPN use infinite queues but these do not exist in reality.

Answer: finite queues can easily be modeled in KPN (also in SDF). How?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 62 / 64

Page 121: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Assessment

Why get excited about Kahn process networks?

Foundations of asynchronous message-passing paradigm.

Deterministic concurrency.

I Writing/debugging concurrent programs made easier.I Contrast this to threads [Lee, 2006].I How is determinism achieved in Kahn Process Networks?I No shared memory! Channels have unique writer/reader processes.I Blocking read.I No “peeking” into input queues allowed, no removing data already

written into output queues, etc.

Criticism: KPN use infinite queues but these do not exist in reality.

Answer: finite queues can easily be modeled in KPN (also in SDF). How?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 62 / 64

Page 122: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Assessment

Why get excited about Kahn process networks?

Foundations of asynchronous message-passing paradigm.

Deterministic concurrency.

I Writing/debugging concurrent programs made easier.I Contrast this to threads [Lee, 2006].I How is determinism achieved in Kahn Process Networks?I No shared memory! Channels have unique writer/reader processes.I Blocking read.I No “peeking” into input queues allowed, no removing data already

written into output queues, etc.

Criticism: KPN use infinite queues but these do not exist in reality.

Answer: finite queues can easily be modeled in KPN (also in SDF). How?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 62 / 64

Page 123: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Assessment

Why get excited about Kahn process networks?

Foundations of asynchronous message-passing paradigm.

Deterministic concurrency.

I Writing/debugging concurrent programs made easier.I Contrast this to threads [Lee, 2006].I How is determinism achieved in Kahn Process Networks?I No shared memory! Channels have unique writer/reader processes.I Blocking read.I No “peeking” into input queues allowed, no removing data already

written into output queues, etc.

Criticism: KPN use infinite queues but these do not exist in reality.

Answer: finite queues can easily be modeled in KPN (also in SDF). How?

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 62 / 64

Page 124: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Kahn Process Networks vs. Petri Nets

[Ignore if you don’t know what Petri nets are]

Petri nets:

More abstract model: processes = transitions.

Non-deterministic:I Each place can have many incoming / outgoing transitions.I Each place may be shared by multiple producers / consumers.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 63 / 64

Page 125: Stavros Tripakis, Edward A. Lee · An SDFG (SDF Graph) Behavior (more formally): I An SDFG semantics = labeled transition system (LTS): states + labeled transitions. I state: # tokens

Bibliography

Brock, J. and Ackerman, W. (1981).

Scenarios: A model of non-determinate computation.In Proc. Intl. Colloq. on Formalization of Programming Concepts, pages 252–259, London, UK. Springer-Verlag.

Davey, B. A. and Priestley, H. A. (2002).

Introduction to Lattices and Order.Cambridge University Press, 2nd edition.

Jonsson, B. (1994).

Compositional specification and verification of distributed systems.ACM Trans. Program. Lang. Syst., 16(2):259–303.

Kahn, G. (1974).

The semantics of a simple language for parallel programming.In Information Processing 74, Proceedings of IFIP Congress 74. North-Holland.

Lee, E. (2006).

The problem with threads.IEEE Computer, 39(5):33–42.

Lee, E. and Messerschmitt, D. (1987).

Synchronous data flow.Proceedings of the IEEE, 75(9):1235–1245.

Lynch, N. and Stark, E. (1989).

A Proof of the Kahn Principle for Input/Output Automata.Information and Computation, 82:81–92.

Stavros Tripakis (UC Berkeley) EE 144/244, Fall 2014 Dataflow 64 / 64