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

[MPS] Introduce torch.mps.Event() APIs #102121

Closed
wants to merge 2 commits into from

Conversation

razarmehr
Copy link
Collaborator

  • Implement MPSEventPool to recycle events.
  • Implement python bindings with torch.mps.Event class using the MPSEventPool backend. The current member functions of the Event class are record(), wait(), synchronize(), query(), and elapsed_time().
  • Add API to measure elapsed time between two event recordings.
  • Added documentation for Event class to mps.rst.
  • Added test case to test_mps.py.

@razarmehr razarmehr added ciflow/trunk Trigger trunk jobs on your pull request ciflow/mps Run MPS tests (subset of trunk) labels May 23, 2023
@pytorch-bot
Copy link

pytorch-bot bot commented May 23, 2023

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/102121

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 49fb3f6:
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot bot added the release notes: mps Release notes category label May 23, 2023
@razarmehr razarmehr force-pushed the MPS_EventAPIs branch 2 times, most recently from 944f2df to a870c7e Compare May 24, 2023 16:01
@razarmehr
Copy link
Collaborator Author

@albanD and @malfet , the CIs are green. Can you please review this PR? Thanks.

@soulitzer soulitzer added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label May 25, 2023
Copy link
Collaborator

@albanD albanD left a comment

Choose a reason for hiding this comment

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

Sorry for the delay in reviewing this.
The change sounds ok (I didn't check the mm implementation in detail as I assume this has already been reviewed in details).

I would say that the id-based binding is not the nicest though for two reasons: you have to __del__ which have some caveats, the lifetime of the different objects are not hard-linked opening to bugs in having one dying earlier than the other and the binding code is not very easy to read.
If you plan on upgrading this, I would suggest to using pybind to directly bind the class via pybind like

py::class_<BenchmarkConfig>(m, "BenchmarkConfig")
this will allow you to remove the need for the ID system and the del (as the python object can hold a strong reference to the c++ one via a shared ptr for example).

torch/mps/event.py Show resolved Hide resolved
test/test_mps.py Outdated Show resolved Hide resolved
- Implement MPSEventPool to recycle events and hook it into MPSAllocator
- Implement python bindings with torch.mps.Event class using the MPSEventPool backend.
The current member functions of the Event class are, record(), wait(), synchronize() and query()
- Add API to measure elapsed time between two event recordings
- Added test case to test_mps.py
- Replace PyLong_From with THPUtils_packUInt() to avoid overflow errors
@razarmehr
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

Cyril-Anto pushed a commit to Cyril-Anto/pytorch that referenced this pull request Aug 17, 2023
- Implement `MPSEventPool` to recycle events.
- Implement python bindings with `torch.mps.Event` class using the MPSEventPool backend. The current member functions of the Event class are `record()`, `wait()`, `synchronize()`, `query()`, and `elapsed_time()`.
- Add API to measure elapsed time between two event recordings.
- Added documentation for Event class to `mps.rst`.
- Added test case to `test_mps.py`.

Pull Request resolved: pytorch#102121
Approved by: https://github.com/albanD, https://github.com/kulinseth
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ciflow/mps Run MPS tests (subset of trunk) ciflow/trunk Trigger trunk jobs on your pull request Merged open source release notes: mps Release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants