Stella: a Python-Based Domain-Specific Language for Simulations David Mohr

Stella: a Python-Based Domain-Specific Language for Simulations David Mohr

University of New Mexico UNM Digital Repository Computer Science ETDs Engineering ETDs 12-1-2015 Stella: A Python-based Domain-Specific Language for Simulations David Mohr Follow this and additional works at: https://digitalrepository.unm.edu/cs_etds Recommended Citation Mohr, David. "Stella: A Python-based Domain-Specific Language for Simulations." (2015). https://digitalrepository.unm.edu/ cs_etds/12 This Dissertation is brought to you for free and open access by the Engineering ETDs at UNM Digital Repository. It has been accepted for inclusion in Computer Science ETDs by an authorized administrator of UNM Digital Repository. For more information, please contact [email protected]. David Mohr Candidate Computer Science Department This dissertation is approved, and it is acceptable in quality and form for publication: Approved by the Dissertation Committee: Darko Stefanovic, Chairperson Manuel Hermenegildo Lydia Tapia Matthew Lakin i STELLA: A Python-based Domain-Specific Language for Simulations by David Mohr M.S., The University of New Mexico, 2010 B.S.C.S., The University of Texas-Pan American, 2006 DISSERTATION Submitted in Partial Fulfillment of the Requirements for the Degree of Doctor of Philosophy Computer Science The University of New Mexico Albuquerque, New Mexico December 2015 ii c 2015, David Mohr iii Dedication To all the open source and free software developers. iv Acknowledgments First of all I would like to thank my advisor Darko Stefanovic. I am very grateful that he gave me the freedom to find my own project, something that truly interests me, and then guided me to turn the small initial idea into the mature project that now lies in your (virtual) hands. My committee, Manuel Hermenegildo, Lydia Tapia, and Matthew Lakin, were a plea- sure to work with. Thank you for your time and effort! I would also like to thank my lab mates Mark Olah and Oleg Semenov, who were fun to work with, fun to hang out with, and whose work gave rise to the idea for my project. And my friend Drew Levin for reviewing this document, and for keeping me steadily supplied with coffee when time was getting tight. My project involved some heavy implementation effort, and I would like to acknowl- edge that it would not have been possible to prove my point without the excellent work done before me. Thank you for all the libraries and programs, little and small, that I used, and which were made graciously available for free by their authors. This material is based upon work supported by the National Science Foundation under grants CCF-0829896, CDI-1028238, and CCF-1422840. v STELLA: A Python-based Domain-Specific Language for Simulations by David Mohr M.S., The University of New Mexico, 2010 B.S.C.S., The University of Texas-Pan American, 2006 Ph.D., Computer Science, University of New Mexico, 2015 Abstract STELLA is a domain-specific language that (1) has single thread performance competitive with low-level languages, (2) supports object-oriented programming (OOP) to properly structure the code, and (3) is very easy to use. Instead of prototyping in a high-level lan- guage and then rewriting in a lower-level language, STELLA is embedded in Python, is transparently usable, retains some OOP features, compiles to machine code, and executes at speed similar to C. STELLA’s source code is compatible with Python, and allows easy integration of C libraries. Its features are focused on the needs of scientific simulations. Other projects to speed up Python focus on easy integration, and smaller critical sections. In contrast, STELLA supports translating larger programs in their entirety, and does not allow interaction with the Python run-time, to ensure predictable performance. My ex- perience developing STELLA shows that by carefully selecting language features, high run-time performance can be achieved in a high-level language that has in practice very few restrictions. vi Contents List of Figures xiv List of Tables xv 0 Preface1 0.1 On Prototyping...............................1 0.2 On Lower-Level Languages.........................3 0.3 On Object-Oriented Programming.....................5 0.4 Many Shoes that Don’t Fit.........................6 0.5 Creating a Domain-Specific Language...................8 1 Introduction 10 1.1 Motivation.................................. 10 1.2 Performance-Critical Sections....................... 13 1.3 The STELLA Language........................... 15 1.4 Related Work................................ 17 vii Contents 1.4.1 Speeding up all of Python..................... 17 1.4.2 Speeding up some of Python.................... 19 1.4.3 Other language projects...................... 22 1.5 Contributions................................ 23 2 Example 24 2.1 Pre-Processing Stage............................ 24 2.2 DSL Stage.................................. 27 2.3 Post-Processing Stage............................ 28 2.4 OOP Extension............................... 29 3 Design 31 3.1 Language Characteristics.......................... 32 3.2 Embedding................................. 36 3.3 Syntax and Semantics............................ 37 3.4 Syntactic Sugar............................... 38 3.5 Typing.................................... 40 3.5.1 Static Typing............................ 40 3.5.2 Types................................ 41 3.6 Arrays.................................... 41 3.7 Typing Rules................................ 43 viii Contents 3.8 Object-Oriented Programming....................... 44 3.9 Variable Scope............................... 47 3.10 Optimization Passes............................. 48 3.10.1 Deviations from Python Semantics................. 48 3.11 Interfacing with C.............................. 49 4 Implementation 51 4.1 Dependencies................................ 51 4.2 LLVM Primer................................ 52 4.3 Intermediate Representation........................ 54 4.4 Analysis................................... 55 4.4.1 Function Objects.......................... 56 4.4.2 Disassembly............................ 57 4.4.3 Rewrite............................... 58 4.4.4 Intra-procedural Control Flow................... 58 4.4.5 Stack Unwinding.......................... 59 4.4.6 Type Analysis............................ 60 4.4.7 Inter-procedural Control Flow Discovery............. 61 4.5 Intrinsics.................................. 62 4.6 Types.................................... 62 4.7 Code Generation and Execution...................... 63 ix Contents 4.7.1 C libraries.............................. 64 4.7.2 Data Transfer............................ 65 4.8 Verification................................. 66 4.9 Debugging.................................. 67 4.10 Bytecodes.................................. 68 4.10.1 Basic Language Support...................... 68 4.10.2 Arithmetic............................. 69 4.10.3 Memory Interaction........................ 71 4.10.4 Control Flow............................ 72 4.10.5 Placeholders............................ 73 5 Evaluation 75 5.1 Benchmark Description........................... 76 5.2 Language Design.............................. 77 5.2.1 Required Program Modifications.................. 77 5.2.2 Summary of Source Changes.................... 79 5.3 Compilation Time.............................. 80 5.4 Performance................................. 83 6 Conclusion 85 6.1 Future Work................................. 86 x Contents A Benchmark Details 90 A.1 Fibonacci.................................. 90 A.1.1 Python and Stella Source...................... 91 A.1.2 C Source.............................. 91 A.2 1D Spider.................................. 92 A.2.1 Python and Stella Source...................... 92 A.2.2 Change Summary.......................... 95 A.2.3 C Source.............................. 95 A.3 nbody.................................... 99 A.3.1 Python Original........................... 99 A.3.2 Modified for Stella......................... 102 A.3.3 Change Summary.......................... 107 A.3.4 C Source.............................. 109 A.4 heat..................................... 112 A.4.1 Python Original........................... 112 A.4.2 Modified for Stella......................... 122 A.4.3 Change Summary.......................... 133 A.4.4 C Source.............................. 134 A.5 Performance per C Compiler........................ 142 B Miscellaneous Source Code 143 xi Contents B.1 Exploratory Program Details........................ 143 B.1.1 GenericSpiderSim......................... 144 B.2 mtpy..................................... 153 B.3 Example Program SpiderSemiInfinite1D.................. 154 B.4 Example Helper Code............................ 156 B.5 Example Program SpiderSemiInfinite1D-Fpt................ 158 CSTELLA Source Code 160 C.1 stella/analysis.py.............................. 160 C.2 stella/tp.py.................................. 172 C.3 stella/intrinsics/python.py.......................... 209 C.4 stella/intrinsics/ init .py.......................... 210 C.5 stella/ version.py.............................. 218 C.6 stella/codegen.py.............................. 229 C.7 stella/ir.py.................................. 234 C.8 stella/bytecode.py.............................. 252 C.9 stella/test/debug gc.py........................... 292 C.10 stella/test/errors.py............................. 294 C.11 stella/test/external func.py......................... 296 C.12 stella/test/benchmark.py.......................... 298 C.13 stella/test/basicmath.py........................... 306 xii Contents C.14 stella/test/virtnet

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    400 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us