skip to main content
article

Staging for generic programming in space and time

Published:23 October 2017Publication History
Skip Abstract Section

Abstract

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).

References

  1. Nada Amin, Tiark Rompf, and Martin Odersky. 2014. Foundations of path-dependent types. In OOPSLA. ACM, 233-249. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Olav Beckmann, Alastair Houghton, Michael R. Mellor, and Paul H. J. Kelly. 2003. Runtime Code Generation in C++ as a Foundation for Domain-Specific Optimisation. In Domain-Specific Program Generation. 291-306.Google ScholarGoogle Scholar
  3. Julia Belyakova. 2016. Language Support for Generic Programming in Object-Oriented Languages: Peculiarities, Drawbacks, Ways of Improvement. Springer, Cham, 1-15.Google ScholarGoogle Scholar
  4. G. Bradski. 2000. Dr. Dobb's Journal of Software Tools (2000).Google ScholarGoogle Scholar
  5. Eugene Burmako. 2013. Scala macros: let our powers combine!: on how rich syntax and static types work with metaprogramming. In Proc. Workshop on Scala. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. Jacques Carette, Oleg Kiselyov, and Chung Chieh Shan. 2009. Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. J. Funct. Program. 19, 5 (2009), 509-543. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. K. D. Cooper, M. W. Hall, and K. Kennedy. 1992. Procedure cloning. In Proc. Computer Languages. 96-105.Google ScholarGoogle Scholar
  8. Keith D Cooper, MaryWHall, and Ken Kennedy. 1993. A Methodology for Procedure Cloning. Proc. Comput. Lang. 19, 2 (April 1993), 105-117. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. Paolo D'Alberto, Peter A. Milder, Aliaksei Sandryhaila, Franz Franchetti, James C. Hoe, José M. F. Moura, Markus Püschel, and Jeremy Johnson. 2007. Generating FPGA Accelerated DFT Libraries. In Proc. IEEE Symposium on Field-Programmable Custom Computing Machines (FCCM). 173-184. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Olivier Danvy, Karoline Malmkjær, and Jens Palsberg. 1996. Eta-Expansion Does The Trick. Proc. Programming Languages and Systems (TOPLAS) 18, 6 (1996), 730-751. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. M. Frigo. 1999. A Fast Fourier Transform Compiler. In Proc. Programming Language Design and Implementation (PLDI). 169-180. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. Matteo Frigo and Steven G. Johnson. 2005. The design and implementation of FFTW3. Proceedings of the IEEE, special issue on "Program Generation, Optimization, and Adaptation" 93, 2 (2005), 216-231.Google ScholarGoogle Scholar
  13. Ronald Garcia, Jaakko Jarvi, Andrew Lumsdaine, Jeremy G. Siek, and Jeremiah Willcock. 2003. A Comparative Study of Language Support for Generic Programming. In Proc. Object-oriented Programming, Systems, Languages, and Applications (OOPSLA). 115-134. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Brian Grant, Markus Mock, Matthai Philipose, Craig Chambers, and Susan J. Eggers. 2000. DyC: an expressive annotation-directed dynamic compiler for C. Theor. Comput. Sci. 248, 1-2 (2000), 147-199. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Douglas Gregor, Jaakko Järvi, Jeremy Siek, Bjarne Stroustrup, Gabriel Dos Reis, and Andrew Lumsdaine. 2006. Concepts: Linguistic Support for Generic Programming in C++. In Proc. Object-oriented Programming Systems, Languages, and Applications (OOPSLA). 291-310. Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Fritz Henglein and Christian Mossin. 1994. Polymorphic binding-time analysis. In Proc. European Symposium on Programming Edinburg. 287-301. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Christian Hofer, Klaus Ostermann, Tillmann Rendel, and Adriaan Moors. 2008. Polymorphic embedding of DSLs. In Proc. Generative Programming: Concepts & Experiences (GPCE). 137-148. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Neil D. Jones, Carsten K. Gomard, and Peter Sestoft. 1993. Partial evaluation and automatic program generation. Prentice-Hall, Inc., Upper Saddle River, NJ, USA. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. Ulrik Jørring and William L. Scherlis. 1986. Compilers and Staging Transformations. In Proc. Symposium on Principles of Programming Languages (POPL). 86-96. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. Oleg Kiselyov. 2014. The design and implementation of BER MetaOCaml. In Proc. Symposium on Functional and Logic Programming (ICFP). 86-102.Google ScholarGoogle ScholarCross RefCross Ref
  21. Andrei V. Klimov. 2009. A Java Supercompiler and Its Application to Verification of Cache-Coherence Protocols. In Proc. Ershov Memorial Conference. 185-192. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Ralf Lämmel and Simon L. Peyton Jones. 2003. Scrap your boilerplate: a practical design pattern for generic programming. In Proc. Workshop on Types in languages design and implementation (TLDI). 26-37. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Ralf Lämmel and Simon L. Peyton Jones. 2005. Scrap your boilerplate with class: extensible generic functions. In Proc. on Functional Programming (ICFP). 204-215. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Geoffrey Mainland. 2007. Why It's Nice to Be Quoted: Quasiquoting for Haskell. In Proc. Workshop on Haskell Workshop. 73-82. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. David R. Musser and Alexander A. Stepanov. 1988. Generic Programming. In Proc. ISSAC (Lecture Notes in Computer Science), Vol. 358. Springer, 13-25. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. Martin Odersky and Tiark Rompf. 2014. Unifying functional and object-oriented programming with Scala. Commun. ACM 57, 4 (2014), 76-86. Google ScholarGoogle ScholarDigital LibraryDigital Library
  27. Georg Ofenbeck. [n. d.]. https://github.com/GeorgOfenbeck/SpaceTime. ([n. d.]). https://github.com/GeorgOfenbeck/SpaceTimeGoogle ScholarGoogle Scholar
  28. Georg Ofenbeck, Tiark Rompf, Alen Stojanov, Martin Odersky, and Markus Püschel. 2013. Spiral in Scala: Towards the Systematic Construction of Generators for Performance Libraries. In Proc. Generative Programming: Concepts & Experiences (GPCE). 125-134. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Markus Püschel, Franz Franchetti, and Yevgen Voronenko. 2011. Encyclopedia of Parallel Computing. Springer, Chapter Spiral.Google ScholarGoogle Scholar
  30. Markus Püschel, José M. F. Moura, Jeremy Johnson, David Padua, Manuela Veloso, Bryan Singer, Jianxin Xiong, Franz Franchetti, Aca Gacic, Yevgen Voronenko, Kang Chen, Robert W. Johnson, and Nicholas Rizzolo. 2005. SPIRAL: Code Generation for DSP Transforms. Proceedings of the IEEE, special issue on "Program Generation, Optimization, and Adaptation" 93, 2 (2005), 232- 275.Google ScholarGoogle ScholarCross RefCross Ref
  31. Jonathan Ragan-Kelley, Connelly Barnes, Andrew Adams, Sylvain Paris, Frédo Durand, and Saman Amarasinghe. 2013. Halide: A Language and Compiler for Optimizing Parallelism, Locality, and Recomputation in Image Processing Pipelines. In Proc. Programming Language Design and Implementation (PLDI). ACM, 519-530. Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. Tiark Rompf and Martin Odersky. 2012. Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. Commun. ACM 55, 6 (2012), 121-130. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. Tiark Rompf, Arvind K. Sujeeth, Kevin J. Brown, HyoukJoong Lee, Hassan Chafi, and Kunle Olukotun. 2014. Surgical precision JIT compilers. In Proc. Programming Language Design and Implementation (PLDI). Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. Henrique Nazare Santos, Pericles Alves, Igor Costa, and Fernando Magno Quintao Pereira. 2013. Just-in-time Value Specialization. In Proc. Symposium on Code Generation and Optimization (CGO). 11. Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. Ulrik P. Schultz, Julia L. Lawall, and Charles Consel. 2003. Automatic Program Specialization for Java. ACM Trans. Program. Lang. Syst. 25, 4 (July 2003), 452-499. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. Amin Shali and William R. Cook. 2011. Hybrid partial evaluation. In Proc. Object-Oriented Programming Systems, Languages, and Applications (OOPSLA). Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. Tim Sheard and Simon Peyton Jones. 2002. Template meta-programming for Haskell. In Proc. Workshop on Haskell. 1-16. Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. Jeremy G. Siek, Lie-Quan Lee, and Andrew Lumsdaine. 2002. The Boost Graph Library - User Guide and Reference Manual. Pearson / Prentice Hall. Google ScholarGoogle ScholarDigital LibraryDigital Library
  39. Alexander Slesarenko. 2012. Lightweight Polytypic Staging: a new approach to an implementation of Nested Data Parallelism in Scala. In Proc. Workshop on Scala (SCALA '13). ACM, New York, NY, USA, Article 3, 10 pages.Google ScholarGoogle Scholar
  40. Alexander Slesarenko, Alexander Filippov, and Alexey Romanov. 2014. First-class Isomorphic Specialization by Staged Evaluation. In Proc. Workshop on Generic Programming (WGP '14). ACM, New York, NY, USA, 35-46. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. Josef Svenningsson and Emil Axelsson. 2015. Combining deep and shallow embedding of domain-specific languages. Proc. Computer Languages, Systems & Structures 44 (2015), 143-165. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. Wouter Swierstra. 2008. Data types à la carte. Journal of Functional Programming 18, 4 (2008), 423-436. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Walid Taha. 1999. Multi-stage programming: Its theory and applications. Ph.D. Dissertation. Oregon Graduate Institute of Science and Technology. Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Yevgen Voronenko, Frédéric de Mesmay, and Markus Püschel. 2009. Computer Generation of General Size Linear Transform Libraries. In Proc. Symposium on Code Generation and Optimization (CGO). 102-113. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. P. Wadler and S. Blott. 1989. How to Make Ad-hoc Polymorphism Less Ad Hoc. In Proceedings of the 16th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL '89). ACM, New York, NY, USA, 60-76. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Piotr Wendykier. 2016. JTransform. (2016). https://sites.google.com/site/piotrwendykier/software/jtransformsGoogle ScholarGoogle Scholar
  47. Jeremy Yallop. 2016. Staging Generic Programming. In Proc. Workshop on Partial Evaluation and Program Manipulation (PEPM '16). ACM, New York, NY, USA, 85-96. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Staging for generic programming in space and time

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      • Published in

        cover image ACM SIGPLAN Notices
        ACM SIGPLAN Notices  Volume 52, Issue 12
        GPCE '17
        December 2017
        258 pages
        ISSN:0362-1340
        EISSN:1558-1160
        DOI:10.1145/3170492
        Issue’s Table of Contents
        • cover image ACM Conferences
          GPCE 2017: Proceedings of the 16th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences
          October 2017
          258 pages
          ISBN:9781450355247
          DOI:10.1145/3136040

        Copyright © 2017 ACM

        Publisher

        Association for Computing Machinery

        New York, NY, United States

        Publication History

        • Published: 23 October 2017

        Check for updates

        Qualifiers

        • article

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!