Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

chunyuan-w
Copy link
Collaborator

@chunyuan-w chunyuan-w commented Oct 24, 2023

@pytorch-bot
Copy link

pytorch-bot bot commented Oct 24, 2023

🔗 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 Failures

As of commit c969590 with merge base 69b9e54 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

chunyuan-w added a commit that referenced this pull request Oct 24, 2023
ghstack-source-id: e2ee8aa007141ecc109676e177e2ea6984293103
Pull Request resolved: #111888
@chunyuan-w chunyuan-w marked this pull request as draft October 24, 2023 03:09
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]
chunyuan-w added a commit that referenced this pull request Oct 24, 2023
ghstack-source-id: 392ca920a7c96eaafd74e323ccd1d8de8ee86929
Pull Request resolved: #111888
@chunyuan-w chunyuan-w marked this pull request as ready for review October 24, 2023 09:28
@@ -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;")
Copy link
Collaborator

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?

Copy link
Collaborator Author

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]
chunyuan-w added a commit that referenced this pull request Oct 25, 2023
ghstack-source-id: f97e9bcc61df81cc280eb3998216fad4d5bcc55e
Pull Request resolved: #111888
Copy link
Contributor

@desertfire desertfire left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test case?

Copy link
Contributor

@jansel jansel left a 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]
chunyuan-w added a commit that referenced this pull request Oct 30, 2023
ghstack-source-id: 41f7b186d5988010f3b8ceec7ffa8a7e84e20bad
Pull Request resolved: #111888
@jgong5
Copy link
Collaborator

jgong5 commented Oct 30, 2023

Is it currently possible for cpp wrapper to call into python code?

I'm not aware of a path in cpp wrapper to call into python code? Any concern about it?

@chunyuan-w
Copy link
Collaborator Author

Test case?

I added a test case to cover the functionality of a multi-threading scenario.

@chunyuan-w
Copy link
Collaborator Author

@pytorchbot rebase

@chunyuan-w chunyuan-w added the ciflow/trunk Trigger trunk jobs on your pull request label Oct 30, 2023
@pytorchmergebot
Copy link
Collaborator

@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]
@pytorchmergebot
Copy link
Collaborator

Successfully rebased gh/chunyuan-w/1/orig onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via ghstack checkout https://github.com/pytorch/pytorch/pull/111888)

pytorchmergebot pushed a commit that referenced this pull request Oct 30, 2023
ghstack-source-id: ed6c39793b7d9fc578ff7d8ad1442880a49a326a
Pull Request resolved: #111888
@chunyuan-w
Copy link
Collaborator Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge failed

Reason: This PR needs a release notes: label
If your changes are user facing and intended to be a part of release notes, please use a label starting with release notes:.

If not, please add the topic: not user facing label.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "topic: not user facing"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

Details for Dev Infra team Raised by workflow job

@chunyuan-w
Copy link
Collaborator Author

@pytorchbot merge

@pytorchmergebot
Copy link
Collaborator

Merge started

Your 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

Advanced Debugging
Check the merge workflow status
here

@facebook-github-bot facebook-github-bot deleted the gh/chunyuan-w/1/head branch November 3, 2023 14:26
xuhancn pushed a commit to xuhancn/pytorch that referenced this pull request Nov 7, 2023
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
Skylion007 pushed a commit to Skylion007/pytorch that referenced this pull request Nov 14, 2023
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
andreigh pushed a commit to andreigh/pytorch that referenced this pull request Nov 19, 2023
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
chunyuan-w added a commit that referenced this pull request Apr 16, 2024
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]
chunyuan-w added a commit that referenced this pull request Apr 16, 2024
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]
chunyuan-w added a commit that referenced this pull request Apr 16, 2024
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]
chunyuan-w added a commit that referenced this pull request Apr 16, 2024
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]
pytorchmergebot pushed a commit that referenced this pull request Apr 17, 2024
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
trieuat pushed a commit to trieuat/pytorch that referenced this pull request Apr 21, 2024
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
sanketpurandare pushed a commit to sanketpurandare/pytorch that referenced this pull request Apr 22, 2024
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
petrex pushed a commit to petrex/pytorch that referenced this pull request May 3, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants