stavros tripakis uc berkeley

36
Modular code generation from synchronous block diagrams: modularity vs. reusability vs. code size vs. … Stavros Tripakis UC Berkeley 1

Upload: javen

Post on 22-Feb-2016

54 views

Category:

Documents


0 download

DESCRIPTION

Modular code generation from synchronous block diagrams: modularity vs. reusability vs. code size vs. …. Stavros Tripakis UC Berkeley. or … on the compositionality of synchronous (and other) models of computation. Stavros Tripakis UC Berkeley. or … on interface synthesis. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Stavros  Tripakis UC Berkeley

1

Modular code generation from synchronous block diagrams:

modularity vs. reusability vs. code size vs. …

Stavros TripakisUC Berkeley

Page 2: Stavros  Tripakis UC Berkeley

2

or …on the compositionality of synchronous (and

other) models of computation

Stavros TripakisUC Berkeley

Page 3: Stavros  Tripakis UC Berkeley

3

or …on interface synthesis

Stavros TripakisUC Berkeley

Page 4: Stavros  Tripakis UC Berkeley

4

What is the parallel composition of two functions?

F1

F2

x1

x2 y2

y1

Page 5: Stavros  Tripakis UC Berkeley

5

What is the parallel composition of two functions?

F1

F2

F

x1

x2 y2

y1

Page 6: Stavros  Tripakis UC Berkeley

6

What is the parallel composition of two functions?

F

x1

x2 y2

y1

a function?

Page 7: Stavros  Tripakis UC Berkeley

7

What is the parallel composition of two functions?

F

x1

x2y2

y1

Page 8: Stavros  Tripakis UC Berkeley

8

What is the parallel composition of two functions?

F1

F2

F

x1

x2y2

y1

False I/O dependency

Page 9: Stavros  Tripakis UC Berkeley

9

What is the parallel composition of two functions?

F1

F2

F

x1

x2 y2

y1 F1

F2 y2

y1x1

x2

Page 10: Stavros  Tripakis UC Berkeley

10

What is the parallel composition of two Mealy machines?

M1

M2

M

x1

x2 y2

y1

output1

output2 y2

y1x1

x2

stateupdate

Page 11: Stavros  Tripakis UC Berkeley

11

What about more complex compositions?

what about this?or this?

Page 12: Stavros  Tripakis UC Berkeley

12

What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors?

3 11 2A B

P

3 2

Page 13: Stavros  Tripakis UC Berkeley

13

P3 2

What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors?

Page 14: Stavros  Tripakis UC Berkeley

14

P3 2

Q23

Deadlocks!

What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors?

Page 15: Stavros  Tripakis UC Berkeley

15

Q23

32A B

11

P

Original diagram does not deadlock

What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors?

Page 16: Stavros  Tripakis UC Berkeley

16

3 11 2A B

P

3 2

http://www.eecs.berkeley.edu/Pubs/TechRpts/2009/EECS-2009-143.html

See tech. report, with D. Bui, B. Rodiers and E.A. Lee:

What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors?

Page 17: Stavros  Tripakis UC Berkeley

17

What has all this got to do with modular code generation?

Page 18: Stavros  Tripakis UC Berkeley

18

Code generation • Generate code (in C, C++, Java, …) that implements the

semantics of a certain modeling language (Simulink, Lustre, Ptolemy, …)

• Code may be used for simulation, embedded control (“X-by-wire”), …– SCADE– Real-Time Workshop– …

A B

P

P.step( in ) returns out{ tmp := A.step( in ); out := B.step( tmp ); return out;}

Page 19: Stavros  Tripakis UC Berkeley

Separate compilation

19

gcc

Source code(e.g., .cc files)

Linker(e.g., ld)

StandardCompiler(e.g., gcc)

Object code(e.g., .o files)

.

.

.

.

.

.

.

.

.

Executable

We want to do the same forsynchronous block diagrams

Page 20: Stavros  Tripakis UC Berkeley

20

Modular code generation

• Goal: generate code for a given block P

• Code should be independent from context:

– Enables component-based design (c.f., AUTOSAR)

A

BP

C

D

P

Will P be connected like this?

…or like that?

Page 21: Stavros  Tripakis UC Berkeley

21

Problem with current approaches: “monolithic” code

F.step(x1, x2) returns (y1, y2){ y1 := F1.step( x1 ); y2 := F2.step( x2 );

return (y1, y2);}

F1

F2

F

x1

x2 y2

y1

False I/O dependencies

Page 22: Stavros  Tripakis UC Berkeley

22

