Docstoc

compiler

Document Sample
compiler Powered By Docstoc
					                                           Compilation
                                          adventures in
                                            Bellman’s
                                              GAP

                                              Georg
                                             Sauthoff
Compilation adventures in Bellman’s GAP
                                          Introduction

                                          Frontend

               Georg Sauthoff              Middleend

                                          Backend
    gsauthof@techfak.uni-bielefeld.de
                                          Conclusion

              Universität Bielefeld
            AG Praktische Informatik


               July 16, 2010
Motivation

                                      Compilation
                                     adventures in
                                       Bellman’s
                                         GAP

   Usability                             Georg
                                        Sauthoff
   Efficient DP-programs
                                     Introduction
   Automatic tricks, Optimizations   Motivation

                                     Frontend

                                     Middleend

                                     Backend

                                     Conclusion
Motivation

                                       Compilation
                                      adventures in
                                        Bellman’s
                                          GAP

    Usability                             Georg
                                         Sauthoff
    Efficient DP-programs
                                      Introduction
    Automatic tricks, Optimizations   Motivation

                                      Frontend

Applications                          Middleend

                                      Backend

    hand-written grammars up to 30    Conclusion

    – 40 non-terminals
    generated grammars with 200 –
    300 non-terminals
Bellman’s GAP Compiler

                                           Compilation
                                          adventures in
                                            Bellman’s
                                              GAP

                                              Georg
                                             Sauthoff

                                          Introduction
                                          Motivation



                                 C++
                                          Frontend


                                 Code
                                          Middleend

                                          Backend


     BGAP
                                          Conclusion

                    BGAP
     Code
                    Compiler
                               Makefile
Basic translation example

                                                                            Compilation
                                                                           adventures in
                              1+2∗3∗4+5                                      Bellman’s
                                                                               GAP

                                                                               Georg
1   f o r m u l a = add ( f o r m u l a , p l u s , f o r m u l a )    |      Sauthoff
2                   mult ( f o r m u l a , t i m e s , f o r m u l a ) |
                                                                           Introduction
3                   number                                         # h ;   Motivation


4                                                                          Frontend

5   plus        = CHAR( ’+ ’ ) ;                                           Middleend

6   times       = CHAR( ’ ∗ ’ ) ;                                          Backend

                                                                           Conclusion
Basic translation example

                                                                                  Compilation
                                                                                 adventures in

                         0 11   +2 23 ∗4 35 ∗6 47 +8 59                            Bellman’s
                                                                                     GAP

                                                                                     Georg
1   f o r m u l a i,j =                                                             Sauthoff
2         add ( f o r m u l a i,k , p l u s k,k+1 , f o r m u l a k+1,j )    |
                                                                                 Introduction
3         mult ( f o r m u l a i,k , t i m e s k,k+1 , f o r m u l a k+1,j ) |   Motivation


4         number i,j                                                     # h ;   Frontend

5                                                                                Middleend

6   plus         = CHAR( ’+ ’ ) ;                                                Backend

7   times        = CHAR( ’ ∗ ’ ) ;                                               Conclusion
Basic translation example

                                                                                  Compilation
                                                                                 adventures in

                         0 11   +2 23 ∗4 35 ∗6 47 +8 59                            Bellman’s
                                                                                     GAP

                                                                                     Georg
1   f o r m u l a i,j =                                                             Sauthoff
2         add ( f o r m u l a i,k , p l u s k,k+1 , f o r m u l a k+1,j )    |
                                                                                 Introduction
3         mult ( f o r m u l a i,k , t i m e s k,k+1 , f o r m u l a k+1,j ) |   Motivation


4         number i,j                                                     # h ;   Frontend

5                                                                                Middleend

6   plus         = CHAR( ’+ ’ ) ;                                                Backend

7   times        = CHAR( ’ ∗ ’ ) ;                                               Conclusion


                        
                        add(Fi,k , plusk,k+1 , Fk+1,j )
                        
                                                        if j − i > 2
     Fi,j   = hi<k<j−1 mult(Fi,k , timesk,k+1 , Fk+1,j ) if j − i > 2
                      
                                                         if j − i > 0
                      
                      number
                              i,j
                                                                    (1)
Parser

                  Compilation
                 adventures in
                   Bellman’s
                     GAP

                     Georg
                    Sauthoff

                 Introduction
   diagnostics
                 Frontend
                 Parser

                 Middleend

                 Backend

                 Conclusion
Parser

                                                       Compilation
                                                      adventures in
                                                        Bellman’s
                                                          GAP

                                                          Georg
                                                         Sauthoff

                                                      Introduction
   diagnostics
                                                      Frontend
                                                      Parser

                                                      Middleend

                                                      Backend
