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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri May 17 14:55:20 PDT 2024


pranavm-nvidia wrote:

That makes sense. So then assuming we accept a Python list of ints/floats, would I just do something like this in the bindings (pseudocode mostly)?
```cpp
auto rawBuffer = ...; // Allocate enough memory to hold sizeInBytes(targetType) * numElements
for (auto number : numbers) {
    switch (targetType) {
        case bfloat16:
            rawBuffer[index] = float2bfloat(number);
        ... // Similar for all other types
    }
}
return mlirDenseElementsAttrRawBufferGet(...,  rawBuffer);
```

Or is there already infrastructure to convert Python numbers? (sorry if this is a dumb question; I'm still quite new to MLIR)

Also, is there any value in allowing existing attributes to be packed into a `DenseElementsAttr`? i.e. should I keep this PR open at all? Maybe it's worth having it just for the sake of parity between the C/Python APIs. 


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


More information about the Mlir-commits mailing list