[Mlir-commits] [mlir] [mlir][python] Add bindings for mlirDenseElementsAttrGet (PR #91389)

Stella Laurenzo llvmlistbot at llvm.org
Fri May 17 19:03:50 PDT 2024


stellaraccident wrote:

+1 to the perils of individual elemental attributes for anything real.

I'm not exactly sure what the goal is. When I'm doing this kind of stuff, I'm always working on things that produce packed in-memory buffers of the thing being created... Because anything else is impractical for real use. 

You may need to do some creative bit manipulation, but you could do what you want without deps in the python standard library just using the array and struct modules, both of which let you swizzle packed data. Of course, since python knows nothing of bf16 or the f8 or weird types, you're on your own unless if you have a library that lets you do anything there. Same as in any language. 

If you're just wanting to use the fact that mlir/llvm already knows how to do these conversions, you could go the other way: teach the FloatAttr type how to give you back an untyped binary buffer of the value (ie. Implement the buffer protocol). Then you could cast that to a bytes in Python and have *something*, I guess. Won't be very good, and will be ruinously expensive if trying to use it as a general numeric conversion library (since it is still uniqued elemental attributes).

Another alternative might be to provide a convenience binding for numeric conversion based on APFloat directly. For reasons I won't go into here, it is legal to use that C++ type directly in the python bindings sans C wrapper.

https://github.com/llvm/llvm-project/pull/91389


More information about the Mlir-commits mailing list