Compiling with Arrays

Authors David Richter , Timon Böhler , Pascal Weisenburger , Mira Mezini



PDF
Thumbnail PDF

File

LIPIcs.ECOOP.2024.33.pdf
  • Filesize: 1 MB
  • 24 pages

Document Identifiers

Author Details

David Richter
  • Technische Universität Darmstadt, Germany
Timon Böhler
  • Technische Universität Darmstadt, Germany
Pascal Weisenburger
  • University of St. Gallen, Switzerland
Mira Mezini
  • Technische Universität Darmstadt, Germany
  • The Hessian Center for Artificial Intelligence (hessian.AI), Darmstadt, Germany

Cite AsGet BibTex

David Richter, Timon Böhler, Pascal Weisenburger, and Mira Mezini. Compiling with Arrays. In 38th European Conference on Object-Oriented Programming (ECOOP 2024). Leibniz International Proceedings in Informatics (LIPIcs), Volume 313, pp. 33:1-33:24, Schloss Dagstuhl – Leibniz-Zentrum für Informatik (2024)
https://doi.org/10.4230/LIPIcs.ECOOP.2024.33

Abstract

Linear algebra computations are foundational for neural networks and machine learning, often handled through arrays. While many functional programming languages feature lists and recursion, arrays in linear algebra demand constant-time access and bulk operations. To bridge this gap, some languages represent arrays as (eager) functions instead of lists. In this paper, we connect this idea to a formal logical foundation by interpreting functions as the usual negative types from polarized type theory, and arrays as the corresponding dual positive version of the function type. Positive types are defined to have a single elimination form whose computational interpretation is pattern matching. Just like (positive) product types bind two variables during pattern matching, (positive) array types bind variables with multiplicity during pattern matching. We follow a similar approach for Booleans by introducing conditionally-defined variables. The positive formulation for the array type enables us to combine typed partial evaluation and common subexpression elimination into an elegant algorithm whose result enjoys a property we call maximal fission, which we argue can be beneficial for further optimizations. For this purpose, we present the novel intermediate representation indexed administrative normal form (A_{i}NF), which relies on the formal logical foundation of the positive formulation for the array type to facilitate maximal loop fission and subsequent optimizations. A_{i}NF is normal with regard to commuting conversion for both let-bindings and for-loops, leading to flat and maximally fissioned terms. We mechanize the translation and normalization from a simple surface language to A_{i}NF, establishing that the process terminates, preserves types, and produces maximally fissioned terms.

Subject Classification

ACM Subject Classification
  • Software and its engineering → Domain specific languages
Keywords
  • array languages
  • functional programming
  • domain-specific languages
  • normalization by evaluation
  • common subexpression elimination
  • polarity
  • positive function type
  • intrinsic types

Metrics

  • Access Statistics
  • Total Accesses (updated on a weekly basis)
    0
    PDF Downloads

