converting dialects in MLIR

Hi,
I am a newcomer in MLIR.
I am curious about how it works on converting dialects and its implementation.
I spent a lot of time searching for examples, but I can’t find a proper one.
Is there any examples can show how to transform tensorflow-level code to vector-dialect-level code step by step?
Thanks a lot

Have you looked at the Dialect Conversion docs and the Toy Tutorial?

Yes, I have.
I still feel confused, so I want to find some complete examples to learn how to build my own project by MLIR.

You can look under mlir/lib/Conversion, most of that code uses the dialect conversion infrastructure one way or another. There are numerous possible pipelines that can be constructed to generate vectorized code. Something like TosaToLinalg. then mlir/lib/Dialect/Linalg/Transforms/Vectorization.cpp, then VectorToLLVM.

Thank you! I have checked these files.
Those seem to convert between two dialects. However, I can’t understand how to use it.
I also ran the official tutorial but they didn’t give me the path to work on.
I would like to know if there is an example that a high level interface (like Tensorflow, PyTorch) converts into low level dialects. (like Vector)
I try to understand how I can start through an end to end example.
Through the example, I could know how to build an MLIR project or I can study by this concrete example.
Could you give me some suggestions?

I am not aware of any conversion from TensorFlow to Vector, or any similarly huge abstraction jump. Such a conversion would be the exact opposite of one of the MLIR cornerstones – progressive lowering – so it is unlikely to exist. We go through multiple conversion steps in most (I suppose, all) pipelines. So you must decompose your problem into steps expressible as conversions or other passes.

If the documentation, tutorials and existing code don’t seem sufficient for you to start, I would suggest starting with a simpler problem than what you are currently trying to solve.

There might be some misunderstanding.
I didn’t mean to find an example which could convert tensorflow level to vector dialect level directly, but convert it step by step.
Maybe the flow is tensor dialect to linalg dialect, and then to affine dialect, and finally to vector dialect, something like that.
Therefore, I want to have an example which has several dialects working on it, and hope the example help me to understand how could I start to build my own project.

Thanks a lot.

You seem to have ignored this part then:

There’s no teaching material on how to do that, only real code.

If you’re looking for examples of such real-world pipelines, you might check out GitHub - google/iree: 👻, which has integrations that start in high-level frontends like tensorflow and goes all the way down to various formats for execution (we have multiple runtime drivers). Be warned though, it’s a real compiler, not written to be a tutorial :slight_smile:

You can also find usage of MLIR in TensorFlow, where it’s used for various purposes, including the TF->XLA bridge (tensorflow/tensorflow/compiler/mlir at master · tensorflow/tensorflow · GitHub)

If you’re particularly interested in how to hook into high-level python frontends, GitHub - llvm/mlir-npcomp has dones some work on that.