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

Parallelism in a Region Inference Context

Published: 06 June 2023 Publication History

Abstract

Region inference is a type-based program analysis that takes a non-annotated program as input and constructs a program that explicitly manages memory allocation and deallocation by dividing the heap into a stack of regions, each of which can grow and shrink independently from other regions, using constant-time operations.
Whereas region-based memory management has shown useful in the contexts of explicit region-based memory management, and in particular, in combination with parallel execution of code, combining region inference with techniques for higher-order parallel programming has not been investigated.
In this paper, we present an implementation of a fork-join parallel construct suitable for a compiler based on region inference. We present a minimal higher-order language incorporating the parallel construct, including typing rules and a dynamic semantics for the language, and demonstrate type soundness. We present a novel effect-based region-protection inference algorithm and discuss benefits and shortcomings of the approach. We also describe an efficient implementation embedded in the MLKit Standard ML compiler. Finally, we evaluate the approach and the implementation based on a number of parallel benchmarks, and thereby demonstrate that the technique effectively utilises multi-core architectures in a higher-order functional setting.

Supplementary Material

Auxiliary Archive (pldi23main-p209-p-archive.zip)
Appendix with proofs.

References

[1]
Alexander Aiken, Manuel Fähndrich, and Raph Levien. 1995. Better Static Memory Management: Improving Region-Based Analysis of Higher-Order Languages. In Proceedings of the ACM SIGPLAN 1995 Conference on Programming Language Design and Implementation (PLDI ’95). Association for Computing Machinery, New York, NY, USA. 174–185. isbn:0897916972 https://doi.org/10.1145/207110.207137
[2]
Jonathan Aldrich, Valentin Kostadinov, and Craig Chambers. 2002. Alias Annotations for Program Understanding. In Proceedings of the 17th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA ’02). Association for Computing Machinery, New York, NY, USA. 311–330. isbn:1581134711 https://doi.org/10.1145/582419.582448
[3]
Joe Armstrong. 2003. Making Reliable Distributed Systems in the Presence of Software Errors. Ph. D. Dissertation. The Royal Institute of Technology, Stockholm, Sweden.
[4]
Jatin Arora, Sam Westrick, and Umut A. Acar. 2021. Provably Space-Efficient Parallel Functional Programming. Proc. ACM Program. Lang., 5, POPL (2021), Article 18, jan, 33 pages. https://doi.org/10.1145/3434299
[5]
Lars Birkedal, Mads Tofte, and Magnus Vejlstrup. 1996. From Region Inference to von Neumann Machines via Region Representation Inference. In Proceedings of the 23rd ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL ’96). Association for Computing Machinery, New York, NY, USA. 171–183. isbn:0897917693 https://doi.org/10.1145/237721.237771
[6]
Fischer Black and Myron Scholes. 1973. The Pricing of Options and Corporate Liabilities. Journal of Political Economy, 81, 3 (1973), 637–654. issn:00223808, 1537534X http://www.jstor.org/stable/1831029
[7]
Chandrasekhar Boyapati, Alexandru Salcianu, William Beebee, and Martin Rinard. 2003. Ownership Types for Safe Region-Based Memory Management in Real-Time Java. In Proceedings of the ACM SIGPLAN 2003 Conference on Programming Language Design and Implementation (PLDI ’03). Association for Computing Machinery, New York, NY, USA. 324–337. isbn:1581136625 https://doi.org/10.1145/781131.781168
[8]
Paul Bratley and Bennett L. Fox. 1988. Algorithm 659: Implementing Sobol’s Quasirandom Sequence Generator. ACM Trans. Math. Softw., 14, 1 (1988), mar, 88–100. issn:0098-3500 https://doi.org/10.1145/42288.214372
[9]
Manuel M.T. Chakravarty, Gabriele Keller, Sean Lee, Trevor L. McDonell, and Vinod Grover. 2011. Accelerating Haskell Array Codes with Multicore GPUs. In Proceedings of the Sixth Workshop on Declarative Aspects of Multicore Programming (DAMP ’11). Association for Computing Machinery, New York, NY, USA. 3–14. isbn:9781450304863 https://doi.org/10.1145/1926354.1926358
[10]
E. Cooper and G. Morrisett. 1990. Adding Threads to Standard ML. Carnegie Mellon University, Department of Computer Science. Technical report
[11]
Matthew Davis, Peter Schachte, Zoltan Somogyi, and Harald Søndergaard. 2013. A Low Overhead Method for Recovering Unused Memory inside Regions. In Proceedings of the ACM SIGPLAN Workshop on Memory Systems Performance and Correctness (MSPC ’13). Association for Computing Machinery, New York, NY, USA. Article 4, 10 pages. isbn:9781450321037 https://doi.org/10.1145/2492408.2492415
[12]
Matthew Davis, Peter Schachte, Zoltan Somogyi, and Harald Søndergaard. 2012. Towards region-based memory management for Go. In Proceedings of the 2012 ACM SIGPLAN Workshop on Memory Systems Performance and Correctness. 58–67. isbn:9781450312196 https://doi.org/10.1145/2247684.2247695
[13]
Martin Elsman. 2003. Garbage Collection Safety for Region-Based Memory Management. In Proceedings of the 2003 ACM SIGPLAN International Workshop on Types in Languages Design and Implementation (TLDI ’03). Association for Computing Machinery, New York, NY, USA. 123–134. isbn:1581136498 https://doi.org/10.1145/604174.604190
[14]
Martin Elsman. 2008. A Framework for Cut-Off Incremental Recompilation and Inter-Module Optimization. IT University of Copenhagen, Rued Langgaards Vej 7, DK-2300 Copenhagen S, Denmark.
[15]
Martin Elsman. 2023. Garbage-Collection Safety for Region-Based Type-Polymorphic Programs. In Proceedings of the 44th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2023). Association for Computing Machinery, New York, NY, USA. https://doi.org/10.1145/3591229
[16]
Martin Elsman and Niels Hallenberg. 1995. An Optimizing Backend for the ML Kit Using a Stack of Regions. Student Project 95-7-8, University of Copenhagen (DIKU).
[17]
Martin Elsman and Niels Hallenberg. 2003. Web Programming with SMLserver. In International Symposium on Practical Aspects of Declarative Languages (PADL’03). Springer-Verlag, 74–91. https://doi.org/10.1007/3-540-36388-2_7
[18]
Martin Elsman and Niels Hallenberg. 2021. Integrating region memory management and tag-free generational garbage collection. Journal of Functional Programming, 31 (2021), e4. https://doi.org/10.1017/S0956796821000010
[19]
Martin Elsman and Troels Henriksen. 2023. Artifact for the PLDI 2023 paper: Parallelism in a Region Inference Context. Zenodo. https://doi.org/10.5281/zenodo.7810545
[20]
Martin Elsman and Ken Friis Larsen. 2004. Typing XHTML Web Applications in ML. In International Symposium on Practical Aspects of Declarative Languages (PADL’04). Springer-Verlag. https://doi.org/10.1007/978-3-540-24836-1_16
[21]
Martin Elsman, Philip Munksgaard, and Ken Friis Larsen. 2018. Experience Report: Type-Safe Multi-Tier Programming with Standard ML Modules. In Proceedings of the ML Family Workshop (ML ’18).
[22]
Kavon Farvardin and John Reppy. 2020. From Folklore to Fact: Comparing Implementations of Stacks and Continuations. In Proceedings of the 41st ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2020). Association for Computing Machinery, New York, NY, USA. 75–90. isbn:9781450376136 https://doi.org/10.1145/3385412.3385994
[23]
Matthew Fluet, Mike Rainey, John Reppy, and Adam Shaw. 2008. Implicitly-Threaded Parallelism in Manticore. In Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming (ICFP ’08). Association for Computing Machinery, New York, NY, USA. 119–130. isbn:9781595939197 https://doi.org/10.1145/1411204.1411224
[24]
David Gay and Alex Aiken. 2001. Language Support for Regions. In Proceedings of the ACM SIGPLAN 2001 Conference on Programming Language Design and Implementation (PLDI ’01). Association for Computing Machinery, New York, NY, USA. 70–80. isbn:1581134142 https://doi.org/10.1145/378795.378815
[25]
Prodromos Gerakios, Nikolaos Papaspyrou, and Konstantinos Sagonas. 2010. Race-Free and Memory-Safe Multithreading: Design and Implementation in Cyclone. In Proceedings of the 5th ACM SIGPLAN Workshop on Types in Language Design and Implementation (TLDI ’10). Association for Computing Machinery, New York, NY, USA. 15–26. isbn:9781605588919 https://doi.org/10.1145/1708016.1708020
[26]
Clemens Grelck and Sven-Bodo Scholz. 2007. SAC: Off-the-Shelf Support for Data-Parallelism on Multicores. In Proceedings of the 2007 Workshop on Declarative Aspects of Multicore Programming (DAMP ’07). Association for Computing Machinery, New York, NY, USA. 25–33. isbn:9781595936905 https://doi.org/10.1145/1248648.1248654
[27]
Dan Grossman, Greg Morrisett, Trevor Jim, Michael Hicks, Yanling Wang, and James Cheney. 2002. Region-Based Memory Management in Cyclone. In Proceedings of the ACM SIGPLAN 2002 Conference on Programming Language Design and Implementation (PLDI ’02). Association for Computing Machinery, New York, NY, USA. 282–293. isbn:1581134630 https://doi.org/10.1145/512529.512563
[28]
Niels Hallenberg, Martin Elsman, and Mads Tofte. 2002. Combining Region Inference and Garbage Collection. In Proceedings of the ACM SIGPLAN 2002 Conference on Programming Language Design and Implementation (PLDI ’02). Association for Computing Machinery, New York, NY, USA. 141–152. isbn:1581134630 https://doi.org/10.1145/512529.512547
[29]
Tim Harris, Simon Marlow, Simon Peyton-Jones, and Maurice Herlihy. 2005. Composable Memory Transactions. In Proceedings of the Tenth ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming (PPoPP ’05). Association for Computing Machinery, New York, NY, USA. 48–60. isbn:1595930809 https://doi.org/10.1145/1065944.1065952
[30]
Troels Henriksen, Niels G. W. Serup, Martin Elsman, Fritz Henglein, and Cosmin E. Oancea. 2017. Futhark: Purely Functional GPU-Programming with Nested Parallelism and in-Place Array Updates. In Proceedings of the 38th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI 2017). Association for Computing Machinery, New York, NY, USA. 556–571. isbn:9781450349888 https://doi.org/10.1145/3062341.3062354
[31]
Ralf Jung, Jacques-Henri Jourdan, Robbert Krebbers, and Derek Dreyer. 2017. RustBelt: Securing the Foundations of the Rust Programming Language. Proc. ACM Program. Lang., 2, POPL (2017), Article 66, dec, 34 pages. https://doi.org/10.1145/3158154
[32]
Muyuan Li, Daniel E. McArdle, Jeffrey C. Murphy, Bhargav Shivkumar, and Lukasz Ziarek. 2016. Adding Real-Time Capabilities to a SML Compiler. SIGBED Rev., 13, 2 (2016), April, 8–13. https://doi.org/10.1145/2930957.2930958
[33]
Simon Marlow, Tim Harris, Roshan P. James, and Simon Peyton Jones. 2008. Parallel Generational-Copying Garbage Collection with a Block-Structured Heap. In Proceedings of the 7th International Symposium on Memory Management (ISMM ’08). Association for Computing Machinery, New York, NY, USA. 11–20. isbn:9781605581347 https://doi.org/10.1145/1375634.1375637
[34]
Simon Marlow, Ryan Newton, and Simon Peyton Jones. 2011. A Monad for Deterministic Parallelism. In Proceedings of the 4th ACM Symposium on Haskell (Haskell ’11). ACM, New York, NY, USA. 71–82. isbn:978-1-4503-0860-1 https://doi.org/10.1145/2034675.2034685
[35]
Greg Morrisett. 1995. Compiling with Types. Ph. D. Dissertation. School of Computer Science, Carnegie Mellon University, Pittsburgh, PA 15213.
[36]
Jun Nakashima and Kenjiro Taura. 2014. MassiveThreads: A Thread Library for High Productivity Languages. Springer Berlin Heidelberg, Berlin, Heidelberg. 222–238. isbn:978-3-662-44471-9 https://doi.org/10.1007/978-3-662-44471-9_10
[37]
M. H. A. Newman. 1942. On Theories with a Combinatorial Definition of "Equivalence". Annals of Mathematics, 43, 2 (1942), 223–243. issn:0003486X http://www.jstor.org/stable/1968867
[38]
Atsushi Ohori, Kenjiro Taura, and Katsuhiro Ueno. 2017. Making SML# a General-purpose High-performance Language. In Draft Proceedings of the ML family workshop (ML ’2017).
[39]
Ram Raghunathan, Stefan K. Muller, Umut A. Acar, and Guy Blelloch. 2016. Hierarchical Memory Management for Parallel Programs. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (ICFP 2016). Association for Computing Machinery, New York, NY, USA. 392–406. isbn:9781450342193 https://doi.org/10.1145/2951913.2951935
[40]
John Reppy, Claudio V. Russo, and Yingqi Xiao. 2009. Parallel Concurrent ML. In Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming (ICFP ’09). Association for Computing Machinery, New York, NY, USA. 257–268. isbn:9781605583327 https://doi.org/10.1145/1596550.1596588
[41]
Guillaume Salagnac, Chaker Nakhli, Christophe Rippert, and Sergio Yovine. 2006. Efficient Region-Based Memory Management for Resource-limited Real-Time Embedded Systems. In Workshop on Implementation, Compilation, Optimization of Object-Oriented Languages, Programs and Systems.
[42]
Sangmin Seo, Abdelhalim Amer, Pavan Balaji, Cyril Bordage, George Bosilca, Alex Brooks, Philip Carns, Adrián Castelló, Damien Genet, Thomas Herault, Shintaro Iwasaki, Prateek Jindal, Laxmikant V. Kalé, Sriram Krishnamoorthy, Jonathan Lifflander, Huiwei Lu, Esteban Meneses, Marc Snir, Yanhua Sun, Kenjiro Taura, and Pete Beckman. 2018. Argobots: A Lightweight Low-Level Threading and Tasking Framework. IEEE Transactions on Parallel and Distributed Systems, 29, 3 (2018), 512–526. https://doi.org/10.1109/TPDS.2017.2766062
[43]
Nir Shavit and Dan Touitou. 1995. Software Transactional Memory. In Proceedings of the Fourteenth Annual ACM Symposium on Principles of Distributed Computing (PODC ’95). Association for Computing Machinery, New York, NY, USA. 204–213. isbn:0897917103 https://doi.org/10.1145/224964.224987
[44]
KC Sivaramakrishnan, Stephen Dolan, Leo White, Sadiq Jaffer, Tom Kelly, Anmol Sahoo, Sudha Parimala, Atul Dhiman, and Anil Madhavapeddy. 2020. Retrofitting Parallelism onto OCaml. Proc. ACM Program. Lang., 4, ICFP (2020), Article 113, Aug., 30 pages. https://doi.org/10.1145/3408995
[45]
KC Sivaramakrishnan, Lukasz Ziarek, Raghavendra Prasad, and Suresh Jagannathan. 2010. Lightweight Asynchrony Using Parasitic Threads. In Proceedings of the 5th ACM SIGPLAN Workshop on Declarative Aspects of Multicore Programming (DAMP ’10). Association for Computing Machinery, New York, NY, USA. 63–72. isbn:9781605588599 https://doi.org/10.1145/1708046.1708059
[46]
K. C. Sivaramakrishnan, Lukasz Ziarek, and Suresh Jagannathan. 2014. MultiMLton: A multicore-aware runtime for Standard ML. Journal of Functional Programming, 24, 6 (2014), 613–674. https://doi.org/10.1017/S0956796814000161
[47]
Nikhil Swamy, Michael Hicks, Greg Morrisett, Dan Grossman, and Trevor Jim. 2006. Safe manual memory management in Cyclone. Science of Computer Programming, 62, 2 (2006), 122–144. issn:0167-6423 https://doi.org/10.1016/j.scico.2006.02.003 Special Issue: Five perspectives on modern memory management - Systems, hardware and theory
[48]
Mads Tofte and Lars Birkedal. 1998. A Region Inference Algorithm. ACM Trans. Program. Lang. Syst., 20, 4 (1998), jul, 724–767. issn:0164-0925 https://doi.org/10.1145/291891.291894
[49]
Mads Tofte and Lars Birkedal. 2000. Unification and Polymorphism in Region Inference. Proof, Language, and Interaction. Essays in Honour of Robin Milner, May, (25 pages)
[50]
Mads Tofte, Lars Birkedal, Martin Elsman, and Niels Hallenberg. 2004. A Retrospective on Region-Based Memory Management. Higher-Order and Symbolic Computation, 17, 3 (2004), 01 Sep, 245–265. https://doi.org/10.1023/B:LISP.0000029446.78563.a4
[51]
Mads Tofte, Lars Birkedal, Martin Elsman, Niels Hallenberg, Tommy Højfeld Olesen, and Peter Sestoft. 2022. Programming with Regions in the MLKit (Revised for Version 4.7.2). IT University of Copenhagen, Denmark.
[52]
Michael Vollmer, Ryan G. Scott, Madanlal Musuvathi, and Ryan R. Newton. 2017. SC-Haskell: Sequential Consistency in Languages That Minimize Mutable Shared Heap. In Proceedings of the 22nd ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming (PPoPP ’17). Association for Computing Machinery, New York, NY, USA. 283–298. isbn:9781450344937 https://doi.org/10.1145/3018743.3018746
[53]
Stephen Weeks. 2006. Whole-Program Compilation in MLton. In Proceedings of the 2006 Workshop on ML (ML ’06). Association for Computing Machinery, New York, NY, USA. 1. isbn:1595934839 https://doi.org/10.1145/1159876.1159877
[54]
Sam Westrick, Jatin Arora, and Umut A. Acar. 2022. Entanglement Detection with Near-Zero Cost. Proc. ACM Program. Lang., 6, ICFP (2022), Article 115, aug, 32 pages. https://doi.org/10.1145/3547646
[55]
Sam Westrick, Rohan Yadav, Matthew Fluet, and Umut A. Acar. 2019. Disentanglement in Nested-Parallel Programs. Proc. ACM Program. Lang., 4, POPL (2019), Article 47, Dec., 32 pages. https://doi.org/10.1145/3371115
[56]
A.K. Wright and M. Felleisen. 1994. A Syntactic Approach to Type Soundness. Inf. Comput., 115, 1 (1994), nov, 38–94. issn:0890-5401 https://doi.org/10.1006/inco.1994.1093