References

  1. Jean-Marc Andreoli. Logic programming with focusing proofs in linear logic. J. Log. Comput., 2(3):297-347, 1992. URL: https://doi.org/10.1093/LOGCOM/2.3.297.
  2. Andrew W. Appel. Compiling with Continuations. Cambridge University Press, 1992. Google Scholar
  3. Emil Axelsson, Koen Claessen, Gergely Dévai, Zoltán Horváth, Karin Keijzer, Bo Lyckegård, Anders Persson, Mary Sheeran, Josef Svenningsson, and András Vajda. Feldspar: A domain specific language for digital signal processing algorithms. In 8th ACM/IEEE International Conference on Formal Methods and Models for Codesign (MEMOCODE 2010), Grenoble, France, 26-28 July 2010, pages 169-178. IEEE Computer Society, 2010. URL: https://doi.org/10.1109/MEMCOD.2010.5558637.
  4. Timon Böhler, David Richter, and Mira Mezini. Using rewrite strategies for efficient functional automatic differentiation. In Aaron Tomb, editor, Proceedings of the 25th ACM International Workshop on Formal Techniques for Java-like Programs, FTfJP 2023, Seattle, WA, USA, 18 July 2023, pages 51-57. ACM, 2023. URL: https://doi.org/10.1145/3605156.3606456.
  5. Adam Chlipala. Parametric higher-order abstract syntax for mechanized semantics. In James Hook and Peter Thiemann, editors, Proceeding of the 13th ACM SIGPLAN international conference on Functional programming, ICFP 2008, Victoria, BC, Canada, September 20-28, 2008, pages 143-156. ACM, 2008. URL: https://doi.org/10.1145/1411204.1411226.
  6. Youyou Cong, Leo Osvald, Grégory M. Essertel, and Tiark Rompf. Compiling with continuations, or without? whatever. Proceedings of the ACM on Programming Languages, 3(ICFP):79:1-79:28, 2019. URL: https://doi.org/10.1145/3341643.
  7. Leonardo de Moura and Sebastian Ullrich. The Lean 4 theorem prover and programming language. In André Platzer and Geoff Sutcliffe, editors, Automated Deduction - CADE 28 - 28th International Conference on Automated Deduction, Virtual Event, July 12-15, 2021, Proceedings, volume 12699 of Lecture Notes in Computer Science, pages 625-635. Springer, 2021. URL: https://doi.org/10.1007/978-3-030-79876-5_37.
  8. Paul Downen and Zena M. Ariola. The duality of construction. In Zhong Shao, editor, Programming Languages and Systems - 23rd European Symposium on Programming, ESOP 2014, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2014, Grenoble, France, April 5-13, 2014, Proceedings, volume 8410 of Lecture Notes in Computer Science, pages 249-269. Springer, 2014. URL: https://doi.org/10.1007/978-3-642-54833-8_14.
  9. Paul Downen and Zena M. Ariola. Compiling with classical connectives. Log. Methods Comput. Sci., 16(3), 2020. URL: https://lmcs.episciences.org/6740.
  10. Paul Downen and Zena M. Ariola. Duality in action (invited talk). In Naoki Kobayashi, editor, 6th International Conference on Formal Structures for Computation and Deduction, FSCD 2021, July 17-24, 2021, Buenos Aires, Argentina (Virtual Conference), volume 195 of LIPIcs, pages 1:1-1:32. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2021. URL: https://doi.org/10.4230/LIPICS.FSCD.2021.1.
  11. Cormac Flanagan, Amr Sabry, Bruce F. Duba, and Matthias Felleisen. The essence of compiling with continuations. In Robert Cartwright, editor, Proceedings of the ACM SIGPLAN'93 Conference on Programming Language Design and Implementation (PLDI), Albuquerque, New Mexico, USA, June 23-25, 1993, pages 237-247. ACM, 1993. URL: https://doi.org/10.1145/155090.155113.
  12. Jeremy Gibbons. APLicative programming with Naperian functors. In Hongseok Yang, editor, Programming Languages and Systems - 26th European Symposium on Programming, ESOP 2017, Held as Part of the European Joint Conferences on Theory and Practice of Software, ETAPS 2017, Uppsala, Sweden, April 22-29, 2017, Proceedings, volume 10201 of Lecture Notes in Computer Science, pages 556-583. Springer, 2017. URL: https://doi.org/10.1007/978-3-662-54434-1_21.
  13. Bastian Hagedorn, Johannes Lenfers, Thomas Koehler, Xueying Qin, Sergei Gorlatch, and Michel Steuwer. Achieving high performance the functional way: Expressing high-performance optimizations as rewrite strategies. Commun. ACM, 66(3):89-97, 2023. URL: https://doi.org/10.1145/3580371.
  14. Charles R. Harris, K. Jarrod Millman, Stéfan van der Walt, Ralf Gommers, Pauli Virtanen, David Cournapeau, Eric Wieser, Julian Taylor, Sebastian Berg, Nathaniel J. Smith, Robert Kern, Matti Picus, Stephan Hoyer, Marten H. van Kerkwijk, Matthew Brett, Allan Haldane, Jaime Fernández del Río, Mark Wiebe, Pearu Peterson, Pierre Gérard-Marchant, Kevin Sheppard, Tyler Reddy, Warren Weckesser, Hameer Abbasi, Christoph Gohlke, and Travis E. Oliphant. Array programming with NumPy. Nat., 585:357-362, 2020. URL: https://doi.org/10.1038/S41586-020-2649-2.
  15. Troels Henriksen, Niels G. W. Serup, Martin Elsman, Fritz Henglein, and Cosmin E. Oancea. Futhark: purely functional GPU-programming with nested parallelism and in-place array updates. In Albert Cohen and Martin T. Vechev, editors, Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2017, Barcelona, Spain, June 18-23, 2017, pages 556-571. ACM, 2017. URL: https://doi.org/10.1145/3062341.3062354.
  16. John Hughes. Generalising monads to arrows. Science of Computer Programming, 37(1-3):67-111, 2000. URL: https://doi.org/10.1016/S0167-6423(99)00023-4.
  17. Neil D. Jones, Carsten K. Gomard, and Peter Sestoft. Partial evaluation and automatic program generation. Prentice Hall international series in computer science. Prentice Hall, 1993. Google Scholar
  18. Andrew Kennedy. Compiling with continuations, continued. In Ralf Hinze and Norman Ramsey, editors, Proceedings of the 12th ACM SIGPLAN International Conference on Functional Programming, ICFP 2007, Freiburg, Germany, October 1-3, 2007, pages 177-190. ACM, 2007. URL: https://doi.org/10.1145/1291151.1291179.
  19. Neelakantan R. Krishnaswami. Focusing on pattern matching. In Zhong Shao and Benjamin C. Pierce, editors, Proceedings of the 36th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages, POPL 2009, Savannah, GA, USA, January 21-23, 2009, pages 366-378. ACM, 2009. URL: https://doi.org/10.1145/1480881.1480927.
  20. Amanda Liu, Gilbert Louis Bernstein, Adam Chlipala, and Jonathan Ragan-Kelley. Verified tensor-program optimization via high-level scheduling rewrites. Proc. ACM Program. Lang., 6(POPL):1-28, 2022. URL: https://doi.org/10.1145/3498717.
  21. Simon Marlow, Simon Peyton Jones, Edward Kmett, and Andrey Mokhov. Desugaring Haskell’s do-notation into applicative operations. In Geoffrey Mainland, editor, Proceedings of the 9th International Symposium on Haskell, Haskell 2016, Nara, Japan, September 22-23, 2016, pages 92-104. ACM, 2016. URL: https://doi.org/10.1145/2976002.2976007.
  22. Luke Maurer, Paul Downen, Zena M. Ariola, and Simon L. Peyton Jones. Compiling without continuations. In Albert Cohen and Martin T. Vechev, editors, Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation, PLDI 2017, Barcelona, Spain, June 18-23, 2017, pages 482-494. ACM, 2017. URL: https://doi.org/10.1145/3062341.3062380.
  23. Dale Miller and Jui-Hsuan Wu. A positive perspective on term representation (invited talk). In Bartek Klin and Elaine Pimentel, editors, 31st EACSL Annual Conference on Computer Science Logic, CSL 2023, February 13-16, 2023, Warsaw, Poland, volume 252 of LIPIcs, pages 3:1-3:21. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2023. URL: https://doi.org/10.4230/LIPICS.CSL.2023.3.
  24. Eugenio Moggi. Computational lambda-calculus and monads. In Proceedings of the Fourth Annual Symposium on Logic in Computer Science (LICS '89), Pacific Grove, California, USA, June 5-8, 1989, pages 14-23. IEEE Computer Society, 1989. URL: https://doi.org/10.1109/LICS.1989.39155.
  25. Aleksandar Nanevski, Frank Pfenning, and Brigitte Pientka. Contextual modal type theory. ACM Trans. Comput. Log., 9(3):23:1-23:49, 2008. URL: https://doi.org/10.1145/1352582.1352591.
  26. nLab authors. function type. https://ncatlab.org/nlab/show/function+type, January 2024. URL: https://ncatlab.org/nlab/revision/function+type/33.
  27. Dominic A. Orchard and Alan Mycroft. A notation for comonads. In Ralf Hinze, editor, Implementation and Application of Functional Languages - 24th International Symposium, IFL 2012, Oxford, UK, August 30 - September 1, 2012, Revised Selected Papers, volume 8241 of Lecture Notes in Computer Science, pages 1-17. Springer, 2012. URL: https://doi.org/10.1007/978-3-642-41582-1_1.
  28. Adam Paszke, Daniel D. Johnson, David Duvenaud, Dimitrios Vytiniotis, Alexey Radul, Matthew J. Johnson, Jonathan Ragan-Kelley, and Dougal Maclaurin. Getting to the point: index sets and parallelism-preserving autodiff for pointful array programming. Proc. ACM Program. Lang., 5(ICFP):1-29, 2021. URL: https://doi.org/10.1145/3473593.
  29. Frank Pfenning and Conal Elliott. Higher-order abstract syntax. In Richard L. Wexelblat, editor, Proceedings of the ACM SIGPLAN'88 Conference on Programming Language Design and Implementation (PLDI), Atlanta, Georgia, USA, June 22-24, 1988, pages 199-208. ACM, 1988. URL: https://doi.org/10.1145/53990.54010.
  30. Gordon D. Plotkin. Call-by-name, call-by-value and the lambda-calculus. Theor. Comput. Sci., 1(2):125-159, 1975. URL: https://doi.org/10.1016/0304-3975(75)90017-1.
  31. Jonathan Ragan-Kelley, Andrew Adams, Dillon Sharlet, Connelly Barnes, Sylvain Paris, Marc Levoy, Saman P. Amarasinghe, and Frédo Durand. Halide: decoupling algorithms from schedules for high-performance image processing. Commun. ACM, 61(1):106-115, 2018. URL: https://doi.org/10.1145/3150211.
  32. David Richter, Timon Böhler, Pascal Weisenburger, and Mira Mezini. stg-tud/ainf-compiling-with-arrays. Software, swhId: https://archive.softwareheritage.org/swh:1:dir:8e0e755d11e4e3e91fb05bf8df1a5c8bec0f553a;origin=https://github.com/stg-tud/ainf-compiling-with-arrays;visit=swh:1:snp:e92b86a1a72b7e96bb4c6207f6d6a157de14195f;anchor=swh:1:rev:a8a88bca53396f58df5ae5d1da0755f1b02b01b8 (visited on 2024-09-02). URL: https://github.com/stg-tud/ainf-compiling-with-arrays.
  33. David Richter, Timon Böhler, Pascal Weisenburger, and Mira Mezini. A direct-style effect notation for sequential and parallel programs. In Karim Ali and Guido Salvaneschi, editors, 37th European Conference on Object-Oriented Programming, ECOOP 2023, July 17-21, 2023, Seattle, Washington, United States, volume 263 of LIPIcs, pages 25:1-25:22. Schloss Dagstuhl - Leibniz-Zentrum für Informatik, 2023. URL: https://doi.org/10.4230/LIPICS.ECOOP.2023.25.
  34. Amr Sabry and Matthias Felleisen. Reasoning about programs in continuation-passing style. LISP Symb. Comput., 6(3-4):289-360, 1993. Google Scholar
  35. Sven-Bodo Scholz. Single Assignment C: efficient support for high-level array operations in a functional setting. J. Funct. Program., 13(6):1005-1059, 2003. URL: https://doi.org/10.1017/S0956796802004458.
  36. Sven-Bodo Scholz and Artjoms Sinkarovs. Tensor comprehensions in SaC. In Jurriën Stutterheim and Wei-Ngan Chin, editors, IFL '19: Implementation and Application of Functional Languages, Singapore, September 25-27, 2019, pages 15:1-15:13. ACM, 2019. URL: https://doi.org/10.1145/3412932.3412947.
  37. Amir Shaikhha, Andrew W. Fitzgibbon, Dimitrios Vytiniotis, and Simon Peyton Jones. Efficient differentiable programming in a functional array-processing language. Proc. ACM Program. Lang., 3(ICFP):97:1-97:30, 2019. URL: https://doi.org/10.1145/3341701.
  38. Guy L. Steele. Rabbit: A compiler for Scheme. Technical report, Massachusetts Institute of Technology, USA, 1978. Google Scholar
  39. Noam Zeilberger. On the unity of duality. Ann. Pure Appl. Log., 153(1-3):66-96, 2008. URL: https://doi.org/10.1016/J.APAL.2008.01.001.
  40. Noam Zeilberger. The logical basis of evaluation order and pattern-matching. PhD thesis, Carnegie Mellon University, USA, 2009. AAI3358066. Google Scholar
Questions / Remarks / Feedback
X

Feedback for Dagstuhl Publishing


Thanks for your feedback!

Feedback submitted

Could not send message

Please try again later or send an E-mail