Wed 17 Jul 2019 16:30 - 16:50 at Epernay - Compilation and verification

MATLAB is a high-level programming language that is widely used in many domains in engineering and science. Consequently, there has been extensive research in automatically optimizing, interpreting, translating and compiling MATLAB. However, the lack of type and shape information, the dynamic aspects of the language, and the heavy overloading of functions impose significant challenges in compiling MATLAB for efficient execution. As a result, there is no compiler that supports the complete specification, even on a reduced subset of the language.

In this work, we take a novel approach: we stage an evaluator for a subset of the MATLAB language using the Lightweight Modular Staging (LMS) [1] framework to produce a compiler that generates low-level C code. We introduce a stage polymorphic data structure, that we refer to as metacontainer, to represent MATLAB tensors and its type and shape information, i.e., its metadata, and use it to apply high-level analysis and transformations and subsequent lowering of computations.

We use metacontainers to “inject” code generation into a high-level intermediate representation (IR) of a MATLAB program, creating constructs that represent shape and type propagation in addition to the existing MATLAB computations. The injected code, coupled with the initial program control-flow, is separated from the numeric computations, leading to a simplified IR used for further analysis. Instead of tensor-specific analysis, this allows us to apply generic reaching definition analysis and constant propagation on integer computations to infer types and dimensions respectively. Finally, the result of the analysis is then applied to specialize each metacontainer with the inferred information, without needing complicated rewrites.

Once type and shape information are inferred, metacontainers are also used as the primary abstraction for lowering the computation, including for type and ISA specialization, through a stage-polymorphic array representation [2] for each tensor. Our prototype Matlab compiler MGen produces static C code that supports MATLAB type-specific numerical computations on all 12 primitive types, including floating point computation and saturation arithmetics. It handles all dynamic aspects of a subset of the language and overloaded computation, and generates correct code with explicit vectorization for Intel SIMD architectures.

[1] Tiark Rompf and Martin Odersky. Lightweight Modular Staging: A Pragmatic Approach to Runtime Code Generation and Compiled DSLs. Proc. of the 9th International Conference on Generative Programming And Component Engineering (GPCE) 2010.

[2] Alen Stojanov, Georg Ofenbeck, Tiark Rompf, and Markus Pueschel. Abstracting Vector Architectures in Library Generators: Case Study Convolution Filters. Proc. of the ACM SIGPLAN International Workshop on Libraries, Languages, and Compilers for Array Programming (ARRAY) 2014.

Wed 17 Jul

scala-2019-papers
15:40 - 17:20: Scala 2019 - Compilation and verification at Epernay
scala-2019-papers15:40 - 16:10
Short-paper
Alceste ScalasAston University, Birmingham, UK, Nobuko YoshidaImperial College London, Elias BenussiFaculty Science Ltd
scala-2019-papers16:10 - 16:30
Talk
scala-2019-papers16:30 - 16:50
Talk
Alen Stojanov, Tiark RompfPurdue University, Markus PüschelETH Zürich