grammar bill uses Bill (axiom=ormula) {               Conclusion
                              ^----^
grammar/no_axiom:14.30-35: Axiom ormula not defined
                           in grammar bill.
Typechecking

                                                               Compilation
                                                              adventures in
                                                                Bellman’s
                                                                  GAP

                                                                  Georg
                                                                 Sauthoff
    conceptual seperation of different typechecking problems
                                                              Introduction
        check grammar against signature
                                                              Frontend
        check each algebra against signature
                                                              Middleend
        check each algebra function                           Typechecking
                                                              Yield Size Analysis
    concise diagnostics                                       Table dimension
                                                              analysis

    diagnostics with context                                  Runtime
                                                              Table Design
                                                              Product combination
    tight integration into the compiler                       analysis

                                                              Backend

                                                              Conclusion
Example (hugs)

                                                        Compilation
                                                       adventures in
                                                         Bellman’s
                                                           GAP

                                                           Georg
                                                          Sauthoff

ERROR "Optbin.lhs":89 - Inferred type is not general   Introduction
  enough                                               Frontend
*** Expression    : tree                               Middleend
                                                       Typechecking
*** Expected type : Tree_Algebra Alphabet a            Yield Size Analysis

                     -> [Alphabet] -> [a]              Table dimension
                                                       analysis
                                                       Runtime
*** Inferred type : Tree_Algebra Alphabet ()           Table Design

                     -> [Alphabet] -> [()]             Product combination
                                                       analysis

                                                       Backend

                                                       Conclusion
Example (New)

                                                      Compilation
                                                     adventures in
                                                       Bellman’s
                                                         GAP

                                                         Georg
                                                        Sauthoff

  plus = mult(formula, plus, formula) | CHAR(’+’);   Introduction
^----^                                               Frontend
grammar/typecheck_elm:98.0-5: Type [Sig answer] is   Middleend
                                                     Typechecking
                      not compatible with            Yield Size Analysis

  plus = mult(formula, plus, formula) | CHAR(’+’);   Table dimension
                                                     analysis
                                                     Runtime
                                       ^---^         Table Design

grammar/typecheck_elm:98.39-43: data type [char].    Product combination
                                                     analysis

                                                     Backend

                                                     Conclusion
YSA Example

                                                                         Compilation
                                                                        adventures in
                                                                          Bellman’s
                                                                            GAP

                                                                            Georg
1   f o r m u l a = add ( f o r m u l a , p l u s , f o r m u l a ) |      Sauthoff

2   // ( 0 , n ) + ( 1 , 1 ) + ( 0 , n ) = ( 1 , n )                    Introduction
3                   number                                              Frontend
4   // ( 1 , n )                                                        Middleend
                                                                        Typechecking
5
                                                                        Yield Size Analysis

6   // ( 1 , n ) / ( 1 , n ) = ( 1 , n )                                Table dimension
                                                                        analysis
                                                                        Runtime
7
                                                                        Table Design

8   // ( 1 , n ) + ( 1 , 1 ) + ( 1 , n ) = ( 3 , n )                    Product combination
                                                                        analysis

9   // ( 3 , n ) / ( 1 , n ) = ( 1 , n )                                Backend

                                                                        Conclusion
     YSA

                                                                                                    Compilation
                                                                                                   adventures in
1    Alt : : Simple : : i n i t _ y s :                                                              Bellman’s
2      foreach ( arg in args ) :                                                                       GAP

3          arg . i n i t _ y s ()                                                                      Georg
                                                                                                      Sauthoff
4          y s += a r g . y s ( )
5      y s |= ( m i n s i z e , m a x s i z e )   1   Alt : : Link : : i n i t _ y s :             Introduction
6                                                 2     ys = nt . ys ( )                           Frontend
7    Alt : : Block : : i n i t _ y s :            3     y s |= ( m i n s i z e , m a x s i z e )
                                                                                                   Middleend
8      foreach ( alt in alts ):                                                                    Typechecking

9          alt . init_ys ()                                                                        Yield Size Analysis
                                                                                                   Table dimension
10         y s /= a l t . y s ( )                                                                  analysis
                                                                                                   Runtime
11     y s |= ( m i n s i z e , m a x s i z e )                                                    Table Design
                                                                                                   Product combination
                                                                                                   analysis
                + = (a, b) = (a. min +b. min, a. max +b. max)                            (2)
                                                                                                   Backend
                  | = (a, b) = (max(a. min, b. min), min(a. max, b. max))                (3)       Conclusion
                 / = (a, b) = (min(a. min, b. min), max(a. max, b. max))                 (4)
YSA

                                                  Compilation
                                                 adventures in
                                                   Bellman’s
                                                     GAP

                                                     Georg
                                                    Sauthoff

                                                 Introduction

                                                 Frontend
      Initialize every Nonterminal with (1, n)   Middleend
                                                 Typechecking
      Fixpoint iteration                         Yield Size Analysis
                                                 Table dimension
                                                 analysis
                                                 Runtime
                                                 Table Design
                                                 Product combination
                                                 analysis

                                                 Backend

                                                 Conclusion
YSA users

                                                  Compilation
                                                 adventures in
                                                   Bellman’s
                                                     GAP

                                                     Georg
                                                    Sauthoff

    detection of endless derivation loops        Introduction
    table size computation                       Frontend

    indices computation, recurrence derivation   Middleend
                                                 Typechecking

    loop detection                               Yield Size Analysis
                                                 Table dimension
                                                 analysis

    dependency graph generation                  Runtime
                                                 Table Design

    runtime analysis                             Product combination
                                                 analysis

                                                 Backend

                                                 Conclusion
Yield Size Analysis

                                  Compilation
                                 adventures in
                                   Bellman’s
                                     GAP
  1   Normal YSA
                                     Georg
                                    Sauthoff

  2   propagate maxsize filters   Introduction

                                 Frontend

                                 Middleend
                                 Typechecking
                                 Yield Size Analysis
                                 Table dimension
                                 analysis
                                 Runtime
                                 Table Design
                                 Product combination
                                 analysis

                                 Backend

                                 Conclusion
    Yield Size Analysis

                                                                             Compilation
                                                                            adventures in
                                                                              Bellman’s
                                                                                GAP
        1   Normal YSA
                                                                                Georg
                incl. min/max-filter constraints                                Sauthoff

        2   propagate maxsize filters                                        Introduction

                                                                            Frontend

    Example                                                    What is      Middleend
                                                                            Typechecking

1   grammar Loop u s e s Foo ( axiom = A)                      the com-     Yield Size Analysis
                                                                            Table dimension
2   {                                                          puted        analysis

3     A = f o o ( REGION w i t h m i n s i z e ( 1 2 ) , P ,                Runtime

                                                               yield-size   Table Design
4                 REGION w i t h m i n s i z e ( 7 ) )                      Product combination

5             with maxsize (42) ;                              of P?        analysis

                                                                            Backend
6
7       P = STRING ;                                                        Conclusion

8   }
    Yield Size Analysis

                                                                             Compilation
                                                                            adventures in
                                                                              Bellman’s
                                                                                GAP
        1   Normal YSA
                                                                                Georg
                incl. min/max-filter constraints                                Sauthoff

        2   propagate maxsize filters                                        Introduction

                                                                            Frontend

    Example                                                    What is      Middleend
                                                                            Typechecking

1   grammar Loop u s e s Foo ( axiom = A)                      the com-     Yield Size Analysis
                                                                            Table dimension
2   {                                                          puted        analysis

3     A = f o o ( REGION w i t h m i n s i z e ( 1 2 ) , P ,                Runtime

                                                               yield-size   Table Design
4                 REGION w i t h m i n s i z e ( 7 ) )                      Product combination

5             with maxsize (42) ;                              of P?        analysis

                                                                            Backend
6                                                              Yes, it is
        P = STRING ;                                                        Conclusion
7                                                              (0, 23)
8   }
Table dimension analysis

                                                                   Compilation
                                                                  adventures in
                                                                    Bellman’s
                                                                      GAP

                                                                      Georg
    Idea: use table of constant (linear) size, if only constant      Sauthoff

    (linear) number entries are needed                            Introduction
    exact vs. asymptotic cases (easy vs. more complicated         Frontend

    cases)                                                        Middleend
                                                                  Typechecking

    needed for runtime analysis/table design/code generation      Yield Size Analysis
                                                                  Table dimension
                                                                  analysis
                                                                  Runtime
                                                                  Table Design
                                                                  Product combination
                                                                  analysis

                                                                  Backend

                                                                  Conclusion
Table dimension analysis

                                                                        Compilation
                                                                       adventures in
                                                                         Bellman’s
                                                                           GAP

                                                                           Georg
         Idea: use table of constant (linear) size, if only constant      Sauthoff

         (linear) number entries are needed                            Introduction
         exact vs. asymptotic cases (easy vs. more complicated         Frontend

         cases)                                                        Middleend
                                                                       Typechecking

         needed for runtime analysis/table design/code generation      Yield Size Analysis
                                                                       Table dimension
                                                                       analysis

1   start =       f (a , b) ;                                          Runtime
                                                                       Table Design
2                                                                      Product combination
                                                                       analysis

3   s k i p R = s k i p _ r i g h t ( s k i p R , CHAR) |              Backend
4               skipL # h ;                                            Conclusion
                                                                                 Compilation
                                                                                adventures in
                                                                                  Bellman’s
 1   s t a r t = x (CHAR, s t a r t ) |                                             GAP
 2               b ;                                                                Georg
                                                                                   Sauthoff
 3                                              Two call locations of c:
 4   b       = x (CHAR, b )           |             l = 0, . . . , l = n − 1,
                                                                                Introduction

 5             x (CHAR, c )               |         r =n
                                                                                Frontend

 6             y ( c , CHAR ) ;                                                 Middleend

 7
                                                    l = 0, . . . , l = n − 1,   Typechecking
                                                                                Yield Size Analysis


 8   c      = z ( REGION , d ) ;                    r =n−1                      Table dimension
                                                                                analysis
                                                                                Runtime

 9                                                                              Table Design
                                                                                Product combination
10   d = w( REGION , REGION ) ;                                                 analysis

                                                                                Backend
          bad analysis: c needs quadratic table                                 Conclusion

          good analysis: c needs linear table
                                                                                 Compilation
                                                                                adventures in
                                                                                  Bellman’s
 1   s t a r t = x (CHAR, s t a r t ) |                                             GAP
 2               b ;                                                                Georg
                                                                                   Sauthoff
 3                                              Two call locations of c:
 4   b       = x (CHAR, b )           |             l = 0, . . . , l = n − 1,
                                                                                Introduction

 5             x (CHAR, c )               |         r =n
                                                                                Frontend

 6             y ( c , CHAR ) ;                                                 Middleend

 7
                                                    l = 0, . . . , l = n − 1,   Typechecking
                                                                                Yield Size Analysis


 8   c      = z ( REGION , d ) ;                    r =n−1                      Table dimension
                                                                                analysis
                                                                                Runtime

 9                                                                              Table Design
                                                                                Product combination
10   d = w( REGION , REGION ) ;                                                 analysis

                                                                                Backend
          bad analysis: c needs quadratic table                                 Conclusion

          good analysis: c needs linear table
                                                                                 Compilation
                                                                                adventures in
                                                                                  Bellman’s
 1   s t a r t = x (CHAR, s t a r t ) |                                             GAP
 2               b ;                                                                Georg
                                                                                   Sauthoff
 3                                              Two call locations of c:
 4   b       = x (CHAR, b )           |             l = 0, . . . , l = n − 1,
                                                                                Introduction

 5             x (CHAR, c )               |         r =n
                                                                                Frontend

 6             y ( c , CHAR ) ;                                                 Middleend

 7
                                                    l = 0, . . . , l = n − 1,   Typechecking
                                                                                Yield Size Analysis


 8   c      = z ( REGION , d ) ;                    r =n−1                      Table dimension
                                                                                analysis
                                                                                Runtime

 9                                                                              Table Design
                                                                                Product combination
10   d = w( REGION , REGION ) ;                                                 analysis

                                                                                Backend
          bad analysis: c needs quadratic table                                 Conclusion

          good analysis: c needs linear table
Runtime computation

                                                            Compilation
                                                           adventures in
                                                             Bellman’s
                                                               GAP

                                                               Georg
                                                              Sauthoff
    Input: table dimensions, annotated dependency graph,
    table configuration                                     Introduction

                                                           Frontend
    Output: runtime
                                                           Middleend
                                                           Typechecking
                                                           Yield Size Analysis
                                                           Table dimension
                                                           analysis
                                                           Runtime
                                                           Table Design
                                                           Product combination
                                                           analysis

                                                           Backend

                                                           Conclusion
Runtime computation

                                                                             Compilation
                                                                            adventures in
                                                                              Bellman’s
                                                                                GAP

                                                                                Georg
                                                                               Sauthoff
    Input: table dimensions, annotated dependency graph,
    table configuration                                                      Introduction

                                                                            Frontend
    Output: runtime
                                                                            Middleend
   rt(program) = rt(axiom) +                      ndim(v ) · rt(v )   (5)   Typechecking
                                                                            Yield Size Analysis
                                   v ∈tabulated                             Table dimension
                                                                            analysis
                                                                            Runtime

                                       rt(x ) if x ∈ tabulated
                                                   /                        Table Design

   rt(v ) =            calls(v , x ) ·                                (6)   Product combination


            x ∈rhs(v )
                                       1      if x ∈ tabulated              analysis

                                                                            Backend

                                                                            Conclusion
Example

                                                                                         Compilation
                                                                                        adventures in
                                                                                          Bellman’s
                                                                                            GAP

                                                                                            Georg
                  pal                                         pal                          Sauthoff

              1         1                                 1         1                   Introduction

  1   skipl       1     skipr       1         1   skipl       1     skipr       1       Frontend

                                                                                        Middleend
              1         1               1                 1         1               1
                                                                                        Typechecking
                                                                                        Yield Size Analysis
              match                                       match                         Table dimension
                                                                                        analysis

                            1                                           1               Runtime
                                                                                        Table Design
                                                                                        Product combination
                                inner                                       inner
                                                                                        analysis

                                                                                        Backend

Runtime: n2                                 Runtime: 2n                                 Conclusion
     Example

                                                                       Compilation
                                                                      adventures in
                                                                        Bellman’s
                                                                          GAP
                                          Two cases:
                                                                          Georg

 1   s t a r t = x (CHAR, s t a r t ) |
                                              bad analysis               Sauthoff


 2               b ;                                                  Introduction
 3                                               dim(c) = 2           Frontend
 4   b       = x (CHAR, b )           |         ⇒ rt(c) = O(n2 · n)   Middleend
 5             x (CHAR, c )           |                               Typechecking
                                                                      Yield Size Analysis
 6             y ( c , CHAR ) ;                                       Table dimension
                                                                      analysis
 7
                                                                      Runtime
 8   c      = z ( REGION , d ) ;              good analysis           Table Design
                                                                      Product combination
 9                                                                    analysis

10   d = w( REGION , REGION ) ;                  dim(c) = 1           Backend

                                                ⇒ rt(c) = O(n · n)    Conclusion
Table Design

                                    Compilation
                                   adventures in
                                     Bellman’s
                                       GAP

                                       Georg
                                      Sauthoff

                                   Introduction

   automatically find the optimal   Frontend

   table configuration              Middleend
                                   Typechecking
                                   Yield Size Analysis
                                   Table dimension
                                   analysis
                                   Runtime
                                   Table Design
                                   Product combination
                                   analysis

                                   Backend

                                   Conclusion
Table Design

                                     Compilation
                                    adventures in
                                      Bellman’s
                                        GAP

                                        Georg
                                       Sauthoff

                                    Introduction

    automatically find the optimal   Frontend

    table configuration              Middleend
                                    Typechecking

 ⇒ find the table configuration of    Yield Size Analysis
                                    Table dimension

   minimal size and get still       analysis
                                    Runtime

   asymptotic optimal runtime       Table Design
                                    Product combination
                                    analysis

                                    Backend

                                    Conclusion
Algorithm

                                                                    Compilation
                                                                   adventures in
                                                                     Bellman’s
                                                                       GAP
  1   score every nonterminal                                          Georg
                                                                      Sauthoff
  2   sort a list of nonterminals
                                                                   Introduction
  3   take the highest scored nt until runtime is asymptotically
                                                                   Frontend
      optimal
                                                                   Middleend
                                                                   Typechecking
                                                                   Yield Size Analysis
                                                                   Table dimension
                                                                   analysis
                                                                   Runtime
                                                                   Table Design
                                                                   Product combination
                                                                   analysis

                                                                   Backend

                                                                   Conclusion
Algorithm

                                                                     Compilation
                                                                    adventures in
                                                                      Bellman’s
                                                                        GAP
  1   score every nonterminal                                           Georg
                                                                       Sauthoff
  2   sort a list of nonterminals
                                                                    Introduction
  3   take the highest scored nt until runtime is asymptotically
                                                                    Frontend
      optimal
                                                                    Middleend
                                                                    Typechecking

Definition                                                           Yield Size Analysis
                                                                    Table dimension
                                                                    analysis
                                                                    Runtime
                                                                    Table Design
             score(nt) = in(nt) · out(nt) · selfrec(nt)       (7)   Product combination
                                                                    analysis

                                                                    Backend

                                                                    Conclusion
Algorithm

                                                                     Compilation
                                                                    adventures in
                                                                      Bellman’s
                                                                        GAP
  1   score every nonterminal                                           Georg
                                                                       Sauthoff
  2   sort a list of nonterminals
                                                                    Introduction
  3   take the highest scored nt until runtime is asymptotically
                                                                    Frontend
      optimal
                                                                    Middleend
                                                                    Typechecking

Definition                                                           Yield Size Analysis
                                                                    Table dimension
                                                                    analysis
                                                                    Runtime
                                                                    Table Design
             score(nt) = in(nt) · out(nt) · selfrec(nt)       (7)   Product combination
                                                                    analysis

                                                                    Backend

⇒ thus, if pre-computed asymptotical optimal runtime is             Conclusion

wrong, table design may fail
Example

                                                                  Compilation
                                                                 adventures in
                                                                   Bellman’s
                                                                     GAP

                                                                     Georg
                  pal                                               Sauthoff


              1         1                                        Introduction

                                                                 Frontend
  1   skipl       1     skipr       1
                                                                 Middleend
                                               in(match) = 3     Typechecking
              1         1               1
                                                                 Yield Size Analysis
                                              out(match) = 1     Table dimension
              match                                              analysis

                                            selfrec(match) = 7   Runtime
                                                                 Table Design
                            1
                                                                 Product combination
                                                                 analysis

                                inner
                                                                 Backend

                                                                 Conclusion
Different kinds of algebras

                                            Compilation
                                           adventures in
                                             Bellman’s
                                               GAP

    selective                                  Georg
                                              Sauthoff
         scoring
                                           Introduction
         classification
                                           Frontend
         pretty-printing
         enumeration                       Middleend
                                           Typechecking

    synthetic                              Yield Size Analysis
                                           Table dimension
                                           analysis
         synoptic                          Runtime
                                           Table Design
 ⇒ different analyses depend on these       Product combination
                                           analysis
   categories                              Backend

    what about combinations of algebras?   Conclusion
Product combination analysis

                                                                    Compilation
                                                                   adventures in
                                                                     Bellman’s
                                                                       GAP

    not every combination makes sense (count · pretty )                Georg
                                                                      Sauthoff
    what is the list size after evaluation of choice function?
                                                                   Introduction
         e.g. scoring algebra ⇒ singleton list
                                                                   Frontend
         e.g. score · pretty ⇒ k co-optimal candidates
                                                                   Middleend
         input for list elimination phase                          Typechecking
                                                                   Yield Size Analysis
    diagnostics                                                    Table dimension
                                                                   analysis
         warn about "missing" choice functions                     Runtime
                                                                   Table Design
         warn about "dangerous" algebra applications (e.g. enum)   Product combination
                                                                   analysis

    eliminate unneeded applications of choice functions (e.g.      Backend
    scoring choice function and singleton input list)              Conclusion
Backtracing Codegeneration

                                      Compilation
                                     adventures in
                                       Bellman’s
                                         GAP

                                         Georg
                                        Sauthoff
   score-matrix as input
                                     Introduction
   backtrace steps how the optimal   Frontend
   score was computed                Middleend

   pretty-print on the way back      Backend
                                     Backtracing
                                     Parallelization

                                     Conclusion
Backtracing Codegeneration

                                       Compilation
                                      adventures in
                                        Bellman’s
                                          GAP

                                          Georg
                                         Sauthoff
    score-matrix as input
                                      Introduction
    backtrace steps how the optimal   Frontend
    score was computed                Middleend

    pretty-print on the way back      Backend
                                      Backtracing

 → GAP-C supports different            Parallelization

                                      Conclusion
   backtracing codegeneration
   schemes
Optimal Backtrace

                                                                                Compilation
                                                                               adventures in
                                                                                 Bellman’s
                                                                                   GAP
    Example
                                                                                   Georg
                                                                                  Sauthoff
1   f o r m u l a = number |
2                   add ( f o r m u l a , p l u s , f o r m u l a ) |          Introduction

3                   mult ( f o r m u l a , t i m e s , f o r m u l a ) # h ;   Frontend

                                                                               Middleend

                                                                               Backend
                                                                               Backtracing
                                                                               Parallelization

                                                                               Conclusion
Optimal Backtrace

                                                                                Compilation
                                                                               adventures in
                                                                                 Bellman’s
                                                                                   GAP
    Example
                                                                                   Georg
                                                                                  Sauthoff
1   f o r m u l a = number |
2                   add ( f o r m u l a , p l u s , f o r m u l a ) |          Introduction

3                   mult ( f o r m u l a , t i m e s , f o r m u l a ) # h ;   Frontend

                                                                               Middleend

                                                                               Backend
                                                                               Backtracing
                                                                               Parallelization

     formulai,j =                                      h[numberi,j ,   (8)     Conclusion

                       add(formulai,k , plusk,k+1 , formulak+1,j ),    (9)
                     mult(formulai,k , timesk,k+1 , formulak+1,j )] (10)
 Optimal Backtrace

                                                                                                Compilation
                                                                                               adventures in
                                                                                                 Bellman’s
                                                                                                   GAP
1    s t r i n g backtrace_formula ( i , j ) :                                                     Georg
2        score = formula [ i , j ]                                                                Sauthoff

3        i f number [ i , j ] == s c o r e :                                                   Introduction

4             return backtrace_number ( i , j )                                                Frontend

5        f o r e a c h k , i <k<j :                                                            Middleend

6             i f add ( f o r m u l a [ i , k ] , p l u s ( k , k +1) ,                        Backend
                                                                                               Backtracing
7                          f o r m u l a [ k +1, j ] ) == s c o r e :                          Parallelization


8                r e t u r n add_pp ( b a c k t r a c e _ f o r m u l a ( i , k ) ,            Conclusion

9                                            p l u s ( k , k +1) ,
10                                           b a c k t r a c e _ f o r m u l a ( k +1, j ) )
11            ...
Optimal Backtrace

                                             Compilation
                                            adventures in
                                              Bellman’s
                                                GAP

                                                Georg
                                               Sauthoff

                                            Introduction

   Optimal-Backtrace in O(n2 ), even with   Frontend

   O(n3 ) DP-algorithms                     Middleend

                                            Backend
   replacement for computing the pretty     Backtracing

   print for all subwords                   Parallelization

                                            Conclusion
Other Backtracing schemes

                             Compilation
                            adventures in
                              Bellman’s
                                GAP

                                Georg
                               Sauthoff

                            Introduction

                            Frontend

   co-optimal               Middleend

                            Backend
   sub-optimal              Backtracing
                            Parallelization
   stochastic
                            Conclusion
Application: Shapes

                                                                   Compilation
                                                                  adventures in
    group rna secondary structure search space into interesting     Bellman’s
                                                                      GAP
    classes
                                                                      Georg
    each structure is classified into a class                         Sauthoff

                                                                  Introduction

                                                                  Frontend

                                                                  Middleend

                                                                  Backend
                                                                  Backtracing
                                                                  Parallelization

                                                                  Conclusion
Application: Shapes

                                                                   Compilation
                                                                  adventures in
    group rna secondary structure search space into interesting     Bellman’s
                                                                      GAP
    classes
                                                                      Georg
    each structure is classified into a class                         Sauthoff

                                                                  Introduction
Example                                                           Frontend
 Structure                                       Shape            Middleend

 ....(((.....)))...                              []               Backend
                                                                  Backtracing
 ....(((...((....))....)))...                    []               Parallelization

 ..(((...((...))...((((...))))...)))..           [[][]]           Conclusion
Application: Shapes

                                                                   Compilation
                                                                  adventures in
    group rna secondary structure search space into interesting     Bellman’s
                                                                      GAP
    classes
                                                                      Georg
    each structure is classified into a class                         Sauthoff

                                                                  Introduction
Example                                                           Frontend
 Structure                                       Shape            Middleend

 ....(((.....)))...                              []               Backend
                                                                  Backtracing
 ....(((...((....))....)))...                    []               Parallelization

 ..(((...((...))...((((...))))...)))..           [[][]]           Conclusion



Questions to ask

    What is the best structure of a class?
    What is the probability of a class?
Boltzmann Distribution

                                                    Compilation
                                                   adventures in
                                                     Bellman’s
                                                       GAP

partition function                                     Georg
                                                      Sauthoff

                                                   Introduction
                        Q=         e −βEs   (11)   Frontend
                             s∈S
                                                   Middleend

                                                   Backend
                                                   Backtracing
structure probability                              Parallelization

                                                   Conclusion


                               e −βEs
                        ps =                (12)
                                  Q
Use case stochastic backtracing: Motivation

                                                                  Compilation
                                                                 adventures in
                                                                   Bellman’s
                                                                     GAP

                                                                     Georg
                                                                    Sauthoff
    The computation of the partition function for a sequence
    is in O(n3 )                                                 Introduction

    The computation of all shapes of a sequence is in   O(2n )   Frontend

                                                                 Middleend
    We want to compute: shape · pf
                                                                 Backend
                                                                 Backtracing
                                                                 Parallelization

                                                                 Conclusion
Use case stochastic backtracing: Motivation

                                                                  Compilation
                                                                 adventures in
                                                                   Bellman’s
                                                                     GAP

                                                                     Georg
                                                                    Sauthoff
    The computation of the partition function for a sequence
    is in O(n3 )                                                 Introduction

    The computation of all shapes of a sequence is in   O(2n )   Frontend

                                                                 Middleend
    We want to compute: shape · pf
                                                                 Backend
     → still in O(2n )                                           Backtracing
                                                                 Parallelization

                                                                 Conclusion
Use case stochastic backtracing: Motivation

                                                                  Compilation
                                                                 adventures in
                                                                   Bellman’s
                                                                     GAP

                                                                     Georg
                                                                    Sauthoff
    The computation of the partition function for a sequence
    is in O(n3 )                                                 Introduction

    The computation of all shapes of a sequence is in   O(2n )   Frontend

                                                                 Middleend
    We want to compute: shape · pf
                                                                 Backend
     → still in O(2n )                                           Backtracing
                                                                 Parallelization

                                                                 Conclusion
Plan B
⇒ just compute pf and do stochastic backtracing!
Stochastic backtracing

                                                                                Compilation
                                                                               adventures in
                                                                                 Bellman’s
    don’t choose some optimal value in each backtracing step,                      GAP
    just a random one                                                              Georg
                                                                                  Sauthoff


Example (Partition Function Algebra)                                           Introduction

                                                                               Frontend

                                                                               Middleend

                                                                               Backend
     lcandidates =   [hl(. . .), ml(. . . , il(. . .), . . .), . . .]   (13)   Backtracing
                                                                               Parallelization

            lpf =                               [1, 23, 42, . . .]      (14)   Conclusion

           hpf =                                              sum       (15)
Stochastic backtracing

                                                                                   Compilation
                                                                                  adventures in
                                                                                    Bellman’s
     don’t choose some optimal value in each backtracing step,                        GAP
     just a random one                                                                Georg
                                                                                     Sauthoff


Example (Partition Function Algebra)                                              Introduction

                                                                                  Frontend

                                                                                  Middleend

                                                                                  Backend
     lcandidates =      [hl(. . .), ml(. . . , il(. . .), . . .), . . .]   (13)   Backtracing
                                                                                  Parallelization

            lpf =                                  [1, 23, 42, . . .]      (14)   Conclusion

           hpf =                                                 sum       (15)


      (p_func|p_func_id) · shape5                 sample_filter _pf
Interpret lpf as discrete probability distribution.
Parallelization

                           Compilation
                          adventures in
                            Bellman’s
                              GAP

                              Georg
       j                     Sauthoff

                  k       Introduction

                          Frontend
i
                          Middleend

                          Backend
                      k   Backtracing
                          Parallelization

                          Conclusion
Parallelization

                                   Compilation
                                  adventures in
                                    Bellman’s
                              j       GAP

                                      Georg
       j                  i          Sauthoff

                  k               Introduction

                                  Frontend
i
                                  Middleend

                                  Backend
                      k           Backtracing
                                  Parallelization

                                  Conclusion
Results, ADPfold, mfe, |s| = 4000

                                             Compilation
                                            adventures in
           30           4 × 4 Xeon            Bellman’s
                                                GAP
                      8 × 4 Opteron
                                                Georg
                    8 × 8 Niagara T1           Sauthoff

                           98%              Introduction
           20
 speedup




                                            Frontend

                                            Middleend

                                            Backend
                                            Backtracing

           10                               Parallelization

                                            Conclusion




           0
                0         10      20   30
                               #CPUs
Results, ADPfold, mfe, |s| = 4000

                                                                       Compilation
                           0     5    10   15     20   25   30   35   adventures in
                                                                        Bellman’s
                                                                          GAP
                      1
                                                                          Georg
                                                                         Sauthoff

                     0.8
 parallel efficiency




                                                                      Introduction

                                                                      Frontend

                     0.6                                              Middleend

                                                                      Backend
                                                                      Backtracing
                                                                      Parallelization
                     0.4
                                   4 × 4 Xeon                         Conclusion

                                 8 × 4 Opteron
                     0.2
                               8 × 8 Niagara T1
                                      98%
                      0

                                           #CPUs
Conclusion

                                                                  Compilation
                                                                 adventures in
                                                                   Bellman’s
                                                                     GAP

                                                                     Georg
                                                                    Sauthoff
    just a selection of DP-compiling challenges presented here
                                                                 Introduction
    there are a lot of optimization possibilities in DP          Frontend
    DP from scratch is tedious and error-prone                   Middleend

    GAP-L is an high-level and user friendly language to         Backend

                                                                 Conclusion
    devleop DP algorithmus
    GAP-C compiles high-level specifications into optimized
    C++ code

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:2
posted:2/23/2012
language:Latin
pages:57