1
Modular code generation from synchronous block diagrams:
modularity vs. reusability vs. code size vs. …
Stavros TripakisUC Berkeley
2
or …on the compositionality of synchronous (and
other) models of computation
Stavros TripakisUC Berkeley
3
or …on interface synthesis
Stavros TripakisUC Berkeley
4
What is the parallel composition of two functions?
F1
F2
x1
x2 y2
y1
5
What is the parallel composition of two functions?
F1
F2
F
x1
x2 y2
y1
6
What is the parallel composition of two functions?
F
x1
x2 y2
y1
a function?
7
What is the parallel composition of two functions?
F
x1
x2y2
y1
8
What is the parallel composition of two functions?
F1
F2
F
x1
x2y2
y1
False I/O dependency
9
What is the parallel composition of two functions?
F1
F2
F
x1
x2 y2
y1 F1
F2 y2
y1x1
x2
10
What is the parallel composition of two Mealy machines?
M1
M2
M
x1
x2 y2
y1
output1
output2 y2
y1x1
x2
stateupdate
11
What about more complex compositions?
what about this?or this?
12
What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors?
3 11 2A B
P
3 2
13
P3 2
What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors?
14
P3 2
Q23
Deadlocks!
What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors?
15
Q23
32A B
11
P
Original diagram does not deadlock
What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors?
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?
17
What has all this got to do with modular code generation?
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;}
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
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?
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
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
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
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
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
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
27
Overall method
A B
DC
P
28
Overall method
Interface for A
Interface for C Interface for D
Interface for B
P
29
Overall methodclustering
30
Overall methodInterface for P
P
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
32
Extensions to triggered and timed synchronous block diagrams
• Inspired from SCADE and Simulink:
Triggered block
Simulink/Stateflow diagram Sample time
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:
Tool and experiments
34
ModularCode
Generator
Simulink model(.mdl file)
Profile libraryfor basic blocks
Profiles for macro blocks
Java code
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
36
In memory of Amir Pnueli
Top Related