[go: up one dir, main page]
More Web Proxy on the site http://driver.im/ skip to main content
research-article
Free access

Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs

Published: 01 June 2012 Publication History

Abstract

Good software engineering practice demands generalization and abstraction, whereas high performance demands specialization and concretization. These goals are at odds, and compilers can only rarely translate expressive high-level programs to modern hardware platforms in a way that makes best use of the available resources.
Generative programming is a promising alternative to fully automatic translation. Instead of writing down the target program directly, developers write a program generator, which produces the target program as its output. The generator can be written in a high-level, generic style and can still produce efficient, specialized target programs. In practice, however, developing high-quality program generators requires a very large effort that is often hard to amortize.
We present lightweight modular staging (LMS), a generative programming approach that lowers this effort significantly. LMS seamlessly combines program generator logic with the generated code in a single program, using only types to distinguish the two stages of execution. Through extensive use of component technology, LMS makes a reusable and extensible compiler framework available at the library level, allowing programmers to tightly integrate domain-specific abstractions and optimizations into the generation process, with common generic optimizations provided by the framework.
LMS is well suited to develop embedded domain-specific languages (DSLs) and has been used to develop powerful performance-oriented DSLs for demanding domains such as machine learning, with code generation for heterogeneous platforms including GPUs. LMS has also been used to generate SQL for embedded database queries and JavaScript for web applications.

References

[1]
Calcagno, C., Taha, W., Huang, L., Leroy, X. Implementing multi-stage languages using asts, gensym, and reflection. GPCE, F. Pfenning and Y. smaragdakis, eds. Volume 2830 of Lecture Notes in Computer Science (2003). Springer, 57--76.
[2]
Carette, J. Kiselyov, O., chieh Shan, C., Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages. J. Funct. Program, 19, 5 (2009), 509--543.
[3]
Cohen, A., Donadio, S., Garzarán, M.J., Herrmann, C.A., Kiselyov, O., Padua, D.A. In search of a program generator to implement generic transformations for high-performance computing. Sci. Comput. Program. 62, 1 (2006), 25--46.
[4]
Czarnecki, K., O'Donnell, J.T., Striegnitz, J., Taha, W., Dsl implementation in metaocaml, template haskell, and c++. In Domain-Specific Program Generation (2003), 51--72.
[5]
Elliott, C., Finne, S., de Moor, O. Compiling embedded languages. J. Funct, Program, 13, 3 (2003), 455-481.
[6]
Frigo, M. A fast Fourier transform compiler. In PLDI (1999), 169--180.
[7]
Guerrero, M., Pizzi, E., Rosenbaum, R., Swadi, K.N., Taha, W. Implementing dsls in metaocaml. OOPSLA Companion, J. M. Vlissides and D. C. Schmidt, eds. (2004). ACM, 41--42.
[8]
Hofer, C., Ostermann, K., Rendel, T., Moors, A. Polymorphic embedding of dsls. GPCE, Y. Smaragdakis and J.G. Siek, eds. (2008). ACM, 137--148.
[9]
Hudak, P. Modular domain specific languages and tools. In Proceedings of Fifth International Conference on Software Reuse (June 1998), 134--142.
[10]
Kameyama, Y., Kiselyov, O., chieh Shan, C. Shifting the stage: staging with delimited control. PEPM, G. Puebla and G. Vidal, eds. (2009). ACM, 111--120.
[11]
Kennedy, K., Broom, B., Cooper, K.D., Dongarra, J., Fowler, R.J., Gannon, D., Johnsson, S.L., Mellor-Crummey, J.M., Torczon, L. Telescoping languages: A strategy for automatic generation of scientific problem-solving systems from annotated libraries. J. Parallel Distrib, Comput. 61, 12 (2001), 1803--1826.
[12]
Kiselyov, O., Swadi, K.N., Taha, W. A methodology for generating verified combinatorial circuits. EMSOFT, G.C. Buttazzo, ed. (2004). ACM, 249--258.
[13]
Lee, H., Brown, K.J., Sujeeth, A.K., Chafi, H., Rompf, T., Odersky, M., Olukotun, K. Implementing domain-specific languages for heterogeneous parallel computing. IEEE Micro 31, 5 (2011), 42--53.
[14]
Leijen, D., Meijer, E. Domain specific embedded compilers. In DSL (1999), 109--122.
[15]
Odersky, M., Zenger, M. Scalable component abstractions. OOPSLA, R. E. Johnson and R.P. Gabriel, eds. (2005). ACM, 41--57.
[16]
Pfenning, F., Elliott, C. Higher-order abstract syntax. In PLDI (1988), 199--208.
[17]
Püschel, M., Moura, J.M.F., Singer, B., Xiong, J., Johnson, J., Padua, D.A., Veloso, M.M., Johnson, R.W. Spiral: A generator for platform-adapted libraries of signal processing alogorithms. IJHPCA, 18, 1 (2004), 21--45.
[18]
Rompf, T., Sujeeth, A.K., Lee, H., Brown, K.J., Chafi, H., Odersky, M., Olukotun, K. Building-blocks for performance oriented dsls. In DSL (2011), 93--117.
[19]
Sheard, T., Benaissa, Z.E.A., Pasalic, E. Dsl implementation using staging and monads. In DSL (1999), 81--94.
[20]
Sheard, T., Jones, S.L.P. Template meta-programming for haskell. SIGPLAN Not. 37, 12 (2002), 60--75.
[21]
Swadi, K.N., Taha, W., Kiselyov, O., Pasalic, E. A monadic approach for avoiding code duplication when staging memoized functions. PEPM, J. Hatcliff and F. Tip, eds. (2006). ACM, 160--169.
[22]
Taha, W., Sheard, T. Metaml and multi-stage programming with explicit annotations. Theor, Comput, Sci. 248(1--2) (2000), 211--242.
[23]
Veldhuizen. T "Expression Templates," in Stanley B. Lippman (Editor), C++ Gems (SIGS Books and Multimedia, 1996), pp. 475--488
[24]
Veldhuizen, T.L. Active libraries and universal languages. PhD thesis, Indiana University Computer Science (May 2004).
[25]
Whaley, R.C., Petitet, A., Dongarra, J. Automated empirical optimizations of software and the atlas project. Parallel Comput. 27(1--2) (2001), 3--35.

