Add the getCapsule() and createFromCapsule() methods to the
PyValue class, as well as the necessary interoperability.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
This is basically https://reviews.llvm.org/D99927 for Values instead of Operations. I've been testing it downstream in CIRCT. We have use-cases where we'd want a Python API that accepts a Value, or returns a Value, and this seemed to be missing for that.
Another thing we'll want is a nice casting helper, like this: https://github.com/llvm/circt/pull/940/commits/69f527952aa5acb2c73cc3b74e836483b5a5a5d8. It seems we have been adding this support downstream when needed. Does that kind of thing belong in the downstream project, or could I add it in MLIR? I don't see much pybind11 casting functionality in MLIR, so I'm curious if it's because it doesn't belong here or if we just haven't had the chance to move it upstream.
mlir/lib/Bindings/Python/IRModule.h | ||
---|---|---|
728 | Frankly I'm in a little over my head here, is this the correct statement about ownership? | |
mlir/test/Bindings/Python/ir_value.py | ||
25 | Is this correct? It was confusing me last night... value2 is value is False, because value is an instance of OpResult not Value. But value2 == value is True, which I think is what we care about in this case. |
Another thing we'll want is a nice casting helper, like this: https://github.com/llvm/circt/pull/940/commits/69f527952aa5acb2c73cc3b74e836483b5a5a5d8. It seems we have been adding this support downstream when needed. Does that kind of thing belong in the downstream project, or could I add it in MLIR? I don't see much pybind11 casting functionality in MLIR, so I'm curious if it's because it doesn't belong here or if we just haven't had the chance to move it upstream.
I originally stole this from npcomp. I think @stellaraccident said it was a candidate for upstreaming, which makes sense to me.
@mehdi_amini since you approved https://reviews.llvm.org/D101398, do you mind taking a look at this one as well?
mlir/lib/Bindings/Python/IRModule.h | ||
---|---|---|
728 | Yes, the statement PyOperation::forOperation in the implementation is ensuring this. | |
mlir/test/Bindings/Python/ir_value.py | ||
25 | Yes, this is the best we can do here (values are just a wrapper and not uniqued between the portion/c side so eq vs is is all we can do). |
It would be nice to upstream the casting helpers once you all have them in a good state. Ideally, we have an out of tree sample that we use them in to avoid submitting dead code. One step at a time....
Thanks Stella!
It would be nice to upstream the casting helpers once you all have them in a good state. Ideally, we have an out of tree sample that we use them in to avoid submitting dead code. One step at a time....
Sounds good to me.
Frankly I'm in a little over my head here, is this the correct statement about ownership?