How to get a value type's encoding in python bindings?

Hi all,
I am using python binding of my IR to parse the prebuilt MLIR file, however, I don’t know how to obtain the type encoding arguments?

It is like
tensor<1x5888x256xsi8, #xml.XExt<bufferLoc = local, fmt = K32M32, addr = 4784128 : si64, bufferId = 1 : si64, FIFONum = 4 : si64, originShape = [1, 5888, 256]>

I want to obtain the encoding of type, say, XExt in python. Now I know I can obtain the type by

x = op.results[0].type

but then what? Where to find the API of python bindings?

Thank you in advance

So you can cast the type to a RankedTensorType and that has an encoding property which will return you the encoding as an Attribute. So in your example it would look like RankedTensorType(x).encoding. Note that this returns a generic Attribute and it’s on you to provide bindings to parse that attribute.

Here’s the stub file for the python bindings but that can sometimes be stale so I recommend just looking at the bindings themselves.

1 Like

As of

you can skip the cast (op.results[0].type will now return a RankedTensorType).


Thanks! that’s clear, I will give it a try

OK! thanks for the advise

Could you please kindly show how to bind the custom defined attribute, and how to use it?
Thanks a lot!

Here’s an example in SparseTensor and here’s the usage.