This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] [Python] Add capsule methods for pybind11 to PyOperation
ClosedPublic

Authored by jdd on Apr 5 2021, 11:07 PM.

Details

Summary

Add the getCapsule() and createFromCapsule() methods to the PyOperation class.

Diff Detail

Event Timeline

jdd created this revision.Apr 5 2021, 11:07 PM
jdd published this revision for review.Apr 5 2021, 11:14 PM

@stellaraccident I really don't understand what I've done here, but it works... not that that means much when it comes to memory management. Am I doing it correctly or is there something I'm missing about Operation ownership semantics and interactions with PyObjectRef?

stellaraccident accepted this revision.Apr 6 2021, 12:17 AM

Thanks! You may not have known why, but this is the right way to do it. The unit test has a leak test which verifies that everything gets freed. The factory functions you are using maintain 1:1 correspondence between context and operation objects and the backing capi instances. Let me know if you run in to further issues: ownership of operations is complicated and this stuff doesn't have a lot of mileage on it.

This revision is now accepted and ready to land.Apr 6 2021, 12:17 AM
jdd added a comment.Apr 6 2021, 2:23 PM

Thanks! I think my success is more a testament to the ownership management infra already there. Landing this now.