New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inductor cpp wrapper: add GIL release and acquire #111888
Conversation
[ghstack-poisoned]
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/111888
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit c969590 with merge base 69b9e54 (): This comment was automatically generated by Dr. CI and updates every 15 minutes. |
ghstack-source-id: e2ee8aa007141ecc109676e177e2ea6984293103 Pull Request resolved: #111888
Support multiple instances inference (in different threads of the same process) as in #93524. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler [ghstack-poisoned]
ghstack-source-id: 392ca920a7c96eaafd74e323ccd1d8de8ee86929 Pull Request resolved: #111888
torch/_inductor/codegen/wrapper.py
Outdated
@@ -1427,6 +1433,7 @@ def generate_return(self, output_refs): | |||
+ f"new at::Tensor({output}));" | |||
) | |||
else: | |||
self.wrapper_call.writeline("py::gil_scoped_acquire acquire;") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with scoped release at the beginning of the function, you don't need to explicitly acquire the gil here, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the explicit acquire here.
Support multiple instances inference (in different threads of the same process) as in #93524 (comment). cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler [ghstack-poisoned]
ghstack-source-id: f97e9bcc61df81cc280eb3998216fad4d5bcc55e Pull Request resolved: #111888
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it currently possible for cpp wrapper to call into python code?
Support multiple instances inference (in different threads of the same process) as in #93524 (comment). cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler [ghstack-poisoned]
ghstack-source-id: 41f7b186d5988010f3b8ceec7ffa8a7e84e20bad Pull Request resolved: #111888
I'm not aware of a path in cpp wrapper to call into python code? Any concern about it? |
I added a test case to cover the functionality of a multi-threading scenario. |
@pytorchbot rebase |
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
Support multiple instances inference (in different threads of the same process) as in #93524 (comment). cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler [ghstack-poisoned]
Successfully rebased |
ghstack-source-id: ed6c39793b7d9fc578ff7d8ad1442880a49a326a Pull Request resolved: #111888
@pytorchbot merge |
Merge failedReason: This PR needs a If not, please add the To add a label, you can comment to pytorchbot, for example For more information, see Details for Dev Infra teamRaised by workflow job |
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Support multiple instances inference (in different threads of the same process) as in pytorch#93524 (comment). Pull Request resolved: pytorch#111888 Approved by: https://github.com/jgong5, https://github.com/jansel, https://github.com/desertfire
Support multiple instances inference (in different threads of the same process) as in pytorch#93524 (comment). Pull Request resolved: pytorch#111888 Approved by: https://github.com/jgong5, https://github.com/jansel, https://github.com/desertfire
Support multiple instances inference (in different threads of the same process) as in pytorch#93524 (comment). Pull Request resolved: pytorch#111888 Approved by: https://github.com/jgong5, https://github.com/jansel, https://github.com/desertfire
Fixes #123517. This PR adds the GIL release (originally added in #111888) back. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler amjames desertfire chauhang [ghstack-poisoned]
Fixes #123517. This PR adds the GIL release (originally added in #111888) back. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler amjames desertfire chauhang [ghstack-poisoned]
Fixes #123517. This PR adds the GIL release (originally added in #111888) back. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler amjames desertfire chauhang [ghstack-poisoned]
Fixes #123517. This PR adds the GIL release (originally added in #111888) back. cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx peterbell10 ipiszy yf225 chenyang78 kadeng muchulee8 aakhundov ColinPeppler amjames desertfire chauhang [ghstack-poisoned]
Fixes #123517. This PR adds the GIL release (originally added in #111888) back following the suggestion here: #123897 (comment). We added a default constructor and an assignment operator for the `RAIIPyObject` class (#123897 (comment)) in order to declare the `custom_op_wrapper` outside of the GIL acquisition scope. Pull Request resolved: #123897 Approved by: https://github.com/peterbell10, https://github.com/jgong5
Fixes pytorch#123517. This PR adds the GIL release (originally added in pytorch#111888) back following the suggestion here: pytorch#123897 (comment). We added a default constructor and an assignment operator for the `RAIIPyObject` class (pytorch#123897 (comment)) in order to declare the `custom_op_wrapper` outside of the GIL acquisition scope. Pull Request resolved: pytorch#123897 Approved by: https://github.com/peterbell10, https://github.com/jgong5
Fixes pytorch#123517. This PR adds the GIL release (originally added in pytorch#111888) back following the suggestion here: pytorch#123897 (comment). We added a default constructor and an assignment operator for the `RAIIPyObject` class (pytorch#123897 (comment)) in order to declare the `custom_op_wrapper` outside of the GIL acquisition scope. Pull Request resolved: pytorch#123897 Approved by: https://github.com/peterbell10, https://github.com/jgong5
Fixes pytorch#123517. This PR adds the GIL release (originally added in pytorch#111888) back following the suggestion here: pytorch#123897 (comment). We added a default constructor and an assignment operator for the `RAIIPyObject` class (pytorch#123897 (comment)) in order to declare the `custom_op_wrapper` outside of the GIL acquisition scope. Pull Request resolved: pytorch#123897 Approved by: https://github.com/peterbell10, https://github.com/jgong5
Stack from ghstack (oldest at bottom):
Support multiple instances inference (in different threads of the same process) as in #93524 (comment).
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @peterbell10 @ipiszy @yf225 @chenyang78 @kadeng @muchulee8 @aakhundov @ColinPeppler