The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros...

74
The Synchronous Model of Computation Stavros Tripakis UC Berkeley [email protected] EE 249 Lecture Sep 9, 2010

Transcript of The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros...

Page 1: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

The SynchronousModel of Computation

Stavros TripakisUC Berkeley

[email protected]

EE 249 Lecture – Sep 9, 2010

Page 2: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Systems

• What is a system?– Everything is a system!– A system is something that has: inputs, outputs, state;

state evolves in time, given (past state and) inputs; outputs are produced from state and inputs, at a given time.

• Real vs. mathematical systems:– The latter are models of (real or IMAGINARY) systems

• Synchronous models = models of synchronous systems.

• What does synchronous mean?

S. Tripakis – EE 249 – The Synchronous MoC 2

Page 3: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Fundamental characteristics of the synchronous MoC

• Notion of synchronous round (or cycle)

3

inputs

outputs

inputs

outputs

rounds

round 1 round 2

S. Tripakis – EE 249 – The Synchronous MoC

Page 4: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Fundamental characteristics of the synchronous MoC

• Notion of synchronous round (or cycle)• Concurrency • Determinism (most of the time)

– Same (sequence of) inputs => same (sequence of) outputs

• Contrast this to:– Concurrency with threads:

• Non-deterministic: results depend on interleaving

– Concurrency in Kahn Process Networks:• Asynchronous (interleaving), but still deterministic• Needs unbounded buffers in general, for communication

4S. Tripakis – EE 249 – The Synchronous MoC

Page 5: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

5

Example: synchronous block diagram

A

C

rounds

A, B, C A, C, B …

B

S. Tripakis – EE 249 – The Synchronous MoC

Page 6: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

6

Example: synchronous block diagram

A

C

rounds

A, …

B

BC

A, BC

deterministic concurrency

S. Tripakis – EE 249 – The Synchronous MoC

Page 7: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Example: FIR filter

