Staging for generic programming in space and time

Metaprogramming is among the most promising candidates to solve the abstraction vs performance trade-off that plagues software engineering through specialization. Metaprogramming has been used to enable low-overhead generic programming for a long time, with C++ templates being one of the most prominent examples. But often a single, fixed pattern of specialization is not enough, and more flexibility is needed. Hence, this paper seeks to apply generic programming techniques to challenges in metaprogramming, in particular to abstract over the execution stage of individual program expressions. We thus extend the scope of generic programming into the dimension of time. The resulting notion of stage polymorphism enables novel abstractions in the design of program generators, which we develop and explore in this paper. We present one possible implementation, in Scala using the lightweight modular staging (LMS) framework, and apply it to two important case studies: convolution on images and the fast Fourier transform (FFT).

[1]  Simon L. Peyton Jones,et al.  Scrap your boilerplate with class: extensible generic functions , 2005, ICFP '05.

[2]  David Padua,et al.  Encyclopedia of Parallel Computing , 2011 .

[3]  Péricles Rafael Oliveira Alves,et al.  Just-in-time value specialization , 2013, Proceedings of the 2013 IEEE/ACM International Symposium on Code Generation and Optimization (CGO).

[4]  Matteo Frigo,et al.  A fast Fourier transform compiler , 1999, SIGP.

[5]  Frédo Durand,et al.  Halide: a language and compiler for optimizing parallelism, locality, and recomputation in image processing pipelines , 2013, PLDI 2013.

[6]  Ulrik Pagh Schultz,et al.  Automatic program specialization for Java , 2000, TOPL.

[7]  Alexander A. Stepanov,et al.  Generic Programming , 1988, ISSAC.

[8]  Ken Kennedy,et al.  Procedure cloning , 1992, Proceedings of the 1992 International Conference on Computer Languages.

[9]  Peter Sestoft,et al.  Partial evaluation and automatic program generation , 1993, Prentice Hall international series in computer science.

[10]  Simon L. Peyton Jones,et al.  Scrap your boilerplate: a practical design pattern for generic programming , 2003, TLDI '03.

[11]  T. Sheard Template Metaprogramming for Haskell , 2014 .

[12]  Jaakko Järvi,et al.  A comparative study of language support for generic programming , 2003, OOPSLA '03.

[13]  Steven G. Johnson,et al.  The Design and Implementation of FFTW3 , 2005, Proceedings of the IEEE.

[14]  Martin Odersky,et al.  Unifying functional and object-oriented programming with Scala , 2014, Commun. ACM.

[15]  Kunle Olukotun,et al.  Surgical precision JIT compilers , 2014, PLDI.

[16]  William L. Scherlis,et al.  Compilers and staging transformations , 1986, POPL '86.

[17]  Jacques Carette,et al.  Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages , 2007, Journal of Functional Programming.

[18]  Wouter Swierstra,et al.  Data types à la carte , 2008, Journal of Functional Programming.

[19]  Ken Kennedy,et al.  A Methodology for Procedure Cloning , 1993, Computer languages.

[20]  Philip Wadler,et al.  How to make ad-hoc polymorphism less ad hoc , 1989, POPL '89.

[21]  Oleg Kiselyov The Design and Implementation of BER MetaOCaml - System Description , 2014, FLOPS.

[22]  Jim Law,et al.  Review of "The boost graph library: user guide and reference manual by Jeremy G. Siek, Lie-Quan Lee, and Andrew Lumsdaine." Addison-Wesley 2002. , 2003, SOEN.

[23]  William R. Cook,et al.  Hybrid partial evaluation , 2011, OOPSLA '11.

[24]  Bjarne Stroustrup,et al.  Concepts: linguistic support for generic programming in C++ , 2006, OOPSLA '06.

[25]  Geoffrey Mainland Why it's nice to be quoted: quasiquoting for haskell , 2007, Haskell '07.

[26]  Jeremy G. Siek,et al.  The Boost Graph Library - User Guide and Reference Manual , 2001, C++ in-depth series.

[27]  Markus Mock,et al.  DyC: an expressive annotation-directed dynamic compiler for C , 2000, Theor. Comput. Sci..

[28]  Andrei V. Klimov,et al.  A Java Supercompiler and Its Application to Verification of Cache-Coherence Protocols , 2009, Ershov Memorial Conference.

[29]  Martin Odersky,et al.  Foundations of path-dependent types , 2014, OOPSLA.

[30]  Julia Belyakova Language Support for Generic Programming in Object-Oriented Languages: Peculiarities, Drawbacks, Ways of Improvement , 2016, SBLP.

[31]  Christian Hofer,et al.  Polymorphic embedding of dsls , 2008, GPCE '08.

[32]  Franz Franchetti,et al.  SPIRAL: Code Generation for DSP Transforms , 2005, Proceedings of the IEEE.

[33]  Alexey Romanov,et al.  First-class isomorphic specialization by staged evaluation , 2014, WGP '14.

[34]  Simon L. Peyton Jones,et al.  Template meta-programming for Haskell , 2002, Haskell '02.

[35]  Eugene Burmako,et al.  Scala macros: let our powers combine!: on how rich syntax and static types work with metaprogramming , 2013, SCALA@ECOOP.

[36]  Walid Taha,et al.  Multi-Stage Programming: Its Theory and Applications , 1999 .

[37]  Markus Püschel,et al.  Computer Generation of General Size Linear Transform Libraries , 2009, 2009 International Symposium on Code Generation and Optimization.

[38]  Martin Odersky,et al.  Spiral in scala: towards the systematic construction of generators for performance libraries , 2014, GPCE '13.

[39]  Nicole Stender Template Metaprogramming for Haskell , 2014 .

[40]  James H. Lambert,et al.  A Methodology for , 2000 .

[41]  Franz Franchetti,et al.  Generating FPGA-Accelerated DFT Libraries , 2007, 15th Annual IEEE Symposium on Field-Programmable Custom Computing Machines (FCCM 2007).

[42]  A V Slesarenko Polytypic Staging: a new approach to an implementation of Nested Data Parallelism in Scala , 2012 .

[43]  Jeremy Yallop Staging generic programming , 2016, PEPM.

[44]  Jens Palsberg,et al.  Eta-expansion does The Trick , 1995, TOPL.

[45]  L. Miles,et al.  2000 , 2000, RDH.

[46]  Emil Axelsson,et al.  Combining deep and shallow embedding of domain-specific languages , 2015, Comput. Lang. Syst. Struct..

[47]  Fritz Henglein,et al.  Polymorphic Binding-Time Analysis , 1994, ESOP.

[48]  Paul H. J. Kelly,et al.  Runtime Code Generation in C++ as a Foundation for Domain-Specific Optimisation , 2003, Domain-Specific Program Generation.