skip to main content
10.1145/3136040.3136060acmconferencesArticle/Chapter ViewAbstractPublication PagesgpceConference Proceedingsconference-collections
research-article

Staging for generic programming in space and time

Published: 23 October 2017 Publication History

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.
[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.
[3]
Julia Belyakova. 2016. Language Support for Generic Programming in Object-Oriented Languages: Peculiarities, Drawbacks, Ways of Improvement. Springer, Cham, 1-15.
[4]
G. Bradski. 2000. Dr. Dobb's Journal of Software Tools (2000).
[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.
[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.
[7]
K. D. Cooper, M. W. Hall, and K. Kennedy. 1992. Procedure cloning. In Proc. Computer Languages. 96-105.
[8]
Keith D Cooper, MaryWHall, and Ken Kennedy. 1993. A Methodology for Procedure Cloning. Proc. Comput. Lang. 19, 2 (April 1993), 105-117.
[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.
[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.
[11]
M. Frigo. 1999. A Fast Fourier Transform Compiler. In Proc. Programming Language Design and Implementation (PLDI). 169-180.
[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.
[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.
[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.
[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.
[16]
Fritz Henglein and Christian Mossin. 1994. Polymorphic binding-time analysis. In Proc. European Symposium on Programming Edinburg. 287-301.
[17]
Christian Hofer, Klaus Ostermann, Tillmann Rendel, and Adriaan Moors. 2008. Polymorphic embedding of DSLs. In Proc. Generative Programming: Concepts & Experiences (GPCE). 137-148.
[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.
[19]
Ulrik Jørring and William L. Scherlis. 1986. Compilers and Staging Transformations. In Proc. Symposium on Principles of Programming Languages (POPL). 86-96.
[20]
Oleg Kiselyov. 2014. The design and implementation of BER MetaOCaml. In Proc. Symposium on Functional and Logic Programming (ICFP). 86-102.
[21]
Andrei V. Klimov. 2009. A Java Supercompiler and Its Application to Verification of Cache-Coherence Protocols. In Proc. Ershov Memorial Conference. 185-192.
[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.
[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.
[24]
Geoffrey Mainland. 2007. Why It's Nice to Be Quoted: Quasiquoting for Haskell. In Proc. Workshop on Haskell Workshop. 73-82.
[25]
David R. Musser and Alexander A. Stepanov. 1988. Generic Programming. In Proc. ISSAC (Lecture Notes in Computer Science), Vol. 358. Springer, 13-25.
[26]
Martin Odersky and Tiark Rompf. 2014. Unifying functional and object-oriented programming with Scala. Commun. ACM 57, 4 (2014), 76-86.
[27]
Georg Ofenbeck. [n. d.]. https://github.com/GeorgOfenbeck/SpaceTime. ([n. d.]). https://github.com/GeorgOfenbeck/SpaceTime
[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.
[29]
Markus Püschel, Franz Franchetti, and Yevgen Voronenko. 2011. Encyclopedia of Parallel Computing. Springer, Chapter Spiral.
[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.
[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.
[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.
[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).
[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.
[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.
[36]
Amin Shali and William R. Cook. 2011. Hybrid partial evaluation. In Proc. Object-Oriented Programming Systems, Languages, and Applications (OOPSLA).
[37]
Tim Sheard and Simon Peyton Jones. 2002. Template meta-programming for Haskell. In Proc. Workshop on Haskell. 1-16.
[38]
Jeremy G. Siek, Lie-Quan Lee, and Andrew Lumsdaine. 2002. The Boost Graph Library - User Guide and Reference Manual. Pearson / Prentice Hall.
[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.
[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.
[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.
[42]
Wouter Swierstra. 2008. Data types à la carte. Journal of Functional Programming 18, 4 (2008), 423-436.
[43]
Walid Taha. 1999. Multi-stage programming: Its theory and applications. Ph.D. Dissertation. Oregon Graduate Institute of Science and Technology.
[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.
[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.
[46]
Piotr Wendykier. 2016. JTransform. (2016). https://sites.google.com/site/piotrwendykier/software/jtransforms
[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.

Cited By

View all
  • (2020)Compiling symbolic execution with staging and algebraic effectsProceedings of the ACM on Programming Languages10.1145/34282324:OOPSLA(1-33)Online publication date: 13-Nov-2020
  • (2019)Iteratively Composing Statically Verified TraitsElectronic Proceedings in Theoretical Computer Science10.4204/EPTCS.299.7299(49-55)Online publication date: 20-Aug-2019
  • (2019)Staged abstract interpreters: fast and modular whole-program analysis via meta-programmingProceedings of the ACM on Programming Languages10.1145/33605523:OOPSLA(1-32)Online publication date: 10-Oct-2019
  • Show More Cited By

Recommendations

Comments

Information & Contributors

Information

Published In

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
  • 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
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than ACM must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected]

Sponsors

In-Cooperation

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 23 October 2017

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. FFT
  2. generic programming
  3. high performance program generation
  4. polymorphism
  5. staging

Qualifiers

  • Research-article

Conference

SPLASH '17
Sponsor:

Acceptance Rates

Overall Acceptance Rate 56 of 180 submissions, 31%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)24
  • Downloads (Last 6 weeks)3
Reflects downloads up to 02 Mar 2025

Other Metrics

Citations

Cited By

View all
  • (2020)Compiling symbolic execution with staging and algebraic effectsProceedings of the ACM on Programming Languages10.1145/34282324:OOPSLA(1-33)Online publication date: 13-Nov-2020
  • (2019)Iteratively Composing Statically Verified TraitsElectronic Proceedings in Theoretical Computer Science10.4204/EPTCS.299.7299(49-55)Online publication date: 20-Aug-2019
  • (2019)Staged abstract interpreters: fast and modular whole-program analysis via meta-programmingProceedings of the ACM on Programming Languages10.1145/33605523:OOPSLA(1-32)Online publication date: 10-Oct-2019
  • (2019)DSL-Based Hardware Generation with ScalaACM Transactions on Reconfigurable Technology and Systems10.1145/335975413:1(1-23)Online publication date: 19-Dec-2019
  • (2019)A stage-polymorphic IR for compiling MATLAB-style dynamic tensor expressionsProceedings of the 18th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences10.1145/3357765.3359514(34-47)Online publication date: 21-Oct-2019
  • (2019)Apla Generic Constraint Matching Detection and Verification2019 24th International Conference on Engineering of Complex Computer Systems (ICECCS)10.1109/ICECCS.2019.00030(210-219)Online publication date: Nov-2019
  • (2018)Backpropagation with continuation callbacksProceedings of the 32nd International Conference on Neural Information Processing Systems10.5555/3327546.3327682(10201-10212)Online publication date: 3-Dec-2018
  • (2018)AnyDSL: a partial evaluation framework for programming high-performance librariesProceedings of the ACM on Programming Languages10.1145/32764892:OOPSLA(1-30)Online publication date: 24-Oct-2018
  • (2018)SPIRAL: Extreme Performance PortabilityProceedings of the IEEE10.1109/JPROC.2018.2873289106:11(1935-1968)Online publication date: Nov-2018
  • (2017)Collapsing towers of interpretersProceedings of the ACM on Programming Languages10.1145/31581402:POPL(1-33)Online publication date: 27-Dec-2017
  • Show More Cited By

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media