Acquire GIL when constructing/destructing ConcretePyObjectHolder#37870
Acquire GIL when constructing/destructing ConcretePyObjectHolder#37870mrshenli wants to merge 7 commits intogh/mrshenli/167/basefrom
Conversation
[ghstack-poisoned]
Differential Revision: [D21410785](https://our.internmc.facebook.com/intern/diff/D21410785) [ghstack-poisoned]
|
Hey @wanchaol, does the change look reasonable to you? |
| static c10::intrusive_ptr<PyObjectHolder> create(py::object py_obj) { | ||
| return c10::make_intrusive<ConcretePyObjectHolder>(py_obj); | ||
| return c10::make_intrusive<ConcretePyObjectHolder>(std::move(py_obj)); | ||
| } |
There was a problem hiding this comment.
Before this change, I think when creating a PyObjectHolder, the passed py obj ref count +2 and then -1. This change makes it only +1 one time.
| @@ -11,17 +11,21 @@ namespace ivalue { | |||
| struct C10_EXPORT ConcretePyObjectHolder final : PyObjectHolder { | |||
| public: | |||
| static c10::intrusive_ptr<PyObjectHolder> create(py::object py_obj) { | |||
There was a problem hiding this comment.
Since you are making this data wrapper take care of acquiring GIL on destruction.
I wonder can it also acquires GIL on creation?
So that you don't have to do it in upper level, as in #37871.
case TypeKind::PyObjectType:
// convert a py::handle to the IValue that holds the py::object
py::object py_obj;
{
py::gil_scoped_acquire ag;
py_obj = obj.cast<py::object>();
}}
return c10::ivalue::ConcretePyObjectHolder::create(
std::move(py_obj));There was a problem hiding this comment.
good point! I will make the change if this looks good to @wanchaol too.
Differential Revision: [D21410785](https://our.internmc.facebook.com/intern/diff/D21410785) [ghstack-poisoned]
…Holder" Differential Revision: [D21410785](https://our.internmc.facebook.com/intern/diff/D21410785) [ghstack-poisoned]
…Holder" Differential Revision: [D21410785](https://our.internmc.facebook.com/intern/diff/D21410785) [ghstack-poisoned]
💊 CI failures summary and remediationsAs of commit dc28784 (more details on the Dr. CI page): ✅ None of the CI failures appear to be your fault 💚
🚧 1 ongoing upstream failure:These were probably caused by upstream breakages that are not fixed yet:
This comment was automatically generated by Dr. CI (expand for details).Follow this link to opt-out of these comments for your Pull Requests.Please report bugs/suggestions on the GitHub issue tracker. This comment has been revised 9 times. |
wanchaol
left a comment
There was a problem hiding this comment.
Some nits, generally looks good to me, thanks!
| public: | ||
| static c10::intrusive_ptr<PyObjectHolder> create(py::object py_obj) { | ||
| return c10::make_intrusive<ConcretePyObjectHolder>(py_obj); | ||
| return c10::make_intrusive<ConcretePyObjectHolder>(std::move(py_obj)); |
There was a problem hiding this comment.
can we move the gil acquisition to the constructor as well (i.e. move the logic from toIValue to here)?
There was a problem hiding this comment.
I guess it's to change the constructor takes py::handle, and cast it to py::object with GIL
There was a problem hiding this comment.
Actually, I would prefer adding a new constructor that takes a py::handle, and move the logic to there. We should still keep the constructor that takes py::object without acquire gil for C++ usage.
…Holder" Differential Revision: [D21410785](https://our.internmc.facebook.com/intern/diff/D21410785) [ghstack-poisoned]
…Holder" Differential Revision: [D21410785](https://our.internmc.facebook.com/intern/diff/D21410785) [ghstack-poisoned]
|
This pull request has been merged in ee1ddce. |
ghstack-source-id: 0ab6f42 Pull Request resolved: pytorch/pytorch#37870
…orch#37870) Summary: Pull Request resolved: pytorch#37870 Test Plan: Imported from OSS Differential Revision: D21410785 fbshipit-source-id: 374d5f40fbdfec98262aa4c84ec4ccdc40fb2ac1
Stack from ghstack:
Differential Revision: D21410785