History log of /llvm-project/mlir/test/python/ir/array_attributes.py (Results 1 – 17 of 17)
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 5d3ae516 29-Jan-2025 Matthias Gehre <matthias.gehre@amd.com>

Reapply "[mlir][python] allow DenseIntElementsAttr for index type (#118947)" (#124804)

This reapplies #118947 and adapts to nanobind.


Revision tags: llvmorg-21-init
# 1b729c3d 28-Jan-2025 Matthias Gehre <matthias.gehre@amd.com>

Revert "[mlir][python] allow DenseIntElementsAttr for index type (#118947)"

This reverts commit 9dd762e8b10586e749b0ddf3542e5dccf8392395.


# 9dd762e8 28-Jan-2025 Matthias Gehre <matthias.gehre@amd.com>

[mlir][python] allow DenseIntElementsAttr for index type (#118947)

Model the `IndexType` as `uint64_t` when converting to a python integer.

With the python bindings,
```python
DenseIntElement

[mlir][python] allow DenseIntElementsAttr for index type (#118947)

Model the `IndexType` as `uint64_t` when converting to a python integer.

With the python bindings,
```python
DenseIntElementsAttr(op.attributes["attr"])
```
used to `assert` when `attr` had `index` type like `dense<[1, 2, 3, 4]>
: vector<4xindex>`.

---------

Co-authored-by: Christopher McGirr <christopher.mcgirr@amd.com>
Co-authored-by: Tiago Trevisan Jost <tiago.trevisanjost@amd.com>

show more ...


Revision tags: llvmorg-19.1.7, llvmorg-19.1.6, llvmorg-19.1.5, llvmorg-19.1.4
# 1824e45c 13-Nov-2024 Kasper Nielsen <kasper0406@gmail.com>

[MLIR,Python] Support converting boolean numpy arrays to and from mlir attributes (unrevert) (#115481)

This PR re-introduces the functionality of
https://github.com/llvm/llvm-project/pull/113064, w

[MLIR,Python] Support converting boolean numpy arrays to and from mlir attributes (unrevert) (#115481)

This PR re-introduces the functionality of
https://github.com/llvm/llvm-project/pull/113064, which was reverted in
https://github.com/llvm/llvm-project/commit/0a68171b3c67503f7143856580f1b22a93ef566e
due to memory lifetime issues.

Notice that I was not able to re-produce the ASan results myself, so I
have not been able to verify that this PR really fixes the issue.

---

Currently it is unsupported to:
1. Convert a MlirAttribute with type i1 to a numpy array
2. Convert a boolean numpy array to a MlirAttribute

Currently the entire Python application violently crashes with a quite
poor error message https://github.com/pybind/pybind11/issues/3336

The complication handling these conversions, is that MlirAttribute
represent booleans as a bit-packed i1 type, whereas numpy represents
booleans as a byte array with 8 bit used per boolean.

This PR proposes the following approach:
1. When converting a i1 typed MlirAttribute to a numpy array, we can not
directly use the underlying raw data backing the MlirAttribute as a
buffer to Python, as done for other types. Instead, a copy of the data
is generated using numpy's unpackbits function, and the result is send
back to Python.
2. When constructing a MlirAttribute from a numpy array, first the
python data is read as a uint8_t to get it converted to the endianess
used internally in mlir. Then the booleans are bitpacked using numpy's
bitpack function, and the bitpacked array is saved as the MlirAttribute
representation.

show more ...


# 0a68171b 05-Nov-2024 Dmitri Gribenko <gribozavr@gmail.com>

Revert "[MLIR,Python] Support converting boolean numpy arrays to and from mlir attributes (#113064)"

This reverts commit fb7bf7a5acc65be44fc546f282942b91472553b3. There is
an ASan issue here, see th

Revert "[MLIR,Python] Support converting boolean numpy arrays to and from mlir attributes (#113064)"

This reverts commit fb7bf7a5acc65be44fc546f282942b91472553b3. There is
an ASan issue here, see the discussion on
https://github.com/llvm/llvm-project/pull/113064.

show more ...


# fb7bf7a5 02-Nov-2024 Kasper Nielsen <kasper0406@gmail.com>

[MLIR,Python] Support converting boolean numpy arrays to and from mlir attributes (#113064)

Currently it is unsupported to:
1. Convert a `MlirAttribute` with type `i1` to a numpy array
2. Convert

[MLIR,Python] Support converting boolean numpy arrays to and from mlir attributes (#113064)

Currently it is unsupported to:
1. Convert a `MlirAttribute` with type `i1` to a numpy array
2. Convert a boolean numpy array to a `MlirAttribute`

Currently the entire Python application violently crashes with a quite
poor error message https://github.com/pybind/pybind11/issues/3336

The complication handling these conversions, is that `MlirAttribute`
represent booleans as a bit-packed `i1` type, whereas numpy represents
booleans as a byte array with 8 bit used per boolean.

This PR proposes the following approach:
1. When converting a `i1` typed `MlirAttribute` to a numpy array, we can
not directly use the underlying raw data backing the `MlirAttribute` as
a buffer to Python, as done for other types. Instead, a copy of the data
is generated using numpy's unpackbits function, and the result is send
back to Python.
2. When constructing a `MlirAttribute` from a numpy array, first the
python data is read as a `uint8_t` to get it converted to the endianess
used internally in mlir. Then the booleans are bitpacked using numpy's
bitpack function, and the bitpacked array is saved as the
`MlirAttribute` representation.

Please note that I am not sure if this approach is the desired solution.
I'd appreciate any feedback.

show more ...


Revision tags: llvmorg-19.1.3, llvmorg-19.1.2, llvmorg-19.1.1, llvmorg-19.1.0, llvmorg-19.1.0-rc4, llvmorg-19.1.0-rc3, llvmorg-19.1.0-rc2, llvmorg-19.1.0-rc1, llvmorg-20-init, llvmorg-18.1.8, llvmorg-18.1.7
# c912f0e7 22-May-2024 pranavm-nvidia <49246958+pranavm-nvidia@users.noreply.github.com>

[mlir][python] Add bindings for mlirDenseElementsAttrGet (#91389)

This change adds bindings for `mlirDenseElementsAttrGet` which accepts a
list of MLIR attributes and constructs a DenseElementsAttr

[mlir][python] Add bindings for mlirDenseElementsAttrGet (#91389)

This change adds bindings for `mlirDenseElementsAttrGet` which accepts a
list of MLIR attributes and constructs a DenseElementsAttr. This allows
for creating `DenseElementsAttr`s of types not natively supported by
Python (e.g. BF16) without requiring other dependencies (e.g. `numpy` +
`ml-dtypes`).

show more ...


Revision tags: llvmorg-18.1.6, llvmorg-18.1.5, llvmorg-18.1.4, llvmorg-18.1.3, llvmorg-18.1.2, llvmorg-18.1.1, llvmorg-18.1.0, llvmorg-18.1.0-rc4, llvmorg-18.1.0-rc3, llvmorg-18.1.0-rc2, llvmorg-18.1.0-rc1, llvmorg-19-init, llvmorg-17.0.6, llvmorg-17.0.5, llvmorg-17.0.4, llvmorg-17.0.3, llvmorg-17.0.2, llvmorg-17.0.1, llvmorg-17.0.0
# f66cd9e9 15-Sep-2023 Stella Laurenzo <stellaraccident@gmail.com>

[mlir] Add Python bindings for DenseResourceElementsAttr. (#66319)

Only construction and type casting are implemented. The method to create
is explicitly named "unsafe" and the documentation calls

[mlir] Add Python bindings for DenseResourceElementsAttr. (#66319)

Only construction and type casting are implemented. The method to create
is explicitly named "unsafe" and the documentation calls out what the
caller is responsible for. There really isn't a better way to do this
and retain the power-user feature this represents.

show more ...


Revision tags: llvmorg-17.0.0-rc4, llvmorg-17.0.0-rc3, llvmorg-17.0.0-rc2, llvmorg-17.0.0-rc1, llvmorg-18-init
# 71a25454 14-Jul-2023 Peter Hawkins <phawkins@google.com>

[MLIR:Python] Make DenseElementsAttr.get() only request a buffer format if no explicit type was provided.

Not every NumPy type (e.g., the `ml_dtypes.bfloat16` NumPy extension
type) has a type in the

[MLIR:Python] Make DenseElementsAttr.get() only request a buffer format if no explicit type was provided.

Not every NumPy type (e.g., the `ml_dtypes.bfloat16` NumPy extension
type) has a type in the Python buffer protocol, so exporting such a
buffer with `PyBUF_FORMAT` may fail.

However, we don't care about the self-reported type of a buffer if the
user provides an explicit type. In the case that an explicit type is
provided, don't request the format from the buffer protocol, which
allows arrays whose element types are unknown to the buffer protocol to
be passed.

Reviewed By: jpienaar, ftynse

Differential Revision: https://reviews.llvm.org/D155209

show more ...


# 974c1596 04-Jul-2023 Rahul Kayaith <rkayaith@gmail.com>

[mlir][python] Downcast attributes in more places

Update remaining `PyAttribute`-returning APIs to return `MlirAttribute` instead,
so that they go through the downcasting mechanism.

Reviewed By: ma

[mlir][python] Downcast attributes in more places

Update remaining `PyAttribute`-returning APIs to return `MlirAttribute` instead,
so that they go through the downcasting mechanism.

Reviewed By: makslevental

Differential Revision: https://reviews.llvm.org/D154462

show more ...


Revision tags: llvmorg-16.0.6, llvmorg-16.0.5
# f9008e63 17-May-2023 Tobias Hieta <tobias@hieta.se>

[NFC][Py Reformat] Reformat python files in mlir subdir

This is an ongoing series of commits that are reformatting our
Python code.

Reformatting is done with `black`.

If you end up having problems

[NFC][Py Reformat] Reformat python files in mlir subdir

This is an ongoing series of commits that are reformatting our
Python code.

Reformatting is done with `black`.

If you end up having problems merging this commit because you
have made changes to a python file, the best way to handle that
is to run git checkout --ours <yourfile> and then reformat it
with black.

If you run into any problems, post to discourse about it and
we will try to help.

RFC Thread below:

https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style

Differential Revision: https://reviews.llvm.org/D150782

show more ...


Revision tags: llvmorg-16.0.4
# ef1b735d 02-May-2023 max <maksim.levental@gmail.com>

[MLIR][python bindings] Add support for DenseElementsAttr of IndexType

Differential Revision: https://reviews.llvm.org/D149690


Revision tags: llvmorg-16.0.3, llvmorg-16.0.2, llvmorg-16.0.1
# f0e847d0 29-Mar-2023 Rahul Kayaith <rkayaith@gmail.com>

[mlir][python] Support buffer protocol for splat dense attributes

These can be made to work by setting the buffer strides to 0.

Reviewed By: stellaraccident

Differential Revision: https://reviews.

[mlir][python] Support buffer protocol for splat dense attributes

These can be made to work by setting the buffer strides to 0.

Reviewed By: stellaraccident

Differential Revision: https://reviews.llvm.org/D147187

show more ...


# 91259963 21-Mar-2023 Adam Paszke <apaszke@google.com>

Support retrieving the splat value from DenseElementsAttrs in Python

This is especially convenient when trying to resize the splat.

Reviewed By: jpienaar

Differential Revision: https://reviews.llv

Support retrieving the splat value from DenseElementsAttrs in Python

This is especially convenient when trying to resize the splat.

Reviewed By: jpienaar

Differential Revision: https://reviews.llvm.org/D146510

show more ...


Revision tags: llvmorg-16.0.0, llvmorg-16.0.0-rc4, llvmorg-16.0.0-rc3, llvmorg-16.0.0-rc2, llvmorg-16.0.0-rc1, llvmorg-17-init, llvmorg-15.0.7, llvmorg-15.0.6, llvmorg-15.0.5, llvmorg-15.0.4, llvmorg-15.0.3, working, llvmorg-15.0.2, llvmorg-15.0.1, llvmorg-15.0.0, llvmorg-15.0.0-rc3, llvmorg-15.0.0-rc2, llvmorg-15.0.0-rc1, llvmorg-16-init, llvmorg-14.0.6, llvmorg-14.0.5, llvmorg-14.0.4, llvmorg-14.0.3, llvmorg-14.0.2, llvmorg-14.0.1, llvmorg-14.0.0, llvmorg-14.0.0-rc4, llvmorg-14.0.0-rc3, llvmorg-14.0.0-rc2, llvmorg-14.0.0-rc1, llvmorg-15-init, llvmorg-13.0.1, llvmorg-13.0.1-rc3, llvmorg-13.0.1-rc2, llvmorg-13.0.1-rc1
# c5f445d1 07-Oct-2021 Stella Laurenzo <stellaraccident@gmail.com>

[mlir][python] Temporarily disable test for converting unsupported DenseElementsAttr types to a buffer.

* Need to investigate the proper solution to https://github.com/pybind/pybind11/issues/3336 or

[mlir][python] Temporarily disable test for converting unsupported DenseElementsAttr types to a buffer.

* Need to investigate the proper solution to https://github.com/pybind/pybind11/issues/3336 or engineer something different.
* The attempt to produce an empty buffer_info as a workaround triggers asan/ubsan.
* Usage of this API does not arise naturally in practice yet, and it is more important to be asan/crash clean than have a solution right now.
* Switching back to raising an exception, even though that triggers terminate().

show more ...


# 5d6d30ed 07-Oct-2021 Stella Laurenzo <stellaraccident@gmail.com>

[mlir] Extend C and Python API to support bulk loading of DenseElementsAttr.

* This already half existed in terms of reading the raw buffer backing a DenseElementsAttr.
* Documented the precise expe

[mlir] Extend C and Python API to support bulk loading of DenseElementsAttr.

* This already half existed in terms of reading the raw buffer backing a DenseElementsAttr.
* Documented the precise expectations of the buffer layout.
* Extended the Python API to support construction from bitcasted buffers, allowing construction of all primitive element types (even those that lack a compatible representation in Python).
* Specifically, the Python API can now load all integer types at all bit widths and all floating point types (f16, f32, f64, bf16).

Differential Revision: https://reviews.llvm.org/D111284

show more ...


Revision tags: llvmorg-13.0.0, llvmorg-13.0.0-rc4, llvmorg-13.0.0-rc3, llvmorg-13.0.0-rc2, llvmorg-13.0.0-rc1, llvmorg-14-init, llvmorg-12.0.1, llvmorg-12.0.1-rc4, llvmorg-12.0.1-rc3, llvmorg-12.0.1-rc2, llvmorg-12.0.1-rc1
# 9f3f6d7b 28-Apr-2021 Stella Laurenzo <stellaraccident@gmail.com>

Move MLIR python sources to mlir/python.

* NFC but has some fixes for CMake glitches discovered along the way (things not cleaning properly, co-mingled depends).
* Includes previously unsubmitted fi

Move MLIR python sources to mlir/python.

* NFC but has some fixes for CMake glitches discovered along the way (things not cleaning properly, co-mingled depends).
* Includes previously unsubmitted fix in D98681 and a TODO to fix it more appropriately in a smaller followup.

Differential Revision: https://reviews.llvm.org/D101493

show more ...