360 likes | 496 Views
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.
E N D
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 Stavros Tripakis UC Berkeley
F1 F2 What is the parallel composition of two functions? y1 x1 x2 y2
F F1 F2 What is the parallel composition of two functions? y1 x1 x2 y2
What is the parallel composition of two functions? y1 x1 F x2 y2 a function?
What is the parallel composition of two functions? x1 y1 F y2 x2
F F1 F2 What is the parallel composition of two functions? False I/O dependency x1 y1 y2 x2
F1 F2 What is the parallel composition of two functions? F1 x1 y1 y1 x1 F2 x2 y2 x2 y2 F
What is the parallel composition of two Mealy machines? output1 x1 y1 M1 y1 x1 state update M2 x2 y2 output2 x2 M y2
What about more complex compositions? what about this? or this?
P A B What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors? 3 1 2 3 1 2
P What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors? 3 2
P What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors? Deadlocks! 3 2 3 2 Q
A B What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors? Original diagram does not deadlock 1 2 3 1 P 3 2 Q
P A B What is the sequential composition of two SDF (Synchronous/Static Data Flow) actors? 3 1 2 3 1 2 See tech. report, with D. Bui, B. Rodiers and E.A. Lee: http://www.eecs.berkeley.edu/Pubs/TechRpts/2009/EECS-2009-143.html
P A B 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 • … P.step( in ) returns out { tmp := A.step( in ); out := B.step( tmp ); return out; }
Separate compilation Standard Compiler (e.g., gcc) . . . . . . Linker (e.g., ld) . . . gcc Object code (e.g., .o files) Source code (e.g., .cc files) Executable We want to do the same for synchronous block diagrams
P P A B C D Modular code generation • Goal: generate code for a given block P • Code should be independent from context: • Enables component-based design (c.f., AUTOSAR) Will P be connected like this? …or like that?
Problem with current approaches: “monolithic” code False I/O dependencies F1 y1 F.step(x1, x2) returns (y1, y2) { y1 := F1.step( x1 ); y2 := F2.step( x2 ); return (y1, y2); } x1 F2 x2 y2 F
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
[DATE’08, RTAS’08, POPL’09], with R. Lublinerman and C. Szegedy P A B 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 ); }
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
class P { public Pstep( in1, in2 ) returns out1, out2; Pstep( in1, in2 ) { return (Astep( in1 ), Bstep( in2 ) ); } } class P { public Pstep1( in1 ) returns out1; public Pstep2( in2 ) returns out2; Pstep1( in1 ) { return Astep( in1 ); } Pstep2( in2 ) { return Bstep( in2 ); } } P P A A B B Modularity vs. Reusability Number of interface functions Set of allowed contexts more modular, less reusable more reusable, less modular tradeoff technique: graph clustering more interface functions fewer interface functions
unit-delay update output Profile dependency graphs • Profile = Interface functions + DEPENDENCY GRAPH • Graph encodes interface usage constraints class UnitDelay { private state; update( in ) returns void { state := in; } output() returns out { return state; } } in out PROFILE DEPENDENCY GRAPH
Overall method A B C D P
Overall method Interface for B Interface for A P Interface for D Interface for C
Overall method clustering
Overall method Interface for P P
Clustering methods and tradeoffs * N = number of block outputs
Extensions to triggered and timed synchronous block diagrams • Inspired from SCADE and Simulink: Triggered block Simulink/Stateflow diagram Sample time
Extensions to triggered and timed synchronous block diagrams • Extensions of interfaces with additional info:
Tool and experiments Profile library for basic blocks Profiles for macro blocks Modular Code Generator Simulink model (.mdl file) Java code
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