A Stage-Polymorphic IR for Compiling MATLAB-Style Dynamic Tensor Expressions
We propose a novel approach for compiling MATLAB and similar languages that are characterized by multi-dimensional arrays with dynamic shapes and element types. We stage an evaluator for a subset of the MATLAB language using the Lightweight Modular Staging (LMS) framework to produce a compiler that generates C code. But the first Futamura projection alone does not lead to efficient code: we need to refine the rigid stage distinction based on inferred type and shape information to remove costly runtime checks.
To this end, we introduce a stage-polymorphic data structure, that we refer to as metacontainer, to represent MATLAB tensors and their type and shape information. We use metacontainers to efficiently ``inject'', in a high-level intermediate representation (IR) of a MATLAB program, constructs for inferring shape and type information.
Once type and shape information are inferred, metacontainers are also used as the primary abstraction for lowering the computation, performing type, shape and ISA specialization. Our prototype MATLAB compiler MGen produces static C code that supports all primitive types, heavily overloaded operators, many other dynamic aspects of the language, and explicit vectorization for SIMD architectures.
Conference DayMon 21 OctDisplayed time zone: Beirut change
14:00 - 15:30
|A Stage-Polymorphic IR for Compiling MATLAB-Style Dynamic Tensor Expressions|
|Reflection in Attribute Grammars|
Lucas KramerUniversity of Minnesota, Ted KaminskiUniversity of Minnesota, Eric Van WykUniversity of Minnesota, USADOI Pre-print
|Polymorphic Extractors for Semantic and Portable Pattern Matching (Short Paper)|
Amir ShaikhhaUniversity of Oxford