Docstoc

grille

Document Sample
grille Powered By Docstoc
					         A Lustre V6 tutorial                                                                      Outline                                                     Outline

                                                                                                                                         Lustre
                                                                             Lustre
                           Verimag
                                                                                                                                         Lustre V6

                                                                             Lustre V6                                                        P. Raymond & the Synchronous group et al.

                                                                                                                                         The Lustre V6 compiler
                                                                             The Lustre V6 compiler
                                 December 4, 2008 - Synchron’08 - Aussois
                                                                                                                                              P. Raymond, J. Ballet, E. Jahier



                                                                                                           3                                                          4


                           Lustre                                                                   Lustre                                                      Lustre

          a Data-flow Synchronous Language                                              Targetting reactive critical systems                          a loop-free first-order language


Generalised synchronous circuits: wires hold numerics                        Time constraints

Operators + wires structured into nodes                                         → we want a predictable bound on execution time
                                                                                                                                          But Can those limitations be overlooked ?
Pre-defined operators                                                         Memory constraints

  Boolean: and, not, ...                                                        → we want a predictable bound on memory usage

  Arithmetic: +, -, ...                                                         → (we want that bound to be as small as possible)

  Temporal: pre, when, current                                                ⇒ No loops, first-order


                                 5                                                                         6


                           Lustre                                                                   Lustre                                                      Lustre

            a loop-free first-order language                                           Example of loops and genericity in V4                       Example of loops and genericity in V4

                                                                            node add(const n:int; t1,t2 : int ^ n)                      node add(const n:int; t1,t2 : int ^ n)
                                                                            returns (res:int ^ n);                                      returns (res:int ^ n);
                                                                            let                                                         let
But Can those limitations be overlooked ?                                     res = t1 + t2; -- for i=0..n-1, res[i] = t1[i] + t2[i];     res = t1 + t2; -- for i=0..n-1, res[i] = t1[i] + t2[i];
                                                                            tel                                                         tel

                                                                                                                                         this is legal as long as n is a ground constant which
→ Yes: loops and genericity were introduced in V4                                                                                       value is known at compile time




                                 7
                         Lustre                                                          Lustre                                                     Outline

            Example of loops and genericity in V4                         Example of loops and genericity in V4
                                                                                                                              Lustre
node add(const n:int; t1,t2 : int ^ n)                           node add(const n:int; t1,t2 : int ^ n)
returns (res:int ^ n);                                           returns (res:int ^ n);
let                                                              let                                                          Lustre V6
  res = t1 + t2; -- for i=0..n-1, res[i] = t1[i] + t2[i];          res = t1 + t2; -- for i=0..n-1, res[i] = t1[i] + t2[i];
tel                                                              tel
                                                                                                                              a statically generic (1.5-order) Lustre
 this is legal as long as n is a ground constant which            this is legal as long as n is a ground constant which
value is known at compile time → static genericity               value is known at compile time → static genericity
                                                                                                                              The Lustre V6 compiler
                                                                  Pushing that idea further ⇒ Lustre V6


                                                                                               8                                                          9


                      Lustre V6                                                       Lustre V6                                                   Lustre V6

               What’s new (compared to V4)                                              Structures                                                  Structures

 Structure and enumerated types                                  type complex = struct {                                     type complex = struct {
 Package mechanism (Ada-like)                                       re : real = 0.;                                             re : real = 0.;
    → Name space                                                    im : real = 0.                                              im : real = 0.
    → Encapsulation                                              };                                                          };
 (Static) Genericity
    → Parametric packages                                                                                                    node plus (a, b : complex) returns (c : complex);
                                                                                                                             let
    → Parametric nodes (well-typed macros)
                                                                                                                               c = complex { re = a.re+b.re ; im = a.im+b.im };
    → Static recursion
                                                                                                                             tel
    → Array iterators (versus homomorphic extension – not new;
different)

                              10                                                                                                                         11


                       Lustre V6                                                      Lustre V6                                                   Lustre V6

                     Enumerated type                                     Enumerated clocks + merge ( c Pouzet)                         Enumerated clocks + merge ( c Pouzet)

