Terra: A Multi-Stage Language for Portable High-Performance Heterogeneous Computing
DOI:
https://doi.org/10.71366/ijwos03062639263Keywords:
Multi-stage programming, code generation, domain specific languages, heterogeneous computing, just-in-time compilation, meta-object protocols
Abstract
Modern high-performance computers are heterogeneous machines containing multi-core CPUs, GPUs, and specialized accelerators. While domain-specific languages (DSLs) and active libraries can provide portability across these diverse
architectures, their implementation remains challenging due to the ntension between high-level meta-programming facilities and low-level performance control. This paper presents Terra, a novel two-language design that separates these concerns: Lua serves as a high-level meta-programming language for generating and optimizing code, while Terra provides a low-level systems language with Clike performance. We adapt multi-stage programming techniques to work across this two-language boundary, introducing shared lexical scoping for intuitive code generation, hygienic variable capture, and separate evaluation for predictable performance. We further contribute exotypes, a mechanism combining meta-object protocols with staged programming to enable runtime generation of high-performance types. Through case studies in linear algebra, image processing, physical simulation, probabilistic programming, serialization, and dynamic assembly, we demonstrate that Terra achieves performance within 20% of ATLAS for matrix multiplication 2.3x faster than hand-written C for image processing, and 11x faster than Kryo for serialization, while reducing implementation complexity by eliminating separate compiler toolchains.
Downloads
Published
Issue
Section
License

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.


