skip to main content
research-article

Type-safe runtime code generation: accelerate to LLVM

Published:30 August 2015Publication History
Skip Abstract Section

Abstract

Embedded languages are often compiled at application runtime; thus, embedded compile-time errors become application runtime errors. We argue that advanced type system features, such as GADTs and type families, play a crucial role in minimising such runtime errors. Specifically, a rigorous type discipline reduces runtime errors due to bugs in both embedded language applications and the implementation of the embedded language compiler itself. In this paper, we focus on the safety guarantees achieved by type preserving compilation. We discuss the compilation pipeline of Accelerate, a high-performance array language targeting both multicore CPUs and GPUs, where we are able to preserve types from the source language down to a low-level register language in SSA form. Specifically, we demonstrate the practicability of our approach by creating a new type-safe interface to the industrial-strength LLVM compiler infrastructure, which we used to build two new Accelerate backends that show competitive runtimes on a set of benchmarks across both CPUs and GPUs.

References

  1. T. Altenkirch and B. Reus. Monadic Presentation of Lambda Terms Using Generalised Inductive Types. In CSL ’99: Computer Science Logic, pages 453–468, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. A. W. Appel. SSA is functional programming. ACM SIGPLAN Notices, 33(4):17–20, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  3. R. Atkey, S. Lindley, and J. Yallop. Unembedding domain-specific languages. In Haskell Symposium, pages 37–48, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. R. D. Blumofe and C. E. Leiserson. Scheduling multithreaded computations by work stealing. Journal of the ACM, 46(5):720–748, 1999. Google ScholarGoogle ScholarDigital LibraryDigital Library
  5. B. Catanzaro, M. Garland, and K. Keutzer. Copperhead: Compiling an embedded data parallel language. In PPoPP: Principles and Practice of Parallel Programming, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. H. Chafi, Z. DeVito, A. Moors, T. Rompf, A. K. Sujeeth, P. Hanrahan, M. Odersky, and K. Olukotun. Language virtualization for heterogeneous parallel computing. In OOPSLA: Object Oriented Programming Systems & Applications, pages 835––847, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. M. M. T. Chakravarty. Converting a HOAS term GADT into a de Bruijn term GADT, 2009. URL http://www.cse.unsw.edu.au/ ~chak/haskell/term-conv/.Google ScholarGoogle Scholar
  8. M. M. T. Chakravarty, G. Keller, and S. Peyton Jones. Associated type synonyms. In POPL: Principles of Programming Languages, pages 241–253, 2005. Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. M. M. T. Chakravarty, G. Keller, S. Lee, T. L. McDonell, and V. Grover. Accelerating Haskell array codes with multicore GPUs. In DAMP: Declarative Aspects of Multicore Programming, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. S. Chatterjee, G. E. Blelloch, and M. Zagha. Scan primitives for vector computers. In Supercomputing, pages 666–675, 1990. Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. N. Chong, A. F. Donaldson, A. Lascu, and C. Lidbury. Many-Core Compiler Fuzzing. In PLDI: Programming Language Design and Implementation, 2015. Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. M. I. Cole. Algorithmic Skeletons: Structured Management of Parallel Computation. The MIT Press, 1989. Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. D. Coutts, R. Leshchinskiy, and D. Stewart. Stream fusion: from lists to streams to nothing at all. In ICFP: International Conference on Functional Programming, pages 315–326, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. R. Cryton, J. Ferrante, B. K. Rosen, M. N. Wegman, and F. K. Zadeck. Efficiently computing static single assignment form and the control dependence graph. ACM Transactions on Programming Languages and Systems, 13(4):451–490, 1991. Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. C. Elliott. Functional Images. In The Fun of Programming. Palgrave, 2003.Google ScholarGoogle Scholar
  16. C. Elliott. Programming graphics processors functionally. In Haskell Symposium, 2004. Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. A. Foltzer, A. Kulkarni, R. Swords, S. Sasidharan, E. Jiang, and R. Newton. A meta-scheduler for the par-monad: composable scheduling for the heterogeneous cloud. In ICFP: International Conference on Functional Programming, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. N. Geoffray, G. Thomas, J. Lawall, G. Muller, and B. Folliot. VMKit: a substrate for managed runtime environments. In Virtual Execution Environments, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. L. J. Guibas and D. K. Wyatt. Compilation and Delayed Evaluation in APL. In POPL: Principles of Programming Languages, pages 1–8, 1978. Google ScholarGoogle ScholarDigital LibraryDigital Library
  20. L.-J. Guillemette and S. Monnier. A type-preserving compiler in Haskell. In ICFP: International conference on Functional programming, pages 75–86, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. C. V. Hall, K. Hammond, S. L. Peyton Jones, and P. L. Wadler. Type classes in Haskell. ACM Transactions on Programming Languages and Systems, 18(2):109–138, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. S. Herhut, R. L. Hudson, T. Shpeisman, and J. Sreeram. River trail: a path to parallelism in JavaScript. In OOPSLA: Object Oriented Programming Systems & Applications, pages 729––744, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. G. Keller, M. M. T. Chakravarty, R. Leshchinskiy, S. Peyton Jones, and B. Lippmeier. Regular, shape-polymorphic, parallel arrays in Haskell. In ICFP: International Conference on Functional Programming, pages 261–272, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. R. A. Kelsey. A correspondence between continuation passing style and static single assignment form. In Workshop on Intermediate Representations, pages 13–22, 1995. Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. G. Klein, K. Elphinstone, G. Heiser, J. Andronick, D. Cock, P. Derrin, D. Elkaduwe, K. Engelhardt, R. Kolanski, M. Norrish, T. Sewell, H. Tuch, and S. Winwood. seL4: Formal Verification of an OS Kernel. In SOSP: Symposium on Operating Systems Principles, pages 207– 220. ACM, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. C. Lattner and V. Adve. Architecture for a Next-Generation GCC. In GCC Developers’ Summit, 2003.Google ScholarGoogle Scholar
  27. X. Leroy. Formal verification of a realistic compiler. Communications of the ACM, 52(7):107, 2009. Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. B. Lippmeier, M. M. T. Chakravarty, G. Keller, and S. Peyton Jones. Guiding parallel array fusion with indexed types. In Haskell Symposium, 2012. Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. W. Ma and G. Agrawal. An integer programming framework for optimizing shared memory use on GPUs. In HiPC ’10: The International Conference on High Performance Computing, pages 1–10, 2010.Google ScholarGoogle Scholar
  30. G. Mainland and G. Morrisett. Nikola: Embedding Compiled GPU Functions in Haskell. In Haskell Symposium, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. C. McBride. Type-Preserving Renaming and Substitution. Journal of Functional Programming, 2006.Google ScholarGoogle Scholar
  32. T. L. McDonell, M. M. T. Chakravarty, G. Keller, and B. Lippmeier. Optimising Purely Functional GPU Programs. In ICFP: International Conference on Functional Programming, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. G. Morrisett, D. Walker, K. Crary, and N. Glew. From System F to Typed Assembly Language. In POPL: Principles of Programming Languages, 1998. Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. NVIDIA. CUDA LLVM Compiler. URL https://developer. nvidia.com/cuda-llvm-compiler.Google ScholarGoogle Scholar
  35. J. Peterson and M. Jones. Implementing type classes. In PLDI: Programming Language Design and Implementation, pages 227–236, 1993. Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. S. Peyton Jones, D. Vytiniotis, S. Weirich, and G. Washburn. Simple unification-based type inference for GADTs. In ICFP: International Conference on Functional Programming, pages 50–61, 2006. Google ScholarGoogle ScholarDigital LibraryDigital Library
  37. M. Pharr and W. R. Mark. ispc: A SPMD compiler for highperformance CPU programming. In Innovative Parallel Computing, pages 1–13, 2012.Google ScholarGoogle Scholar
  38. R. Rivest. The MD5 Message-Digest Algorithm, 1992.Google ScholarGoogle Scholar
  39. T. Rompf, A. K. Sujeeth, N. Amin, K. J. Brown, V. Jovanovic, H. Lee, M. Jonnalagedda, K. Olukotun, and M. Odersky. Optimizing data structures in high-level programs: new directions for extensible compilers based on staging. In POPL: Principles of Programming Languages, 2013. Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. T. Rompf, A. K. Sujeeth, K. J. Brown, H. Lee, H. Chafi, and K. Olukotun. Surgical precision JIT compilers. In PLDI: Programming Language Design and Implementation, pages 41–52, 2014. Google ScholarGoogle ScholarDigital LibraryDigital Library
  41. T. Schrijvers, S. Peyton Jones, M. M. T. Chakravarty, and M. Sulzmann. Type checking with open type functions. In ICFP: International Conference on Functional Programming, pages 51–62, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. S. Sengupta, M. Harris, Y. Zhang, and J. D. Owens. Scan primitives for GPU computing. In Graphics Hardware, pages 97–106, 2007. Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. B. J. Svensson and R. Newton. Programming Future Parallel Architectures with Haskell and Intel ArBB. In FASPP ’11: Future Architectural Support for Parallel Programming, pages 3–14, 2011.Google ScholarGoogle Scholar
  44. B. J. Svensson, M. Sheeran, and K. Claessen. Obsidian: A domain specific embedded language for parallel programming of graphics processors. In IFL: Implementation and Application of Functional Languages, 2008. Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. D. Tarditi, G. Morrisett, P. Cheng, C. Stone, R. Harper, and P. Lee. TIL: a type-directed optimizing compiler for ML. In PLDI: Programming Language Design and Implementation, pages 181–192, 1996. Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. D. A. Terei and M. M. T. Chakravarty. An LLVM backend for GHC. In Haskell Symposium, pages 109–120, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. A. Tzannes, G. C. Caragea, R. Barua, and U. Vishkin. Lazy binarysplitting: a run-time adaptive work-stealing scheduler. In PPoPP: Principles and Practice of Parallel Programming, pages 179–190, 2010. Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. X. Yang, Y. Chen, E. Eide, and J. Regehr. Finding and understanding bugs in C compilers. In PLDI: Programming Language Design and Implementation, pages 283–294, 2011. Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Type-safe runtime code generation: accelerate to LLVM

      Recommendations

      Comments

      Login options

      Check if you have access through your login credentials or your institution to get full access on this article.

      Sign in

      Full Access

      PDF Format

      View or Download as a PDF file.

      PDF

      eReader

      View online with eReader.

      eReader
      About Cookies On This Site

      We use cookies to ensure that we give you the best experience on our website.

      Learn more

      Got it!