type trival = enum { Pile, Face, Tranche };                      type trival = enum { Pile, Face, Tranche };                 type trival = enum { Pile, Face, Tranche };
                                                                                                                             node merge_node(clk: trival;




                              12
                  Lustre V6                                           Lustre V6                                                Lustre V6

      Enumerated clocks + merge ( c Pouzet)                Enumerated clocks + merge ( c Pouzet)                                 Packages

type trival = enum { Pile, Face, Tranche };          type trival = enum { Pile, Face, Tranche };             package complex
node merge_node(clk: trival;                         node merge_node(clk: trival;                            provides
   i1 when Pile(clk); i2 when Face(clk);                 i1 when Pile(clk); i2 when Face(clk);                 type t; -- Encapsulation
   i3 when Tranche(clk))                                 i3 when Tranche(clk))                                 const i:t;
returns (y: int);                                    returns (y: int);                                         node re(c: t) returns (r:real);
                                                     let
                                                          y = merge clk
                                                              (Pile:    i1)
                                                              (Face:    i2)
                                                              (Tranche: i3);
                                                     tel
                                                                             13


                  Lustre V6                                           Lustre V6                                                Lustre V6

                    Packages                                         Generic packages                                         Generic packages

package complex                                      model modSimple                                         model modSimple
provides                                              needs type t;                                            needs type t;
  type t; -- Encapsulation                            provides                                                 provides
  const i:t;                                                node fby1(init, fb: t) returns (next: t);                 node fby1(init, fb: t) returns (next: t);
  node re(c: t) returns (r:real);                                                                            body
body                                                                                                           node fby1(init, fb: t) returns (next: t);
  type t = struct { re : real ; im : real };                                                                   let next = init -> pre fb; tel
  const i:t = t { re = 0. ; im = 1. };                                                                       end
  node re(c: t) returns (re:real);
  let re = c.re; tel;
end
                         14


                  Lustre V6                                           Lustre V6                                                Lustre V6

                 Generic packages                                     Generic nodes                                            Generic nodes

model modSimple
  needs type t;                                      node mk_tab<<type t; const init: t; const size: int>>   node mk_tab<<type t; const init: t; const size: int>>
  provides                                                  (a:t) returns (res: t^size);                            (a:t) returns (res: t^size);
         node fby1(init, fb: t) returns (next: t);   let                                                     let
body                                                   res = init ^ size;                                      res = init ^ size;
  node fby1(init, fb: t) returns (next: t);          tel                                                     tel
  let next = init -> pre fb; tel                                                                             node tab_int3 = mk_tab<<int, 0, 3>>;
end
package pint is modSimple(t=int);



                         15
                  Lustre V6                                                    Lustre V6                                                        Lustre V6

                  Generic nodes                                                Generic nodes                                                    Generic nodes


node mk_tab<<type t; const init: t; const size: int>>    node toto_n<<                                                    node toto_n<<
       (a:t) returns (res: t^size);                          node f(a, b: int) returns (x: int);                              node f(a, b: int) returns (x: int);
let                                                          const n : int                                                    const n : int
  res = init ^ size;                                       >>(a: int) returns (x: int^n);                                   >>(a: int) returns (x: int^n);
tel                                                      var v : int;                                                     var v : int;
node tab_int3 = mk_tab<<int, 0, 3>>;                     let                                                              let
node tab_bool4 = mk_tab<<bool, true, 4>>;                  v = f(a, 1);                                                     v = f(a, 1);
                                                           x = v ^ n;                                                       x = v ^ n;
                                                         tel                                                              tel
                                                                                                                          node toto_3 = toto_n<<Lustre::iplus, 3>>;
                         16                                                                                                                              17


                  Lustre V6                                                    Lustre V6                                                        Lustre V6

                 Static recursion                                   Are parametric nodes necessary?                                                 Arrays

node consensus<<const n : int>>(T: bool^n)
returns (a: bool);                                                                                                         As in Lustre V4
let                                                       Indeed, parametric nodes could be emulated with the
                                                         package mechanism                                                   → The array size is static (var mat23: int ˆ 2 ˆ 3;)
  a = with (n = 1) then T[0]
      else T[0] and consensus << n-1 >> (T[1 .. n-1]);                                                                       → Array slices (T1[3..5] = T2[0..2];)
tel                                                          → but we keep them to keep the syntax ligth                   But no more homomorphic extension
node main = consensus<<8>>;                                                                                                  where t1 + t2 means ∀i ∈ {0, .., size − 1}, t1[i] + t2[i]
                                                             → we didn’t really want to have recursive packages
                                                                                                                             ⇒ operate on arrays via iterators


                         18                                                             19                                                               20


                  Lustre V6                                                    Lustre V6                                                        Lustre V6

                 The fill iterator                                             The fill iterator                                                 The red iterator




                                                         node incr (acc : int) returns (acc’, res :               int);
                                                         fill<<incr; 4>>(0)  (4, [0,1,2,3])

                                                                                        21
                  Lustre V6                                          Lustre V6                                               Lustre V6

                 The red iterator                             fill+red=mapred, fillred, fold                          fill+red=mapred, fillred, fold




                                                                                                      fill<<incr; 4>>(0) ≡ fold<<incr; 4>>(0)
                                                                                                      red<<+; 3>>(0, [1,2,3]) ≡ fold<<+; 3>>(0, [1,2,3])
red<<+; 3>>(0, [1,2,3])    6


                          22                                                                                                           23


                  Lustre V6                                          Lustre V6                                               Lustre V6

                 The fold iterator                                  The fold iterator                                       The fold iterator
node cumul(acc in,x:int) returns (acc out,y:int)   node cumul(acc in,x:int) returns (acc out,y:int)   node cumul(acc in,x:int) returns (acc out,y:int)
let                                                let                                                let
   y = acc in+x;                                      y = acc in+x;                                      y = acc in+x;
   acc out = y;                                       acc out = y;                                       acc out = y;
tel                                                tel                                                tel


 fold<<cumul>>(0, [1,2,3])                          fold<<cumul>>(0, [1,2,3])    (6, [1,3,6])          fold<<cumul>>(0, [1,2,3])            (6, [1,3,6])
                                                                                                       fold<<fold<<fold<<full adder; n>>; m>>; p>>
                                                                                                                            (false, x, y)   (r,’’x+y’’)

                                                                                                                                       24


                  Lustre V6                                          Lustre V6                                               Lustre V6

                 The map iterator                                   The map iterator                              About Lustre V6 array iterators




                                                                                                       More general that usual iterators:



                                                                                                         their are of variable arity
map <<+; 3>>([1,0,2],[3,6,-1])       [4,6,1]       map <<+; 3>>([1,0,2],[3,6,-1])       [4,6,1]




                                                                            25                                                         26
                      Outline                                     The Lustre V6 compiler                       The Lustre V6 compiler

Lustre                                                                    The Front-end: lus2lic                       The Front-end: lus2lic

Lustre V6                                                Perform usual checks                         Perform usual checks
                                                           → Syntax, Types, Clocks                      → Syntax, Types, Clocks
The Lustre V6 compiler                                     → Unique definition of outputs                → Unique definition of outputs
                                                           → Combinational cycles detection             → Combinational cycles detection
  The front-end                                                                                       Perform some static evaluation
                                                                                                        → arrays size
  The back-end (J. Ballet)
                                                                                                        → parametric packages and nodes
  The back-back-end (J. Ballet)                                                                         → recursive nodes


                            27


         The Lustre V6 compiler                                Lustre Internal Code ( LIC)                  Lustre Internal Code ( LIC)

               The Front-end: lus2lic                                   was: expanded code (ec)                      was: expanded code (ec)

Perform usual checks
                                                         LIC ≡ core Lustre                            LIC ≡ core Lustre
  → Syntax, Types, Clocks
  → Unique definition of outputs                            No more packages                             No more packages

  → Combinational cycles detection                         Parametric constructs are instanciated       Parametric constructs are instanciated
Perform some static evaluation
                                                            → constants                                  → constants
  → arrays size
  → parametric packages and nodes                           → types                                      → types
  → recursive nodes                                         → nodes                                      → nodes
Generate intermediate code: LIC (Lustre internal code)

                            28                                                                                                       29


     Lustre Internal Code ( LIC)                               Lustre Internal Code ( LIC)                             Lustre potatoes

            was: expanded code (ec) cont.                            was: expanded code (ec) cont.


LIC versus ec                                            LIC versus ec                                           lustre
                                                                                                                  core
  → Nodes are not (necessarily) expanded                    → Nodes are not (necessarily) expanded

  → Arrays are not (necessarily) expanded                   → Arrays are not (necessarily) expanded

                                                         LIC versus Lustre v4

                                                            → Structures and enums

                                                            → array iterators


                                                                                        30
                  Lustre potatoes                                    Lustre potatoes                                            Lustre potatoes




             lustre                                             lustre                                                     lustre
              core         V4                                    core         V4                                     lic    core          V4
               ec                                                 ec                                                         ec
                                                     V6                                                         V6




                  Lustre potatoes                                    Lustre potatoes                                            Lustre potatoes
struct, enums, packages, genericity, ...           struct, enums, packages, genericity, ...                   struct, enums, packages, genericity, ...
                                                                                arrays                                                     arrays

             lustre                                             lustre                                                     lustre
       lic    core         V4                             lic    core         V4                                     lic    core          V4
               ec                                                 ec                                                         ec
  V6                                                 V6                                                         V6
                                                                                                                                                  homomorphic
                                                                                                                                                  extension




                  Lustre potatoes                               The Lustre V6 compiler                                              The back-end
struct, enums, packages, genericity, ...
                                                                         The back-end                         maps each node to a Synchronous Object Component (
                             arrays                                                                                                 SOC)


             lustre                                                                                            A SOC is made of:
              core                                   The role of the backend is to generate sequential code
       lic                 V4                                                                                    a set of memories
               ec
  V6                                                                                                             a set of methods: typically, an init and a step method
                                     homomorphic     We defined (yet) another intermediary format to repre-
                                     extension     sent sequential code: SOC (Synchronous Object Code)
    array iterators
                                                     The idea is that translating this format into any se-
                                                   quential language is easy, and done at the very end



                                31                                                 32
                   The back-end                                                The back-end                                                 The back-end

maps each node to a Synchronous Object Component (          maps each node to a Synchronous Object Component (                             From node to SOC
                      SOC)                                                        SOC)
                                                                                                                         For each node, we:
 A SOC is made of:                                           A SOC is made of:
                                                                                                                           Identify memories
   a set of memories                                           a set of memories
                                                                                                                          Explicitely separate the control (clocks) from the computations
   a set of methods: typically, an init and a step method      a set of methods: typically, an init and a step method
                                                                                                                           → set of guarded equations
 each method is made of a sequence of guarded atomic         each method is made of a sequence of guarded atomic
operations                                                  operations                                                     Split equations into more finer-grained steps: actions

                                                             atomic operation (named actions) can be                       → a set of guarded actions (a wire or a call)
                                                               another SOC method call                                     Find a correct ordering for actions (sheduling)

                                                               an assignment (a wire)                                      → a sequence of guarded actions

                                                                                            33                                                          34


               The back-back-end                                           Lustre V6 compiler                                          Lustre V6 compiler

                       From SOC to C                                      An alpha release is available                               An alpha release is available

                                                            http://www-verimag.imag.fr/∼synchron/lustre-v6/             http://www-verimag.imag.fr/∼synchron/lustre-v6/

 pretty-print the SOC into, let’s say, C                     The front-end lus2lic seems ok                              The front-end lus2lic seems ok


                                                                                                                         lus2lic --lustre-v4: added last friday; seems to work
 provide a C implementation of every predefined (non-
temporal) operators




                                35


               Lustre V6 compiler

              An alpha release is available

http://www-verimag.imag.fr/∼synchron/lustre-v6/


 The front-end lus2lic seems ok
                                                              Thanks for your attention

 lus2lic --lustre-v4: added last friday; seems to work


  The back-back: generates C code... But its not fin-
ished.


                                36                                                          37
                                                                                        Outline                                                  Outline
          A Lustre V6 tutorial
                                                                                                                          Lustre
                                                                   Lustre
                                                                                                                          Lustre V6
                            Verimag
                                                                   Lustre V6                                                    P. Raymond & the Synchronous group et al.

                                                                                                                          The Lustre V6 compiler
                                                                   The Lustre V6 compiler
                                              December 5, 2008 -                                                                P. Raymond, J. Ballet, E. Jahier



                                                                                                3                                                       4


                            Lustre                                                       Lustre                                                   Lustre

           a Data-flow Synchronous Language                                  Targetting reactive critical systems                      a loop-free first-order language


 Generalised synchronous circuits: wires hold numerics             Time constraints

 Operators + wires structured into nodes                             → we want a predictable bound on execution time
                                                                                                                           But Can those limitations be overlooked ?
 Pre-defined operators                                              Memory constraints

   Boolean: and, not, ...                                            → we want a predictable bound on memory usage
                                                                                                                           → Yes: loops and genericity were introduced in V4
   Arithmetic: +, -, ...                                             → (we want that bound to be as small as possible)

   Temporal: pre, when, current                                    ⇒ No loops, first-order


                                  5                                                             6                                                       7


                            Lustre                                                      Outline                                               Lustre V6

         Example of loops and genericity in V4                                                                                        What’s new (compared to V4)
                                                                   Lustre
node add(const n:int; t1,t2 : int ^ n)                                                                                    Structure and enumerated types
returns (res:int ^ n);                                                                                                    Package mechanism (Ada-like)
let                                                                Lustre V6                                                 → Name space
  res = t1 + t2; -- for i=0..n-1, res[i] = t1[i] + t2[i];
                                                                                                                             → Encapsulation
tel
                                                                                                                          (Static) Genericity
                                                                   a statically generic (1.5-order) Lustre
 this is legal as long as n is a ground constant which                                                                       → Parametric packages
value is known at compile time → static genericity                                                                           → Parametric nodes (well-typed macros)
                                                                   The Lustre V6 compiler                                    → Static recursion
 Pushing that idea further ⇒ Lustre V6                                                                                       → Array iterators (versus homomorphic extension – not new;
                                                                                                                         different)

                                  8                                                             9                                                      10
                 Lustre V6                                             Lustre V6                                                    Lustre V6

                   Structures                                        Enumerated type                                 Enumerated clocks + merge ( c Pouzet)

type complex = struct {                              type trival = enum { Pile, Face, Tranche };              type trival = enum { Pile, Face, Tranche };
   re : real = 0.;                                                                                            node merge_node(clk: trival;
   im : real = 0.                                                                                                 i1 when Pile(clk); i2 when Face(clk);
};                                                                                                                i3 when Tranche(clk))
                                                                                                              returns (y: int);
node plus (a, b : complex) returns (c : complex);                                                             let
let                                                                                                                y = merge clk
  c = complex { re = a.re+b.re ; im = a.im+b.im };                                                                     (Pile:    i1)
tel                                                                                                                    (Face:    i2)
                                                                                                                       (Tranche: i3);
                                                                                                              tel
                          11                                                  12                                                             13


                  Lustre V6                                            Lustre V6                                                    Lustre V6

                    Packages                                          Generic packages                                              Generic nodes

package complex                                      model modSimple
provides                                               needs type t;                                          node mk_tab<<type t; const init: t; const size: int>>
  type t; -- Encapsulation                             provides                                                      (a:t) returns (res: t^size);
  const i:t;                                                  node fby1(init, fb: t) returns (next: t);       let
  node re(c: t) returns (r:real);                    body                                                       res = init ^ size;
body                                                   node fby1(init, fb: t) returns (next: t);              tel
  type t = struct { re : real ; im : real };           let next = init -> pre fb; tel                         node tab_int3 = mk_tab<<int, 0, 3>>;
  const i:t = t { re = 0. ; im = 1. };               end                                                      node tab_bool4 = mk_tab<<bool, true, 4>>;
  node re(c: t) returns (re:real);                   package pint is modSimple(t=int);
  let re = c.re; tel;
end
                          14                                                  15                                                             16


                  Lustre V6                                            Lustre V6                                                    Lustre V6

                  Generic nodes                                       Static recursion                                   Are parametric nodes necessary?

                                                     node consensus<<const n : int>>(T: bool^n)
node toto_n<<                                        returns (a: bool);
    node f(a, b: int) returns (x: int);              let                                                       Indeed, parametric nodes could be emulated with the
    const n : int                                      a = with (n = 1) then T[0]                             package mechanism
  >>(a: int) returns (x: int^n);                           else T[0] and consensus << n-1 >> (T[1 .. n-1]);
var v : int;                                         tel                                                          → but we keep them to keep the syntax ligth
let
  v = f(a, 1);                                       node main = consensus<<8>>;
  x = v ^ n;                                                                                                      → we didn’t really want to have recursive packages
tel
node toto_3 = toto_n<<Lustre::iplus, 3>>;
                          17                                                  18                                                             19
                       Lustre V6                                                   Lustre V6                                           Lustre V6

                            Arrays                                                The fill iterator                                    The red iterator


 As in Lustre V4

   → The array size is static (var mat23: int ˆ 2 ˆ 3;)

   → Array slices (T1[3..5] = T2[0..2];)

 But no more homomorphic extension

   where t1 + t2 means ∀i ∈ {0, .., size − 1}, t1[i] + t2[i]
                                                               node incr (acc : int) returns (acc’, res :   int);
   ⇒ operate on arrays via iterators                           fill<<incr; 4>>(0)  (4, [0,1,2,3])                   red<<+; 3>>(0, [1,2,3])     6


                                 20                                                       21                                                   22


                       Lustre V6                                                   Lustre V6                                           Lustre V6

              fill+red=mapred, fillred, fold                                        The fold iterator                                   The map iterator
                                                               node cumul(acc in,x:int) returns (acc out,y:int)
                                                               let
                                                                  y = acc in+x;
                                                                  acc out = y;
                                                               tel


                                                                fold<<cumul>>(0, [1,2,3]) (6, [1,3,6])
fill<<incr; 4>>(0) ≡ fold<<incr; 4>>(0)                                                                             map <<+; 3>>([1,0,2],[3,6,-1])       [4,6,1]
red<<+; 3>>(0, [1,2,3]) ≡ fold<<+; 3>>(0, [1,2,3])              fold<<fold<<fold<<full adder; n>>; m>>; p>>
                                                                                     (false, x, y)   (r,’’x+y’’)

                                 23                                                       24                                                   25


                       Lustre V6                                                    Outline                                  The Lustre V6 compiler

            About Lustre V6 array iterators                                                                                       The Front-end: lus2lic
                                                                Lustre

                                                                Lustre V6                                            Perform usual checks
                                                                                                                       → Syntax, Types, Clocks
 More general that usual iterators:                             The Lustre V6 compiler                                 → Unique definition of outputs
                                                                                                                       → Combinational cycles detection
                                                                  The front-end                                      Perform some static evaluation
                                                                                                                       → arrays size
   their are of variable arity                                    The back-end (J. Ballet)
                                                                                                                       → parametric packages and nodes
                                                                  The back-back-end (J. Ballet)                        → recursive nodes
                                                                                                                     Generate intermediate code: LIC (Lustre internal code)

                                 26                                                       27                                                   28
       Lustre Internal Code ( LIC)                                Lustre Internal Code ( LIC)                                            Lustre potatoes
                                                                                                                       struct, enums, packages, genericity, ...
                was: expanded code (ec)                                 was: expanded code (ec) cont.
                                                                                                                                                    arrays

  LIC ≡ core Lustre                                          LIC versus ec                                                          lustre
                                                                                                                              lic    core          V4
   No more packages                                            → Nodes are not (necessarily) expanded                                 ec
                                                                                                                         V6
   Parametric constructs are instanciated                      → Arrays are not (necessarily) expanded                                                       homomorphic
                                                                                                                                                             extension
    → constants                                              LIC versus Lustre v4
                                                                                                                           array iterators
    → types                                                    → Structures and enums

    → nodes                                                    → array iterators


                                29                                                         30                                                           31


          The Lustre V6 compiler                                              The back-end                                                   The back-end

                       The back-end                        maps each node to a Synchronous Object Component (                                From node to SOC
                                                                                 SOC)
                                                                                                                         For each node, we:
                                                            A SOC is made of:
  The role of the backend is to generate sequential code                                                                  Identify memories
                                                              a set of memories
                                                                                                                          Explicitely separate the control (clocks) from the computations
                                                              a set of methods: typically, an init and a step method
  We defined (yet) another intermediary format to repre-                                                                    → set of guarded equations
sent sequential code: SOC (Synchronous Object Code)         each method is made of a sequence of guarded atomic
                                                           operations                                                     Split equations into more finer-grained steps: actions

                                                            atomic operation (named actions) can be                        → a set of guarded actions (a wire or a call)
  The idea is that translating this format into any se-
quential language is easy, and done at the very end           another SOC method call                                     Find a correct ordering for actions (sheduling)

                                                              an assignment (a wire)                                       → a sequence of guarded actions

                                32                                                         33                                                           34


              The back-back-end                                           Lustre V6 compiler

                      From SOC to C                                      An alpha release is available

                                                           http://www-verimag.imag.fr/∼synchron/lustre-v6/

 pretty-print the SOC into, let’s say, C                    The front-end lus2lic seems ok
                                                                                                                         Thanks for your attention

                                                            lus2lic --lustre-v4: added last friday; seems to work
 provide a C implementation of every predefined (non-
temporal) operators                                          The back-back: generates C code... But its not fin-
                                                           ished.


                                35                                                         36                                                           37
                                                                                       Outline
         A Lustre V6 tutorial

                                                            Lustre

                     Verimag
                                                            Lustre V6



                                                            The Lustre V6 compiler
                                       December 5, 2008 -




                                                                                             3


                   Outline                                                             Lustre

                                                                      a Data-flow Synchronous Language
Lustre

                                                            Generalised synchronous circuits: wires hold numerics
Lustre V6
                                                            Operators + wires structured into nodes
    P. Raymond & the Synchronous group et al.
                                                            Pre-defined operators

The Lustre V6 compiler                                        Boolean: and, not, ...

                                                              Arithmetic: +, -, ...
    P. Raymond, J. Ballet, E. Jahier
                                                              Temporal: pre, when, current


                         4                                                                   5
                        Lustre                                                    Lustre

          Targetting reactive critical systems                          a loop-free first-order language


 Time constraints

    → we want a predictable bound on execution time
                                                            But Can those limitations be overlooked ?
 Memory constraints

    → we want a predictable bound on memory usage
                                                            → Yes: loops and genericity were introduced in V4
    → (we want that bound to be as small as possible)

  ⇒ No loops, first-order


                               6                                                        7


                        Lustre                                                    Outline

         Example of loops and genericity in V4
                                                            Lustre
node add(const n:int; t1,t2 : int ^ n)
returns (res:int ^ n);
let                                                         Lustre V6
  res = t1 + t2; -- for i=0..n-1, res[i] = t1[i] + t2[i];
tel
                                                            a statically generic (1.5-order) Lustre
 this is legal as long as n is a ground constant which
value is known at compile time → static genericity
                                                            The Lustre V6 compiler
 Pushing that idea further ⇒ Lustre V6


                               8                                                        9
                     Lustre V6                                                    Lustre V6

             What’s new (compared to V4)                                            Structures

 Structure and enumerated types                                  type complex = struct {
 Package mechanism (Ada-like)                                       re : real = 0.;
    → Name space                                                    im : real = 0.
    → Encapsulation                                              };
 (Static) Genericity
    → Parametric packages                                        node plus (a, b : complex) returns (c : complex);
                                                                 let
    → Parametric nodes (well-typed macros)
                                                                   c = complex { re = a.re+b.re ; im = a.im+b.im };
    → Static recursion
                                                                 tel
    → Array iterators (versus homomorphic extension – not new;
different)

                              10                                                           11


                      Lustre V6                                                    Lustre V6

                   Enumerated type                                     Enumerated clocks + merge ( c Pouzet)

type trival = enum { Pile, Face, Tranche };                      type trival = enum { Pile, Face, Tranche };
                                                                 node merge_node(clk: trival;
                                                                     i1 when Pile(clk); i2 when Face(clk);
                                                                     i3 when Tranche(clk))
                                                                 returns (y: int);
                                                                 let
                                                                      y = merge clk
                                                                          (Pile:    i1)
                                                                          (Face:    i2)
                                                                          (Tranche: i3);
                                                                 tel
                              12                                                           13
                 Lustre V6                                                Lustre V6

                    Packages                                             Generic packages

package complex                                         model modSimple
provides                                                  needs type t;
  type t; -- Encapsulation                                provides
  const i:t;                                                     node fby1(init, fb: t) returns (next: t);
  node re(c: t) returns (r:real);                       body
body                                                      node fby1(init, fb: t) returns (next: t);
  type t = struct { re : real ; im : real };              let next = init -> pre fb; tel
  const i:t = t { re = 0. ; im = 1. };                  end
  node re(c: t) returns (re:real);                      package pint is modSimple(t=int);
  let re = c.re; tel;
end
                        14                                                       15


                 Lustre V6                                                Lustre V6

                 Generic nodes                                            Generic nodes


node mk_tab<<type t; const init: t; const size: int>>   node toto_n<<
       (a:t) returns (res: t^size);                         node f(a, b: int) returns (x: int);
let                                                         const n : int
  res = init ^ size;                                      >>(a: int) returns (x: int^n);
tel                                                     var v : int;
node tab_int3 = mk_tab<<int, 0, 3>>;                    let
node tab_bool4 = mk_tab<<bool, true, 4>>;                 v = f(a, 1);
                                                          x = v ^ n;
                                                        tel
                                                        node toto_3 = toto_n<<Lustre::iplus, 3>>;
                        16                                                       17
                      Lustre V6                                                      Lustre V6

                     Static recursion                                     Are parametric nodes necessary?

node consensus<<const n : int>>(T: bool^n)
returns (a: bool);
let                                                             Indeed, parametric nodes could be emulated with the
  a = with (n = 1) then T[0]                                   package mechanism
      else T[0] and consensus << n-1 >> (T[1 .. n-1]);
tel                                                                → but we keep them to keep the syntax ligth

node main = consensus<<8>>;
                                                                   → we didn’t really want to have recursive packages



                               18                                                             19


                      Lustre V6                                                      Lustre V6

                          Arrays                                                    The fill iterator


 As in Lustre V4

   → The array size is static (var mat23: int ˆ 2 ˆ 3;)

   → Array slices (T1[3..5] = T2[0..2];)

 But no more homomorphic extension

   where t1 + t2 means ∀i ∈ {0, .., size − 1}, t1[i] + t2[i]
                                                               node incr (acc : int) returns (acc’, res :               int);
   ⇒ operate on arrays via iterators                           fill<<incr; 4>>(0)  (4, [0,1,2,3])

                               20                                                             21
                  Lustre V6                                           Lustre V6

                 The red iterator                              fill+red=mapred, fillred, fold




                                                    fill<<incr; 4>>(0) ≡ fold<<incr; 4>>(0)
                                                    red<<+; 3>>(0, [1,2,3]) ≡ fold<<+; 3>>(0, [1,2,3])
red<<+; 3>>(0, [1,2,3])    6


                          22                                                 23


                  Lustre V6                                           Lustre V6

                 The fold iterator                                   The map iterator
node cumul(acc in,x:int) returns (acc out,y:int)
let
   y = acc in+x;
   acc out = y;
tel


 fold<<cumul>>(0, [1,2,3]) (6, [1,3,6])
                                                    map <<+; 3>>([1,0,2],[3,6,-1])      [4,6,1]
 fold<<fold<<fold<<full adder; n>>; m>>; p>>
                      (false, x, y)   (r,’’x+y’’)

                          24                                                 25
                      Lustre V6                                                  Outline

           About Lustre V6 array iterators
                                                         Lustre

                                                         Lustre V6


More general that usual iterators:                       The Lustre V6 compiler

                                                           The front-end

  their are of variable arity                              The back-end (J. Ballet)

                                                           The back-back-end (J. Ballet)


                                26                                                      27


         The Lustre V6 compiler                                Lustre Internal Code ( LIC)

                The Front-end: lus2lic                                  was: expanded code (ec)

Perform usual checks
                                                         LIC ≡ core Lustre
  → Syntax, Types, Clocks
  → Unique definition of outputs                            No more packages
  → Combinational cycles detection
                                                           Parametric constructs are instanciated
Perform some static evaluation
  → arrays size                                            → constants
  → parametric packages and nodes                          → types
  → recursive nodes
Generate intermediate code: LIC (Lustre internal code)     → nodes

                                28                                                      29
       Lustre Internal Code ( LIC)                                           Lustre potatoes
                                                           struct, enums, packages, genericity, ...
            was: expanded code (ec) cont.
                                                                                        arrays

  LIC versus ec                                                         lustre
                                                                  lic    core          V4
    → Nodes are not (necessarily) expanded                                ec
                                                             V6
    → Arrays are not (necessarily) expanded                                                      homomorphic
                                                                                                 extension
  LIC versus Lustre v4
                                                               array iterators
    → Structures and enums

    → array iterators


                              30                                                            31


          The Lustre V6 compiler                                                 The back-end

                        The back-end                       maps each node to a Synchronous Object Component (
                                                                                 SOC)

                                                            A SOC is made of:
  The role of the backend is to generate sequential code
                                                              a set of memories
                                                              a set of methods: typically, an init and a step method
  We defined (yet) another intermediary format to repre-
sent sequential code: SOC (Synchronous Object Code)         each method is made of a sequence of guarded atomic
                                                           operations
  The idea is that translating this format into any se-     atomic operation (named actions) can be
quential language is easy, and done at the very end           another SOC method call
                                                              an assignment (a wire)


                              32                                                            33
                    The back-end                                                  The back-back-end

                   From node to SOC                                                     From SOC to C

  For each node, we:
   Identify memories
   Explicitely separate the control (clocks) from the computations
                                                                      pretty-print the SOC into, let’s say, C

    → set of guarded equations
   Split equations into more finer-grained steps: actions
                                                                      provide a C implementation of every predefined (non-
    → a set of guarded actions (a wire or a call)                    temporal) operators
   Find a correct ordering for actions (sheduling)
    → a sequence of guarded actions

                                34                                                                 35


               Lustre V6 compiler

              An alpha release is available

http://www-verimag.imag.fr/∼synchron/lustre-v6/


 The front-end lus2lic seems ok
                                                                       Thanks for your attention

 lus2lic --lustre-v4: added last friday; seems to work


  The back-back: generates C code... But its not fin-
ished.


                                36                                                                 37

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:5
posted:2/11/2012
language:Estonian
pages:21