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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon May 20 11:38:46 PDT 2024


pranavm-nvidia wrote:

Yeah, let me elaborate on the use case a bit more. Basically, I need to construct small `DenseElementsAttr` (on the order of 10s of values) to use for operation parameters, e.g. things like the permutation to use for a transpose. So performance is not a huge concern in my specific case. 
Maybe there is a better kind of attribute to use for cases like this (`ArrayAttr`?) but the constraint comes from the stack below me, although I can look into changing that if `DenseElementsAttr` isn't the right approach. 

> If you're just wanting to use the fact that mlir/llvm already knows how to do these conversions

Yes, this is exactly it. As you noted, it's not too hard for types that `array`/`struct` support but I wanted to avoid doing manual bit manipulation for unsupported types like BF16/FP8. 

> teach the FloatAttr type how to give you back an untyped binary buffer of the value

Would this be any more beneficial than what I'm doing in this PR? I'm imagining something like this:
```py
buffer = FloatAttr.get(BF16Type.get(), 1.0).tobytes() + FloatAttr.get(BF16Type.get(), 2.0).tobytes()
attr = DenseElementsAttr.get_from_buffer(buffer, ...)
``` 

And I guess I'm still curious about what the intended use case for the `mlirDenseElementsAttrGet` C API is. 

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


More information about the Mlir-commits mailing list