A stage-polymorphic IR for compiling MATLAB-style dynamic tensor expressions
Proceedings of the 18th ACM SIGPLAN International Conference on Generative Programming: Concepts and Experiences(2019)
摘要
We propose a novel approach for compiling MATLAB and similar languages that are characterized by tensors with dynamic shapes and types. We stage an evaluator for a subset of MATLAB 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 type and shape inference 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" constructs into a high-level intermediate representation (IR) to infer shape and type information. Once 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.
更多查看译文
关键词
MATLAB, SIMD, generic programming, polymorphism, staging, tensor computations
AI 理解论文
溯源树
样例
生成溯源树,研究论文发展脉络