Newbie question regarding addArgumentMaterialization function

I followed the toy tutorials and get the basic understanding of MLIR. But while trying to learn more by diving a little bit deeper into the openai-triton project which uses MLIR to do codegen, and having a little difficulty understanding some topics regarding dialect conversion framework.
In the original toy tutorials, we didn’t use type converter because it’s not needed there. But in a lot of occasions, for example in triton( triton ir → tritongpu ir), or in mlir’s source code, when using linalg-detensorize pass, I saw the usage of customized type converter, and of course the usage of several hook functions. By reading the source code and docs, I only managed to understand partially due to my background is not very solid in this area.
One thing I noticed that, for example, in linalg-detensorize pass as in mlir/lib/Dialect/Linalg/Transforms/Detensorize.cpp, the source and argument materialization use the same callback to convert from legal “element type”( not sure how to describe this, maybe a fp64 type) to an illegal TensorType( Tensor I guess); and for target materializaiton, it uses the reversed version of callback to convert from illegal TensorType to “element type”.
I also checked that in the Bufferization/Transforms/Bufferize.cpp, the same logic applys.

However, as I read the doc and the header file in DialectConversion.h here, the documentation says the argument materialization

will be called when converting an illegal block argument type, to a legal type

This seems contradict with what the code does, so I’m more confused here. Is this doc wrong or I understood things wrong? Please help, thanks.

Argument conversion is usually triggered to convert entry block arguments (such as function arguments) to the types that are accepted by the following operations. The original use case was to convert unpacked memref to a structure that represents the memref in LLVM, which is a legal type. Check out the user documentation here Dialect Conversion - MLIR.

Both the (progressive) bufferization and the detensorize pass follow the structure described by Sean in his talk MLIR_ Open design meetings (2020-11-19 at 10_04 GMT-8).mp4 - Google Drive.

Separately, I wouldn’t advise using triton as source of good practices and rather take something upstream.

1 Like