Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
research-article
Open access

A Verified Compiler for a Functional Tensor Language

Published: 20 June 2024 Publication History

Abstract

Producing efficient array code is crucial in high-performance domains like image processing and machine learning. It requires the ability to control factors like compute intensity and locality by reordering computations into different stages and granularities with respect to where they are stored. However, traditional pure, functional tensor languages struggle to do so. In a previous publication, we introduced ATL as a pure, functional tensor language capable of systematically decoupling compute and storage order via a set of high-level combinators known as reshape operators. Reshape operators are a unique functional-programming construct since they manipulate storage location in the generated code by modifying the indices that appear on the left-hand sides of storage expressions. We present a formal correctness proof for an implementation of the compilation algorithm, marking the first verification of a lowering algorithm targeting imperative loop nests from a source functional language that enables separate control of compute and storage ordering. One of the core difficulties of this proof required properly formulating the complex invariants to ensure that these storage-index remappings were well-formed. Notably, this exercise revealed a soundness bug in the original published compilation algorithm regarding the truncation reshape operators. Our fix is a new type system that captures safety conditions that were previously implicit and enables us to prove compiler correctness for well-typed source programs. We evaluate this type system and compiler implementation on a range of common programs and optimizations, including but not limited to those previously studied to demonstrate performance comparable to established compilers like Halide.

Supplementary Material

Auxiliary Archive (pldi24main-p55-p-archive.zip)
Appendix supplement to conference paper

References

