Partydonk / partydonk

MIT License
33 stars 1 forks source link

Leveraging MLIR #4

Open migueldeicaza opened 4 years ago

migueldeicaza commented 4 years ago

Leveraging MLIR

MLIR is a compiler framework that can use rich high-level information to optimize code, and progressively lower the internal representation down to the machine level. The richer the information that can be provided the MLIR, the better the results that it can deliver.

It is an extensible platform that is particularly suitable to use with hardware accelerators. Given that there are some ~40 startups plus large companies working on different forms of AI accelerators, having a high-level optimizer that can target different architectures makes sense.

MLIR allows the mixing of high-level code with lower-level code, and as optimizations phases take place, the high-level code is progressively lowered to lower representations until they reach the machine level. And the high-level code is a pluggable platform, that today includes SPIR-V, GPUs, TensorFlow, affine operations, matrix operations and some others. The lower-level representation today is made up of LLVM.

Microsoft could produce high-level operations like “onnxruntime” and low-level representations like “graphcore” and use MLIR to build high performance code for this.

The results are quite impressive, when comparing hand-written C, hand-written assembly code and MLIR optimized code.

We have been thinking of ways of supporting MLIR with .NET and we have considered two options. One is to surface MLIR operations as types, and have the JIT compiler turn the IL that references these classes into MLIR data (this is “Partydonk” proposal, link). The other approach that we are exploring is F# specific, but would be both more robust and is based on F# quotations.
The F# approach would also be simpler to implement and maintain.