7

)2(3

1)1(

3

1)(

3

1)( nxnxnxny

Where is the synchronous round here?

S. Tripakis – EE 249 – The Synchronous MoC

Page 8: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Example: sequential logic diagram

8

Where is the synchronous round here?

S. Tripakis – EE 249 – The Synchronous MoC

Page 9: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Example: control loop

9

initialize state;

while (true) do

read inputs;

compute outputs;

update state;

write outputs;

end while;

Where is the synchronous round here?

S. Tripakis – EE 249 – The Synchronous MoC

Page 10: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Example: control loop (v2)

10

initialize state;

while (true) do

await clock tick;

read inputs;

compute outputs;

update state;

write outputs;

end while;

S. Tripakis – EE 249 – The Synchronous MoC

Page 11: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Is this an important model of computation?

• Yes!

– Extremely widespread, both in terms of models/languages, and in terms of applications

• Examples of applications:

– Synchronous digital circuits

– 99% (?) of control software

• Read-compute-write control loops

• Nuclear, avionics, automotive, …

– Multimedia, …

11S. Tripakis – EE 249 – The Synchronous MoC

Page 12: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Is this an important model of computation?

12

Copyright The Mathworks

Engine control model in Simulink

HW SW ++c.f. Simulink to FPGA,

or to HDL

S. Tripakis – EE 249 – The Synchronous MoC

Page 13: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Is this an important model of computation?

• Yes!– Extremely widespread, both in terms of

models/languages, and in terms of applications

• Examples of models and languages:– Mealy/Moore machines– Verilog, VHDL, …– (discrete-time) Simulink– Synchronous languages– (Synchronous) Statecharts– The synchronous-reactive (SR) domain in Ptolemy II– …

13S. Tripakis – EE 249 – The Synchronous MoC

Page 14: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Myths about synchronous models

• Synchronous models have zero-time semantics– Synchronous semantics are essentially untimed: they do

not have a quantitative notion of time.

– Famous Esterel statements [Berry-Gonthier ‘92+:• every 1000 MILLISEC do emit SEC end

• every 1000 MILLIMETER do emit METER end

– Synchronous models can capture both time-triggeredand event-triggered systems. E.g.:

• Do something every 20ms

• Do something whenever you receive an interrupt from the engine

14S. Tripakis – EE 249 – The Synchronous MoC

Page 15: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Example: control loop (v3)

15

initialize state;

while (true) do

await clock tick

or any other interrupt;

read inputs;

compute outputs;

update state;

write outputs;

end while;

S. Tripakis – EE 249 – The Synchronous MoC

Page 16: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Myths about synchronous models

• But:– The synchronous cycles

could be interpreted as discrete time: 0, 1, 2, 3, …, in which case we have a discrete-time semantics…

– … and this can also be seen as an abstraction of real-time:

– C.f. timing analysis of digital circuits

– C.f. WCET analysis of synchronous control loops

16S. Tripakis – EE 249 – The Synchronous MoC

Page 17: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Myths about synchronous models

• Synchronous models are non-implementable(because zero-time is impossible to achieve)

– ???

17

Real-Time Workshop

S. Tripakis – EE 249 – The Synchronous MoC

Page 18: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Benefits of synchronous models

• Deterministic:– Easier to understand, easier to verify

– More light-weight than asynchronous:• No interleaving => less state explosion

• Simpler SW implementations:– No operating system required

– Static scheduling, no memory allocations, no dynamic creation of processes, …

• Simpler timing/schedulability analysis– Often simpler WCET analysis also: no loops

18S. Tripakis – EE 249 – The Synchronous MoC

Page 19: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Asynchronous vs. Synchronous Product

19S. Tripakis – EE 249 – The Synchronous MoC

Page 20: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Lecture plan

• Part 1: Single-rate synchronous models

• Part 2: Multi-rate synchronous models

• Part 3: Feedback and Causality

20S. Tripakis – EE 249 – The Synchronous MoC

Page 21: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Part 1: Single-rate synchronous models

• Moore/Mealy machines

• Synchronous block diagrams

– Inspired by discrete-time Simulink, and SCADE

• Lustre

• Esterel

21S. Tripakis – EE 249 – The Synchronous MoC

Page 22: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Moore Machines

22

• States: {q0, q1, q2, q3}

• Initial state: q0

• Input symbols: {x,y,z}

• Output symbols: {a,b,c}

• Output function:– Out : States -> Outputs

• Transition function:– Next: States x Inputs -> States

Where is the synchronous round here?

deterministic

S. Tripakis – EE 249 – The Synchronous MoC

Page 23: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Moore machine: a circuit view

23

Next Out

clock

x(n)

y(n)

s(n)

S. Tripakis – EE 249 – The Synchronous MoC

Page 24: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Mealy Machines

24

• States: {S0, S1, S2}

• Initial state: S0

• Input symbols: {0,1}

• Output symbols: {0,1}

• Output function:– Out : States x Inputs -> Outputs

• Transition function:– Next: States x Inputs -> States

Where is the synchronous round here?S. Tripakis – EE 249 – The Synchronous MoC

Page 25: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Mealy machine: a circuit view

25

Next Out

clock

x(n)

y(n)

s(n)

Is this a “purely synchronous” model?

S. Tripakis – EE 249 – The Synchronous MoC

Page 26: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Moore vs. Mealy machines

26

Moore or Mealy?

Moore or Mealy?

S. Tripakis – EE 249 – The Synchronous MoC

Page 27: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Moore vs. Mealy machines

• Every Moore machine is also a Mealy machine

– Why?

• Is it possible to transform a Mealy machine to a Moore machine?

27S. Tripakis – EE 249 – The Synchronous MoC

Page 28: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

28

Synchronous block diagrams

• Physical models often described in continuous-time

• Controller part (e.g., Transmission Control Unit) is discrete-time

S. Tripakis – EE 249 – The Synchronous MoC

Page 29: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

29

Synchronous block diagrams

S. Tripakis – EE 249 – The Synchronous MoC

Page 30: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Example: FIR filter

30

)2(3

1)1(

3

1)(

3

1)( nxnxnxny

state initial)0(

state initial)0(

)()1(

)()1(

)(3

1)(

3

1)(

3

1)(

2

1

12

1

21

S

S

nSnS

nxnS

nSnSnxny

What is the Mealy machine for this diagram?S. Tripakis – EE 249 – The Synchronous MoC

Page 31: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

31

Hierarchy in synchronous block diagrams

A B

P

S. Tripakis – EE 249 – The Synchronous MoC

Page 32: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

32

Hierarchy in synchronous block diagrams

Fundamental modularity concept

P

S. Tripakis – EE 249 – The Synchronous MoC

Page 33: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Semantics of hierarchical SBDs

• Can we define the semantics of a composite SBD as a Mealy machine?

– In particular, with a pair of (Out, Next) functions?

33S. Tripakis – EE 249 – The Synchronous MoC

Page 34: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

34

Problem with “monolithic” semantics

A

B

P

P.out(x1, x2) returns (y1, y2)

{

y1 := A.out( x1 );

y2 := B.out( x2 );

return (y1, y2);

}

x1

x2y2

y1

False I/O dependencies =>

Model not usable in some contexts

S. Tripakis – EE 249 – The Synchronous MoC

Page 35: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

35

Solution

• Generalize from a single, to MANY output functions

P.out1( in1 ) returns out1 {

return A.out( in1 );

}

P.out2( in2 ) returns out2 {

return B.out( in2 );

}

A

B

P

*DATE’08, RTAS’08, POPL’09+

S. Tripakis – EE 249 – The Synchronous MoC

Interesting questions: How many output functions do we need?

How to compute them?

Page 36: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Lustre

• The FIR filter in Lustre:

36

node fir (x : real) returns (y : real);

var

s1, s2 : real;

let

s1 = 0 -> pre x;

s2 = 0 -> pre s1;

y = x/3 + s1/3 + s2/3;

tel

S. Tripakis – EE 249 – The Synchronous MoC

Page 37: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Lustre

• The FIR filter in Lustre:

37

node fir (x : real) returns (y : real);

var

s1, s2 : real;

let

s1 = 0 -> pre x;

s2 = 0 -> pre s1;

y = x/3 + s1/3 + s2/3;

tel

S. Tripakis – EE 249 – The Synchronous MoC

Page 38: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Lustre

• The FIR filter in Lustre:

38

node fir (x : real) returns (y : real);

var

s1, s2 : real;

let

y = x/3 + s1/3 + s2/3;

s2 = 0 -> pre s1;

s1 = 0 -> pre x;

tel

What has changed? Is this correct?

S. Tripakis – EE 249 – The Synchronous MoC

Page 39: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Lustre

• The FIR filter in Lustre (no explicit state vars):

39

node fir (x : real) returns (y : real);

let

y = x/3

+ (0 -> pre x)/3

+ (0 -> (0 -> pre pre x))/3;

tel

S. Tripakis – EE 249 – The Synchronous MoC

Page 40: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Exercise

• Write a counter in Lustre

40S. Tripakis – EE 249 – The Synchronous MoC

Page 41: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Esterel

• The FIR filter in Esterel:

41

module FIR:

input x : double;

output y : double;

var s1 := 0 : double, s2 := 0 : double in

loop

await x ;

emit y(x/3 + s1/3 + s2/3) ;

s2 := s1 ;

s1 := x ;

end loop

end var.

S. Tripakis – EE 249 – The Synchronous MoC

Page 42: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Esterel

• The FIR filter in Esterel:

42

module FIR:

input x : double;

output y : double;

var s1 := 0 : double, s2 := 0 : double in

loop

await x ;

emit y(x/3 + s1/3 + s2/3) ;

s1 := x ;

s2 := s1 ;

end loop

end var.

What has changed? Is this correct?

S. Tripakis – EE 249 – The Synchronous MoC

Page 43: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Esterel

• A speedometer in Esterel:

43

module SPEEDOMETER:

input sec, cm; % pure signals

output speed : double; % valued signal

loop

var cpt := 0 : double in

abort

loop

await cm ;

cpt := cpt + 1.0

end loop

when sec do

emit speed(cpt)

end abort

end var

end loop. S. Tripakis – EE 249 – The Synchronous MoC

Page 44: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Lustre

• The speedometer in Lustre:

44

node speedometer(sec, cm: bool) returns (speed: real);

var

cpt1, cpt2 : int;

sp1, sp2 : real;

let

cpt1 = counter(cm, sec);

sp1 = if sec then real(cpt1) else 0.0;

cpt2 = counter(sec, cm);

sp2 = if (cm and (cpt2 > 0))

then 1.0/(real(cpt2))

else 0.0;

speed = max(sp1, sp2);

tel

S. Tripakis – EE 249 – The Synchronous MoC

Page 45: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Part 2: Multi-rate synchronous models

• Synchronous block diagrams with triggers

– Inspired by discrete-time Simulink, and SCADE

• Lustre with when/current

• What about Esterel?

45S. Tripakis – EE 249 – The Synchronous MoC

Page 46: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

46

Triggered and timed synchronous block diagrams

• Motivated by Simulink, SCADE

Triggered block

Simulink/Stateflow diagram Sample time

S. Tripakis – EE 249 – The Synchronous MoC

Page 47: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

47

Triggered synchronous block diagrams

A

B C

P

TRIGGEREDBLOCK

TRIGGER

multi-ratemodels:

• B executed only when

trigger = true

• All signals “present” always

• But not all updated at the

same time

• E.g., output of B updated only

when trigger is trueneed initial

value in case

trigger = false

at n = 0 (initial

round)

v

Question: do triggers increase expressiveness?S. Tripakis – EE 249 – The Synchronous MoC

Page 48: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

48

Trigger elimination

S. Tripakis – EE 249 – The Synchronous MoC

Page 49: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

49

Trigger elimination: atomic blocks

S. Tripakis – EE 249 – The Synchronous MoC

Page 50: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

50

Timed diagrams

A

(3,1)

BC

P

“TIMED”BLOCKS

“static”multi-ratemodels (2,0)

(period, phase)specifications

S. Tripakis – EE 249 – The Synchronous MoC

Page 51: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

51

Timed diagrams = statically triggered diagrams

A

(3,1)

BC

P

(2,0)A B C

P

(3,1) (2,0)

=

(2,0)where

produces: true, false, true, false, …

S. Tripakis – EE 249 – The Synchronous MoC

Page 52: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Multi-clock synchronous programs in Lustre

• Then when and current operators:

52

node A(x: int, b: bool) returns (y: int);

let

y = current (x when b);

tel

0 1 2 3 4 5 ...

T F T F F T ...

0 2 5 ...

0 0 2 2 2 5 ...

x:

b:

x when b:

y:

S. Tripakis – EE 249 – The Synchronous MoC

Page 53: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Multi-clock synchronous programs in Lustre

53

node A(x1,x2: int, b: bool) returns (y: int);

let

y = x1 + (x2 when b);

tel

What is the meaning of this program?

Forbidden in Lustre

S. Tripakis – EE 249 – The Synchronous MoC

Page 54: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Multi-clock synchronous programs in Lustre

• In Lustre, every signal has a clock = “temporal” type

• The clock-calculus: a sort of type checking

– Only signals with same clock can be added, multiplied, …

– How to check whether two clocks (i.e., booleansignals) are the same?

• Problem undecidable in general

• In Lustre, check is syntactic

54S. Tripakis – EE 249 – The Synchronous MoC

Page 55: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Multi-rate in Esterel

55

every 1000 MILLISEC do

emit SEC

end

||

every 1000 MILLIMETER do

emit METER

end

MILLISEC

MILLIMETER

SEC

METER

S. Tripakis – EE 249 – The Synchronous MoC

Page 56: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Part 3: Feedback and Causality

• Vanilla feedback:

– Cyclic dependencies “broken” by registers, delays, …

• Unbroken cyclic dependencies:

– Lustre/SBD solution: forbidden

– Esterel/HW solution: forbidden unless if it makes sense

• Malik’s example

• Constructive semantics

56S. Tripakis – EE 249 – The Synchronous MoC

Page 57: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Feedback in Lustre

57

node counter() returns (c : int);

let

c = 0 -> (pre c) + 1;

tel

node counter() returns (c : int);

let

c = 0 -> c + 1;

tel

OK

Rejected

S. Tripakis – EE 249 – The Synchronous MoC

Page 58: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Feedback in Synchronous Block Diagrams

• Same as Lustre:

58

A B

Rejected, unless A or B is Moore machine

S. Tripakis – EE 249 – The Synchronous MoC

Page 59: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

What about this?

59

Cyclic combinational circuit.Useful: equivalent acyclic circuit is almost 2x larger

[Malik’94]

z = if c then

F(G(x))

else

G(F(x))

S. Tripakis – EE 249 – The Synchronous MoC

Page 60: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Can we give meaning to cyclic synchronous models?

• Think of them as fix-point equations:– x = F(x)

• What is the meaning of these:– x = not x

– x = x

• Is unique solution enough?

– x = x or not x

60S. Tripakis – EE 249 – The Synchronous MoC

Page 61: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Can we give meaning to cyclic synchronous models?

• Think of them as fix-point equations:– x = F(x)

• What is the meaning of these:– x = not x

– x = x

• Is unique solution enough?

– x = x or not x

61

0

1

0

S. Tripakis – EE 249 – The Synchronous MoC

Page 62: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Can we give meaning to cyclic synchronous models?

• Think of them as fix-point equations:– x = F(x)

• What is the meaning of these:– x = not x

– x = x

• Is unique solution enough?

– x = x or not x

62

1

1

0

S. Tripakis – EE 249 – The Synchronous MoC

Page 63: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Can we give meaning to cyclic synchronous models?

• Think of them as fix-point equations:– x = F(x)

• What is the meaning of these:– x = not x

– x = x

• Is unique solution enough?

– x = x or not x

63

1

0

0

S. Tripakis – EE 249 – The Synchronous MoC

Page 64: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Can we give meaning to cyclic synchronous models?

• Think of them as fix-point equations:– x = F(x)

• What is the meaning of these:– x = not x

– x = x

• Is unique solution enough?

– x = x or not x

64

0

0

0

S. Tripakis – EE 249 – The Synchronous MoC

Page 65: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Constructive semantics

• Reason in constructive logic instead of classical logic

• “x or not x” not an axiom

• Then we cannot prove x=1 from:

– x = x or not x

65S. Tripakis – EE 249 – The Synchronous MoC

Page 66: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Constructive semantics

• Fix-point analysis in a flat CPO:– Start with “bottom” (undefined),

iterate until fix-point is reached:• Guaranteed in finite number of

iterations, because no. signals and no. values are both finite

– If solution contains no undefined values, then circuit is constructive

• In our example:– x = x or not x

– Bottom is the fix-point– Circuit not constructive

66

True

Т

False

Т

Т

S. Tripakis – EE 249 – The Synchronous MoC

Page 67: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Constructive semantics: theoretical basis

• Kleene fixed point theorem:– Let L be a CPO and f : L → L be a continuous (and

therefore monotone) function. Then f has a least fixed point equal to sup { bot, f(bot), f(f(bot)), … }

• In our flat CPO, continuous = monotone:– Non-monotone: f(bot) > f(a), where a is not bot

– Not a realistic function

• In out flat CPO, termination is guaranteed.

67S. Tripakis – EE 249 – The Synchronous MoC

Page 68: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Constructive semantics

• Another example:– x = a and not y

– y = b and not x

• Here we have external inputs, must try for all possible input combinations

• Exercise!

68S. Tripakis – EE 249 – The Synchronous MoC

Page 69: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Summary

• Synchronous model of computation:– Widespread, many languages, many applications– Easier to understand, easier to verify (than asynchronous

interleaving)– Interesting semantically

• To go further:– Interesting implementation problems: how to preserve the

properties that the synchronous abstraction provides (determinism, values, …) during implementation?

• Especially on asynchronous, distributed execution platforms

– How to add dynamicity, adaptivity, reconfigurability, … ?

69S. Tripakis – EE 249 – The Synchronous MoC

Page 70: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Questions?

70S. Tripakis – EE 249 – The Synchronous MoC

Page 71: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

References

• State machines (Moore, Mealy, …):– Switching and Finite Automata Theory. Zvi Kohavi, McGraw-Hill, 1978.

• Synchronous block diagrams:– Lublinerman and Tripakis papers on modular code generation: available from

http://www-verimag.imag.fr/~tripakis/publis.html

• Synchronous languages:– “The synchronous languages 12 years later”, Proc. IEEE, Jan 2003, and

references therein.

• Constructive semantics:– Sharad Malik. Analysis of cyclic combinational circuits. ICCAD 1993.– Gerard Berry. The Constructive Semantics of Pure Esterel. Draft book, 1996,

downloadable, google it.

• General, overview:– P. Caspi, P. Raymond and S. Tripakis. Synchronous Programming. In I. Lee, J.

Leung, and S. Son, editors, Handbook of Real-Time and Embedded Systems. Chapman & Hall, 2007. Available from site above.

71S. Tripakis – EE 249 – The Synchronous MoC

Page 72: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Back-up slides

72S. Tripakis – EE 249 – The Synchronous MoC

Page 73: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Mealy Machine

A0/0

A1/1

B/0

10

10

00

1001

01

00

0001

A10/0 B

00/1

00/0, 01/1 10/0, 01/0

Moore Machine

From Mealy to Moore

73S. Tripakis – EE 249 – The Synchronous MoC

Page 74: The Synchronous Model of Computation · 2014-01-08 · The Synchronous Model of Computation Stavros Tripakis UC Berkeley stavros@eecs.berkeley.edu EE 249 Lecture –Sep 9, 2010. ...

Moore vs. Mealy machines

• Every Moore machine is also a Mealy machine

– Why?

• Every Mealy machine can be transformed to an equivalent Moore machine

– How?

– What’s the cost?

– What does “equivalent” mean?

74S. Tripakis – EE 249 – The Synchronous MoC