[1]
Oskar Abrahamsson, Son Ho, Hrutvik Kanabar, Ramana Kumar, Magnus O. Myreen, Michael Norrish, and Yong Kiam Tan. 2020. Proof-Producing Synthesis of CakeML from Monadic HOL Functions. J. Autom. Reason., 64, 7 (2020), oct, 1287–1306. issn:0168-7433 https://doi.org/10.1007/s10817-020-09559-8
[2]
Tianqi Chen, Thierry Moreau, Ziheng Jiang, Lianmin Zheng, Eddie Yan, Meghan Cowan, Haichen Shen, Leyuan Wang, Yuwei Hu, Luis Ceze, Carlos Guestrin, and Arvind Krishnamurthy. 2018. TVM: An Automated End-to-end Optimizing Compiler for Deep Learning. In Proceedings of the 12th USENIX Conference on Operating Systems Design and Implementation (OSDI’18). USENIX Association, Berkeley, CA, USA. 579–594. isbn:978-1-931971-47-8 http://dl.acm.org/citation.cfm?id=3291168.3291211
[3]
Basile Clément and Albert Cohen. 2022. End-to-End Translation Validation for the Halide Language. Proc. ACM Program. Lang., 6, OOPSLA1 (2022), Article 84, apr, 30 pages. https://doi.org/10.1145/3527328
[4]
Nathanaël Courant and Xavier Leroy. 2021. Verified Code Generation for the Polyhedral Model. Proc. ACM Program. Lang., 5, POPL (2021), Article 40, jan, 24 pages. https://doi.org/10.1145/3434321
[5]
Benjamin Delaware, Clément Pit-Claudel, Jason Gross, and Adam Chlipala. 2015. Fiat: Deductive Synthesis of Abstract Data Types in a Proof Assistant. In Proceedings of the 42nd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’15). Association for Computing Machinery, New York, NY, USA. 689–700. isbn:9781450333009 https://doi.org/10.1145/2676726.2677006
[6]
Andres Erbsen, Jade Philipoom, Jason Gross, Robert Sloan, and Adam Chlipala. 2019. Simple High-Level Code for Cryptographic Arithmetic - With Proofs, Without Compromises. 2019 IEEE Symposium on Security and Privacy (SP), 54, 1 (2019), May, 1202–1219. https://doi.org/10.1109/sp.2019.00005
[7]
Scott Kovach, Praneeth Kolichala, Tiancheng Gu, and Fredrik Kjolstad. 2023. Indexed Streams: A Formal Intermediate Representation for Fused Contraction Programs. Proc. ACM Program. Lang., 7, PLDI (2023), Article 154, jun, 25 pages. https://doi.org/10.1145/3591268
[8]
Ramana Kumar, Magnus O. Myreen, Michael Norrish, and Scott Owens. 2014. CakeML: A Verified Implementation of ML. In Proceedings of the 41st ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’14). Association for Computing Machinery, New York, NY, USA. 179–191. isbn:9781450325448 https://ts.data61.csiro.au/publications/nicta_full_text/7494.pdf 10.1145/2535838.2535841
[9]
Peter Lammich. 2013. Automatic Data Refinement. In Interactive Theorem Proving - 4th International Conference, ITP 2013, Rennes, France, July 22-26, 2013. Proceedings, Sandrine Blazy, Christine Paulin-Mohring, and David Pichardie (Eds.) (Lecture Notes in Computer Science, Vol. 7998). Springer, Berlin, Heidelberg. 84–99. https://doi.org/10.1007/978-3-642-39634-2_9
[10]
Peter Lammich. 2019. Refinement to Imperative HOL. J. Autom. Reason., 62, 4 (2019), apr, 481–503. issn:0168-7433 https://doi.org/10.1007/s10817-017-9437-1
[11]
Xavier Leroy. 2009. A Formally Verified Compiler Back-End. Journal of Automated Reasoning, 43, 4 (2009), Dec., 363–446. issn:0168-7433, 1573-0670 https://doi.org/10.1007/s10817-009-9155-4
[12]
Zhitao Lin and Christophe Dubach. 2022. From Functional to Imperative: Combining Destination-Passing Style and Views. In Proceedings of the 8th ACM SIGPLAN International Workshop on Libraries, Languages and Compilers for Array Programming (ARRAY 2022). Association for Computing Machinery, New York, NY, USA. 25–36. isbn:9781450392693 https://doi.org/10.1145/3520306.3534502
[13]
Amanda Liu. 2024. Verified Lowering Artifact. https://doi.org/10.5281/zenodo.10932109
[14]
Amanda Liu, Gilbert Louis Bernstein, Adam Chlipala, and Jonathan Ragan-Kelley. 2022. Verified Tensor-Program Optimization via High-Level Scheduling Rewrites. Proc. ACM Program. Lang., 6, POPL (2022), Article 55, jan, 28 pages. https://doi.org/10.1145/3498717
[15]
Philip Munksgaard, Cosmin Oancea, and Troels Henriksen. 2023. Compiling a Functional Array Language with Non-Semantic Memory Information. In Proceedings of the 34th Symposium on Implementation and Application of Functional Languages (IFL ’22). Association for Computing Machinery, New York, NY, USA. Article 2, 13 pages. isbn:9781450398312 https://doi.org/10.1145/3587216.3587218
[16]
Magnus O. Myreen and Scott Owens. 2012. Proof-producing synthesis of ML from higher-order logic. In International Conference on Functional Programming (ICFP), Peter Thiemann and Robby Bruce Findler (Eds.). ACM, New York, NY, USA. 115–126.
[17]
Zoe Paraskevopoulou, John M. Li, and Andrew W. Appel. 2021. Compositional Optimizations for CertiCoq. Proc. ACM Program. Lang., 5, ICFP (2021), Article 86, aug, 30 pages. https://doi.org/10.1145/3473591
[18]
Clément Pit-Claudel, Jade Philipoom, Dustin Jamner, Andres Erbsen, and Adam Chlipala. 2022. Relational Compilation for Performance-Critical Applications: Extensible Proof-Producing Translation of Functional Models into Low-Level Code. In Proceedings of the 43rd ACM SIGPLAN International Conference on Programming Language Design and Implementation (PLDI 2022). Association for Computing Machinery, New York, NY, USA. 918–933. isbn:9781450392655 https://doi.org/10.1145/3519939.3523706
[19]
Clément Pit-Claudel, Peng Wang, Benjamin Delaware, Jason Gross, and Adam Chlipala. 2020. Extensible Extraction of Efficient Imperative Programs with Foreign Functions, Manually Managed Memory, and Proofs. In IJCAR’20: Proceedings of the 9th International Joint Conference on Automated Reasoning. Springer, Paris, France. 119–137. https://doi.org/10.1007/978-3-030-51054-1_7
[20]
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. SIGPLAN Not., 48, 6 (2013), jun, 519–530. issn:0362-1340 https://doi.org/10.1145/2499370.2462176
[21]
Amir Shaikhha, Andrew Fitzgibbon, Simon Peyton Jones, and Dimitrios Vytiniotis. 2017. Destination-Passing Style for Efficient Memory Management. In Proceedings of the 6th ACM SIGPLAN International Workshop on Functional High-Performance Computing (FHPC 2017). Association for Computing Machinery, New York, NY, USA. 12–23. isbn:9781450351812 https://doi.org/10.1145/3122948.3122949

Recommendations

Comments

Information & Contributors

Information

Published In

cover image Proceedings of the ACM on Programming Languages
Proceedings of the ACM on Programming Languages  Volume 8, Issue PLDI
June 2024
2198 pages
EISSN:2475-1421
DOI:10.1145/3554317
Issue’s Table of Contents
This work is licensed under a Creative Commons Attribution International 4.0 License.

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 20 June 2024
Published in PACMPL Volume 8, Issue PLDI

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. array programming
  2. formal verification
  3. functional programming
  4. tensors
  5. type systems

Qualifiers

  • Research-article

Funding Sources

  • NSF (National Science Foundation)

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 559
    Total Downloads
  • Downloads (Last 12 months)559
  • Downloads (Last 6 weeks)156
Reflects downloads up to 10 Oct 2024

Other Metrics

Citations

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Get Access

Login options

Full Access

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media