aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Frontend/CompilerInvocationTest.cpp
diff options
context:
space:
mode:
authorKasper Nielsen <kasper0406@gmail.com>2024-11-12 22:23:10 -0800
committerGitHub <noreply@github.com>2024-11-13 01:23:10 -0500
commit1824e45cd799a19fb9b5f9a84f9a0197157af8c8 (patch)
tree1aa5e87b1a6af9fdc31f8cf90c62fbb51f5b9082 /clang/unittests/Frontend/CompilerInvocationTest.cpp
parent804d3c4ce192391ef7ba8724c6b9eff456b5c4b2 (diff)
downloadllvm-1824e45cd799a19fb9b5f9a84f9a0197157af8c8.zip
llvm-1824e45cd799a19fb9b5f9a84f9a0197157af8c8.tar.gz
llvm-1824e45cd799a19fb9b5f9a84f9a0197157af8c8.tar.bz2
[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.
Diffstat (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp')
0 files changed, 0 insertions, 0 deletions