Cited By

View all
  • (2024)Associated Effects: Flexible Abstractions for Effectful ProgrammingProceedings of the ACM on Programming Languages10.1145/36563938:PLDI(394-416)Online publication date: 20-Jun-2024
  • (2024)Explicit Effects and Effect Constraints in ReMLProceedings of the ACM on Programming Languages10.1145/36329218:POPL(2370-2394)Online publication date: 5-Jan-2024

Recommendations

Comments

Information & Contributors

Information

Published In

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

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 06 June 2023
Published in PACMPL Volume 7, Issue PLDI

Permissions

Request permissions for this article.

Check for updates

Badges

Author Tags

  1. Memory Management
  2. Parallelism
  3. Region Inference

Qualifiers

  • Research-article

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)196
  • Downloads (Last 6 weeks)31
Reflects downloads up to 30 Aug 2024

Other Metrics

Citations

Cited By

View all
  • (2024)Associated Effects: Flexible Abstractions for Effectful ProgrammingProceedings of the ACM on Programming Languages10.1145/36563938:PLDI(394-416)Online publication date: 20-Jun-2024
  • (2024)Explicit Effects and Effect Constraints in ReMLProceedings of the ACM on Programming Languages10.1145/36329218:POPL(2370-2394)Online publication date: 5-Jan-2024

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