Cited By

View all
  • (2024)HiPy: Extracting High-Level Semantics from Python Code for Data ProcessingProceedings of the ACM on Programming Languages10.1145/36897378:OOPSLA2(736-762)Online publication date: 8-Oct-2024
  • (2024)Restaging Domain-Specific Languages: A Flexible Design Pattern for Rapid Development of Optimizing CompilersProceedings of the 23rd ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences10.1145/3689484.3690739(80-93)Online publication date: 21-Oct-2024
  • (2024)Closure-Free Functional Programming in a Two-Level Type TheoryProceedings of the ACM on Programming Languages10.1145/36746488:ICFP(659-692)Online publication date: 15-Aug-2024
  • Show More Cited By

Index Terms

  1. Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs

      Recommendations

      Comments

      Please enable JavaScript to view thecomments powered by Disqus.

      Information & Contributors

      Information

      Published In

      cover image Communications of the ACM
      Communications of the ACM  Volume 55, Issue 6
      June 2012
      124 pages
      ISSN:0001-0782
      EISSN:1557-7317
      DOI:10.1145/2184319
      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]

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      Published: 01 June 2012
      Published in CACM Volume 55, Issue 6

      Permissions

      Request permissions for this article.

      Check for updates

      Qualifiers

      • Research-article
      • Popular
      • Refereed

      Contributors

      Other Metrics

      Bibliometrics & Citations

      Bibliometrics

      Article Metrics

      • Downloads (Last 12 months)491
      • Downloads (Last 6 weeks)104
      Reflects downloads up to 21 Dec 2024

      Other Metrics

      Citations

      Cited By

      View all
      • (2024)HiPy: Extracting High-Level Semantics from Python Code for Data ProcessingProceedings of the ACM on Programming Languages10.1145/36897378:OOPSLA2(736-762)Online publication date: 8-Oct-2024
      • (2024)Restaging Domain-Specific Languages: A Flexible Design Pattern for Rapid Development of Optimizing CompilersProceedings of the 23rd ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences10.1145/3689484.3690739(80-93)Online publication date: 21-Oct-2024
      • (2024)Closure-Free Functional Programming in a Two-Level Type TheoryProceedings of the ACM on Programming Languages10.1145/36746488:ICFP(659-692)Online publication date: 15-Aug-2024
      • (2024)Generating CScience of Computer Programming10.1016/j.scico.2023.103015231:COnline publication date: 1-Jan-2024
      • (2024)Rhyme: A Data-Centric Expressive Query Language for Nested Data StructuresPractical Aspects of Declarative Languages10.1007/978-3-031-52038-9_5(64-81)Online publication date: 15-Jan-2024
      • (2023)Mat2Stencil: A Modular Matrix-Based DSL for Explicit and Implicit Matrix-Free PDE Solvers on Structured GridProceedings of the ACM on Programming Languages10.1145/36228227:OOPSLA2(686-715)Online publication date: 16-Oct-2023
      • (2023)Low-Code Programming ModelsCommunications of the ACM10.1145/358769166:10(76-85)Online publication date: 22-Sep-2023
      • (2022)Generating Fast Specialized Simulators for Stochastic Reaction Networks via Partial EvaluationACM Transactions on Modeling and Computer Simulation10.1145/348546532:2(1-25)Online publication date: 4-Mar-2022
      • (2022)Creating a Language for Writing Real-Time Applications for the Internet of Things2022 20th ACM-IEEE International Conference on Formal Methods and Models for System Design (MEMOCODE)10.1109/MEMOCODE57689.2022.9954383(1-20)Online publication date: 13-Oct-2022
      • (2022)Generating CFunctional and Logic Programming10.1007/978-3-030-99461-7_5(75-93)Online publication date: 10-May-2022
      • Show More Cited By

      View Options

      View options

      PDF

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader

      Digital Edition

      View this article in digital edition.

      Digital Edition

      Magazine Site

      View this article on the magazine site (external)

      Magazine Site

      Login options

      Full Access

      Media

      Figures

      Other

      Tables

      Share

      Share

      Share this Publication link

      Share on social media