State of the art• SCADE: add unit delays to “break’’ cycles at all levels of

hierarchy– Destroys control properties (stability)

• Simulink (Real-Time Workshop): flattening– Not modular– Not scalable

• Ptolemy [Edwards, Lee’03]: iterate step() until fixpoint is reached (à la Esterel)– Handles larger class of models– Fixpoint may contain undefined values (“bottom”)– Expensive/undecidable to prove statically that this won’t happen

Page 23: Stavros  Tripakis UC Berkeley

23

Our solution• Generate for each block a PROFILE = INTERFACE• Interface may contain MANY functions• Automatically

P.step1( x1 ) returns y1 { return A.step( x1 ); }

P.step2( x2 ) returns y2 { return B.step( x2 ); }

A

B

P

[DATE’08, RTAS’08, POPL’09], with R. Lublinerman and C. Szegedy

Page 24: Stavros  Tripakis UC Berkeley

24

How many functions?

• Would like to have as few as possible– Scalability, IP concerns, …– Modularity = small number of interface functions

=> small size of interface– Modularity becomes quantifiable!• The smaller the interface, the more modular

Page 25: Stavros  Tripakis UC Berkeley

25

Modularity vs. Reusability

moremodular,

lessreusable

morereusable,

lessmodular

moreinterfacefunctions

fewerinterfacefunctions

class P { public Pstep1( in1 ) returns out1; public Pstep2( in2 ) returns out2;

Pstep1( in1 ) { return Astep( in1 ); }

Pstep2( in2 ) { return Bstep( in2 ); }}

A

B

P

class P { public Pstep( in1, in2 ) returns out1, out2;

Pstep( in1, in2 ) { return (Astep( in1 ), Bstep( in2 ) ); }

}

A

B

P

Number ofinterfacefunctions

Set ofallowedcontexts

tradeoff

technique: graph clustering

Page 26: Stavros  Tripakis UC Berkeley

26

Profile dependency graphs• Profile = Interface functions + DEPENDENCY GRAPH• Graph encodes interface usage constraints

unit-delay

class UnitDelay {

private state;

update( in ) returns void { state := in; }

output() returns out { return state; }}

update

output

PROFILEDEPENDENCYGRAPH

in

out

Page 27: Stavros  Tripakis UC Berkeley

27

Overall method

A B

DC

P

Page 28: Stavros  Tripakis UC Berkeley

28

Overall method

Interface for A

Interface for C Interface for D

Interface for B

P

Page 29: Stavros  Tripakis UC Berkeley

29

Overall methodclustering

Page 30: Stavros  Tripakis UC Berkeley

30

Overall methodInterface for P

P

Page 31: Stavros  Tripakis UC Berkeley

Clustering methods and tradeoffs

Clustering method

Complexity Achieves maximal

reusability?

Achieves optimal

modularity?

Modularity bound?

Achieves minimal code

size?“step-get” Polynomial No Almost <=2 functions Yes

“dynamic” Polynomial Yes Yes <=N+1 functions*

No

“disjoint” NP-complete Yes Yes ? Yes

31

* N = number of block outputs

Page 32: Stavros  Tripakis UC Berkeley

32

Extensions to triggered and timed synchronous block diagrams

• Inspired from SCADE and Simulink:

Triggered block

Simulink/Stateflow diagram Sample time

Page 33: Stavros  Tripakis UC Berkeley

33

Extensions to triggered and timed synchronous block diagrams

Firing Time Automata

B

A

P = A U B

A

(3,2)

BP

(2,1)

FTA division

A

(4,0)

BP

(2,0)

A

(2,0)

B

P(2,0)

(1,0)

A U B A

A U B B

A U B

B

A

• Extensions of interfaces with additional info:

Page 34: Stavros  Tripakis UC Berkeley

Tool and experiments

34

ModularCode

Generator

Simulink model(.mdl file)

Profile libraryfor basic blocks

Profiles for macro blocks

Java code

Page 35: Stavros  Tripakis UC Berkeley

35

Related work

• Cronos [Hainque et al. ‘99]• [Raymond ’88, Pouzet-Raymond ‘09]• [Benveniste et al. ‘97]• [Schneider et al. ‘06, ‘09]• [Mosterman, Ciolfi ‘04]• …• More in the papers:

– http://www-verimag.imag.fr/~tripakis/papers/popl09.pdf– http://www-verimag.imag.fr/~tripakis/papers/rtas08.pdf– http://www-verimag.imag.fr/~tripakis/papers/date08.pdf

Page 36: Stavros  Tripakis UC Berkeley

36

In memory of Amir Pnueli