MATLAB Coder: Partial Evaluation in Practice
summary
MATLAB Coder converts MATLAB into embeddable C/C++ by using online partial evaluation and a type-driven engine that does function specialization on types and values to produce unboxed C types. It reimplements about 3,000 MATLAB functions, generates multiple specialized versions (example: four versions of sum), turns many runtime errors into compile-time errors, supports opt-in no-dynamic-memory for constrained targets, emits readable C for examples like a Kalman filter, and runs in seconds for small cases and minutes (≈6 min) for large builds.
AI-written summary · about
chapters (20)
- 0:00Intro
- 0:50MATLAB is designed for prototyping
- 2:33Our goal is to enable MATLAB in production
- 7:37Focus: MATLAB Coder's "type inference" algorithm
- 22:25Takeaways from the examples...
- 23:36MATLAB Coder's Type Inference Engine
- 25:26Types propagate bottom-up in each statement
- 26:31Type inference visits statement in natural order
- 26:57Multiple types assigned to the same variable cause a type
- 27:21Constant folding and control-flow pruning help avoid type
- 28:13Function calls produce new function specializations by recursively invoking type inference on the callee
- 29:07Functions can be specialized not only on input types, but also on constant input values, demand-driven
- 30:16Iteration over heterogeneous arrays is another use case for specialization
- 31:01Complete loop unrolling for typing uses of heterogeneous arrays
- 31:25Type Inference Engine Summary
- 32:28Future work planned to make type inference more permissive
- 36:59Compiling for embedded systems requires more than just type inference
- 39:49Partial evaluation powers tools that enable running MATLAB "anywhere"
- 40:53And powers MATLAB embedded in Simulink and Stateflow
- 41:24You can deploy high-level languages to embedded systems
related talks
59mCoq to C Translation with Partial Evaluation + Counterexample Generation
09mCompilers for nothing, executables for free!
28mCode Generation in Linnea
06mCode Generation: The Lisp Way
01h 01mA partial history of partial evaluation
01h 01m“How bad is Meta-Programming still today?"
24mCakes That Bake Cakes: Dynamic Computation in CakeML
01h 06m“C++ Metaprogramming: Journey from simple to insanity and back"
