MLIR For Beginners: A series of articles on the MLIR framework
github.com
github.com
On one hand MLIR seems like it would be nice to work with. LLVM IR is fairly low-level and hard to debug, but has a great API; it would be great to use such an API but keep things like type-safety and invariants, and worry less about tricky undefined behavior. On the other hand, despite claims of extensibility and flexibility, it's hard to imagine it being easier to work with than a custom IR. Plus, it seems MLIR's extensibility was build to support some things in particular (custom architectures, "affine / polyhedral" optimizations).
> Plus, it seems MLIR's extensibility was build to support some things in particular
this isn't true in the least. just go to https://mlir.llvm.org/docs/Dialects/ and you'll see the set of upstream dialects is very diverse. and that's just upstream.
Why?
I attended an MLIR online meeting months back and there was someone presenting who had a diagram that literally had a dozen different dialects and converters that were being written between different ones (but not MxN, so it was a strictly relatively arbitrary set of combinations that were being converted between, and mostly one-directional if I recall correctly). This was the “solution” to being able to make various things interoperate, but from a distance it looks a lot like a relatively obvious problem caused by the very nature of the design of MLIR.
Then with MLIR you want to do ML optimizations, which require even _higher_ level constructions like identifying linear algebra ops, so you can do stuff like tiling optimizations and lower to dedicated hardware instructions. THe high level MLIR dialects enables that information to be preserved as long as possible so that it's easier to implement all the magic.
That fell out of favor due to the fact that you end up having to choose and commit to the phase ordering fairly early on and writing separate lowering steps to convert between dialects. So the tide turned toward having a single mid-level IR (and sometimes a single high-level IR for things like specific loop optimizations that was then lowered to that mid-level IR).
You realize this is only feasible if you have one team working on a compiler for one domain right? Eg Rust's MIR is probably a good target for a systems language like rust but a bad target for a SQL like language.
>phase ordering fairly early on and writing separate lowering steps to convert between dialects.
I don't see how a single IR solves the phase ordering problem? LLVM IR is a single IR (not talking about backends) and yet you still have phase ordering problems.
It sounds like you think I’m advocating for something. I’m not. These are all just engineering trade offs that depend on your goals.
Regarding phase ordering: A single IR allows you to freely reorder passes rather than having to reimplement them if you want to move them earlier or later in the phase order.
Single IR passes from that perspective are roughly equivalent to MLIR-style `ir = loop_to_generic_dialect(my_loop_optimization(generic_to_loop_dialect(ir))`.
This assumes the existence of bidirectional dialect tranformations. Note that even LLVM IR, while a single IR, is technically multi-level as well, eg. for instruction selection, it needs to be canonicalized & expanded first, and feeding arbitrary IR into that pass will result in an exception (or sometimes even a segfault, considering it is C++).
Also, even though passes for single IR can theoretically be run in an arbitrary order, they are generally run in an order that can re-use (some) intermediate analysis results. This is, again, equivalent to minimizing the number of inter-dialect transformations in a multi-dialect IR.
...i'm not trying to be rude here but... that's not how any of this works...
you can scholar.google.com "phase ordering llvm ir" to find thousands of papers that demonstrate.
I didn’t bring up solving the phase ordering problem, you did.
I’m simply pointing out that if you have a compiler where you have multiple IRs or dialects of IR, and you have a pass that is written to work on IR “X”, and then at some point after that pass you translate to IR “Y”, if you want to move your pass after that point of translation, you either need to rewrite your pass so that it operates on “Y”, or you need to translate back to “X” again.
what? the first mention of phase ordering this thread is due to you
>That fell out of favor due to the fact that you end up having to choose and commit to the phase ordering fairly early on
no one stumbles on this repo by accident (jeremy didn't post it here). the only way you find it is you google "mlir tutorial" ie you know what MLIR is and you're actively explicitly looking for a tut. there is no situation where you're ambushed by this content.
like if i write a tutorial "integration by parts for beginners" but don't define integration are you gonna claim that it fails at being for beginners? does every title from now on need to explicitly have "... for beginners who know what this is and have already made the decision to start studying".
but the guy himself didn't post it. how are people so entitled that they're upset about a deficiency in a thing that they sought out. no one is making you go the repo (or asking you to go).
it's literally like complaining about free samples at costco - if you don't like what they have don't take one!
The Costco example is perfect because if I was the sample manager or whatever and I overheard people rudely complaining to each other that they didn't like not knowing what was in the sample products, I might consider putting the ingredients list up next to the sample station. The goal is, after all, to get as many people to come check out the product as possible, right?
the goal of this repo is to do something nice for people, not attract attention. i know that 100% if this was the reaction to my public service, i would immediately take the repo private because ungrateful people don't deserve to have nice things.
"As we announced recently, my team at Google has started a new effort to build production-worthy engineering tools for Fully Homomorphic Encryption (FHE). One focal point of this, and one which I’ll be focusing on as long as Google is willing to pay me to do so, is building out a compiler toolchain for FHE in the MLIR framework (Multi-Level Intermediate Representation). The project is called Homomorphic Encryption Intermediate Representation, or HEIR."
By the way, the author of the GitHub repo has updated the README to have a link to the MLIR framework now. ¯\_(ツ)_/¯. Can't wait to read about it.He added a single link on one line, and that's all it took. I appreciate people recognizing positive intent and not someone taking potshots.
> As we announced recently, my team at Google has started a new effort to build production-worthy engineering tools for Fully Homomorphic Encryption (FHE). One focal point of this, and one which I’ll be focusing on as long as Google is willing to pay me to do so, is building out a compiler toolchain for FHE in the MLIR framework (Multi-Level Intermediate Representation). The project is called Homomorphic Encryption Intermediate Representation, or HEIR
And MLIR there links to the MLIR project page.
> This is the code repository for a series of articles on the MLIR framework.
And then has links to the (currently written) articles, the first one with "(Getting Started)" in the title. Seems like an obvious place to, you know, start reading about things.
see eg. https://github.com/j2kun/mlir-tutorial/blob/92723e224c1a6e8c...
I found the standalone example https://github.com/llvm/llvm-project/tree/main/mlir/examples... in the MLIR repo to be very useful, on the other hand.