[Mlir-commits] [mlir] [mlir] Add Python bindings for DenseResourceElementsAttr. (PR #66319)
Stella Laurenzo
llvmlistbot at llvm.org
Wed Sep 13 23:29:29 PDT 2023
================
@@ -997,6 +1022,56 @@ class PyDenseIntElementsAttribute
}
};
+class PyDenseResourceElementsAttribute
+ : public PyConcreteAttribute<PyDenseResourceElementsAttribute> {
+public:
+ static constexpr IsAFunctionTy isaFunction =
+ mlirAttributeIsADenseResourceElements;
+ static constexpr const char *pyClassName = "DenseResourceElementsAttr";
+ using PyConcreteAttribute::PyConcreteAttribute;
+
+ static PyDenseResourceElementsAttribute
+ getFromBuffer(py::buffer buffer, std::string name, PyType type,
+ DefaultingPyMlirContext contextWrapper) {
+ // Do not request any conversions as we must ensure to use caller
+ // managed memory.
+ int flags = 0;
+ Py_buffer view;
+ if (PyObject_GetBuffer(buffer.ptr(), &view, flags) != 0) {
+ throw py::error_already_set();
+ }
+ auto freeBuffer = llvm::make_scope_exit([&]() { PyBuffer_Release(&view); });
----------------
stellaraccident wrote:
I figured out how to test the memory freeing from Python.
https://github.com/llvm/llvm-project/pull/66319
More information about the Mlir-commits
mailing list